Date   

[PATCH] BaseTools/VolInfo: Show FV section boundaries

Konstantin Aladyshev
 

Currently there is no labels for start and end of the
EFI_SECTION_FIRMWARE_VOLUME_IMAGE type section. Therefore it is not
possible to see where the FV section ends and another section starts.
Add labels for start and end of the FV sections to fix the issue.

Signed-off-by: Konstantin Aladyshev <aladyshev22@...>
---
BaseTools/Source/C/VolInfo/VolInfo.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/BaseTools/Source/C/VolInfo/VolInfo.c b/BaseTools/Source/C/VolI=
nfo/VolInfo.c
index 47a8f80f46..a78a7e7976 100644
--- a/BaseTools/Source/C/VolInfo/VolInfo.c
+++ b/BaseTools/Source/C/VolInfo/VolInfo.c
@@ -1796,11 +1796,13 @@ Returns:
break;=0D
=0D
case EFI_SECTION_FIRMWARE_VOLUME_IMAGE:=0D
+ printf ("/------------ Firmware Volume section start ---------------=
\\\n");=0D
Status =3D PrintFvInfo (Ptr + SectionHeaderLen, TRUE);=0D
if (EFI_ERROR (Status)) {=0D
Error (NULL, 0, 0003, "printing of FV section contents failed", NU=
LL);=0D
return EFI_SECTION_ERROR;=0D
}=0D
+ printf ("\\------------ Firmware Volume section end ----------------=
-/\n");=0D
break;=0D
=0D
case EFI_SECTION_COMPATIBILITY16:=0D
--=20
2.25.1


Re: [PATCH v3 3/3] DynamicTablesPkg: AcpiSsdtPcieLibArm: Create support library

Sami Mujawar
 

Hi Jeff,

Thank you for this patch.

I have some minor updates like removing ssdtpcieosctemplate_aml_code[] from SsdtPcieGenerator.h as it has been moved to SsdtPcieSupportLibPrivate.h, and adding SsdtPcieSupportLib to DynamicTables.dsc.inc so that the Package Dsc build succeeds.
Otherwise, these changes look good to me.

I will make the changes locally before pushing.

Reviewed-by: Sami Mujawar <sami.mujawar@...>

Regards,

Sami Mujawar


Re: [PATCH v3 2/3] DynamicTablesPkg: AcpiSsdtPcieLibArm: Support UID > 0xF

Sami Mujawar
 

Hi Jeff,

Thank you for this patch. These changes look good to me.

Reviewed-by: Sami Mujawar <sami.mujawar@...>

Regards,

Sami Mujawar


Re: [PATCH v3 1/3] DynamicTablesPkg: AcpiSsdtPcieLibArm: Correct translation value

Sami Mujawar
 

Hi Jeff,

Thank you for this fix.
This patch looks good to me.

Reviewed-by: Sami Mujawar <sami.mujawar@...>

Regards,

Sami Mujawar


Re: [PATCH] MdeModulePkg/UefiBootManagerLib: Add Disk Info support for Ufs

Jeff Brasen
 

Yes, Universal Flash Storage is based on the SCSI architectural model and installs gEfiExtScsiPassThruProtocolGuid to function.

Thanks,
Jeff

-----Original Message-----
From: gaoliming <gaoliming@...>
Sent: Monday, July 18, 2022 7:44 PM
To: devel@edk2.groups.io; Jeff Brasen <jbrasen@...>
Cc: jian.j.wang@...; zhichao.gao@...; ray.ni@...
Subject: 回复: [edk2-devel] [PATCH] MdeModulePkg/UefiBootManagerLib:
Add Disk Info support for Ufs

External email: Use caution opening links or attachments


Jeff:
I want to confirm why UFS apply the same rule to SCSI. Does UFS follows
SCSI spec?

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Jeff Brasen
via
groups.io
发送时间: 2022年6月15日 1:54
收件人: devel@edk2.groups.io
抄送: jian.j.wang@...; gaoliming@...;
zhichao.gao@...; ray.ni@...; Jeff Brasen
<jbrasen@...>
主题: [edk2-devel] [PATCH] MdeModulePkg/UefiBootManagerLib: Add
Disk
Info support for Ufs

Add support for getting disk info from UFS devices.

Signed-off-by: Jeff Brasen <jbrasen@...>
---
MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c | 3
++-
MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf | 1
+
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git
a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c
b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c
index fac33b9ee9..87b82f299f 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c
@@ -195,7 +195,8 @@ BmGetDescriptionFromDiskInfo (


BmEliminateExtraSpaces (Description);

}

- } else if (CompareGuid (&DiskInfo->Interface,
&gEfiDiskInfoScsiInterfaceGuid)) {

+ } else if (CompareGuid (&DiskInfo->Interface,
&gEfiDiskInfoScsiInterfaceGuid) ||

+ CompareGuid (&DiskInfo->Interface,
&gEfiDiskInfoUfsInterfaceGuid)) {

BufferSize = sizeof (EFI_SCSI_INQUIRY_DATA);

Status = DiskInfo->Inquiry (

DiskInfo,

diff --git
a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
index fe05d5f1cc..2fc0a80a4e 100644
---
a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
+++
b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
@@ -85,6 +85,7 @@
gEfiDiskInfoIdeInterfaceGuid ##
SOMETIMES_CONSUMES ## GUID

gEfiDiskInfoScsiInterfaceGuid ##
SOMETIMES_CONSUMES ## GUID

gEfiDiskInfoSdMmcInterfaceGuid ##
SOMETIMES_CONSUMES ## GUID

+ gEfiDiskInfoUfsInterfaceGuid ##
SOMETIMES_CONSUMES ## GUID



[Protocols]

gEfiPciRootBridgeIoProtocolGuid ## CONSUMES

--
2.25.1






[PATCH 1/1] OvmfPkg/QemuBootOrderLib: add StoreQemuBootOrder()

Gerd Hoffmann
 

The function reads the boot order from qemu fw_cfg, translates it into
device paths and stores them in 'QemuBootOrderNNNN' variables. In case
there is no boot ordering configured the function will do nothing.

Use case: Allow applications loaded via 'qemu -kernel bootloader.efi'
obey the boot order.

Signed-off-by: Gerd Hoffmann <kraxel@...>
---
OvmfPkg/OvmfPkg.dec | 1 +
.../QemuBootOrderLib/QemuBootOrderLib.inf | 1 +
OvmfPkg/Include/Library/QemuBootOrderLib.h | 14 ++
.../PlatformBootManagerLib/BdsPlatform.c | 5 +
.../QemuBootOrderLib/QemuBootOrderLib.c | 122 ++++++++++++++++++
5 files changed, 143 insertions(+)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 5af76a540529..6b1296b15afa 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -146,6 +146,7 @@ [Guids]
gConfidentialComputingSecretGuid = {0xadf956ad, 0xe98c, 0x484c, {0xae, 0x11, 0xb5, 0x1c, 0x7d, 0x33, 0x64, 0x47}}
gConfidentialComputingSevSnpBlobGuid = {0x067b1f5f, 0xcf26, 0x44c5, {0x85, 0x54, 0x93, 0xd7, 0x77, 0x91, 0x2d, 0x42}}
gUefiOvmfPkgPlatformInfoGuid = {0xdec9b486, 0x1f16, 0x47c7, {0x8f, 0x68, 0xdf, 0x1a, 0x41, 0x88, 0x8b, 0xa5}}
+ gQemuBootOrderGuid = {0x668f4529, 0x63d0, 0x4bb5, {0xb6, 0x5d, 0x6f, 0xbb, 0x9d, 0x36, 0xa4, 0x4a}}

[Ppis]
# PPI whose presence in the PPI database signals that the TPM base address
diff --git a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf
index 7c02f04e7009..211344fb0b89 100644
--- a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf
+++ b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf
@@ -49,6 +49,7 @@ [LibraryClasses]
[Guids]
gEfiGlobalVariableGuid
gVirtioMmioTransportGuid
+ gQemuBootOrderGuid

[FeaturePcd]
gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation
diff --git a/OvmfPkg/Include/Library/QemuBootOrderLib.h b/OvmfPkg/Include/Library/QemuBootOrderLib.h
index 9f06439aed1e..f0369298a134 100644
--- a/OvmfPkg/Include/Library/QemuBootOrderLib.h
+++ b/OvmfPkg/Include/Library/QemuBootOrderLib.h
@@ -47,6 +47,20 @@ ConnectDevicesFromQemu (
VOID
);

+/**
+ Write qemu boot order to uefi variables.
+
+ Attempt to retrieve the "bootorder" fw_cfg file from QEMU. Translate
+ the OpenFirmware device paths therein to UEFI device path fragments.
+
+ On Success store the device path in QemuBootOrderNNNN variables.
+**/
+VOID
+EFIAPI
+StoreQemuBootOrder (
+ VOID
+ );
+
/**

Set the boot order based on configuration retrieved from QEMU.
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
index 51016a5548cb..98f6f07341ec 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -1694,6 +1694,11 @@ PlatformBootManagerAfterConsole (
//
PciAcpiInitialization ();

+ //
+ // Write qemu bootorder to efi variables
+ //
+ StoreQemuBootOrder ();
+
//
// Process QEMU's -kernel command line option
//
diff --git a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c
index 67d29ac6429f..398de7fab4ba 100644
--- a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c
+++ b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c
@@ -1686,6 +1686,128 @@ ConnectDevicesFromQemu (
return Status;
}

+/**
+ Write qemu boot order to uefi variables.
+
+ Attempt to retrieve the "bootorder" fw_cfg file from QEMU. Translate
+ the OpenFirmware device paths therein to UEFI device path fragments.
+
+ On Success store the device path in QemuBootOrderNNNN variables.
+**/
+VOID
+EFIAPI
+StoreQemuBootOrder (
+ VOID
+ )
+{
+ RETURN_STATUS Status;
+ FIRMWARE_CONFIG_ITEM FwCfgItem;
+ UINTN FwCfgSize;
+ CHAR8 *FwCfg;
+ EFI_STATUS EfiStatus;
+ EXTRA_ROOT_BUS_MAP *ExtraPciRoots;
+ CONST CHAR8 *FwCfgPtr;
+ UINTN TranslatedSize;
+ CHAR16 Translated[TRANSLATION_OUTPUT_SIZE];
+ UINTN VariableIndex = 0;
+ CHAR16 VariableName[20];
+
+ Status = QemuFwCfgFindFile ("bootorder", &FwCfgItem, &FwCfgSize);
+ if (RETURN_ERROR (Status)) {
+ return;
+ }
+
+ if (FwCfgSize == 0) {
+ return;
+ }
+
+ FwCfg = AllocatePool (FwCfgSize);
+ if (FwCfg == NULL) {
+ return;
+ }
+
+ QemuFwCfgSelectItem (FwCfgItem);
+ QemuFwCfgReadBytes (FwCfgSize, FwCfg);
+ if (FwCfg[FwCfgSize - 1] != '\0') {
+ Status = RETURN_INVALID_PARAMETER;
+ goto FreeFwCfg;
+ }
+
+ DEBUG ((DEBUG_VERBOSE, "%a: FwCfg:\n", __FUNCTION__));
+ DEBUG ((DEBUG_VERBOSE, "%a\n", FwCfg));
+ DEBUG ((DEBUG_VERBOSE, "%a: FwCfg: <end>\n", __FUNCTION__));
+
+ if (FeaturePcdGet (PcdQemuBootOrderPciTranslation)) {
+ EfiStatus = CreateExtraRootBusMap (&ExtraPciRoots);
+ if (EFI_ERROR (EfiStatus)) {
+ Status = (RETURN_STATUS)EfiStatus;
+ goto FreeFwCfg;
+ }
+ } else {
+ ExtraPciRoots = NULL;
+ }
+
+ //
+ // Translate each OpenFirmware path to a UEFI devpath prefix.
+ //
+ FwCfgPtr = FwCfg;
+ TranslatedSize = ARRAY_SIZE (Translated);
+ Status = TranslateOfwPath (
+ &FwCfgPtr,
+ ExtraPciRoots,
+ Translated,
+ &TranslatedSize
+ );
+ while (!RETURN_ERROR (Status)) {
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+
+ //
+ // Convert the UEFI devpath prefix to binary representation.
+ //
+ ASSERT (Translated[TranslatedSize] == L'\0');
+ DevicePath = ConvertTextToDevicePath (Translated);
+ if (DevicePath == NULL) {
+ Status = RETURN_OUT_OF_RESOURCES;
+ goto FreeExtraPciRoots;
+ }
+
+ UnicodeSPrint (
+ VariableName,
+ sizeof (VariableName),
+ L"QemuBootOrder%04d",
+ VariableIndex++
+ );
+ DEBUG ((DEBUG_INFO, "%a: %s = %s\n", __FUNCTION__, VariableName, Translated));
+ gRT->SetVariable (
+ VariableName,
+ &gQemuBootOrderGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ GetDevicePathSize (DevicePath),
+ DevicePath
+ );
+ FreePool (DevicePath);
+
+ //
+ // Move to the next OFW devpath.
+ //
+ TranslatedSize = ARRAY_SIZE (Translated);
+ Status = TranslateOfwPath (
+ &FwCfgPtr,
+ ExtraPciRoots,
+ Translated,
+ &TranslatedSize
+ );
+ }
+
+FreeExtraPciRoots:
+ if (ExtraPciRoots != NULL) {
+ DestroyExtraRootBusMap (ExtraPciRoots);
+ }
+
+FreeFwCfg:
+ FreePool (FwCfg);
+}
+
/**

Convert the UEFI DevicePath to full text representation with DevPathToText,
--
2.36.1


[PATCH] BaseTools/GenSec: Fix typo

Konstantin Aladyshev
 

Fix typo in the help message.

Signed-off-by: Konstantin Aladyshev <aladyshev22@...>
---
BaseTools/Source/C/GenSec/GenSec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec=
/GenSec.c
index b1d05367ec..35a1ac64ea 100644
--- a/BaseTools/Source/C/GenSec/GenSec.c
+++ b/BaseTools/Source/C/GenSec/GenSec.c
@@ -191,7 +191,7 @@ Returns:
as 0, tool get alignment value from SectionFile. I=
t is\n\=0D
specified in same order that the section file is i=
nput.\n");=0D
fprintf (stdout, " --dummy dummyfile\n\=0D
- compare dummpyfile with input_file to decide wheth=
er\n\=0D
+ compare dummyfile with input_file to decide whethe=
r\n\=0D
need to set PROCESSING_REQUIRED attribute.\n");=0D
fprintf (stdout, " -v, --verbose Turn on verbose output with in=
formational messages.\n");=0D
fprintf (stdout, " -q, --quiet Disable all messages except ke=
y message and fatal error\n");=0D
--=20
2.25.1


[PATCH v4 1/1] NetworkPkg/HttpBootDxe: Add Support for HTTP Boot Basic Authentication

Saloni Kasbekar
 

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

Add support for TLS Client Authentication using Basic Authentication
for HTTP Boot

Cc: Maciej Rabeda <maciej.rabeda@...>
Cc: Wu Jiaxin <jiaxin.wu@...>
Cc: Siyuan Fu <siyuan.fu@...>
Signed-off-by: Saloni Kasbekar <saloni.kasbekar@...>
---
MdePkg/Include/IndustryStandard/Http11.h | 8 ++
MdePkg/Include/Protocol/HttpBootCallback.h | 6 +-
NetworkPkg/HttpBootDxe/HttpBootClient.c | 99 +++++++++++++++++++++-
NetworkPkg/HttpBootDxe/HttpBootClient.h | 6 +-
NetworkPkg/HttpBootDxe/HttpBootDxe.h | 6 ++
NetworkPkg/HttpBootDxe/HttpBootImpl.c | 23 ++++-
6 files changed, 143 insertions(+), 5 deletions(-)

diff --git a/MdePkg/Include/IndustryStandard/Http11.h b/MdePkg/Include/IndustryStandard/Http11.h
index f1f113e04b69..2137ef1f1ac3 100644
--- a/MdePkg/Include/IndustryStandard/Http11.h
+++ b/MdePkg/Include/IndustryStandard/Http11.h
@@ -204,6 +204,14 @@
///
#define HTTP_HEADER_IF_NONE_MATCH "If-None-Match"

+///
+/// The WWW-Authenticate Response Header
+/// If a server receives a request for an access-protected object, and an
+/// acceptable Authorization header is not sent, the server responds with
+/// a "401 Unauthorized" status code, and a WWW-Authenticate header.
+///
+#define HTTP_HEADER_WWW_AUTHENTICATE "WWW-Authenticate"
+
///
/// Authorization Request Header
/// The Authorization field value consists of credentials
diff --git a/MdePkg/Include/Protocol/HttpBootCallback.h b/MdePkg/Include/Protocol/HttpBootCallback.h
index 926f6c1b3076..b56c631b1f4f 100644
--- a/MdePkg/Include/Protocol/HttpBootCallback.h
+++ b/MdePkg/Include/Protocol/HttpBootCallback.h
@@ -32,7 +32,7 @@ typedef enum {
///
HttpBootDhcp6,
///
- /// Data points to an EFI_HTTP_MESSAGE structure, whichcontians a HTTP request message
+ /// Data points to an EFI_HTTP_MESSAGE structure, which contains a HTTP request message
/// to be transmitted.
///
HttpBootHttpRequest,
@@ -46,6 +46,10 @@ typedef enum {
/// buffer of the entity body data.
///
HttpBootHttpEntityBody,
+ ///
+ /// Data points to the authentication information to provide to the HTTP server.
+ ///
+ HttpBootHttpAuthInfo,
HttpBootTypeMax
} EFI_HTTP_BOOT_CALLBACK_DATA_TYPE;

diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c b/NetworkPkg/HttpBootDxe/HttpBootClient.c
index 62e87238fef7..40f64fcb6bf8 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootClient.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c
@@ -922,6 +922,7 @@ HttpBootGetBootFileCallback (
@retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry.
BufferSize has been updated with the size needed to complete
the request.
+ @retval EFI_ACCESS_DENIED The server needs to authenticate the client.
@retval Others Unexpected error happened.

**/
@@ -951,6 +952,9 @@ HttpBootGetBootFile (
CHAR16 *Url;
BOOLEAN IdentityMode;
UINTN ReceivedSize;
+ CHAR8 BaseAuthValue[80];
+ EFI_HTTP_HEADER *HttpHeader;
+ CHAR8 *Data;

ASSERT (Private != NULL);
ASSERT (Private->HttpCreated);
@@ -1009,8 +1013,9 @@ HttpBootGetBootFile (
// Host
// Accept
// User-Agent
+ // [Authorization]
//
- HttpIoHeader = HttpIoCreateHeader (3);
+ HttpIoHeader = HttpIoCreateHeader ((Private->AuthData != NULL) ? 4 : 3);
if (HttpIoHeader == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ERROR_2;
@@ -1063,6 +1068,35 @@ HttpBootGetBootFile (
goto ERROR_3;
}

+ //
+ // Add HTTP header field 4: Authorization
+ //
+ if (Private->AuthData != NULL) {
+ ASSERT (HttpIoHeader->MaxHeaderCount == 4);
+
+ if ((Private->AuthScheme != NULL) && (CompareMem (Private->AuthScheme, "Basic", 5) != 0)) {
+ Status = EFI_UNSUPPORTED;
+ goto ERROR_3;
+ }
+
+ AsciiSPrint (
+ BaseAuthValue,
+ sizeof (BaseAuthValue),
+ "%a %a",
+ "Basic",
+ Private->AuthData
+ );
+
+ Status = HttpIoSetHeader (
+ HttpIoHeader,
+ HTTP_HEADER_AUTHORIZATION,
+ BaseAuthValue
+ );
+ if (EFI_ERROR (Status)) {
+ goto ERROR_3;
+ }
+ }
+
//
// 2.2 Build the rest of HTTP request info.
//
@@ -1111,6 +1145,7 @@ HttpBootGetBootFile (
goto ERROR_4;
}

+ Data = NULL;
Status = HttpIoRecvResponse (
&Private->HttpIo,
TRUE,
@@ -1121,6 +1156,68 @@ HttpBootGetBootFile (
StatusCode = HttpIo->RspToken.Message->Data.Response->StatusCode;
HttpBootPrintErrorMessage (StatusCode);
Status = ResponseData->Status;
+ if ((StatusCode == HTTP_STATUS_401_UNAUTHORIZED) || \
+ (StatusCode == HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED))
+ {
+ if ((Private->AuthData != NULL) || (Private->AuthScheme != NULL)) {
+ if (Private->AuthData != NULL) {
+ FreePool (Private->AuthData);
+ Private->AuthData = NULL;
+ }
+
+ if (Private->AuthScheme != NULL) {
+ FreePool (Private->AuthScheme);
+ Private->AuthScheme = NULL;
+ }
+
+ Status = EFI_ACCESS_DENIED;
+ goto ERROR_4;
+ }
+
+ //
+ // Server indicates the user has to provide a user-id and password as a means of identification.
+ //
+ if (Private->HttpBootCallback != NULL) {
+ Data = AllocateZeroPool (sizeof (CHAR8) * HTTP_BOOT_AUTHENTICATION_INFO_MAX_LEN);
+ if (Data == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto ERROR_4;
+ }
+
+ Status = Private->HttpBootCallback->Callback (
+ Private->HttpBootCallback,
+ HttpBootHttpAuthInfo,
+ TRUE,
+ HTTP_BOOT_AUTHENTICATION_INFO_MAX_LEN,
+ Data
+ );
+ if (EFI_ERROR (Status)) {
+ if (Data != NULL) {
+ FreePool (Data);
+ }
+
+ goto ERROR_5;
+ }
+
+ Private->AuthData = (CHAR8 *)Data;
+ }
+
+ HttpHeader = HttpFindHeader (
+ ResponseData->HeaderCount,
+ ResponseData->Headers,
+ HTTP_HEADER_WWW_AUTHENTICATE
+ );
+ if (HttpHeader != NULL) {
+ Private->AuthScheme = AllocateZeroPool (AsciiStrLen (HttpHeader->FieldValue) + 1);
+ if (Private->AuthScheme == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ CopyMem (Private->AuthScheme, HttpHeader->FieldValue, AsciiStrLen (HttpHeader->FieldValue));
+ }
+
+ Status = EFI_ACCESS_DENIED;
+ }
}

goto ERROR_5;
diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.h b/NetworkPkg/HttpBootDxe/HttpBootClient.h
index 406529dfd927..2fba71367950 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootClient.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootClient.h
@@ -10,8 +10,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef __EFI_HTTP_BOOT_HTTP_H__
#define __EFI_HTTP_BOOT_HTTP_H__

-#define HTTP_BOOT_BLOCK_SIZE 1500
-#define HTTP_USER_AGENT_EFI_HTTP_BOOT "UefiHttpBoot/1.0"
+#define HTTP_BOOT_BLOCK_SIZE 1500
+#define HTTP_USER_AGENT_EFI_HTTP_BOOT "UefiHttpBoot/1.0"
+#define HTTP_BOOT_AUTHENTICATION_INFO_MAX_LEN 255

//
// Record the data length and start address of a data block.
@@ -106,6 +107,7 @@ HttpBootCreateHttpIo (
@retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry.
BufferSize has been updated with the size needed to complete
the request.
+ @retval EFI_ACCESS_DENIED The server needs to authenticate the client.
@retval Others Unexpected error happened.

**/
diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
index 5acbae9bfa76..5ff8ad4698b2 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootDxe.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
@@ -183,6 +183,12 @@ struct _HTTP_BOOT_PRIVATE_DATA {
UINT64 ReceivedSize;
UINT32 Percentage;

+ //
+ // Data for the server to authenticate the client
+ //
+ CHAR8 *AuthData;
+ CHAR8 *AuthScheme;
+
//
// HII callback info block
//
diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
index 3da585a29164..b4c61925b94f 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
@@ -360,7 +360,18 @@ HttpBootLoadFile (
NULL,
&Private->ImageType
);
- if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
+ if ((Private->AuthData != NULL) && (Status == EFI_ACCESS_DENIED)) {
+ //
+ // Try to use HTTP HEAD method again since the Authentication information is provided.
+ //
+ Status = HttpBootGetBootFile (
+ Private,
+ TRUE,
+ &Private->BootFileSize,
+ NULL,
+ &Private->ImageType
+ );
+ } else if ((EFI_ERROR (Status)) && (Status != EFI_BUFFER_TOO_SMALL)) {
//
// Failed to get file size by HEAD method, may be trunked encoding, try HTTP GET method.
//
@@ -489,6 +500,16 @@ HttpBootStop (
}
}

+ if (Private->AuthData != NULL) {
+ FreePool (Private->AuthData);
+ Private->AuthData = NULL;
+ }
+
+ if (Private->AuthScheme != NULL) {
+ FreePool (Private->AuthScheme);
+ Private->AuthScheme = NULL;
+ }
+
if (Private->DnsServerIp != NULL) {
FreePool (Private->DnsServerIp);
Private->DnsServerIp = NULL;
--
2.36.1.windows.1


[PATCH 1/1] OvmfPkg/XenPvBlkDxe: Fix memory barrier macro

Anthony PERARD
 

From: Anthony PERARD <anthony.perard@...>

The macro "xen_mb()" needs to be a full memory barrier, that is it
needs to also prevent stores from been reorder after loads which an
x86 CPU can do (as I understand from reading [1]). So this patch makes
use of "mfence" instruction.

Currently, there's a good chance that OvmfXen hang in
XenPvBlockSync(), in an infinite loop, waiting for the last request to
be consumed by the backend. On the other hand, the backend didn't know
there were a new request and don't do anything. This is because there
is two ways the backend look for request, either it's working on one
and use RING_FINAL_CHECK_FOR_REQUESTS(), or it's waiting for an
event/notification. So the frontend (OvmfXen) doesn't need to send
a notification if the backend is already working, checking for needed
notification is done by RING_PUSH_REQUESTS_AND_CHECK_NOTIFY().

That last marco is where order of store vs load is important, the
macro first store the fact that there's a new request, then load the
value of the last event that the backend have done to check if an
asynchronous notification is needed. If those store and load are
reorder, OvmfXen could take the wrong decision of not sending a
notification and both sides just wait.

To fix this, we need to tell the CPU to not reorder stores after loads.

Aarch64 implementation of MemoryFence() is using "dmb sy" which seems
to prevent any reordering.

[1] https://en.wikipedia.org/wiki/Memory_ordering#Runtime_memory_ordering

Signed-off-by: Anthony PERARD <anthony.perard@...>
---

I'm not sure what would be the correct implementation on MSFT,
_ReadWriteBarrier() seems to be only a compiler barrier, and I don't
know whether _mm_mfence() is just "mfence" or if it act as a compiler
barrier as well.

Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Julien Grall <julien@...>
---
OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf | 8 ++++++
OvmfPkg/XenPvBlkDxe/FullMemoryFence.h | 27 ++++++++++++++++++++
OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.h | 3 ++-
OvmfPkg/XenPvBlkDxe/X86GccFullMemoryFence.c | 20 +++++++++++++++
OvmfPkg/XenPvBlkDxe/X86MsftFullMemoryFence.c | 22 ++++++++++++++++
5 files changed, 79 insertions(+), 1 deletion(-)
create mode 100644 OvmfPkg/XenPvBlkDxe/FullMemoryFence.h
create mode 100644 OvmfPkg/XenPvBlkDxe/X86GccFullMemoryFence.c
create mode 100644 OvmfPkg/XenPvBlkDxe/X86MsftFullMemoryFence.c

diff --git a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
index 5dd8e8be1183..dc91865265c1 100644
--- a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
+++ b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
@@ -30,9 +30,17 @@ [Sources]
ComponentName.c
ComponentName.h
DriverBinding.h
+ FullMemoryFence.h
XenPvBlkDxe.c
XenPvBlkDxe.h

+[Sources.IA32]
+ X86GccFullMemoryFence.c | GCC
+ X86MsftFullMemoryFence.c | MSFT
+
+[Sources.X64]
+ X86GccFullMemoryFence.c | GCC
+ X86MsftFullMemoryFence.c | MSFT

[LibraryClasses]
UefiDriverEntryPoint
diff --git a/OvmfPkg/XenPvBlkDxe/FullMemoryFence.h b/OvmfPkg/XenPvBlkDxe/FullMemoryFence.h
new file mode 100644
index 000000000000..e3d1df3d0e9d
--- /dev/null
+++ b/OvmfPkg/XenPvBlkDxe/FullMemoryFence.h
@@ -0,0 +1,27 @@
+/** @file
+ Copyright (C) 2022, Citrix Ltd.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
+
+//
+// Like MemoryFence() but prevent stores from been reorded with loads by
+// the CPU on X64.
+//
+VOID
+EFIAPI
+FullMemoryFence (
+ VOID
+ );
+
+#else
+
+//
+// Only implement FullMemoryFence() on X86 as MemoryFence() is probably
+// fine on other platform.
+//
+#define FullMemoryFence() MemoryFence()
+
+#endif
diff --git a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.h b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.h
index 350b7bd309c0..67ee1899e9a8 100644
--- a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.h
+++ b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.h
@@ -11,8 +11,9 @@
#define __EFI_XEN_PV_BLK_DXE_H__

#include <Uefi.h>
+#include "FullMemoryFence.h"

-#define xen_mb() MemoryFence()
+#define xen_mb() FullMemoryFence()
#define xen_rmb() MemoryFence()
#define xen_wmb() MemoryFence()

diff --git a/OvmfPkg/XenPvBlkDxe/X86GccFullMemoryFence.c b/OvmfPkg/XenPvBlkDxe/X86GccFullMemoryFence.c
new file mode 100644
index 000000000000..92d107def470
--- /dev/null
+++ b/OvmfPkg/XenPvBlkDxe/X86GccFullMemoryFence.c
@@ -0,0 +1,20 @@
+/** @file
+ Copyright (C) 2022, Citrix Ltd.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include "FullMemoryFence.h"
+
+//
+// Like MemoryFence() but prevent stores from been reorded with loads by
+// the CPU on X64.
+//
+VOID
+EFIAPI
+FullMemoryFence (
+ VOID
+ )
+{
+ __asm__ __volatile__ ("mfence":::"memory");
+}
diff --git a/OvmfPkg/XenPvBlkDxe/X86MsftFullMemoryFence.c b/OvmfPkg/XenPvBlkDxe/X86MsftFullMemoryFence.c
new file mode 100644
index 000000000000..fcb08f7601cd
--- /dev/null
+++ b/OvmfPkg/XenPvBlkDxe/X86MsftFullMemoryFence.c
@@ -0,0 +1,22 @@
+/** @file
+ Copyright (C) 2022, Citrix Ltd.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include "FullMemoryFence.h"
+#include <intrin.h>
+
+//
+// Like MemoryFence() but prevent stores from been reorded with loads by
+// the CPU on X64.
+//
+VOID
+EFIAPI
+FullMemoryFence (
+ VOID
+ )
+{
+ _ReadWriteBarrier ();
+ _mm_mfence ();
+}
--
Anthony PERARD


[PATCH] BaseTools/VolInfo: Correct buffer for GenCrc32 tool

Konstantin Aladyshev
 

If the guided section was encoded with GenCrc32 tool the resulting
'EFI_GUID_DEFINED_SECTION.DataOffset' field points to the start of
the meaningfull data that follows the CRC32 value.
But if we want to decode the section with GenCrc32 tool we need to
provide a buffer that includes the CRC32 value itself.

Signed-off-by: Konstantin Aladyshev <aladyshev22@...>
---
BaseTools/Source/C/VolInfo/VolInfo.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/BaseTools/Source/C/VolInfo/VolInfo.c b/BaseTools/Source/C/VolI=
nfo/VolInfo.c
index f450796f9c..47a8f80f46 100644
--- a/BaseTools/Source/C/VolInfo/VolInfo.c
+++ b/BaseTools/Source/C/VolInfo/VolInfo.c
@@ -1999,6 +1999,13 @@ Returns:
);=0D
free (ExtractionTool);=0D
=0D
+ if (!CompareGuid (=0D
+ EfiGuid,=0D
+ &gEfiCrc32GuidedSectionExtractionProtocolGuid=0D
+ )=0D
+ ) {=0D
+ DataOffset -=3D 4;=0D
+ }=0D
Status =3D=0D
PutFileImage (=0D
ToolInputFile,=0D
--=20
2.25.1


[PATCH v2] BaseTools/VolInfo: Fix EFI_SECTION_GUID_DEFINED parsing

Konstantin Aladyshev
 

Currently 'PutFileImage' function is called with arguments that are
not advanced on each section parsing. This would lead to an error if
EFI_SECTION_GUID_DEFINED is not the first in a file.
The same mistake is present in the parsing of CRC32 guided section
case.
Use correct arguments to fix the issue.

Signed-off-by: Konstantin Aladyshev <aladyshev22@...>
---
BaseTools/Source/C/VolInfo/VolInfo.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Source/C/VolInfo/VolInfo.c b/BaseTools/Source/C/VolI=
nfo/VolInfo.c
index ed56587058..b550815765 100644
--- a/BaseTools/Source/C/VolInfo/VolInfo.c
+++ b/BaseTools/Source/C/VolInfo/VolInfo.c
@@ -2000,8 +2000,8 @@ Returns:
Status =3D=0D
PutFileImage (=0D
ToolInputFile,=0D
- (CHAR8*) SectionBuffer + DataOffset,=0D
- BufferLength - DataOffset=0D
+ (CHAR8*)Ptr + DataOffset,=0D
+ SectionLength - DataOffset=0D
);=0D
=0D
system (SystemCommand);=0D
@@ -2043,8 +2043,8 @@ Returns:
// CRC32 guided section=0D
//=0D
Status =3D ParseSection (=0D
- SectionBuffer + DataOffset,=0D
- BufferLength - DataOffset=0D
+ Ptr + DataOffset,=0D
+ SectionLength - DataOffset=0D
);=0D
if (EFI_ERROR (Status)) {=0D
Error (NULL, 0, 0003, "parse of CRC32 GUIDED section failed", NU=
LL);=0D
--=20
2.25.1


[PATCH v2] BaseTools/VolInfo: Show encapsulation sections

Konstantin Aladyshev
 

Currently there is no labels for start and end of the encapsulation
sections. Therefore it is not possible to see where the encapsulation
section ends and another section starts.
Add labels for start and end of encapsulation sections to fix the
issue.

Signed-off-by: Konstantin Aladyshev <aladyshev22@...>
---
BaseTools/Source/C/VolInfo/VolInfo.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/BaseTools/Source/C/VolInfo/VolInfo.c b/BaseTools/Source/C/VolI=
nfo/VolInfo.c
index c1f81f2dcb..ce1775f7fd 100644
--- a/BaseTools/Source/C/VolInfo/VolInfo.c
+++ b/BaseTools/Source/C/VolInfo/VolInfo.c
@@ -1903,7 +1903,9 @@ Returns:
return EFI_SECTION_ERROR;=0D
}=0D
=0D
+ printf ("/------------ Encapsulation section start -----------------=
\\\n");=0D
Status =3D ParseSection (UncompressedBuffer, UncompressedLength);=0D
+ printf ("\\------------ Encapsulation section end ------------------=
-/\n");=0D
=0D
if (CompressionType =3D=3D EFI_STANDARD_COMPRESSION) {=0D
//=0D
@@ -2022,6 +2024,7 @@ Returns:
return EFI_SECTION_ERROR;=0D
}=0D
=0D
+ printf ("/------------ Encapsulation section start ---------------=
--\\\n");=0D
Status =3D ParseSection (=0D
ToolOutputBuffer,=0D
ToolOutputLength=0D
@@ -2030,6 +2033,7 @@ Returns:
Error (NULL, 0, 0003, "parse of decoded GUIDED section failed", =
NULL);=0D
return EFI_SECTION_ERROR;=0D
}=0D
+ printf ("\\------------ Encapsulation section end ----------------=
---/\n");=0D
=0D
//=0D
// Check for CRC32 sections which we can handle internally if needed=
.=0D
@@ -2042,6 +2046,7 @@ Returns:
//=0D
// CRC32 guided section=0D
//=0D
+ printf ("/------------ Encapsulation section start ---------------=
--\\\n");=0D
Status =3D ParseSection (=0D
SectionBuffer + DataOffset,=0D
BufferLength - DataOffset=0D
@@ -2050,6 +2055,7 @@ Returns:
Error (NULL, 0, 0003, "parse of CRC32 GUIDED section failed", NU=
LL);=0D
return EFI_SECTION_ERROR;=0D
}=0D
+ printf ("\\------------ Encapsulation section end ----------------=
---/\n");=0D
} else {=0D
//=0D
// We don't know how to parse it now.=0D
--=20
2.25.1


[PATCH] BaseTools/VolInfo: Show encapsulation sections

Konstantin Aladyshev
 

Currently there is no labels for start and end of the encapsulation
sections. Therefore it is not possible to see where the encapsulation
section ends and another section starts.
Add labels for start and end of encapsulation sections to fix the
issue.

Signed-off-by: Konstantin Aladyshev <aladyshev22@...>
---
BaseTools/Source/C/VolInfo/VolInfo.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/BaseTools/Source/C/VolInfo/VolInfo.c b/BaseTools/Source/C/VolI=
nfo/VolInfo.c
index c1f81f2dcb..cfc65a8a6d 100644
--- a/BaseTools/Source/C/VolInfo/VolInfo.c
+++ b/BaseTools/Source/C/VolInfo/VolInfo.c
@@ -1903,7 +1903,9 @@ Returns:
return EFI_SECTION_ERROR;=0D
}=0D
=0D
+ printf ("/------------ Encapsulation section start -----------------=
\\\n");=0D
Status =3D ParseSection (UncompressedBuffer, UncompressedLength);=0D
+ printf ("\\----------- Encapsulation section end -------------------=
-/\n");=0D
=0D
if (CompressionType =3D=3D EFI_STANDARD_COMPRESSION) {=0D
//=0D
@@ -2022,6 +2024,7 @@ Returns:
return EFI_SECTION_ERROR;=0D
}=0D
=0D
+ printf ("/------------ Encapsulation section start ---------------=
--\\\n");=0D
Status =3D ParseSection (=0D
ToolOutputBuffer,=0D
ToolOutputLength=0D
@@ -2030,6 +2033,7 @@ Returns:
Error (NULL, 0, 0003, "parse of decoded GUIDED section failed", =
NULL);=0D
return EFI_SECTION_ERROR;=0D
}=0D
+ printf ("\\----------- Encapsulation section end -----------------=
---/\n");=0D
=0D
//=0D
// Check for CRC32 sections which we can handle internally if needed=
.=0D
@@ -2042,6 +2046,7 @@ Returns:
//=0D
// CRC32 guided section=0D
//=0D
+ printf ("/------------ Encapsulation section start ---------------=
--\\\n");=0D
Status =3D ParseSection (=0D
SectionBuffer + DataOffset,=0D
BufferLength - DataOffset=0D
@@ -2050,6 +2055,7 @@ Returns:
Error (NULL, 0, 0003, "parse of CRC32 GUIDED section failed", NU=
LL);=0D
return EFI_SECTION_ERROR;=0D
}=0D
+ printf ("\\----------- Encapsulation section end -----------------=
---/\n");=0D
} else {=0D
//=0D
// We don't know how to parse it now.=0D
--=20
2.25.1


[PATCH] BaseTools/VolInfo: Fix EFI_SECTION_GUID_DEFINED parsing

Konstantin Aladyshev
 

Currently 'PutFileImage' function is called with arguments that are
not advanced on each section parsing. This would lead to an error if
EFI_SECTION_GUID_DEFINED is not the first in a file.
Use correct arguments to fix the issue.

Signed-off-by: Konstantin Aladyshev <aladyshev22@...>
---
BaseTools/Source/C/VolInfo/VolInfo.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/C/VolInfo/VolInfo.c b/BaseTools/Source/C/VolI=
nfo/VolInfo.c
index ed56587058..c1f81f2dcb 100644
--- a/BaseTools/Source/C/VolInfo/VolInfo.c
+++ b/BaseTools/Source/C/VolInfo/VolInfo.c
@@ -2000,8 +2000,8 @@ Returns:
Status =3D=0D
PutFileImage (=0D
ToolInputFile,=0D
- (CHAR8*) SectionBuffer + DataOffset,=0D
- BufferLength - DataOffset=0D
+ (CHAR8*)Ptr + DataOffset,=0D
+ SectionLength - DataOffset=0D
);=0D
=0D
system (SystemCommand);=0D
--=20
2.25.1


Re: [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Don't always check PixelInformation

G Edhaya Chandran
 

Upstreamed through commit : https://github.com/tianocore/edk2-test/commit/4a25c3b3c79f63bd9f98b4fffcb21b5c66dd14bb


Re: [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Don't always check PixelInformation

G Edhaya Chandran
 

Reviewed-by: G Edhaya Chandran <edhaya.chandran@...>


Re: [PATCH 01/10] UefiCpuPkg: Create CpuPageTableLib for manipulating X86 paging structs

Ni, Ray
 

It has been in my todo list for years.
I wish this lib could be created earlier so that existing duplicated page table
manipulation logics could be avoided.

The Map() supports different PagingModes (4Level, 4Level1G, 5Level, 5Level1G).
It creates big page entry as the PagingMode allows (e.g.: 4Level1G allows to create PDPTE
entry mapping to 1G physical mem while 4Level only allows to create PDE entry mapping
to 2M physical mem.) All are hidden from the Map() API.

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Gerd
Hoffmann
Sent: Monday, July 18, 2022 9:50 PM
To: devel@edk2.groups.io; Ni, Ray <ray.ni@...>
Cc: Dong, Eric <eric.dong@...>
Subject: Re: [edk2-devel] [PATCH 01/10] UefiCpuPkg: Create
CpuPageTableLib for manipulating X86 paging structs

On Mon, Jul 18, 2022 at 09:18:22PM +0800, Ni, Ray wrote:
The lib includes two APIs:
* PageTableMap
It creates/updates mapping from LA to PA.
The implementation only supports paging structures used in 64bit
mode now. PAE paging structure support will be added in future.

* PageTableParse
It parses the page table and returns the mapping relations in an
array of IA32_MAP_ENTRY.

It passed some stress tests. These test code will be upstreamed in
other patches following edk2 Unit Test framework.
Nice to finally see the paging library arrive.

What is the plan for splitting huge pages? I remember several places
needed that functionality. Will the library get functions for that in
the future? Or is the plan to hide that from callers, i.e. have
PageTableMap() automatically create huge pages if possible and split
them if needed?

thanks,
Gerd





[PATCH v2 2/2] UefiPayloadPkg: Allow DxeMain.inf to consume the new SerialPortLib

Kavya
 

Let DxeMain.inf consume new SerialPortLib to support
multiple channel debug message on early DXE.

Cc: Guo Dong <guo.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Maurice Ma <maurice.ma@...>
Cc: Benjamin You <benjamin.you@...>
Cc: Sean Rhodes <sean@...>
Signed-off-by: Kavya <k.kavyax.sravanthi@...>
---
UefiPayloadPkg/UefiPayloadPkg.dsc | 2 ++
1 file changed, 2 insertions(+)

diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 5e947526b7..33eed40370 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -582,6 +582,8 @@
#
MdeModulePkg/Core/Dxe/DxeMain.inf {
<LibraryClasses>
+ DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+ SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf
NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
}

--
2.30.2.windows.1


[PATCH v2 1/2] UefiPayloadPkg: Implement a new SerialPortLib instance

Kavya
 

Add new Serial port library instance that consumes the HOB defined
in MdeModulePkg/Include/UniversalPayload/SerialPortInfo.h to support
multiple UART's.

Cc: Guo Dong <guo.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Maurice Ma <maurice.ma@...>
Cc: Benjamin You <benjamin.you@...>
Cc: Sean Rhodes <sean@...>
Signed-off-by: Kavya <k.kavyax.sravanthi@...>
---
UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c | 794 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 834 insertions(+)

diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
new file mode 100644
index 0000000000..8c39befafe
--- /dev/null
+++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
@@ -0,0 +1,794 @@
+/** @file
+ UART Serial Port library functions.
+
+ Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+#include <PiDxe.h>
+#include <Base.h>
+#include <Library/PcdLib.h>
+#include <Library/IoLib.h>
+#include <Library/BaseLib.h>
+#include <Library/HobLib.h>
+#include <Library/TimerLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Protocol/SerialIo.h>
+#include <UniversalPayload/SerialPortInfo.h>
+
+//
+// 16550 UART register offsets and bitfields
+//
+#define R_UART_RXBUF 0 // LCR_DLAB = 0
+#define R_UART_TXBUF 0 // LCR_DLAB = 0
+#define R_UART_BAUD_LOW 0 // LCR_DLAB = 1
+#define R_UART_BAUD_HIGH 1 // LCR_DLAB = 1
+#define R_UART_IER 1 // LCR_DLAB = 0
+#define R_UART_FCR 2
+#define B_UART_FCR_FIFOE BIT0
+#define B_UART_FCR_FIFO64 BIT5
+#define R_UART_LCR 3
+#define B_UART_LCR_DLAB BIT7
+#define R_UART_MCR 4
+#define B_UART_MCR_DTRC BIT0
+#define B_UART_MCR_RTS BIT1
+#define R_UART_LSR 5
+#define B_UART_LSR_RXRDY BIT0
+#define B_UART_LSR_TXRDY BIT5
+#define B_UART_LSR_TEMT BIT6
+#define R_UART_MSR 6
+#define B_UART_MSR_CTS BIT4
+#define B_UART_MSR_DSR BIT5
+#define B_UART_MSR_RI BIT6
+#define B_UART_MSR_DCD BIT7
+
+typedef struct {
+ UINTN BaseAddress;
+ BOOLEAN UseMmio;
+ UINT32 BaudRate;
+} UART_INFO;
+
+UART_INFO **mUartInfo;
+UINT8 mUartCount;
+
+/**
+ Reads an 8-bit register. If UseMmio is TRUE, then the value is read from
+ MMIO space. If UseMmio is FALSE, then the value is read from I/O space. The
+ parameter Offset is added to the base address of the register.
+
+ @param Base The base address register of UART device.
+ @param Offset The offset of the register to read.
+ @param UseMmio Check if value has to be read from MMIO space or IO space.
+
+ @return The value read from the register.
+
+**/
+UINT8
+SerialPortReadRegister (
+ UINTN Base,
+ UINTN Offset,
+ BOOLEAN UseMmio
+ )
+{
+ if (UseMmio) {
+ return MmioRead8 (Base + Offset/4);
+ } else {
+ return IoRead8 (Base + Offset);
+ }
+}
+
+/**
+ Writes an 8-bit register.. If UseMmio is TRUE, then the value is written to
+ MMIO space. If UseMmio is FALSE, then the value is written to I/O space. The
+ parameter Offset is added to the base address of the registers.
+
+ @param Base The base address register of UART device.
+ @param Offset The offset of the register to write.
+ @param Value Value to be written.
+ @param UseMmio Check if value has to be written to MMIO space or IO space.
+
+ @return The value written to the register.
+
+**/
+UINT8
+SerialPortWriteRegister (
+ UINTN Base,
+ UINTN Offset,
+ UINT8 Value,
+ BOOLEAN UseMmio
+ )
+{
+ if (UseMmio) {
+ return MmioWrite8 (Base + Offset/4, Value);
+ } else {
+ return IoWrite8 (Base + Offset, Value);
+ }
+}
+
+/**
+ Initialize the serial device hardware.
+
+ If no initialization is required, then return RETURN_SUCCESS.
+ If the serial device was successfully initialized, then return RETURN_SUCCESS.
+ If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
+
+ @retval RETURN_SUCCESS The serial device was initialized.
+ @retval RETURN_DEVICE_ERROR The serial device could not be initialized.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortInitialize (
+ VOID
+ )
+{
+ UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *SerialPortInfo;
+ EFI_HOB_GUID_TYPE *GuidHob;
+ UINTN SerialRegisterBase;
+ UINT32 Divisor;
+ UINT32 CurrentDivisor;
+ UINT32 BaudRate;
+ BOOLEAN Initialized;
+ BOOLEAN MmioEnable;
+ UINT8 Index;
+ UINT8 Count;
+
+ Count = 0;
+
+ GuidHob = GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid);
+ while (GuidHob != NULL) {
+ Count++;
+ GuidHob = GET_NEXT_HOB (GuidHob);
+ GuidHob = GetNextGuidHob (&gUniversalPayloadSerialPortInfoGuid, GuidHob);
+ }
+
+ mUartCount = Count;
+
+ mUartInfo = (UART_INFO **)AllocateZeroPool (sizeof (UART_INFO *) * Count);
+ ASSERT (mUartInfo != NULL);
+
+ for (Index = 0; Index < Count; Index++) {
+ mUartInfo[Index] = (UART_INFO *)AllocateZeroPool (sizeof (UART_INFO));
+ }
+
+ Index = 0;
+ GuidHob = GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid);
+ while (GuidHob != NULL) {
+ SerialPortInfo = (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *)GET_GUID_HOB_DATA (GuidHob);
+ SerialRegisterBase = SerialPortInfo->RegisterBase;
+ MmioEnable = SerialPortInfo->UseMmio;
+ BaudRate = SerialPortInfo->BaudRate;
+
+ mUartInfo[Index]->BaseAddress = SerialRegisterBase;
+ mUartInfo[Index]->UseMmio = MmioEnable;
+ mUartInfo[Index]->BaudRate = BaudRate;
+ Index++;
+
+ if (SerialRegisterBase == 0) {
+ return RETURN_DEVICE_ERROR;
+ }
+
+ Divisor = PcdGet32 (PcdSerialClockRate) / (BaudRate * 16);
+ if ((PcdGet32 (PcdSerialClockRate) % (BaudRate * 16)) >= BaudRate * 8) {
+ Divisor++;
+ }
+
+ //
+ // See if the serial port is already initialized
+ //
+ Initialized = TRUE;
+ if ((SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, MmioEnable) & 0x3F) != (PcdGet8 (PcdSerialLineControl) & 0x3F)) {
+ Initialized = FALSE;
+ }
+
+ SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, MmioEnable) | B_UART_LCR_DLAB), MmioEnable);
+ CurrentDivisor = SerialPortReadRegister (SerialRegisterBase, R_UART_BAUD_HIGH, MmioEnable) << 8;
+ CurrentDivisor |= (UINT32)SerialPortReadRegister (SerialRegisterBase, R_UART_BAUD_LOW, MmioEnable);
+ SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, MmioEnable) & ~B_UART_LCR_DLAB), MmioEnable);
+ if (CurrentDivisor != Divisor) {
+ Initialized = FALSE;
+ }
+
+ if (Initialized) {
+ GuidHob = GET_NEXT_HOB (GuidHob);
+ GuidHob = GetNextGuidHob (&gUniversalPayloadSerialPortInfoGuid, GuidHob);
+ continue;
+ }
+
+ //
+ // Configure baud rate
+ //
+ SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, B_UART_LCR_DLAB, MmioEnable);
+ SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_HIGH, (UINT8)(Divisor >> 8), MmioEnable);
+ SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_LOW, (UINT8)(Divisor & 0xff), MmioEnable);
+
+ //
+ // Clear DLAB and configure Data Bits, Parity, and Stop Bits.
+ // Strip reserved bits from PcdSerialLineControl
+ //
+ SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(PcdGet8 (PcdSerialLineControl) & 0x3F), MmioEnable);
+
+ //
+ // Enable and reset FIFOs
+ // Strip reserved bits from PcdSerialFifoControl
+ //
+ SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, 0x00, MmioEnable);
+ SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, (UINT8)(PcdGet8 (PcdSerialFifoControl) & (B_UART_FCR_FIFOE | B_UART_FCR_FIFO64)), MmioEnable);
+
+ //
+ // Set FIFO Polled Mode by clearing IER after setting FCR
+ //
+ SerialPortWriteRegister (SerialRegisterBase, R_UART_IER, 0x00, MmioEnable);
+
+ //
+ // Put Modem Control Register(MCR) into its reset state of 0x00.
+ //
+ SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, 0x00, MmioEnable);
+
+ GuidHob = GET_NEXT_HOB (GuidHob);
+ GuidHob = GetNextGuidHob (&gUniversalPayloadSerialPortInfoGuid, GuidHob);
+ }
+
+ return RETURN_SUCCESS;
+}
+
+/**
+ Write data from buffer to serial device.
+
+ Writes NumberOfBytes data bytes from Buffer to the serial device.
+ The number of bytes actually written to the serial device is returned.
+ If the return value is less than NumberOfBytes, then the write operation failed.
+
+ If Buffer is NULL, then return 0.
+
+ If NumberOfBytes is zero, then return 0.
+
+ @param Buffer Pointer to the data buffer to be written.
+ @param NumberOfBytes Number of bytes to written to the serial device.
+
+ @retval 0 NumberOfBytes is 0.
+ @retval >0 The number of bytes written to the serial device.
+ If this value is less than NumberOfBytes, then the write operation failed.
+
+**/
+UINTN
+EFIAPI
+SerialPortWrite (
+ IN UINT8 *Buffer,
+ IN UINTN NumberOfBytes
+ )
+{
+ UINTN BaseAddress;
+ BOOLEAN UseMmio;
+ UINTN BytesLeft;
+ UINTN Index;
+ UINTN FifoSize;
+ UINT8 *DataBuffer;
+ UINT8 Count;
+
+ if (Buffer == NULL || NumberOfBytes == 0) {
+ return 0;
+ }
+
+ //
+ // Compute the maximum size of the Tx FIFO
+ //
+ FifoSize = 1;
+ if ((PcdGet8 (PcdSerialFifoControl) & B_UART_FCR_FIFOE) != 0) {
+ if ((PcdGet8 (PcdSerialFifoControl) & B_UART_FCR_FIFO64) == 0) {
+ FifoSize = 16;
+ } else {
+ FifoSize = PcdGet32 (PcdSerialExtendedTxFifoSize);
+ }
+ }
+
+ Count = 0;
+ while (Count < mUartCount) {
+ BaseAddress = mUartInfo[Count]->BaseAddress;
+ UseMmio = mUartInfo[Count]->UseMmio;
+
+ DataBuffer = Buffer;
+ BytesLeft = NumberOfBytes;
+
+ while (BytesLeft != 0) {
+ //
+ // Fill the entire Tx FIFO
+ //
+ for (Index = 0; Index < FifoSize && BytesLeft != 0; Index++, BytesLeft--, DataBuffer++) {
+ //
+ // Write byte to the transmit buffer.
+ //
+ SerialPortWriteRegister (BaseAddress, R_UART_TXBUF, *DataBuffer, UseMmio);
+ }
+ MicroSecondDelay (20);
+ }
+ Count++;
+ }
+
+ return NumberOfBytes;
+}
+
+/**
+ Reads data from a serial device into a buffer.
+
+ @param Buffer Pointer to the data buffer to store the data read from the serial device.
+ @param NumberOfBytes Number of bytes to read from the serial device.
+
+ @retval 0 NumberOfBytes is 0.
+ @retval >0 The number of bytes read from the serial device.
+ If this value is less than NumberOfBytes, then the read operation failed.
+
+**/
+UINTN
+EFIAPI
+SerialPortRead (
+ OUT UINT8 *Buffer,
+ IN UINTN NumberOfBytes
+ )
+{
+ UINTN BaseAddress;
+ BOOLEAN UseMmio;
+ UINT8 *DataBuffer;
+ UINTN BytesLeft;
+ UINTN Result;
+ UINT8 Mcr;
+ UINT8 Count;
+
+ if (Buffer == NULL) {
+ return 0;
+ }
+
+ Count = 0;
+ while (Count < mUartCount) {
+ BaseAddress = mUartInfo[Count]->BaseAddress;
+ UseMmio = mUartInfo[Count]->UseMmio;
+
+ DataBuffer = Buffer;
+ BytesLeft = NumberOfBytes;
+
+ if (BaseAddress == 0) {
+ return 0;
+ }
+
+ Mcr = (UINT8)(SerialPortReadRegister (BaseAddress, R_UART_MCR, UseMmio) & ~B_UART_MCR_RTS);
+
+ for (Result = 0; BytesLeft-- != 0; Result++, DataBuffer++) {
+ //
+ // Wait for the serial port to have some data.
+ //
+ while ((SerialPortReadRegister (BaseAddress, R_UART_LSR, UseMmio) & B_UART_LSR_RXRDY) == 0) {
+ if (PcdGetBool (PcdSerialUseHardwareFlowControl)) {
+ //
+ // Set RTS to let the peer send some data
+ //
+ SerialPortWriteRegister (BaseAddress, R_UART_MCR, (UINT8)(Mcr | B_UART_MCR_RTS), UseMmio);
+ }
+ }
+
+ if (PcdGetBool (PcdSerialUseHardwareFlowControl)) {
+ //
+ // Clear RTS to prevent peer from sending data
+ //
+ SerialPortWriteRegister (BaseAddress, R_UART_MCR, Mcr, UseMmio);
+ }
+
+ //
+ // Read byte from the receive buffer.
+ //
+ *DataBuffer = SerialPortReadRegister (BaseAddress, R_UART_RXBUF, UseMmio);
+ }
+ Count++;
+ }
+
+ return Result;
+}
+
+/**
+ Polls a serial device to see if there is any data waiting to be read.
+
+ Polls a serial device to see if there is any data waiting to be read.
+ If there is data waiting to be read from the serial device, then TRUE is returned.
+ If there is no data waiting to be read from the serial device, then FALSE is returned.
+
+ @retval TRUE Data is waiting to be read from the serial device.
+ @retval FALSE There is no data waiting to be read from the serial device.
+
+**/
+BOOLEAN
+EFIAPI
+SerialPortPoll (
+ VOID
+ )
+{
+ UINTN BaseAddress;
+ BOOLEAN UseMmio;
+ UINT8 Count;
+
+ Count = 0;
+ while (Count < mUartCount) {
+ BaseAddress = mUartInfo[Count]->BaseAddress;
+ UseMmio = mUartInfo[Count]->UseMmio;
+
+ if (BaseAddress == 0) {
+ return FALSE;
+ }
+
+ //
+ // Read the serial port status
+ //
+ if ((SerialPortReadRegister (BaseAddress, R_UART_LSR, UseMmio) & B_UART_LSR_RXRDY) != 0) {
+ if (PcdGetBool (PcdSerialUseHardwareFlowControl)) {
+ //
+ // Clear RTS to prevent peer from sending data
+ //
+ SerialPortWriteRegister (BaseAddress, R_UART_MCR, (UINT8)(SerialPortReadRegister (BaseAddress, R_UART_MCR, UseMmio) & ~B_UART_MCR_RTS), UseMmio);
+ }
+ return TRUE;
+ }
+
+ if (PcdGetBool (PcdSerialUseHardwareFlowControl)) {
+ //
+ // Set RTS to let the peer send some data
+ //
+ SerialPortWriteRegister (BaseAddress, R_UART_MCR, (UINT8)(SerialPortReadRegister (BaseAddress, R_UART_MCR, UseMmio) | B_UART_MCR_RTS), UseMmio);
+ }
+ Count++;
+ }
+ return FALSE;
+}
+
+/**
+ Sets the control bits on a serial device.
+
+ @param Control Sets the bits of Control that are settable.
+
+ @retval RETURN_SUCCESS The new control bits were set on the serial device.
+ @retval RETURN_UNSUPPORTED The serial device does not support this operation.
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortSetControl (
+ IN UINT32 Control
+ )
+{
+ UINTN BaseAddress;
+ BOOLEAN UseMmio;
+ UINT8 Mcr;
+ UINT8 Count;
+
+ Count = 0;
+ while (Count < mUartCount) {
+ BaseAddress = mUartInfo[Count]->BaseAddress;
+ UseMmio = mUartInfo[Count]->UseMmio;
+
+ if (BaseAddress == 0) {
+ return RETURN_UNSUPPORTED;
+ }
+
+ //
+ // First determine the parameter is invalid.
+ //
+ if ((Control & (~(EFI_SERIAL_REQUEST_TO_SEND | EFI_SERIAL_DATA_TERMINAL_READY |
+ EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE))) != 0)
+ {
+ return RETURN_UNSUPPORTED;
+ }
+
+ //
+ // Read the Modem Control Register.
+ //
+ Mcr = SerialPortReadRegister (BaseAddress, R_UART_MCR, UseMmio);
+ Mcr &= (~(B_UART_MCR_DTRC | B_UART_MCR_RTS));
+
+ if ((Control & EFI_SERIAL_DATA_TERMINAL_READY) == EFI_SERIAL_DATA_TERMINAL_READY) {
+ Mcr |= B_UART_MCR_DTRC;
+ }
+
+ if ((Control & EFI_SERIAL_REQUEST_TO_SEND) == EFI_SERIAL_REQUEST_TO_SEND) {
+ Mcr |= B_UART_MCR_RTS;
+ }
+
+ //
+ // Write the Modem Control Register.
+ //
+ SerialPortWriteRegister (BaseAddress, R_UART_MCR, Mcr, UseMmio);
+ Count++;
+ }
+
+ return RETURN_SUCCESS;
+}
+
+/**
+ Retrieve the status of the control bits on a serial device.
+
+ @param Control A pointer to return the current control signals from the serial device.
+
+ @retval RETURN_SUCCESS The control bits were read from the serial device.
+ @retval RETURN_UNSUPPORTED The serial device does not support this operation.
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortGetControl (
+ OUT UINT32 *Control
+ )
+{
+ UINTN BaseAddress;
+ BOOLEAN UseMmio;
+ UINT8 Msr;
+ UINT8 Mcr;
+ UINT8 Lsr;
+ UINT8 Count;
+
+ Count = 0;
+ while (Count < mUartCount) {
+ BaseAddress = mUartInfo[Count]->BaseAddress;
+ UseMmio = mUartInfo[Count]->UseMmio;
+
+ if (BaseAddress == 0) {
+ return RETURN_UNSUPPORTED;
+ }
+
+ *Control = 0;
+
+ //
+ // Read the Modem Status Register.
+ //
+ Msr = SerialPortReadRegister (BaseAddress, R_UART_MSR, UseMmio);
+
+ if ((Msr & B_UART_MSR_CTS) == B_UART_MSR_CTS) {
+ *Control |= EFI_SERIAL_CLEAR_TO_SEND;
+ }
+
+ if ((Msr & B_UART_MSR_DSR) == B_UART_MSR_DSR) {
+ *Control |= EFI_SERIAL_DATA_SET_READY;
+ }
+
+ if ((Msr & B_UART_MSR_RI) == B_UART_MSR_RI) {
+ *Control |= EFI_SERIAL_RING_INDICATE;
+ }
+
+ if ((Msr & B_UART_MSR_DCD) == B_UART_MSR_DCD) {
+ *Control |= EFI_SERIAL_CARRIER_DETECT;
+ }
+
+ //
+ // Read the Modem Control Register.
+ //
+ Mcr = SerialPortReadRegister (BaseAddress, R_UART_MCR, UseMmio);
+
+ if ((Mcr & B_UART_MCR_DTRC) == B_UART_MCR_DTRC) {
+ *Control |= EFI_SERIAL_DATA_TERMINAL_READY;
+ }
+
+ if ((Mcr & B_UART_MCR_RTS) == B_UART_MCR_RTS) {
+ *Control |= EFI_SERIAL_REQUEST_TO_SEND;
+ }
+
+ if (PcdGetBool (PcdSerialUseHardwareFlowControl)) {
+ *Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;
+ }
+
+ //
+ // Read the Line Status Register.
+ //
+ Lsr = SerialPortReadRegister (BaseAddress, R_UART_LSR, UseMmio);
+
+ if ((Lsr & (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) == (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) {
+ *Control |= EFI_SERIAL_OUTPUT_BUFFER_EMPTY;
+ }
+
+ if ((Lsr & B_UART_LSR_RXRDY) == 0) {
+ *Control |= EFI_SERIAL_INPUT_BUFFER_EMPTY;
+ }
+ Count++;
+ }
+
+ return RETURN_SUCCESS;
+}
+
+/**
+ Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,
+ data bits, and stop bits on a serial device.
+
+ @param BaudRate The requested baud rate. A BaudRate value of 0 will use the
+ device's default interface speed.
+ On output, the value actually set.
+ @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the
+ serial interface. A ReceiveFifoDepth value of 0 will use
+ the device's default FIFO depth.
+ On output, the value actually set.
+ @param Timeout The requested time out for a single character in microseconds.
+ This timeout applies to both the transmit and receive side of the
+ interface. A Timeout value of 0 will use the device's default time
+ out value.
+ On output, the value actually set.
+ @param Parity The type of parity to use on this serial device. A Parity value of
+ DefaultParity will use the device's default parity value.
+ On output, the value actually set.
+ @param DataBits The number of data bits to use on the serial device. A DataBits
+ vaule of 0 will use the device's default data bit setting.
+ On output, the value actually set.
+ @param StopBits The number of stop bits to use on this serial device. A StopBits
+ value of DefaultStopBits will use the device's default number of
+ stop bits.
+ On output, the value actually set.
+
+ @retval RETURN_SUCCESS The new attributes were set on the serial device.
+ @retval RETURN_UNSUPPORTED The serial device does not support this operation.
+ @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortSetAttributes (
+ IN OUT UINT64 *BaudRate,
+ IN OUT UINT32 *ReceiveFifoDepth,
+ IN OUT UINT32 *Timeout,
+ IN OUT EFI_PARITY_TYPE *Parity,
+ IN OUT UINT8 *DataBits,
+ IN OUT EFI_STOP_BITS_TYPE *StopBits
+ )
+{
+ UINTN BaseAddress;
+ BOOLEAN UseMmio;
+ UINT32 SerialBaudRate;
+ UINTN Divisor;
+ UINT8 Lcr;
+ UINT8 LcrData;
+ UINT8 LcrParity;
+ UINT8 LcrStop;
+ UINT8 Count;
+
+ Count = 0;
+ while (Count < mUartCount) {
+ BaseAddress = mUartInfo[Count]->BaseAddress;
+ UseMmio = mUartInfo[Count]->UseMmio;
+
+ if (BaseAddress == 0) {
+ return RETURN_UNSUPPORTED;
+ }
+
+ //
+ // Check for default settings and fill in actual values.
+ //
+ if (*BaudRate == 0) {
+ *BaudRate = mUartInfo[Count]->BaudRate;
+ }
+
+ SerialBaudRate = (UINT32)*BaudRate;
+
+ if (*DataBits == 0) {
+ LcrData = (UINT8)(PcdGet8 (PcdSerialLineControl) & 0x3);
+ *DataBits = LcrData + 5;
+ } else {
+ if ((*DataBits < 5) || (*DataBits > 8)) {
+ return RETURN_INVALID_PARAMETER;
+ }
+
+ //
+ // Map 5..8 to 0..3
+ //
+ LcrData = (UINT8)(*DataBits - (UINT8)5);
+ }
+
+ if (*Parity == DefaultParity) {
+ LcrParity = (UINT8)((PcdGet8 (PcdSerialLineControl) >> 3) & 0x7);
+ switch (LcrParity) {
+ case 0:
+ *Parity = NoParity;
+ break;
+
+ case 3:
+ *Parity = EvenParity;
+ break;
+
+ case 1:
+ *Parity = OddParity;
+ break;
+
+ case 7:
+ *Parity = SpaceParity;
+ break;
+
+ case 5:
+ *Parity = MarkParity;
+ break;
+
+ default:
+ break;
+ }
+ } else {
+ switch (*Parity) {
+ case NoParity:
+ LcrParity = 0;
+ break;
+
+ case EvenParity:
+ LcrParity = 3;
+ break;
+
+ case OddParity:
+ LcrParity = 1;
+ break;
+
+ case SpaceParity:
+ LcrParity = 7;
+ break;
+
+ case MarkParity:
+ LcrParity = 5;
+ break;
+
+ default:
+ return RETURN_INVALID_PARAMETER;
+ }
+ }
+
+ if (*StopBits == DefaultStopBits) {
+ LcrStop = (UINT8)((PcdGet8 (PcdSerialLineControl) >> 2) & 0x1);
+ switch (LcrStop) {
+ case 0:
+ *StopBits = OneStopBit;
+ break;
+
+ case 1:
+ if (*DataBits == 5) {
+ *StopBits = OneFiveStopBits;
+ } else {
+ *StopBits = TwoStopBits;
+ }
+
+ break;
+
+ default:
+ break;
+ }
+ } else {
+ switch (*StopBits) {
+ case OneStopBit:
+ LcrStop = 0;
+ break;
+
+ case OneFiveStopBits:
+ case TwoStopBits:
+ LcrStop = 1;
+ break;
+
+ default:
+ return RETURN_INVALID_PARAMETER;
+ }
+ }
+
+ //
+ // Calculate divisor for baud generator
+ // Ref_Clk_Rate / Baud_Rate / 16
+ //
+ Divisor = PcdGet32 (PcdSerialClockRate) / (SerialBaudRate * 16);
+ if ((PcdGet32 (PcdSerialClockRate) % (SerialBaudRate * 16)) >= SerialBaudRate * 8) {
+ Divisor++;
+ }
+
+ //
+ // Configure baud rate
+ //
+ SerialPortWriteRegister (BaseAddress, R_UART_LCR, B_UART_LCR_DLAB, UseMmio);
+ SerialPortWriteRegister (BaseAddress, R_UART_BAUD_HIGH, (UINT8)(Divisor >> 8), UseMmio);
+ SerialPortWriteRegister (BaseAddress, R_UART_BAUD_LOW, (UINT8)(Divisor & 0xff), UseMmio);
+
+ //
+ // Clear DLAB and configure Data Bits, Parity, and Stop Bits.
+ // Strip reserved bits from line control value
+ //
+ Lcr = (UINT8)((LcrParity << 3) | (LcrStop << 2) | LcrData);
+ SerialPortWriteRegister (BaseAddress, R_UART_LCR, (UINT8)(Lcr & 0x3F), UseMmio);
+ Count++;
+ }
+
+ return RETURN_SUCCESS;
+}
diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf
new file mode 100644
index 0000000000..1dbe107dbd
--- /dev/null
+++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf
@@ -0,0 +1,40 @@
+## @file
+# SerialPortLib instance for UART information retrieved from bootloader.
+#
+# Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = BaseSerialPortLibHob
+ FILE_GUID = d8d22930-e8ec-469f-8184-5a069149b2ff
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = SerialPortLib
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ PcdLib
+ IoLib
+ HobLib
+ TimerLib
+ MemoryAllocationLib
+
+[Sources]
+ BaseSerialPortLibHob.c
+
+[Pcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl
+
+[Guids]
+ gUniversalPayloadSerialPortInfoGuid
--
2.30.2.windows.1


[PATCH v5] MdeModulePkg/Include: Long debug string is truncated to 104 char

Cosmo Lai
 

From: Cosmo Lai <cosmo.lai@...>

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

The EFI_STATUS_CODE_DATA_MAX_SIZE is defined as 200 in MdeModulePkg.
After reducing 96byte buffer for variable parameters it is limited to
only 104 char debug string. This is a non-necessary limitation.
This change sets EFI_STATUS_CODE_DATA_MAX_SIZE to 0x200, and moves
MAX_EXTENDED_DATA_SIZE definition to the same header file with value
of EFI_STATUS_CODE_DATA_MAX_SIZE + sizeof (EFI_STATUS_CODE_DATA)
which is used in ReportStatusCodeLib to support longer debug string.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Liming Gao <gaoliming@...>
Cc: Dandan Bi <dandan.bi@...>

Signed-off-by: Cosmo Lai <cosmo.lai@...>
---
MdeModulePkg/Include/Guid/StatusCodeDataTypeDebug.h | 10 +++++++++-
.../Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c | 6 ------
.../Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c | 5 -----
.../RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c | 5 -----
4 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/MdeModulePkg/Include/Guid/StatusCodeDataTypeDebug.h b/MdeModulePkg/Include/Guid/StatusCodeDataTypeDebug.h
index 16203452e4..6f2688064b 100644
--- a/MdeModulePkg/Include/Guid/StatusCodeDataTypeDebug.h
+++ b/MdeModulePkg/Include/Guid/StatusCodeDataTypeDebug.h
@@ -10,6 +10,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _STATUS_CODE_DATA_TYPE_DEBUG_H_
#define _STATUS_CODE_DATA_TYPE_DEBUG_H_

+#include <Pi/PiStatusCode.h>
+
///
/// The Global ID used to identify a structure of type EFI_DEBUG_INFO.
///
@@ -21,7 +23,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
///
/// The maximum size of an EFI_DEBUG_INFO structure.
///
-#define EFI_STATUS_CODE_DATA_MAX_SIZE 200
+#define EFI_STATUS_CODE_DATA_MAX_SIZE 0x200
+
+///
+/// Define the maximum extended data size that is supported when a
+/// status code is reported.
+///
+#define MAX_EXTENDED_DATA_SIZE (EFI_STATUS_CODE_DATA_MAX_SIZE + sizeof(EFI_STATUS_CODE_DATA))

///
/// This structure contains the ErrorLevel passed into the DEBUG() macro, followed
diff --git a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
index ed01d8aacb..da254b755f 100644
--- a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
+++ b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
@@ -19,12 +19,6 @@
#include <Guid/StatusCodeDataTypeId.h>
#include <Guid/StatusCodeDataTypeDebug.h>

-//
-// Define the maximum extended data size that is supported when a status code is
-// reported at TPL_HIGH_LEVEL.
-//
-#define MAX_EXTENDED_DATA_SIZE 0x200
-
EFI_STATUS_CODE_PROTOCOL *mReportStatusCodeLibStatusCodeProtocol = NULL;

/**
diff --git a/MdeModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c
index b0a5f61cda..71da0e94fc 100644
--- a/MdeModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c
+++ b/MdeModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c
@@ -17,11 +17,6 @@
#include <Library/OemHookStatusCodeLib.h>
#include <Library/PcdLib.h>

-//
-// Define the maximum extended data size that is supported in the PEI phase
-//
-#define MAX_EXTENDED_DATA_SIZE 0x200
-
/**
Internal worker function that reports a status code through the PEI Status Code Service or
OEM Hook Status Code Library.
diff --git a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c
index fdda288d33..8fd20ff239 100644
--- a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c
+++ b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c
@@ -21,11 +21,6 @@
#include <Guid/StatusCodeDataTypeDebug.h>
#include <Guid/EventGroup.h>

-//
-// Define the maximum extended data size that is supported when a status code is reported.
-//
-#define MAX_EXTENDED_DATA_SIZE 0x200
-
EFI_STATUS_CODE_PROTOCOL *mReportStatusCodeLibStatusCodeProtocol = NULL;
EFI_EVENT mReportStatusCodeLibVirtualAddressChangeEvent;
EFI_EVENT mReportStatusCodeLibExitBootServicesEvent;
--
2.16.2.windows.1