summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.azurepipelines/templates/defaults.yml2
-rw-r--r--.pytool/Plugin/UncrustifyCheck/uncrustify_ext_dep.yaml11
-rw-r--r--ArmPkg/Include/IndustryStandard/ArmTransferList.h20
-rw-r--r--ArmPkg/Include/Library/ArmTransferListLib.h37
-rw-r--r--ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c89
-rw-r--r--ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf3
-rw-r--r--ArmVirtPkg/ArmVirt.dsc.inc1
-rw-r--r--ArmVirtPkg/ArmVirtQemu.dsc32
-rw-r--r--ArmVirtPkg/ArmVirtQemu.fdf4
-rw-r--r--ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLib.c15
-rw-r--r--ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFlash.inf1
-rw-r--r--ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartRam.inf2
-rw-r--r--ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL011Uart.inf2
-rw-r--r--BaseTools/Source/C/VfrCompile/VfrSyntax.g5
-rw-r--r--BaseTools/Source/Python/Workspace/MetaFileParser.py6
-rw-r--r--CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPem.c2
-rw-r--r--CryptoPkg/Library/BaseCryptLibMbedTls/UnitTestHostBaseCryptLib.inf86
-rw-r--r--CryptoPkg/Test/CryptoPkgHostUnitTest.dsc20
-rw-r--r--CryptoPkg/Test/UnitTest/Library/BaseCryptLib/RsaPkcs7Tests.c227
-rw-r--r--EmbeddedPkg/EmbeddedPkg.dec4
-rw-r--r--Maintainers.txt4
-rw-r--r--MdeModulePkg/Bus/Pci/UhciPei/DmaMem.c225
-rw-r--r--MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.c3303
-rw-r--r--MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.h1383
-rw-r--r--MdeModulePkg/Bus/Pci/UhciPei/UhciPei.inf60
-rw-r--r--MdeModulePkg/Bus/Pci/UhciPei/UhciPei.uni17
-rw-r--r--MdeModulePkg/Bus/Pci/UhciPei/UhciPeiExtra.uni14
-rw-r--r--MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c9
-rw-r--r--MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c60
-rw-r--r--MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c56
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBotPei/BotPeim.h1
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBotPei/UsbBotPeim.h1
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c2
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c4
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c2
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c14
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusPei/UsbBusPei.inf5
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusPei/UsbIoPeim.c88
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c383
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h4
-rw-r--r--MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c26
-rw-r--r--MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c12
-rw-r--r--MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c2
-rw-r--r--MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.h2
-rw-r--r--MdeModulePkg/Core/Pei/FwVol/FwVol.c38
-rw-r--r--MdeModulePkg/Include/Ppi/UsbHostController.h249
-rw-r--r--MdeModulePkg/Include/Protocol/UfsHostControllerPlatform.h10
-rw-r--r--MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c73
-rw-r--r--MdeModulePkg/MdeModulePkg.dec11
-rw-r--r--MdeModulePkg/MdeModulePkg.dsc1
-rw-r--r--MdeModulePkg/Universal/BdsDxe/BdsDxe.inf1
-rw-r--r--MdeModulePkg/Universal/BdsDxe/BdsEntry.c4
-rw-r--r--MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c9
-rw-r--r--MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h4
-rw-r--r--MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c40
-rw-r--r--MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c3
-rw-r--r--MdeModulePkg/Universal/Variable/Pei/Variable.c4
-rw-r--r--MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c126
-rw-r--r--MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c7
-rw-r--r--MdePkg/Include/Guid/Fdt.h (renamed from EmbeddedPkg/Include/Guid/Fdt.h)5
-rw-r--r--MdePkg/Include/IndustryStandard/SmBios.h6
-rw-r--r--MdePkg/Include/Protocol/SimplePointer.h4
-rw-r--r--MdePkg/Library/BaseFdtLib/LibFdtSupport.h31
-rw-r--r--MdePkg/Library/BaseRngLib/Riscv/Rng.c95
-rw-r--r--MdePkg/MdePkg.dec4
-rw-r--r--NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c2
-rw-r--r--OvmfPkg/Library/MemDebugLogLib/MemDebugLogPei.c29
-rw-r--r--OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiCore.c30
-rw-r--r--OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiLib.inf5
-rw-r--r--OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootDefaultKeysInit/SecureBootDefaultKeysInit.c643
-rw-r--r--OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootDefaultKeysInit/SecureBootDefaultKeysInit.inf49
-rw-r--r--OvmfPkg/RiscVVirt/PlatformPei/PlatformPeim.c130
-rw-r--r--OvmfPkg/RiscVVirt/PlatformPei/PlatformPeim.inf7
-rw-r--r--OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc25
-rw-r--r--OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf28
-rw-r--r--OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf3
-rw-r--r--RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c42
-rw-r--r--SecurityPkg/FvReportPei/FvReportPei.c54
-rw-r--r--SecurityPkg/HddPassword/HddPasswordDxe.c26
-rw-r--r--SecurityPkg/Library/AuthVariableLib/AuthService.c6
-rw-r--r--SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c13
-rw-r--r--SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c111
-rw-r--r--SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c2
-rw-r--r--SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c14
-rw-r--r--SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c5
-rw-r--r--SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c5
-rw-r--r--SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c17
-rw-r--r--SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c22
-rw-r--r--SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c9
-rw-r--r--SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c2
-rw-r--r--SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c2
-rw-r--r--SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c1
-rw-r--r--SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c7
-rw-r--r--SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c6
-rw-r--r--SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c25
-rw-r--r--SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c6
-rw-r--r--SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c6
-rw-r--r--SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c16
-rw-r--r--SecurityPkg/Tcg/TcgDxe/TcgDxe.c5
-rw-r--r--SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c6
-rw-r--r--SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c46
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c12
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf1
-rw-r--r--ShellPkg/ShellPkg.ci.yaml1
-rw-r--r--StandaloneMmPkg/Core/StandaloneMmCore.c2
-rw-r--r--StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c6
-rw-r--r--UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c55
-rw-r--r--UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c34
-rw-r--r--UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h7
-rw-r--r--UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf5
-rw-r--r--UefiPayloadPkg/BlSupportDxe/X86/BlSupport.c86
-rw-r--r--UefiPayloadPkg/Include/Coreboot.h28
-rw-r--r--UefiPayloadPkg/Include/Guid/FirmwareInfoGuid.h26
-rw-r--r--UefiPayloadPkg/Include/Library/BlParseLib.h36
-rw-r--r--UefiPayloadPkg/Include/Library/SmmStoreLib.h51
-rw-r--r--UefiPayloadPkg/Library/CbParseLib/CbParseLib.c112
-rw-r--r--UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf1
-rw-r--r--UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.c1143
-rw-r--r--UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.inf47
-rw-r--r--UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.uni13
-rw-r--r--UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c33
-rw-r--r--UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c39
-rw-r--r--UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.h2
-rw-r--r--UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf2
-rw-r--r--UefiPayloadPkg/Library/SblParseLib/SblParseLib.c38
-rw-r--r--UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf2
-rw-r--r--UefiPayloadPkg/Library/SmmStoreLib/SmmStore.c174
-rw-r--r--UefiPayloadPkg/Library/SmmStoreLib/SmmStore.h4
-rw-r--r--UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.c459
-rw-r--r--UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.h20
-rw-r--r--UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf43
-rw-r--r--UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c2
-rw-r--r--UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFuncFit.c2
-rw-r--r--UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFunc.c2
-rw-r--r--UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFuncFit.c6
-rw-r--r--UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c32
-rw-r--r--UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h1
-rw-r--r--UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf1
-rw-r--r--UefiPayloadPkg/UefiPayloadPkg.dec1
-rw-r--r--UefiPayloadPkg/UefiPayloadPkg.dsc72
-rw-r--r--UefiPayloadPkg/UefiPayloadPkg.fdf11
-rw-r--r--pip-requirements.txt2
142 files changed, 4538 insertions, 6452 deletions
diff --git a/.azurepipelines/templates/defaults.yml b/.azurepipelines/templates/defaults.yml
index e6d02cd..c748459 100644
--- a/.azurepipelines/templates/defaults.yml
+++ b/.azurepipelines/templates/defaults.yml
@@ -9,4 +9,4 @@
variables:
default_python_version: "3.12"
- default_linux_image: "ghcr.io/tianocore/containers/fedora-40-test:c98ff99"
+ default_linux_image: "ghcr.io/tianocore/containers/fedora-41-test:4dbfa9e"
diff --git a/.pytool/Plugin/UncrustifyCheck/uncrustify_ext_dep.yaml b/.pytool/Plugin/UncrustifyCheck/uncrustify_ext_dep.yaml
index 74f3ffe..78b9a40 100644
--- a/.pytool/Plugin/UncrustifyCheck/uncrustify_ext_dep.yaml
+++ b/.pytool/Plugin/UncrustifyCheck/uncrustify_ext_dep.yaml
@@ -7,10 +7,13 @@
{
"id": "uncrustify-ci-1",
"scope": "cibuild",
- "type": "nuget",
- "name": "mu-uncrustify-release",
- "source": "https://pkgs.dev.azure.com/projectmu/Uncrustify/_packaging/mu_uncrustify/nuget/v3/index.json",
- "version": "73.0.8",
+ "type": "web",
+ "name": "tianocore-uncrustify-release",
+ "source": "https://github.com/tianocore/uncrustify/releases/download/73.0.10/uncrustify-release.zip",
+ "version": "73.0.10",
+ "sha256": "65d6f0f2e2bba9f25edaa1a9a5e5b9af32ba8d5c2792e467b84abfdf39b5e8ee",
+ "compression_type": "zip",
+ "internal_path": "/",
"flags": ["set_shell_var", "host_specific"],
"var_name": "UNCRUSTIFY_CI_PATH"
}
diff --git a/ArmPkg/Include/IndustryStandard/ArmTransferList.h b/ArmPkg/Include/IndustryStandard/ArmTransferList.h
index 3033846..2bc0d80 100644
--- a/ArmPkg/Include/IndustryStandard/ArmTransferList.h
+++ b/ArmPkg/Include/IndustryStandard/ArmTransferList.h
@@ -74,6 +74,12 @@
#define TRANSFER_LIST_FL_HAS_CHECKSUM BIT0
/*
+ * Flag values for TPM event log table entry layout XFERLIST_EVLOG->Flags,
+ * see https://github.com/FirmwareHandoff/firmware_handoff/blob/main/source/transfer_list.rst#tpm-event-log-table-entry-layout-xferlist_evlog
+ */
+#define TRANSFER_LIST_EVENTLOG_FL_NEED_TO_REPLAY BIT0 /* Need to replay */
+
+/*
* Operation codes indicating the validity of the Transfer List.
*/
typedef enum {
@@ -137,4 +143,18 @@ typedef struct TransferEntryHeader {
UINT32 DataSize;
} TRANSFER_ENTRY_HEADER;
+/*
+ * TPM event log information entry,
+ * see Section 'TPM event log table entry layout (XFERLIST_EVLOG)' in
+ * the Firmware Handoff specification.
+ */
+typedef struct TransferListEventLog {
+ /// See the TRANSFER_LIST_EVENT_LOG_FL_*
+ UINT32 Flags;
+
+ /// TPM event log as much as
+ /// TRNASFER_ENTRY_HEADER->DataSize - sizeof (TRANSFER_LIST_EVENTLOG)->Flags
+ UINT8 EventLog[];
+} TRANSFER_LIST_EVENTLOG;
+
#endif // ARM_TRANSFER_LIST_
diff --git a/ArmPkg/Include/Library/ArmTransferListLib.h b/ArmPkg/Include/Library/ArmTransferListLib.h
index fb0c699..09ade9f 100644
--- a/ArmPkg/Include/Library/ArmTransferListLib.h
+++ b/ArmPkg/Include/Library/ArmTransferListLib.h
@@ -19,6 +19,21 @@
#include <Pi/PiHob.h>
/**
+ Get the TransferList from HOB list.
+
+ @param[out] TransferList TransferList
+
+ @retval EFI_SUCCESS TransferList is found.
+ @retval EFI_NOT_FOUND TransferList is not found.
+
+**/
+EFI_STATUS
+EFIAPI
+TransferListGetFromHobList (
+ OUT TRANSFER_LIST_HEADER **TransferList
+ );
+
+/**
Return the first Transfer Entry Node in the Transfer List.
@param [in] TransferListHeader Pointer to the Transfer List Header.
@@ -157,4 +172,26 @@ TransferListFindEntry (
IN UINT16 TagId
);
+/**
+ Get TPM event log from TransferList
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+ @param [out] EventLog Pointer to Eventlog in TransferList
+ @param [out] EventLogSize Size of Event log
+ @param [out] EventLogFlags Flags for Event log
+
+ @return EFI_SUCCESS
+ @return EFI_NOT_FOUND No Event log in TransferListHeader
+ @return EFI_INVALID_PARAMETER Invalid parameters
+
+**/
+EFI_STATUS
+EFIAPI
+TransferListGetEventLog (
+ IN TRANSFER_LIST_HEADER *TransferListHeader,
+ OUT VOID **EventLog,
+ OUT UINTN *EventLogSize,
+ OUT UINT32 *EventLogFlags OPTIONAL
+ );
+
#endif // ARM_TRANSFER_LIST_LIB_
diff --git a/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c b/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c
index af8170e..06d6629 100644
--- a/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c
+++ b/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c
@@ -13,6 +13,45 @@
#include <Library/ArmTransferListLib.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+
+/**
+ Get the TransferList from HOB list.
+
+ @param[out] TransferList TransferList
+
+ @retval EFI_SUCCESS TransferList is found.
+ @retval EFI_NOT_FOUND TransferList is not found.
+
+**/
+EFI_STATUS
+EFIAPI
+TransferListGetFromHobList (
+ OUT TRANSFER_LIST_HEADER **TransferList
+ )
+{
+ VOID *HobList;
+ EFI_HOB_GUID_TYPE *GuidHob;
+ UINTN *GuidHobData;
+
+ *TransferList = NULL;
+
+ HobList = GetHobList ();
+ if (HobList == NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ GuidHob = GetNextGuidHob (&gArmTransferListHobGuid, HobList);
+ if (GuidHob == NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ GuidHobData = GET_GUID_HOB_DATA (GuidHob);
+
+ *TransferList = (TRANSFER_LIST_HEADER *)(*GuidHobData);
+
+ return EFI_SUCCESS;
+}
/**
This function verifies the checksum of the Transfer List.
@@ -275,6 +314,56 @@ TransferListFindEntry (
}
/**
+ Get TPM event log from TransferList
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+ @param [out] EventLog Pointer to Eventlog in TransferList
+ @param [out] EventLogSize Size of Event log
+ @param [out] EventLogFlags Flags for Event log
+
+ @return EFI_SUCCESS
+ @return EFI_NOT_FOUND No Event log in TransferListHeader
+ @return EFI_INVALID_PARAMETER Invalid parameters
+
+**/
+EFI_STATUS
+EFIAPI
+TransferListGetEventLog (
+ IN TRANSFER_LIST_HEADER *TransferListHeader,
+ OUT VOID **EventLog,
+ OUT UINTN *EventLogSize,
+ OUT UINT32 *EventLogFlags OPTIONAL
+ )
+{
+ TRANSFER_ENTRY_HEADER *Entry;
+ TRANSFER_LIST_EVENTLOG *EntryData;
+
+ if ((TransferListHeader == NULL) || (EventLog == NULL) || (EventLogSize == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *EventLog = NULL;
+ *EventLogSize = 0;
+
+ Entry = TransferListFindFirstEntry (TransferListHeader, TRANSFER_ENTRY_TAG_ID_TPM_EVENT_LOG);
+ if ((Entry == NULL) || (Entry->DataSize == 0) ||
+ ((Entry->DataSize - OFFSET_OF (TRANSFER_LIST_EVENTLOG, EventLog)) == 0))
+ {
+ return EFI_NOT_FOUND;
+ }
+
+ EntryData = TransferListGetEntryData (Entry);
+ if (EventLogFlags != NULL) {
+ *EventLogFlags = EntryData->Flags;
+ }
+
+ *EventLogSize = Entry->DataSize - OFFSET_OF (TRANSFER_LIST_EVENTLOG, EventLog);
+ *EventLog = (VOID *)&EntryData->EventLog;
+
+ return EFI_SUCCESS;
+}
+
+/**
Dump the transfer list to the debug output.
@param [in] TransferListHeader Pointer to the Transfer List Header
diff --git a/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf b/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf
index b1eeb8a..5ffb1a4 100644
--- a/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf
+++ b/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf
@@ -25,3 +25,6 @@
[LibraryClasses]
BaseLib
+
+[Guids]
+ gArmTransferListHobGuid
diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc
index d791351..2dc36d6 100644
--- a/ArmVirtPkg/ArmVirt.dsc.inc
+++ b/ArmVirtPkg/ArmVirt.dsc.inc
@@ -72,6 +72,7 @@
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
+ MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogLibNull.inf
!include OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 1e239bb..c8e8ab2 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -103,6 +103,11 @@
!endif
ArmMonitorLib|ArmVirtPkg/Library/ArmVirtMonitorLib/ArmVirtMonitorLib.inf
+!if $(DEBUG_TO_MEM)
+ MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogDxeLib.inf
+!else
+ MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogLibNull.inf
+!endif
[LibraryClasses.AARCH64]
ArmPlatformLib|ArmVirtPkg/Library/ArmPlatformLibQemu/ArmPlatformLibQemu.inf
@@ -115,6 +120,12 @@
ArmMonitorLib|ArmVirtPkg/Library/ArmVirtMonitorPeiLib/ArmVirtMonitorPeiLib.inf
FdtLib|MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
+ QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgMmioPeiLib.inf
+!if $(DEBUG_TO_MEM)
+ MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiLib.inf
+!else
+ MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogLibNull.inf
+!endif
[LibraryClasses.AARCH64.PEIM]
ArmMmuLib|UefiCpuPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf
@@ -335,6 +346,23 @@
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
!endif
+[LibraryClasses.common.SEC]
+ MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogLibNull.inf
+
+[LibraryClasses.common.PEI_CORE]
+!if $(DEBUG_TO_MEM)
+ MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiCoreLib.inf
+!else
+ MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogLibNull.inf
+!endif
+
+[LibraryClasses.common.DXE_RUNTIME_DRIVER]
+!if $(DEBUG_TO_MEM)
+ MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogRtLib.inf
+!else
+ MemDebugLogLib|OvmfPkg/Library/MemDebugLogLib/MemDebugLogLibNull.inf
+!endif
+
################################################################################
#
# Components Section - list of all EDK II Modules needed by this Platform
@@ -350,6 +378,10 @@
ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf
ArmPkg/Drivers/CpuPei/CpuPei.inf
+!if $(DEBUG_TO_MEM)
+ OvmfPkg/MemDebugLogPei/MemDebugLogPei.inf
+!endif
+
!if $(TPM2_ENABLE) == TRUE
MdeModulePkg/Universal/PCD/Pei/Pcd.inf {
<LibraryClasses>
diff --git a/ArmVirtPkg/ArmVirtQemu.fdf b/ArmVirtPkg/ArmVirtQemu.fdf
index ac2040a..1e45d51 100644
--- a/ArmVirtPkg/ArmVirtQemu.fdf
+++ b/ArmVirtPkg/ArmVirtQemu.fdf
@@ -111,6 +111,10 @@ READ_LOCK_STATUS = TRUE
INF ArmPkg/Drivers/CpuPei/CpuPei.inf
INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
+!if $(DEBUG_TO_MEM)
+ INF OvmfPkg/MemDebugLogPei/MemDebugLogPei.inf
+!endif
+
!if $(TPM2_ENABLE) == TRUE
INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
INF MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf
diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLib.c b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLib.c
index 83d52e9..18222aa 100644
--- a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLib.c
+++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLib.c
@@ -24,6 +24,7 @@
#include <Library/PcdLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugPrintErrorLevelLib.h>
+#include <Library/MemDebugLogLib.h>
#include "Write.h"
@@ -117,6 +118,13 @@ DebugPrintMarker (
}
//
+ // Send string to Memory Debug Log if enabled
+ //
+ if (MemDebugLogEnabled ()) {
+ MemDebugLogWrite ((CHAR8 *)Buffer, AsciiStrLen (Buffer));
+ }
+
+ //
// Send the print string to a Serial Port
//
DebugLibFdtPL011UartWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
@@ -213,6 +221,13 @@ DebugAssert (
AsciiSPrint (Buffer, sizeof (Buffer), "ASSERT [%a] %a(%d): %a\n", gEfiCallerBaseName, FileName, LineNumber, Description);
//
+ // Send string to Memory Debug Log if enabled
+ //
+ if (MemDebugLogEnabled ()) {
+ MemDebugLogWrite ((CHAR8 *)Buffer, AsciiStrLen (Buffer));
+ }
+
+ //
// Send the print string to the Console Output device
//
DebugLibFdtPL011UartWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFlash.inf b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFlash.inf
index f35a091..6b3b331 100644
--- a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFlash.inf
+++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartFlash.inf
@@ -40,6 +40,7 @@
PL011UartLib
PcdLib
PrintLib
+ MemDebugLogLib
[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress # Flash.c
diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartRam.inf b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartRam.inf
index a5f4c2d..568fc3e 100644
--- a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartRam.inf
+++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLibFdtPL011UartRam.inf
@@ -34,6 +34,7 @@
ArmPlatformPkg/ArmPlatformPkg.dec
ArmVirtPkg/ArmVirtPkg.dec
MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
[LibraryClasses]
BaseLib
@@ -43,6 +44,7 @@
PL011UartLib
PcdLib
PrintLib
+ MemDebugLogLib
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue
diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL011Uart.inf b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL011Uart.inf
index 84e9dba..1ae3f99 100644
--- a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL011Uart.inf
+++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL011Uart.inf
@@ -35,6 +35,7 @@
ArmPlatformPkg/ArmPlatformPkg.dec
ArmVirtPkg/ArmVirtPkg.dec
MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
[LibraryClasses]
BaseLib
@@ -44,6 +45,7 @@
PL011UartLib
PcdLib
PrintLib
+ MemDebugLogLib
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue
diff --git a/BaseTools/Source/C/VfrCompile/VfrSyntax.g b/BaseTools/Source/C/VfrCompile/VfrSyntax.g
index 942e0ed..0f17b9d 100644
--- a/BaseTools/Source/C/VfrCompile/VfrSyntax.g
+++ b/BaseTools/Source/C/VfrCompile/VfrSyntax.g
@@ -2,6 +2,7 @@
Vfr Syntax
Copyright (c) 2004 - 2025, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2025, Loongson Technology Corporation Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
--*/
@@ -1618,7 +1619,7 @@ vfrConstantValueField[UINT8 Type, EFI_IFR_TYPE_VALUE &Value, BOOLEAN &ListType]
$Value.b = _STOU8(N1->getText(), N1->getLine());
break;
case EFI_IFR_TYPE_STRING :
- $Value.string = _STOU16(N1->getText(), N1->getLine());
+ _PCATCH (VFR_RETURN_INVALID_PARAMETER, N1->getLine(), "string type can't be numeric constant.");
break;
case EFI_IFR_TYPE_TIME :
case EFI_IFR_TYPE_DATE :
@@ -3127,7 +3128,7 @@ vfrStatementString :
UINT8 StringMaxSize;
>>
L:String << SObj.SetLineNo(L->getLine()); gIsStringOp = TRUE;>>
- vfrQuestionHeader[SObj] ","
+ vfrQuestionHeader[SObj] "," << _GET_CURRQEST_VARTINFO().mVarType = EFI_IFR_TYPE_STRING;>>
{ F:FLAGS "=" vfrStringFlagsField[SObj, F->getLine()] "," }
{
Key "=" KN:Number "," << AssignQuestionKey (SObj, KN); >>
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index ed1ccb1..5d2a444 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -1407,7 +1407,11 @@ class DscParser(MetaFileParser):
if self._ContentIndex >= len(self._Content):
break
Record = self._Content[self._ContentIndex]
- if LineStart == Record[10] and LineEnd == Record[12]:
+ #
+ # Avoid merging includes with different owners to make sure an
+ # include is correctly processed per arch.
+ #
+ if Owner == Record[8] and LineStart == Record[10] and LineEnd == Record[12]:
if [Record[5], Record[6], Record[7]] not in self._Scope:
self._Scope.append([Record[5], Record[6], Record[7]])
self._ContentIndex += 1
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPem.c b/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPem.c
index 5641117..ddcf8f4 100644
--- a/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPem.c
+++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Pem/CryptPem.c
@@ -57,7 +57,7 @@ RsaGetPrivateKeyFromPem (
return FALSE;
}
- CopyMem (NewPemData, PemData, PemSize + 1);
+ CopyMem (NewPemData, PemData, PemSize);
NewPemData[PemSize] = 0;
PemData = NewPemData;
PemSize += 1;
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/UnitTestHostBaseCryptLib.inf b/CryptoPkg/Library/BaseCryptLibMbedTls/UnitTestHostBaseCryptLib.inf
new file mode 100644
index 0000000..ae1f0b3
--- /dev/null
+++ b/CryptoPkg/Library/BaseCryptLibMbedTls/UnitTestHostBaseCryptLib.inf
@@ -0,0 +1,86 @@
+## @file
+# Cryptographic Library Instance for Unit Test Host.
+#
+# Caution: This module requires additional review when modified.
+# This library will have external input - signature.
+# This external input must be validated carefully to avoid security issues such as
+# buffer overflow or integer overflow.
+#
+# Copyright (c) 2025, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = BaseCryptLib
+ FILE_GUID = 5C14CE62-000E-4CC6-803C-683018EA5F97
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = BaseCryptLib|HOST_APPLICATION
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ InternalCryptLib.h
+ Hash/CryptMd5.c
+ Hash/CryptSha1.c
+ Hash/CryptSha256.c
+ Hash/CryptSha512.c
+ Hash/CryptParallelHashNull.c
+ Hash/CryptSm3.c
+ Hmac/CryptHmac.c
+ Kdf/CryptHkdf.c
+ Cipher/CryptAes.c
+ Cipher/CryptAeadAesGcm.c
+ Pk/CryptRsaBasic.c
+ Pk/CryptRsaExt.c
+ Pk/CryptPkcs1Oaep.c
+ Pk/CryptPkcs5Pbkdf2.c
+ Pk/CryptPkcs7Sign.c
+ Pk/CryptPkcs7VerifyCommon.c
+ Pk/CryptPkcs7VerifyBase.c
+ Pk/CryptPkcs7VerifyEku.c
+ Pk/CryptDhNull.c
+ Pk/CryptX509.c
+ Pk/CryptAuthenticode.c
+ Pk/CryptTs.c
+ Pk/CryptRsaPss.c
+ Pk/CryptRsaPssSign.c
+ Pk/CryptEcNull.c
+ Pem/CryptPem.c
+ Bn/CryptBnNull.c
+ Rand/CryptRand.c
+
+ SysCall/CrtWrapper.c
+ SysCall/UnitTestHostCrtWrapper.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ CryptoPkg/CryptoPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ DebugLib
+ MbedTlsLib
+ OpensslLib
+ PrintLib
+ RngLib
+
+#
+# Remove these [BuildOptions] after this library is cleaned up
+#
+[BuildOptions]
+ #
+ # suppress the following warnings so we do not break the build with warnings-as-errors:
+ #
+ GCC:*_CLANGDWARF_*_CC_FLAGS = -std=c99 -Wno-error=incompatible-pointer-types
+ GCC:*_CLANGPDB_*_CC_FLAGS = -std=c99 -Wno-error=incompatible-pointer-types
+
+ XCODE:*_*_*_CC_FLAGS = -std=c99
diff --git a/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc b/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc
index e22363a..d4d9bf0 100644
--- a/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc
+++ b/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc
@@ -17,6 +17,15 @@
BUILD_TARGETS = NOOPT
SKUID_IDENTIFIER = DEFAULT
+!ifndef CRYPTO_TEST_TYPE
+ DEFINE CRYPTO_TEST_TYPE = OPENSSL
+!endif
+
+!if $(CRYPTO_TEST_TYPE) IN "OPENSSL MBEDTLS"
+!else
+ !error CRYPTO_TEST_TYPE must be set to one of OPENSSL MBEDTLS.
+!endif
+
!include UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
!include CryptoPkg/CryptoPkgFeatureFlagPcds.dsc.inc
@@ -34,6 +43,7 @@
#
# Build HOST_APPLICATION that tests the SampleUnitTest
#
+!if $(CRYPTO_TEST_TYPE) IN "OPENSSL"
CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf {
<LibraryClasses>
OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibFull.inf
@@ -44,6 +54,16 @@
<LibraryClasses>
OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf
}
+!endif
+
+!if $(CRYPTO_TEST_TYPE) IN "MBEDTLS"
+ CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf {
+ <LibraryClasses>
+ BaseCryptLib|CryptoPkg/Library/BaseCryptLibMbedTls/UnitTestHostBaseCryptLib.inf
+ OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibSm3.inf
+ MbedTlsLib|CryptoPkg/Library/MbedTlsLib/MbedTlsLib.inf
+ }
+!endif
[BuildOptions]
*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/RsaPkcs7Tests.c b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/RsaPkcs7Tests.c
index aba049f..dcb9323 100644
--- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/RsaPkcs7Tests.c
+++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/RsaPkcs7Tests.c
@@ -228,6 +228,164 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 TestCert[] = {
};
//
+// TestCase2: Non self issued CA (partial certificate chains)
+//
+//
+// Password-protected PEM Key data for RSA Private Key Retrieving (encryption key is "non-self-issued").
+// (Generated by OpenSSL utility).
+// $ openssl genrsa -aes256 -out TestKeyCert2Pem -passout pass:non-self-issued 1024
+// password should match TestKeyCert2PemPass in this file
+// $ xxd --include TestKeyCert2Pem
+//
+GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 TestKeyCert2Pem[] = {
+ 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52,
+ 0x53, 0x41, 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b,
+ 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0d, 0x0a, 0x50, 0x72, 0x6f,
+ 0x63, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x34, 0x2c, 0x45, 0x4e,
+ 0x43, 0x52, 0x59, 0x50, 0x54, 0x45, 0x44, 0x0d, 0x0a, 0x44, 0x45, 0x4b,
+ 0x2d, 0x49, 0x6e, 0x66, 0x6f, 0x3a, 0x20, 0x41, 0x45, 0x53, 0x2d, 0x32,
+ 0x35, 0x36, 0x2d, 0x43, 0x42, 0x43, 0x2c, 0x39, 0x43, 0x39, 0x38, 0x32,
+ 0x33, 0x31, 0x38, 0x42, 0x46, 0x37, 0x38, 0x33, 0x38, 0x46, 0x34, 0x32,
+ 0x45, 0x34, 0x33, 0x31, 0x32, 0x42, 0x42, 0x30, 0x43, 0x39, 0x31, 0x33,
+ 0x36, 0x43, 0x44, 0x0d, 0x0a, 0x0d, 0x0a, 0x62, 0x32, 0x77, 0x62, 0x64,
+ 0x75, 0x49, 0x30, 0x76, 0x6b, 0x48, 0x41, 0x6c, 0x45, 0x4a, 0x78, 0x30,
+ 0x6d, 0x69, 0x64, 0x57, 0x6f, 0x77, 0x6d, 0x71, 0x32, 0x62, 0x64, 0x75,
+ 0x65, 0x4f, 0x7a, 0x49, 0x71, 0x44, 0x59, 0x46, 0x6e, 0x4d, 0x41, 0x76,
+ 0x79, 0x58, 0x5a, 0x45, 0x74, 0x45, 0x4c, 0x79, 0x42, 0x41, 0x72, 0x7a,
+ 0x4c, 0x6c, 0x55, 0x72, 0x54, 0x73, 0x78, 0x41, 0x49, 0x62, 0x73, 0x0d,
+ 0x0a, 0x47, 0x4d, 0x46, 0x45, 0x47, 0x44, 0x59, 0x46, 0x69, 0x72, 0x7a,
+ 0x6c, 0x55, 0x77, 0x2f, 0x54, 0x6a, 0x36, 0x43, 0x2f, 0x78, 0x71, 0x45,
+ 0x67, 0x76, 0x79, 0x2b, 0x6c, 0x47, 0x57, 0x42, 0x46, 0x6b, 0x6c, 0x64,
+ 0x34, 0x7a, 0x49, 0x2b, 0x68, 0x73, 0x62, 0x77, 0x45, 0x70, 0x53, 0x6d,
+ 0x36, 0x4a, 0x61, 0x6a, 0x4e, 0x73, 0x69, 0x61, 0x79, 0x35, 0x6f, 0x6f,
+ 0x37, 0x6b, 0x41, 0x54, 0x68, 0x0d, 0x0a, 0x69, 0x6e, 0x51, 0x54, 0x33,
+ 0x43, 0x71, 0x76, 0x6e, 0x64, 0x41, 0x44, 0x50, 0x44, 0x5a, 0x72, 0x6f,
+ 0x38, 0x7a, 0x44, 0x52, 0x64, 0x4d, 0x2b, 0x58, 0x67, 0x65, 0x53, 0x42,
+ 0x37, 0x69, 0x65, 0x78, 0x6a, 0x55, 0x32, 0x55, 0x69, 0x42, 0x48, 0x4e,
+ 0x6b, 0x73, 0x76, 0x52, 0x77, 0x49, 0x4f, 0x75, 0x52, 0x50, 0x57, 0x41,
+ 0x75, 0x56, 0x4c, 0x41, 0x77, 0x6e, 0x6a, 0x57, 0x79, 0x66, 0x51, 0x0d,
+ 0x0a, 0x6e, 0x39, 0x52, 0x59, 0x4e, 0x78, 0x44, 0x37, 0x63, 0x73, 0x2f,
+ 0x56, 0x54, 0x38, 0x50, 0x50, 0x55, 0x75, 0x35, 0x69, 0x4d, 0x70, 0x65,
+ 0x4e, 0x49, 0x6a, 0x44, 0x44, 0x6a, 0x48, 0x5a, 0x2b, 0x78, 0x2f, 0x75,
+ 0x37, 0x77, 0x6e, 0x75, 0x46, 0x65, 0x76, 0x56, 0x73, 0x62, 0x67, 0x4e,
+ 0x50, 0x76, 0x4e, 0x78, 0x74, 0x6a, 0x74, 0x6a, 0x33, 0x66, 0x73, 0x6c,
+ 0x49, 0x75, 0x6d, 0x6c, 0x59, 0x0d, 0x0a, 0x53, 0x36, 0x35, 0x6b, 0x41,
+ 0x59, 0x6f, 0x36, 0x2f, 0x69, 0x51, 0x69, 0x50, 0x2b, 0x48, 0x52, 0x2b,
+ 0x59, 0x71, 0x57, 0x55, 0x53, 0x73, 0x4e, 0x7a, 0x55, 0x6f, 0x35, 0x52,
+ 0x72, 0x49, 0x51, 0x6d, 0x41, 0x52, 0x2f, 0x74, 0x66, 0x66, 0x55, 0x5a,
+ 0x66, 0x69, 0x4f, 0x37, 0x76, 0x53, 0x67, 0x4b, 0x49, 0x32, 0x47, 0x72,
+ 0x4e, 0x66, 0x69, 0x5a, 0x55, 0x6c, 0x49, 0x4f, 0x49, 0x7a, 0x39, 0x0d,
+ 0x0a, 0x67, 0x78, 0x56, 0x58, 0x73, 0x56, 0x69, 0x56, 0x2b, 0x47, 0x6b,
+ 0x70, 0x52, 0x49, 0x5a, 0x71, 0x7a, 0x46, 0x38, 0x53, 0x76, 0x4d, 0x72,
+ 0x35, 0x57, 0x4b, 0x63, 0x51, 0x49, 0x4b, 0x79, 0x61, 0x44, 0x52, 0x66,
+ 0x72, 0x57, 0x54, 0x75, 0x55, 0x4b, 0x4a, 0x67, 0x50, 0x57, 0x77, 0x30,
+ 0x42, 0x70, 0x45, 0x43, 0x65, 0x62, 0x6c, 0x77, 0x58, 0x79, 0x42, 0x56,
+ 0x70, 0x4b, 0x55, 0x72, 0x71, 0x0d, 0x0a, 0x77, 0x67, 0x56, 0x6c, 0x55,
+ 0x37, 0x42, 0x55, 0x55, 0x4b, 0x57, 0x6c, 0x36, 0x52, 0x66, 0x38, 0x32,
+ 0x42, 0x4d, 0x59, 0x63, 0x75, 0x47, 0x39, 0x2f, 0x36, 0x6a, 0x37, 0x61,
+ 0x4b, 0x6c, 0x6b, 0x42, 0x67, 0x42, 0x41, 0x33, 0x58, 0x75, 0x32, 0x33,
+ 0x68, 0x42, 0x64, 0x45, 0x33, 0x63, 0x55, 0x30, 0x47, 0x5a, 0x74, 0x50,
+ 0x66, 0x78, 0x33, 0x65, 0x4d, 0x64, 0x69, 0x2f, 0x6e, 0x4b, 0x4b, 0x0d,
+ 0x0a, 0x32, 0x66, 0x74, 0x33, 0x71, 0x79, 0x71, 0x2b, 0x32, 0x47, 0x56,
+ 0x73, 0x63, 0x74, 0x48, 0x65, 0x30, 0x75, 0x68, 0x37, 0x44, 0x4a, 0x6a,
+ 0x55, 0x30, 0x78, 0x37, 0x59, 0x48, 0x4f, 0x4f, 0x52, 0x51, 0x6b, 0x4f,
+ 0x79, 0x77, 0x79, 0x72, 0x6b, 0x34, 0x45, 0x61, 0x44, 0x42, 0x73, 0x72,
+ 0x71, 0x44, 0x6e, 0x51, 0x7a, 0x76, 0x2b, 0x4c, 0x34, 0x61, 0x70, 0x4a,
+ 0x71, 0x44, 0x31, 0x39, 0x72, 0x0d, 0x0a, 0x72, 0x64, 0x2b, 0x6e, 0x47,
+ 0x38, 0x75, 0x4d, 0x4b, 0x2f, 0x32, 0x4c, 0x38, 0x62, 0x73, 0x53, 0x71,
+ 0x4e, 0x7a, 0x46, 0x52, 0x2f, 0x46, 0x64, 0x51, 0x77, 0x6f, 0x39, 0x32,
+ 0x5a, 0x33, 0x6b, 0x4c, 0x63, 0x6a, 0x36, 0x61, 0x31, 0x36, 0x50, 0x6b,
+ 0x2f, 0x78, 0x38, 0x6e, 0x64, 0x70, 0x67, 0x54, 0x58, 0x35, 0x6a, 0x71,
+ 0x44, 0x41, 0x72, 0x4b, 0x36, 0x79, 0x38, 0x43, 0x65, 0x48, 0x70, 0x0d,
+ 0x0a, 0x33, 0x75, 0x48, 0x4b, 0x67, 0x77, 0x45, 0x52, 0x30, 0x52, 0x30,
+ 0x43, 0x34, 0x33, 0x6f, 0x37, 0x61, 0x41, 0x76, 0x6f, 0x79, 0x76, 0x5a,
+ 0x36, 0x44, 0x4e, 0x75, 0x5a, 0x46, 0x77, 0x65, 0x7a, 0x7a, 0x4c, 0x50,
+ 0x31, 0x35, 0x33, 0x78, 0x36, 0x35, 0x78, 0x75, 0x4b, 0x47, 0x57, 0x33,
+ 0x5a, 0x2b, 0x38, 0x68, 0x63, 0x5a, 0x53, 0x42, 0x32, 0x2b, 0x79, 0x76,
+ 0x33, 0x74, 0x36, 0x56, 0x69, 0x0d, 0x0a, 0x39, 0x45, 0x4b, 0x51, 0x65,
+ 0x58, 0x65, 0x36, 0x7a, 0x4f, 0x5a, 0x57, 0x36, 0x74, 0x42, 0x6d, 0x4a,
+ 0x51, 0x2f, 0x51, 0x65, 0x66, 0x51, 0x37, 0x45, 0x34, 0x70, 0x62, 0x78,
+ 0x65, 0x54, 0x46, 0x43, 0x4e, 0x33, 0x56, 0x4c, 0x51, 0x41, 0x75, 0x31,
+ 0x4d, 0x47, 0x75, 0x4b, 0x48, 0x70, 0x30, 0x5a, 0x59, 0x39, 0x42, 0x58,
+ 0x4f, 0x62, 0x77, 0x44, 0x48, 0x53, 0x39, 0x57, 0x51, 0x67, 0x6d, 0x0d,
+ 0x0a, 0x79, 0x31, 0x66, 0x37, 0x78, 0x70, 0x77, 0x30, 0x34, 0x38, 0x69,
+ 0x68, 0x67, 0x6c, 0x70, 0x32, 0x6e, 0x44, 0x32, 0x63, 0x72, 0x4b, 0x4b,
+ 0x57, 0x57, 0x38, 0x68, 0x6d, 0x41, 0x59, 0x6d, 0x6f, 0x51, 0x63, 0x42,
+ 0x36, 0x4f, 0x73, 0x58, 0x4f, 0x36, 0x45, 0x35, 0x77, 0x73, 0x4b, 0x65,
+ 0x75, 0x59, 0x41, 0x30, 0x6f, 0x79, 0x65, 0x61, 0x33, 0x6a, 0x6e, 0x55,
+ 0x4b, 0x71, 0x6a, 0x41, 0x58, 0x0d, 0x0a, 0x49, 0x56, 0x73, 0x43, 0x79,
+ 0x75, 0x68, 0x50, 0x48, 0x78, 0x65, 0x2b, 0x58, 0x38, 0x6e, 0x67, 0x38,
+ 0x52, 0x30, 0x72, 0x70, 0x78, 0x41, 0x30, 0x4d, 0x6f, 0x78, 0x71, 0x71,
+ 0x72, 0x67, 0x71, 0x78, 0x46, 0x32, 0x61, 0x4c, 0x33, 0x39, 0x38, 0x6d,
+ 0x51, 0x54, 0x46, 0x4f, 0x68, 0x4b, 0x46, 0x62, 0x2b, 0x73, 0x41, 0x69,
+ 0x6e, 0x7a, 0x34, 0x48, 0x59, 0x52, 0x59, 0x65, 0x4b, 0x72, 0x48, 0x0d,
+ 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53,
+ 0x41, 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4b, 0x45,
+ 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0d, 0x0a
+};
+//
+// Password for private key retrieving from encrypted PEM ("TestKeyCert2PemPass").
+//
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *TestKeyCert2PemPass = "non-self-issued";
+//
+// X509 Cert Data for RSA Public Key Retrieving and X509 Verification (Generated by OpenSSL utility).
+// $ openssl req -new -key TestKeyCert2Pem -out TestCertCsr2 -subj "/C=US/ST=WA/L=Seattle/O=Tianocore/OU=EDK2CHILD/CN=UEFINOSELFISSUED"
+// $ openssl x509 -days 10000 -CA TestCACert.pem -CAkey TestKeyPem -req -out TestCert2 -set_serial 3432 --outform DER -in TestCertCsr2
+// password should be in the PemPass variable
+// $ xxd --include TestCert2
+GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 TestCert2[] = {
+ 0x30, 0x82, 0x02, 0x3f, 0x30, 0x82, 0x01, 0xa8, 0x02, 0x02, 0x0d, 0x68,
+ 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
+ 0x0b, 0x05, 0x00, 0x30, 0x5e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
+ 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
+ 0x55, 0x04, 0x08, 0x0c, 0x02, 0x57, 0x41, 0x31, 0x10, 0x30, 0x0e, 0x06,
+ 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c,
+ 0x65, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x09,
+ 0x54, 0x69, 0x61, 0x6e, 0x6f, 0x63, 0x6f, 0x72, 0x65, 0x31, 0x0d, 0x30,
+ 0x0b, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x04, 0x45, 0x44, 0x4b, 0x32,
+ 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x04, 0x55,
+ 0x45, 0x46, 0x49, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x35, 0x30, 0x38, 0x32,
+ 0x31, 0x30, 0x33, 0x34, 0x36, 0x35, 0x34, 0x5a, 0x18, 0x0f, 0x32, 0x30,
+ 0x35, 0x33, 0x30, 0x31, 0x30, 0x36, 0x30, 0x33, 0x34, 0x36, 0x35, 0x34,
+ 0x5a, 0x30, 0x6f, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06,
+ 0x13, 0x02, 0x55, 0x53, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
+ 0x08, 0x0c, 0x02, 0x57, 0x41, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
+ 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31,
+ 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x09, 0x54, 0x69,
+ 0x61, 0x6e, 0x6f, 0x63, 0x6f, 0x72, 0x65, 0x31, 0x12, 0x30, 0x10, 0x06,
+ 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x09, 0x45, 0x44, 0x4b, 0x32, 0x43, 0x48,
+ 0x49, 0x4c, 0x44, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03,
+ 0x0c, 0x10, 0x55, 0x45, 0x46, 0x49, 0x4e, 0x4f, 0x53, 0x45, 0x4c, 0x46,
+ 0x49, 0x53, 0x53, 0x55, 0x45, 0x44, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06,
+ 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00,
+ 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xa3,
+ 0x08, 0x50, 0xc5, 0x20, 0xea, 0x2c, 0xf6, 0xfe, 0xa9, 0xa0, 0xee, 0x9b,
+ 0xa1, 0xd7, 0x5a, 0x24, 0x99, 0x8f, 0xe3, 0x27, 0xd9, 0xbf, 0x59, 0x73,
+ 0x5d, 0x88, 0x1a, 0x0d, 0x98, 0x0e, 0xaf, 0xe8, 0x98, 0x77, 0x67, 0x04,
+ 0xdc, 0x6d, 0x2d, 0xea, 0x3d, 0x94, 0x35, 0x56, 0x85, 0x4b, 0xad, 0xd3,
+ 0xb5, 0x19, 0xcb, 0x6e, 0x3f, 0xeb, 0x4c, 0x31, 0x85, 0xb5, 0xf5, 0x6c,
+ 0x5c, 0xd1, 0x71, 0x05, 0xef, 0x39, 0xf5, 0x0a, 0xca, 0x73, 0x0d, 0x4e,
+ 0xdc, 0x76, 0x29, 0xa3, 0xc7, 0x0d, 0xb7, 0x96, 0x83, 0x38, 0xaa, 0x49,
+ 0x93, 0xc9, 0x17, 0xe7, 0x13, 0xb6, 0xd3, 0xb5, 0xc0, 0xe4, 0x27, 0xd0,
+ 0x4f, 0x4a, 0x82, 0xe4, 0x79, 0x7e, 0xcc, 0xf5, 0x25, 0xb9, 0x2c, 0xe3,
+ 0xcd, 0xf1, 0x8b, 0xc3, 0x5a, 0x37, 0x5d, 0xe7, 0x34, 0xef, 0x9e, 0xd0,
+ 0xb9, 0x5a, 0x0c, 0xdc, 0x30, 0x13, 0xdf, 0x02, 0x03, 0x01, 0x00, 0x01,
+ 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
+ 0x0b, 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, 0x87, 0x53, 0xea, 0x99, 0xbc,
+ 0x6d, 0xc4, 0xd3, 0x7f, 0xb2, 0xca, 0xe7, 0x19, 0x44, 0xc5, 0xcf, 0xdf,
+ 0xcb, 0x41, 0xee, 0x3b, 0xf6, 0x4f, 0x2a, 0x48, 0x5f, 0x32, 0xca, 0x11,
+ 0xae, 0x21, 0x46, 0x5d, 0xb4, 0xb0, 0x8a, 0x6b, 0x43, 0x4a, 0xc1, 0x49,
+ 0xc9, 0x83, 0x61, 0xce, 0x3f, 0x90, 0x7d, 0xc5, 0x0b, 0x5c, 0x93, 0xb7,
+ 0x76, 0x2b, 0xe5, 0x2f, 0xac, 0xb2, 0xc6, 0x3d, 0x82, 0xee, 0x70, 0x4a,
+ 0x0a, 0x62, 0x5e, 0xb2, 0x33, 0xe0, 0xed, 0xcc, 0x83, 0xbd, 0x45, 0x27,
+ 0x94, 0xc1, 0x98, 0x84, 0x9e, 0x22, 0x00, 0xa8, 0xfe, 0x18, 0x0a, 0xe7,
+ 0xaa, 0x23, 0xaf, 0x6e, 0xaa, 0xe5, 0x03, 0x55, 0x37, 0x5a, 0x98, 0x08,
+ 0x7b, 0xab, 0x4c, 0xba, 0x46, 0x27, 0xf1, 0xd3, 0x63, 0x16, 0x20, 0x2f,
+ 0xe8, 0x58, 0xd6, 0x34, 0x3f, 0x83, 0xe5, 0x33, 0x5b, 0xf5, 0x6e, 0x6a,
+ 0x25, 0x9f, 0x16
+};
+
+//
// Message Hash for Signing & Verification Validation.
//
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 MsgHash[] = {
@@ -426,6 +584,72 @@ TestVerifyPkcs7SignVerify (
return UNIT_TEST_PASSED;
}
+//
+// TestCase2: Non self issued CA (partial certificate chains)
+// This case uses a non-self-issued certificate as the signing certificate and CA.
+// BaseCryptLib can pass this case (with X509_V_FLAG_PARTIAL_CHAIN enabled).
+// BaseCryptLibMbedTls cannot, because Mbedtls certificate chain validation lacks support for partial certificate chains currently .
+//
+UNIT_TEST_STATUS
+EFIAPI
+TestVerifyPkcs7SignVerifyNonSelfIssued (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ BOOLEAN Status;
+ UINT8 *P7SignedData;
+ UINTN P7SignedDataSize;
+ UINT8 *SignCert;
+
+ P7SignedData = NULL;
+ SignCert = NULL;
+
+ //
+ // Construct Signer Certificate from RAW data.
+ //
+ Status = X509ConstructCertificate (TestCert2, sizeof (TestCert2), (UINT8 **)&SignCert);
+ UT_ASSERT_TRUE (Status);
+ UT_ASSERT_NOT_NULL (SignCert);
+
+ //
+ // Create PKCS#7 signedData on Payload.
+ // Note: Caller should release P7SignedData manually.
+ //
+ Status = Pkcs7Sign (
+ TestKeyCert2Pem,
+ sizeof (TestKeyCert2Pem),
+ (CONST UINT8 *)TestKeyCert2PemPass,
+ (UINT8 *)Payload,
+ AsciiStrLen (Payload),
+ SignCert,
+ NULL,
+ &P7SignedData,
+ &P7SignedDataSize
+ );
+ UT_ASSERT_TRUE (Status);
+ UT_ASSERT_NOT_EQUAL (P7SignedDataSize, 0);
+
+ Status = Pkcs7Verify (
+ P7SignedData,
+ P7SignedDataSize,
+ TestCert2,
+ sizeof (TestCert2),
+ (UINT8 *)Payload,
+ AsciiStrLen (Payload)
+ );
+ UT_ASSERT_TRUE (Status);
+
+ if (P7SignedData != NULL) {
+ FreePool (P7SignedData);
+ }
+
+ if (SignCert != NULL) {
+ X509Free (SignCert);
+ }
+
+ return UNIT_TEST_PASSED;
+}
+
TEST_DESC mRsaCertTest[] = {
//
// -----Description--------------------------------------Class----------------------Function-----------------Pre---Post--Context
@@ -439,7 +663,8 @@ TEST_DESC mPkcs7Test[] = {
//
// -----Description--------------------------------------Class----------------------Function-----------------Pre---Post--Context
//
- { "TestVerifyPkcs7SignVerify()", "CryptoPkg.BaseCryptLib.Pkcs7", TestVerifyPkcs7SignVerify, NULL, NULL, NULL },
+ { "TestVerifyPkcs7SignVerify()", "CryptoPkg.BaseCryptLib.Pkcs7", TestVerifyPkcs7SignVerify, NULL, NULL, NULL },
+ { "TestVerifyPkcs7SignVerifyNonSelfIssued()", "CryptoPkg.BaseCryptLib.Pkcs7", TestVerifyPkcs7SignVerifyNonSelfIssued, NULL, NULL, NULL },
};
UINTN mPkcs7TestNum = ARRAY_SIZE (mPkcs7Test);
diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec
index d386bda..4f0de24 100644
--- a/EmbeddedPkg/EmbeddedPkg.dec
+++ b/EmbeddedPkg/EmbeddedPkg.dec
@@ -50,10 +50,6 @@
[Guids.common]
gEmbeddedTokenSpaceGuid = { 0xe0d8ca17, 0x4276, 0x4386, { 0xbb, 0x79, 0x48, 0xcb, 0x81, 0x3d, 0x3c, 0x4f }}
- ## FDT Configuration Table
- # Include/Guid/Fdt.h
- gFdtTableGuid = { 0xb1b621d5, 0xf19c, 0x41a5, { 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 } }
- gFdtVariableGuid = { 0x25a4fd4a, 0x9703, 0x4ba9, { 0xa1, 0x90, 0xb7, 0xc8, 0x4e, 0xfb, 0x3e, 0x57 } }
## Include/Guid/PlatformHasDeviceTree.h
gEdkiiPlatformHasDeviceTreeGuid = { 0x7ebb920d, 0x1aaf, 0x46d9, { 0xb2, 0xaf, 0x54, 0x1e, 0x1d, 0xce, 0x14, 0x8b } }
diff --git a/Maintainers.txt b/Maintainers.txt
index 6beda4c..8be4f96 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -615,7 +615,7 @@ R: Min Xu <min.m.xu@intel.com> [mxu9]
SecurityPkg: Tcg related modules
F: SecurityPkg/Tcg/
-R: Rahul Kumar <rahul1.kumar@intel.com> [rahul1-kumar]
+R: Arun Subramanian Baskaran <arun.subramanian.baskaran@intel.com> [arunsbaskaran]
SecurityPkg: SVSM related modules
F: SecurityPkg/Library/Tpm2DeviceLibDTpm/*Svsm*
@@ -657,7 +657,7 @@ M: Ray Ni <ray.ni@intel.com> [niruiyu]
M: Jiaxin Wu <jiaxin.wu@intel.com> [jiaxinwu]
R: Zhiguang Liu <zhiguang.liu@intel.com> [LiuZhiguang001]
R: Dun Tan <dun.tan@intel.com> [td36]
-R: Rahul Kumar <rahul1.kumar@intel.com> [rahul1-kumar]
+R: Arun Subramanian Baskaran <arun.subramanian.baskaran@intel.com> [arunsbaskaran]
R: Gerd Hoffmann <kraxel@redhat.com> [kraxel]
R: Star Zeng <star.zeng@intel.com> [lzeng14]
R: Eduardo Cuevas Farfan <eduardo.cuevas.farfan@intel.com> [ecuevasf]
diff --git a/MdeModulePkg/Bus/Pci/UhciPei/DmaMem.c b/MdeModulePkg/Bus/Pci/UhciPei/DmaMem.c
deleted file mode 100644
index c6ef129..0000000
--- a/MdeModulePkg/Bus/Pci/UhciPei/DmaMem.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/** @file
-The DMA memory help functions.
-
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
-
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "UhcPeim.h"
-
-/**
- Provides the controller-specific addresses required to access system memory from a
- DMA bus master.
-
- @param IoMmu Pointer to IOMMU PPI.
- @param Operation Indicates if the bus master is going to read or write to system memory.
- @param HostAddress The system memory address to map to the PCI controller.
- @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
- that were mapped.
- @param DeviceAddress The resulting map address for the bus master PCI controller to use to
- access the hosts HostAddress.
- @param Mapping A resulting value to pass to Unmap().
-
- @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
- @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
- @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
-
-**/
-EFI_STATUS
-IoMmuMap (
- IN EDKII_IOMMU_PPI *IoMmu,
- IN EDKII_IOMMU_OPERATION Operation,
- IN VOID *HostAddress,
- IN OUT UINTN *NumberOfBytes,
- OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
- OUT VOID **Mapping
- )
-{
- EFI_STATUS Status;
- UINT64 Attribute;
-
- if (IoMmu != NULL) {
- Status = IoMmu->Map (
- IoMmu,
- Operation,
- HostAddress,
- NumberOfBytes,
- DeviceAddress,
- Mapping
- );
- if (EFI_ERROR (Status)) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- switch (Operation) {
- case EdkiiIoMmuOperationBusMasterRead:
- case EdkiiIoMmuOperationBusMasterRead64:
- Attribute = EDKII_IOMMU_ACCESS_READ;
- break;
- case EdkiiIoMmuOperationBusMasterWrite:
- case EdkiiIoMmuOperationBusMasterWrite64:
- Attribute = EDKII_IOMMU_ACCESS_WRITE;
- break;
- case EdkiiIoMmuOperationBusMasterCommonBuffer:
- case EdkiiIoMmuOperationBusMasterCommonBuffer64:
- Attribute = EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE;
- break;
- default:
- ASSERT (FALSE);
- return EFI_INVALID_PARAMETER;
- }
-
- Status = IoMmu->SetAttribute (
- IoMmu,
- *Mapping,
- Attribute
- );
- if (EFI_ERROR (Status)) {
- IoMmu->Unmap (IoMmu, Mapping);
- *Mapping = NULL;
- return Status;
- }
- } else {
- *DeviceAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress;
- *Mapping = NULL;
- Status = EFI_SUCCESS;
- }
-
- return Status;
-}
-
-/**
- Completes the Map() operation and releases any corresponding resources.
-
- @param IoMmu Pointer to IOMMU PPI.
- @param Mapping The mapping value returned from Map().
-
-**/
-VOID
-IoMmuUnmap (
- IN EDKII_IOMMU_PPI *IoMmu,
- IN VOID *Mapping
- )
-{
- if (IoMmu != NULL) {
- IoMmu->SetAttribute (IoMmu, Mapping, 0);
- IoMmu->Unmap (IoMmu, Mapping);
- }
-}
-
-/**
- Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
- OperationBusMasterCommonBuffer64 mapping.
-
- @param IoMmu Pointer to IOMMU PPI.
- @param Pages The number of pages to allocate.
- @param HostAddress A pointer to store the base system memory address of the
- allocated range.
- @param DeviceAddress The resulting map address for the bus master PCI controller to use to
- access the hosts HostAddress.
- @param Mapping A resulting value to pass to Unmap().
-
- @retval EFI_SUCCESS The requested memory pages were allocated.
- @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
- MEMORY_WRITE_COMBINE and MEMORY_CACHED.
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
- @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
-
-**/
-EFI_STATUS
-IoMmuAllocateBuffer (
- IN EDKII_IOMMU_PPI *IoMmu,
- IN UINTN Pages,
- OUT VOID **HostAddress,
- OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
- OUT VOID **Mapping
- )
-{
- EFI_STATUS Status;
- UINTN NumberOfBytes;
- EFI_PHYSICAL_ADDRESS HostPhyAddress;
-
- *HostAddress = NULL;
- *DeviceAddress = 0;
- *Mapping = NULL;
-
- if (IoMmu != NULL) {
- Status = IoMmu->AllocateBuffer (
- IoMmu,
- EfiBootServicesData,
- Pages,
- HostAddress,
- 0
- );
- if (EFI_ERROR (Status)) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- NumberOfBytes = EFI_PAGES_TO_SIZE (Pages);
- Status = IoMmu->Map (
- IoMmu,
- EdkiiIoMmuOperationBusMasterCommonBuffer,
- *HostAddress,
- &NumberOfBytes,
- DeviceAddress,
- Mapping
- );
- if (EFI_ERROR (Status)) {
- IoMmu->FreeBuffer (IoMmu, Pages, *HostAddress);
- *HostAddress = NULL;
- return EFI_OUT_OF_RESOURCES;
- }
-
- Status = IoMmu->SetAttribute (
- IoMmu,
- *Mapping,
- EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE
- );
- if (EFI_ERROR (Status)) {
- IoMmu->Unmap (IoMmu, *Mapping);
- IoMmu->FreeBuffer (IoMmu, Pages, *HostAddress);
- *Mapping = NULL;
- *HostAddress = NULL;
- return Status;
- }
- } else {
- Status = PeiServicesAllocatePages (
- EfiBootServicesData,
- Pages,
- &HostPhyAddress
- );
- if (EFI_ERROR (Status)) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- *HostAddress = (VOID *)(UINTN)HostPhyAddress;
- *DeviceAddress = HostPhyAddress;
- *Mapping = NULL;
- }
-
- return Status;
-}
-
-/**
- Initialize IOMMU.
-
- @param IoMmu Pointer to pointer to IOMMU PPI.
-
-**/
-VOID
-IoMmuInit (
- OUT EDKII_IOMMU_PPI **IoMmu
- )
-{
- *IoMmu = NULL;
- PeiServicesLocatePpi (
- &gEdkiiIoMmuPpiGuid,
- 0,
- NULL,
- (VOID **)IoMmu
- );
-}
diff --git a/MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.c b/MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.c
deleted file mode 100644
index 96abf3a..0000000
--- a/MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.c
+++ /dev/null
@@ -1,3303 +0,0 @@
-/** @file
-PEIM to produce gPeiUsbHostControllerPpiGuid based on gPeiUsbControllerPpiGuid
-which is used to enable recovery function from USB Drivers.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. <BR>
-
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "UhcPeim.h"
-
-/**
- Stop the host controller.
-
- @param Uhc The UHCI device.
- @param Timeout Max time allowed.
-
- @retval EFI_SUCCESS The host controller is stopped.
- @retval EFI_TIMEOUT Failed to stop the host controller.
-
-**/
-EFI_STATUS
-UhciStopHc (
- IN USB_UHC_DEV *Uhc,
- IN UINTN Timeout
- )
-{
- UINT16 CommandContent;
- UINT16 UsbSts;
- UINTN Index;
-
- CommandContent = USBReadPortW (Uhc, Uhc->UsbHostControllerBaseAddress + USBCMD);
- CommandContent &= USBCMD_RS;
- USBWritePortW (Uhc, Uhc->UsbHostControllerBaseAddress + USBCMD, CommandContent);
-
- //
- // ensure the HC is in halt status after send the stop command
- // Timeout is in us unit.
- //
- for (Index = 0; Index < (Timeout / 50) + 1; Index++) {
- UsbSts = USBReadPortW (Uhc, Uhc->UsbHostControllerBaseAddress + USBSTS);
-
- if ((UsbSts & USBSTS_HCH) == USBSTS_HCH) {
- return EFI_SUCCESS;
- }
-
- MicroSecondDelay (50);
- }
-
- return EFI_TIMEOUT;
-}
-
-/**
- One notified function to stop the Host Controller at the end of PEI
-
- @param[in] PeiServices Pointer to PEI Services Table.
- @param[in] NotifyDescriptor Pointer to the descriptor for the Notification event that
- caused this function to execute.
- @param[in] Ppi Pointer to the PPI data associated with this function.
-
- @retval EFI_SUCCESS The function completes successfully
- @retval others
-**/
-EFI_STATUS
-EFIAPI
-UhcEndOfPei (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
- IN VOID *Ppi
- )
-{
- USB_UHC_DEV *Uhc;
-
- Uhc = PEI_RECOVERY_USB_UHC_DEV_FROM_THIS_NOTIFY (NotifyDescriptor);
-
- //
- // Stop the Host Controller
- //
- UhciStopHc (Uhc, 1000 * 1000);
-
- return EFI_SUCCESS;
-}
-
-/**
- Initializes Usb Host Controller.
-
- @param FileHandle Handle of the file being invoked.
- @param PeiServices Describes the list of possible PEI Services.
-
- @retval EFI_SUCCESS PPI successfully installed.
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcPeimEntry (
- IN EFI_PEI_FILE_HANDLE FileHandle,
- IN CONST EFI_PEI_SERVICES **PeiServices
- )
-{
- PEI_USB_CONTROLLER_PPI *ChipSetUsbControllerPpi;
- EFI_STATUS Status;
- UINT8 Index;
- UINTN ControllerType;
- UINTN BaseAddress;
- UINTN MemPages;
- USB_UHC_DEV *UhcDev;
- EFI_PHYSICAL_ADDRESS TempPtr;
-
- //
- // Shadow this PEIM to run from memory
- //
- if (!EFI_ERROR (PeiServicesRegisterForShadow (FileHandle))) {
- return EFI_SUCCESS;
- }
-
- Status = PeiServicesLocatePpi (
- &gPeiUsbControllerPpiGuid,
- 0,
- NULL,
- (VOID **)&ChipSetUsbControllerPpi
- );
- //
- // If failed to locate, it is a bug in dispather as depex has gPeiUsbControllerPpiGuid.
- //
- ASSERT_EFI_ERROR (Status);
-
- Index = 0;
- while (TRUE) {
- Status = ChipSetUsbControllerPpi->GetUsbController (
- (EFI_PEI_SERVICES **)PeiServices,
- ChipSetUsbControllerPpi,
- Index,
- &ControllerType,
- &BaseAddress
- );
- //
- // When status is error, meant no controller is found
- //
- if (EFI_ERROR (Status)) {
- break;
- }
-
- //
- // This PEIM is for UHC type controller.
- //
- if (ControllerType != PEI_UHCI_CONTROLLER) {
- Index++;
- continue;
- }
-
- MemPages = sizeof (USB_UHC_DEV) / EFI_PAGE_SIZE + 1;
-
- Status = PeiServicesAllocatePages (
- EfiBootServicesData,
- MemPages,
- &TempPtr
- );
- if (EFI_ERROR (Status)) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- UhcDev = (USB_UHC_DEV *)((UINTN)TempPtr);
- UhcDev->Signature = USB_UHC_DEV_SIGNATURE;
- IoMmuInit (&UhcDev->IoMmu);
- UhcDev->UsbHostControllerBaseAddress = (UINT32)BaseAddress;
-
- //
- // Init local memory management service
- //
- Status = InitializeMemoryManagement (UhcDev);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Initialize Uhc's hardware
- //
- Status = InitializeUsbHC (UhcDev);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- UhcDev->UsbHostControllerPpi.ControlTransfer = UhcControlTransfer;
- UhcDev->UsbHostControllerPpi.BulkTransfer = UhcBulkTransfer;
- UhcDev->UsbHostControllerPpi.GetRootHubPortNumber = UhcGetRootHubPortNumber;
- UhcDev->UsbHostControllerPpi.GetRootHubPortStatus = UhcGetRootHubPortStatus;
- UhcDev->UsbHostControllerPpi.SetRootHubPortFeature = UhcSetRootHubPortFeature;
- UhcDev->UsbHostControllerPpi.ClearRootHubPortFeature = UhcClearRootHubPortFeature;
-
- UhcDev->PpiDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
- UhcDev->PpiDescriptor.Guid = &gPeiUsbHostControllerPpiGuid;
- UhcDev->PpiDescriptor.Ppi = &UhcDev->UsbHostControllerPpi;
-
- Status = PeiServicesInstallPpi (&UhcDev->PpiDescriptor);
- if (EFI_ERROR (Status)) {
- Index++;
- continue;
- }
-
- UhcDev->EndOfPeiNotifyList.Flags = (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
- UhcDev->EndOfPeiNotifyList.Guid = &gEfiEndOfPeiSignalPpiGuid;
- UhcDev->EndOfPeiNotifyList.Notify = UhcEndOfPei;
-
- PeiServicesNotifyPpi (&UhcDev->EndOfPeiNotifyList);
-
- Index++;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Submits control transfer to a target USB device.
-
- @param PeiServices The pointer of EFI_PEI_SERVICES.
- @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
- @param DeviceAddress The target device address.
- @param DeviceSpeed Target device speed.
- @param MaximumPacketLength Maximum packet size the default control transfer
- endpoint is capable of sending or receiving.
- @param Request USB device request to send.
- @param TransferDirection Specifies the data direction for the data stage.
- @param Data Data buffer to be transmitted or received from USB device.
- @param DataLength The size (in bytes) of the data buffer.
- @param TimeOut Indicates the maximum timeout, in millisecond.
- If Timeout is 0, then the caller must wait for the function
- to be completed until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.
- @param TransferResult Return the result of this control transfer.
-
- @retval EFI_SUCCESS Transfer was completed successfully.
- @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resources.
- @retval EFI_INVALID_PARAMETER Some parameters are invalid.
- @retval EFI_TIMEOUT Transfer failed due to timeout.
- @retval EFI_DEVICE_ERROR Transfer failed due to host controller or device error.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcControlTransfer (
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 DeviceAddress,
- IN UINT8 DeviceSpeed,
- IN UINT8 MaximumPacketLength,
- IN EFI_USB_DEVICE_REQUEST *Request,
- IN EFI_USB_DATA_DIRECTION TransferDirection,
- IN OUT VOID *Data OPTIONAL,
- IN OUT UINTN *DataLength OPTIONAL,
- IN UINTN TimeOut,
- OUT UINT32 *TransferResult
- )
-{
- USB_UHC_DEV *UhcDev;
- UINT32 StatusReg;
- UINT8 PktID;
- QH_STRUCT *PtrQH;
- TD_STRUCT *PtrTD;
- TD_STRUCT *PtrPreTD;
- TD_STRUCT *PtrSetupTD;
- TD_STRUCT *PtrStatusTD;
- EFI_STATUS Status;
- UINT32 DataLen;
- UINT8 DataToggle;
- UINT8 *RequestPhy;
- VOID *RequestMap;
- UINT8 *DataPhy;
- VOID *DataMap;
-
- UhcDev = PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS (This);
-
- StatusReg = UhcDev->UsbHostControllerBaseAddress + USBSTS;
-
- PktID = INPUT_PACKET_ID;
-
- RequestMap = NULL;
-
- if ((Request == NULL) || (TransferResult == NULL)) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // if errors exist that cause host controller halt,
- // then return EFI_DEVICE_ERROR.
- //
-
- if (!IsStatusOK (UhcDev, StatusReg)) {
- ClearStatusReg (UhcDev, StatusReg);
- *TransferResult = EFI_USB_ERR_SYSTEM;
- return EFI_DEVICE_ERROR;
- }
-
- ClearStatusReg (UhcDev, StatusReg);
-
- //
- // Map the Request and data for bus master access,
- // then create a list of TD for this transfer
- //
- Status = UhciMapUserRequest (UhcDev, Request, &RequestPhy, &RequestMap);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- Status = UhciMapUserData (UhcDev, TransferDirection, Data, DataLength, &PktID, &DataPhy, &DataMap);
-
- if (EFI_ERROR (Status)) {
- if (RequestMap != NULL) {
- IoMmuUnmap (UhcDev->IoMmu, RequestMap);
- }
-
- return Status;
- }
-
- //
- // generate Setup Stage TD
- //
-
- PtrQH = UhcDev->ConfigQH;
-
- GenSetupStageTD (
- UhcDev,
- DeviceAddress,
- 0,
- DeviceSpeed,
- (UINT8 *)Request,
- RequestPhy,
- (UINT8)sizeof (EFI_USB_DEVICE_REQUEST),
- &PtrSetupTD
- );
-
- //
- // link setup TD structures to QH structure
- //
- LinkTDToQH (PtrQH, PtrSetupTD);
-
- PtrPreTD = PtrSetupTD;
-
- //
- // Data Stage of Control Transfer
- //
-
- if (TransferDirection == EfiUsbNoData) {
- DataLen = 0;
- } else {
- DataLen = (UINT32)*DataLength;
- }
-
- DataToggle = 1;
-
- PtrTD = PtrSetupTD;
- while (DataLen > 0) {
- //
- // create TD structures and link together
- //
- UINT8 PacketSize;
-
- //
- // PacketSize is the data load size of each TD carries.
- //
- PacketSize = (UINT8)DataLen;
- if (DataLen > MaximumPacketLength) {
- PacketSize = MaximumPacketLength;
- }
-
- GenDataTD (
- UhcDev,
- DeviceAddress,
- 0,
- Data,
- DataPhy,
- PacketSize,
- PktID,
- DataToggle,
- DeviceSpeed,
- &PtrTD
- );
-
- //
- // Link two TDs in vertical depth
- //
- LinkTDToTD (PtrPreTD, PtrTD);
- PtrPreTD = PtrTD;
-
- DataToggle ^= 1;
- Data = (VOID *)((UINT8 *)Data + PacketSize);
- DataPhy += PacketSize;
- DataLen -= PacketSize;
- }
-
- //
- // PtrPreTD points to the last TD before the Setup-Stage TD.
- //
- PtrPreTD = PtrTD;
-
- //
- // Status Stage of Control Transfer
- //
- if (PktID == OUTPUT_PACKET_ID) {
- PktID = INPUT_PACKET_ID;
- } else {
- PktID = OUTPUT_PACKET_ID;
- }
-
- //
- // create Status Stage TD structure
- //
- CreateStatusTD (
- UhcDev,
- DeviceAddress,
- 0,
- PktID,
- DeviceSpeed,
- &PtrStatusTD
- );
-
- LinkTDToTD (PtrPreTD, PtrStatusTD);
-
- //
- // Poll QH-TDs execution and get result.
- // detail status is returned
- //
- Status = ExecuteControlTransfer (
- UhcDev,
- PtrSetupTD,
- DataLength,
- TimeOut,
- TransferResult
- );
-
- //
- // TRUE means must search other framelistindex
- //
- SetQHVerticalValidorInvalid (PtrQH, FALSE);
- DeleteQueuedTDs (UhcDev, PtrSetupTD);
-
- //
- // if has errors that cause host controller halt, then return EFI_DEVICE_ERROR directly.
- //
- if (!IsStatusOK (UhcDev, StatusReg)) {
- *TransferResult |= EFI_USB_ERR_SYSTEM;
- Status = EFI_DEVICE_ERROR;
- }
-
- ClearStatusReg (UhcDev, StatusReg);
-
- if (DataMap != NULL) {
- IoMmuUnmap (UhcDev->IoMmu, DataMap);
- }
-
- if (RequestMap != NULL) {
- IoMmuUnmap (UhcDev->IoMmu, RequestMap);
- }
-
- return Status;
-}
-
-/**
- Submits bulk transfer to a bulk endpoint of a USB device.
-
- @param PeiServices The pointer of EFI_PEI_SERVICES.
- @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
- @param DeviceAddress Target device address.
- @param EndPointAddress Endpoint number and its direction in bit 7.
- @param MaximumPacketLength Maximum packet size the endpoint is capable of
- sending or receiving.
- @param Data Array of pointers to the buffers of data to transmit
- from or receive into.
- @param DataLength The lenght of the data buffer.
- @param DataToggle On input, the initial data toggle for the transfer;
- On output, it is updated to to next data toggle to use of
- the subsequent bulk transfer.
- @param TimeOut Indicates the maximum time, in millisecond, which the
- transfer is allowed to complete.
- If Timeout is 0, then the caller must wait for the function
- to be completed until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.
- @param TransferResult A pointer to the detailed result information of the
- bulk transfer.
-
- @retval EFI_SUCCESS The transfer was completed successfully.
- @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource.
- @retval EFI_INVALID_PARAMETER Parameters are invalid.
- @retval EFI_TIMEOUT The transfer failed due to timeout.
- @retval EFI_DEVICE_ERROR The transfer failed due to host controller error.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcBulkTransfer (
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 DeviceAddress,
- IN UINT8 EndPointAddress,
- IN UINT8 MaximumPacketLength,
- IN OUT VOID *Data,
- IN OUT UINTN *DataLength,
- IN OUT UINT8 *DataToggle,
- IN UINTN TimeOut,
- OUT UINT32 *TransferResult
- )
-{
- USB_UHC_DEV *UhcDev;
- UINT32 StatusReg;
-
- UINT32 DataLen;
-
- QH_STRUCT *PtrQH;
- TD_STRUCT *PtrFirstTD;
- TD_STRUCT *PtrTD;
- TD_STRUCT *PtrPreTD;
-
- UINT8 PktID;
-
- BOOLEAN IsFirstTD;
-
- EFI_STATUS Status;
-
- EFI_USB_DATA_DIRECTION TransferDirection;
-
- BOOLEAN ShortPacketEnable;
-
- UINT16 CommandContent;
-
- UINT8 *DataPhy;
- VOID *DataMap;
-
- UhcDev = PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS (This);
-
- //
- // Enable the maximum packet size (64bytes)
- // that can be used for full speed bandwidth reclamation
- // at the end of a frame.
- //
- CommandContent = USBReadPortW (UhcDev, UhcDev->UsbHostControllerBaseAddress + USBCMD);
- if ((CommandContent & USBCMD_MAXP) != USBCMD_MAXP) {
- CommandContent |= USBCMD_MAXP;
- USBWritePortW (UhcDev, UhcDev->UsbHostControllerBaseAddress + USBCMD, CommandContent);
- }
-
- StatusReg = UhcDev->UsbHostControllerBaseAddress + USBSTS;
-
- //
- // these code lines are added here per complier's strict demand
- //
- PktID = INPUT_PACKET_ID;
- PtrTD = NULL;
- PtrFirstTD = NULL;
- PtrPreTD = NULL;
- DataLen = 0;
-
- ShortPacketEnable = FALSE;
-
- if ((DataLength == 0) || (Data == NULL) || (TransferResult == NULL)) {
- return EFI_INVALID_PARAMETER;
- }
-
- if ((*DataToggle != 1) && (*DataToggle != 0)) {
- return EFI_INVALID_PARAMETER;
- }
-
- if ( (MaximumPacketLength != 8) && (MaximumPacketLength != 16)
- && (MaximumPacketLength != 32) && (MaximumPacketLength != 64))
- {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // if has errors that cause host controller halt, then return EFI_DEVICE_ERROR directly.
- //
- if (!IsStatusOK (UhcDev, StatusReg)) {
- ClearStatusReg (UhcDev, StatusReg);
- *TransferResult = EFI_USB_ERR_SYSTEM;
- return EFI_DEVICE_ERROR;
- }
-
- ClearStatusReg (UhcDev, StatusReg);
-
- //
- // Map the source data buffer for bus master access,
- // then create a list of TDs
- //
- if ((EndPointAddress & 0x80) != 0) {
- TransferDirection = EfiUsbDataIn;
- } else {
- TransferDirection = EfiUsbDataOut;
- }
-
- Status = UhciMapUserData (UhcDev, TransferDirection, Data, DataLength, &PktID, &DataPhy, &DataMap);
-
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- DataLen = (UINT32)*DataLength;
-
- PtrQH = UhcDev->BulkQH;
-
- IsFirstTD = TRUE;
- while (DataLen > 0) {
- //
- // create TD structures and link together
- //
- UINT8 PacketSize;
-
- PacketSize = (UINT8)DataLen;
- if (DataLen > MaximumPacketLength) {
- PacketSize = MaximumPacketLength;
- }
-
- GenDataTD (
- UhcDev,
- DeviceAddress,
- EndPointAddress,
- Data,
- DataPhy,
- PacketSize,
- PktID,
- *DataToggle,
- USB_FULL_SPEED_DEVICE,
- &PtrTD
- );
-
- //
- // Enable short packet detection.
- // (default action is disabling short packet detection)
- //
- if (ShortPacketEnable) {
- EnableorDisableTDShortPacket (PtrTD, TRUE);
- }
-
- if (IsFirstTD) {
- PtrFirstTD = PtrTD;
- PtrFirstTD->PtrNextTD = NULL;
- IsFirstTD = FALSE;
- } else {
- //
- // Link two TDs in vertical depth
- //
- LinkTDToTD (PtrPreTD, PtrTD);
- }
-
- PtrPreTD = PtrTD;
-
- *DataToggle ^= 1;
- Data = (VOID *)((UINT8 *)Data + PacketSize);
- DataPhy += PacketSize;
- DataLen -= PacketSize;
- }
-
- //
- // link TD structures to QH structure
- //
- LinkTDToQH (PtrQH, PtrFirstTD);
-
- //
- // Execute QH-TD and get result
- //
- //
- // detail status is put into the Result field in the pIRP
- // the Data Toggle value is also re-updated to the value
- // of the last successful TD
- //
- Status = ExecBulkTransfer (
- UhcDev,
- PtrFirstTD,
- DataLength,
- DataToggle,
- TimeOut,
- TransferResult
- );
-
- //
- // Delete Bulk transfer TD structure
- //
- DeleteQueuedTDs (UhcDev, PtrFirstTD);
-
- //
- // if has errors that cause host controller halt, then return EFI_DEVICE_ERROR directly.
- //
- if (!IsStatusOK (UhcDev, StatusReg)) {
- *TransferResult |= EFI_USB_ERR_SYSTEM;
- Status = EFI_DEVICE_ERROR;
- }
-
- ClearStatusReg (UhcDev, StatusReg);
-
- if (DataMap != NULL) {
- IoMmuUnmap (UhcDev->IoMmu, DataMap);
- }
-
- return Status;
-}
-
-/**
- Retrieves the number of root hub ports.
-
- @param[in] PeiServices The pointer to the PEI Services Table.
- @param[in] This The pointer to this instance of the
- PEI_USB_HOST_CONTROLLER_PPI.
- @param[out] PortNumber The pointer to the number of the root hub ports.
-
- @retval EFI_SUCCESS The port number was retrieved successfully.
- @retval EFI_INVALID_PARAMETER PortNumber is NULL.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcGetRootHubPortNumber (
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- OUT UINT8 *PortNumber
- )
-{
- USB_UHC_DEV *UhcDev;
- UINT32 PSAddr;
- UINT16 RHPortControl;
- UINT32 Index;
-
- UhcDev = PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS (This);
-
- if (PortNumber == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- *PortNumber = 0;
-
- for (Index = 0; Index < 2; Index++) {
- PSAddr = UhcDev->UsbHostControllerBaseAddress + USBPORTSC1 + Index * 2;
- RHPortControl = USBReadPortW (UhcDev, PSAddr);
- //
- // Port Register content is valid
- //
- if (RHPortControl != 0xff) {
- (*PortNumber)++;
- }
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Retrieves the current status of a USB root hub port.
-
- @param PeiServices The pointer of EFI_PEI_SERVICES.
- @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
- @param PortNumber The root hub port to retrieve the state from.
- @param PortStatus Variable to receive the port state.
-
- @retval EFI_SUCCESS The status of the USB root hub port specified.
- by PortNumber was returned in PortStatus.
- @retval EFI_INVALID_PARAMETER PortNumber is invalid.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcGetRootHubPortStatus (
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 PortNumber,
- OUT EFI_USB_PORT_STATUS *PortStatus
- )
-{
- USB_UHC_DEV *UhcDev;
- UINT32 PSAddr;
- UINT16 RHPortStatus;
- UINT8 TotalPortNumber;
-
- if (PortStatus == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- UhcGetRootHubPortNumber (PeiServices, This, &TotalPortNumber);
- if (PortNumber > TotalPortNumber) {
- return EFI_INVALID_PARAMETER;
- }
-
- UhcDev = PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS (This);
- PSAddr = UhcDev->UsbHostControllerBaseAddress + USBPORTSC1 + PortNumber * 2;
-
- PortStatus->PortStatus = 0;
- PortStatus->PortChangeStatus = 0;
-
- RHPortStatus = USBReadPortW (UhcDev, PSAddr);
-
- //
- // Current Connect Status
- //
- if ((RHPortStatus & USBPORTSC_CCS) != 0) {
- PortStatus->PortStatus |= USB_PORT_STAT_CONNECTION;
- }
-
- //
- // Port Enabled/Disabled
- //
- if ((RHPortStatus & USBPORTSC_PED) != 0) {
- PortStatus->PortStatus |= USB_PORT_STAT_ENABLE;
- }
-
- //
- // Port Suspend
- //
- if ((RHPortStatus & USBPORTSC_SUSP) != 0) {
- PortStatus->PortStatus |= USB_PORT_STAT_SUSPEND;
- }
-
- //
- // Port Reset
- //
- if ((RHPortStatus & USBPORTSC_PR) != 0) {
- PortStatus->PortStatus |= USB_PORT_STAT_RESET;
- }
-
- //
- // Low Speed Device Attached
- //
- if ((RHPortStatus & USBPORTSC_LSDA) != 0) {
- PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
- }
-
- //
- // Fill Port Status Change bits
- //
- //
- // Connect Status Change
- //
- if ((RHPortStatus & USBPORTSC_CSC) != 0) {
- PortStatus->PortChangeStatus |= USB_PORT_STAT_C_CONNECTION;
- }
-
- //
- // Port Enabled/Disabled Change
- //
- if ((RHPortStatus & USBPORTSC_PEDC) != 0) {
- PortStatus->PortChangeStatus |= USB_PORT_STAT_C_ENABLE;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Sets a feature for the specified root hub port.
-
- @param PeiServices The pointer of EFI_PEI_SERVICES
- @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI
- @param PortNumber Root hub port to set.
- @param PortFeature Feature to set.
-
- @retval EFI_SUCCESS The feature specified by PortFeature was set.
- @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
- @retval EFI_TIMEOUT The time out occurred.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcSetRootHubPortFeature (
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 PortNumber,
- IN EFI_USB_PORT_FEATURE PortFeature
- )
-{
- USB_UHC_DEV *UhcDev;
- UINT32 PSAddr;
- UINT32 CommandRegAddr;
- UINT16 RHPortControl;
- UINT8 TotalPortNumber;
-
- UhcGetRootHubPortNumber (PeiServices, This, &TotalPortNumber);
- if (PortNumber > TotalPortNumber) {
- return EFI_INVALID_PARAMETER;
- }
-
- UhcDev = PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS (This);
- PSAddr = UhcDev->UsbHostControllerBaseAddress + USBPORTSC1 + PortNumber * 2;
- CommandRegAddr = UhcDev->UsbHostControllerBaseAddress + USBCMD;
-
- RHPortControl = USBReadPortW (UhcDev, PSAddr);
-
- switch (PortFeature) {
- case EfiUsbPortSuspend:
- if ((USBReadPortW (UhcDev, CommandRegAddr) & USBCMD_EGSM) == 0) {
- //
- // if global suspend is not active, can set port suspend
- //
- RHPortControl &= 0xfff5;
- RHPortControl |= USBPORTSC_SUSP;
- }
-
- break;
-
- case EfiUsbPortReset:
- RHPortControl &= 0xfff5;
- RHPortControl |= USBPORTSC_PR;
- //
- // Set the reset bit
- //
- break;
-
- case EfiUsbPortPower:
- break;
-
- case EfiUsbPortEnable:
- RHPortControl &= 0xfff5;
- RHPortControl |= USBPORTSC_PED;
- break;
-
- default:
- return EFI_INVALID_PARAMETER;
- }
-
- USBWritePortW (UhcDev, PSAddr, RHPortControl);
-
- return EFI_SUCCESS;
-}
-
-/**
- Clears a feature for the specified root hub port.
-
- @param PeiServices The pointer of EFI_PEI_SERVICES.
- @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
- @param PortNumber Specifies the root hub port whose feature
- is requested to be cleared.
- @param PortFeature Indicates the feature selector associated with the
- feature clear request.
-
- @retval EFI_SUCCESS The feature specified by PortFeature was cleared
- for the USB root hub port specified by PortNumber.
- @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcClearRootHubPortFeature (
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 PortNumber,
- IN EFI_USB_PORT_FEATURE PortFeature
- )
-{
- USB_UHC_DEV *UhcDev;
- UINT32 PSAddr;
- UINT16 RHPortControl;
- UINT8 TotalPortNumber;
-
- UhcGetRootHubPortNumber (PeiServices, This, &TotalPortNumber);
-
- if (PortNumber > TotalPortNumber) {
- return EFI_INVALID_PARAMETER;
- }
-
- UhcDev = PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS (This);
- PSAddr = UhcDev->UsbHostControllerBaseAddress + USBPORTSC1 + PortNumber * 2;
-
- RHPortControl = USBReadPortW (UhcDev, PSAddr);
-
- switch (PortFeature) {
- //
- // clear PORT_ENABLE feature means disable port.
- //
- case EfiUsbPortEnable:
- RHPortControl &= 0xfff5;
- RHPortControl &= ~USBPORTSC_PED;
- break;
-
- //
- // clear PORT_SUSPEND feature means resume the port.
- // (cause a resume on the specified port if in suspend mode)
- //
- case EfiUsbPortSuspend:
- RHPortControl &= 0xfff5;
- RHPortControl &= ~USBPORTSC_SUSP;
- break;
-
- //
- // no operation
- //
- case EfiUsbPortPower:
- break;
-
- //
- // clear PORT_RESET means clear the reset signal.
- //
- case EfiUsbPortReset:
- RHPortControl &= 0xfff5;
- RHPortControl &= ~USBPORTSC_PR;
- break;
-
- //
- // clear connect status change
- //
- case EfiUsbPortConnectChange:
- RHPortControl &= 0xfff5;
- RHPortControl |= USBPORTSC_CSC;
- break;
-
- //
- // clear enable/disable status change
- //
- case EfiUsbPortEnableChange:
- RHPortControl &= 0xfff5;
- RHPortControl |= USBPORTSC_PEDC;
- break;
-
- //
- // root hub does not support this request
- //
- case EfiUsbPortSuspendChange:
- break;
-
- //
- // root hub does not support this request
- //
- case EfiUsbPortOverCurrentChange:
- break;
-
- //
- // root hub does not support this request
- //
- case EfiUsbPortResetChange:
- break;
-
- default:
- return EFI_INVALID_PARAMETER;
- }
-
- USBWritePortW (UhcDev, PSAddr, RHPortControl);
-
- return EFI_SUCCESS;
-}
-
-/**
- Initialize UHCI.
-
- @param UhcDev UHCI Device.
-
- @retval EFI_SUCCESS UHCI successfully initialized.
- @retval EFI_OUT_OF_RESOURCES Resource can not be allocated.
-
-**/
-EFI_STATUS
-InitializeUsbHC (
- IN USB_UHC_DEV *UhcDev
- )
-{
- EFI_STATUS Status;
- UINT32 FrameListBaseAddrReg;
- UINT32 CommandReg;
- UINT16 Command;
-
- //
- // Create and Initialize Frame List For the Host Controller.
- //
- Status = CreateFrameList (UhcDev);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- FrameListBaseAddrReg = UhcDev->UsbHostControllerBaseAddress + USBFLBASEADD;
- CommandReg = UhcDev->UsbHostControllerBaseAddress + USBCMD;
-
- //
- // Set Frame List Base Address to the specific register to inform the hardware.
- //
- SetFrameListBaseAddress (UhcDev, FrameListBaseAddrReg, (UINT32)(UINTN)(UhcDev->FrameListEntry));
-
- Command = USBReadPortW (UhcDev, CommandReg);
- Command |= USBCMD_GRESET;
- USBWritePortW (UhcDev, CommandReg, Command);
-
- MicroSecondDelay (50 * 1000);
-
- Command &= ~USBCMD_GRESET;
-
- USBWritePortW (UhcDev, CommandReg, Command);
-
- //
- // UHCI spec page120 reset recovery time
- //
- MicroSecondDelay (20 * 1000);
-
- //
- // Set Run/Stop bit to 1.
- //
- Command = USBReadPortW (UhcDev, CommandReg);
- Command |= USBCMD_RS | USBCMD_MAXP;
- USBWritePortW (UhcDev, CommandReg, Command);
-
- return EFI_SUCCESS;
-}
-
-/**
- Create Frame List Structure.
-
- @param UhcDev UHCI device.
-
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
- @retval EFI_SUCCESS Success.
-
-**/
-EFI_STATUS
-CreateFrameList (
- USB_UHC_DEV *UhcDev
- )
-{
- EFI_STATUS Status;
- EFI_PHYSICAL_ADDRESS FrameListBaseAddr;
- FRAMELIST_ENTRY *FrameListPtr;
- UINTN Index;
-
- //
- // The Frame List ocupies 4K bytes,
- // and must be aligned on 4-Kbyte boundaries.
- //
- Status = PeiServicesAllocatePages (
- EfiBootServicesData,
- 1,
- &FrameListBaseAddr
- );
-
- if (Status != EFI_SUCCESS) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- //
- // Create Control QH and Bulk QH and link them into Framelist Entry
- //
- Status = CreateQH (UhcDev, &UhcDev->ConfigQH);
- if (Status != EFI_SUCCESS) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- ASSERT (UhcDev->ConfigQH != NULL);
-
- Status = CreateQH (UhcDev, &UhcDev->BulkQH);
- if (Status != EFI_SUCCESS) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- ASSERT (UhcDev->BulkQH != NULL);
-
- //
- // Set the corresponding QH pointer
- //
- SetQHHorizontalLinkPtr (UhcDev->ConfigQH, UhcDev->BulkQH);
- SetQHHorizontalQHorTDSelect (UhcDev->ConfigQH, TRUE);
- SetQHHorizontalValidorInvalid (UhcDev->ConfigQH, TRUE);
-
- UhcDev->FrameListEntry = (FRAMELIST_ENTRY *)((UINTN)FrameListBaseAddr);
-
- FrameListPtr = UhcDev->FrameListEntry;
-
- for (Index = 0; Index < 1024; Index++) {
- FrameListPtr->FrameListPtrTerminate = 0;
- FrameListPtr->FrameListPtr = (UINT32)(UINTN)UhcDev->ConfigQH >> 4;
- FrameListPtr->FrameListPtrQSelect = 1;
- FrameListPtr->FrameListRsvd = 0;
- FrameListPtr++;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Read a 16bit width data from Uhc HC IO space register.
-
- @param UhcDev The UHCI device.
- @param Port The IO space address of the register.
-
- @retval the register content read.
-
-**/
-UINT16
-USBReadPortW (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 Port
- )
-{
- return IoRead16 (Port);
-}
-
-/**
- Write a 16bit width data into Uhc HC IO space register.
-
- @param UhcDev The UHCI device.
- @param Port The IO space address of the register.
- @param Data The data written into the register.
-
-**/
-VOID
-USBWritePortW (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 Port,
- IN UINT16 Data
- )
-{
- IoWrite16 (Port, Data);
-}
-
-/**
- Write a 32bit width data into Uhc HC IO space register.
-
- @param UhcDev The UHCI device.
- @param Port The IO space address of the register.
- @param Data The data written into the register.
-
-**/
-VOID
-USBWritePortDW (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 Port,
- IN UINT32 Data
- )
-{
- IoWrite32 (Port, Data);
-}
-
-/**
- Clear the content of UHCI's Status Register.
-
- @param UhcDev The UHCI device.
- @param StatusAddr The IO space address of the register.
-
-**/
-VOID
-ClearStatusReg (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 StatusAddr
- )
-{
- //
- // Clear the content of UHCI's Status Register
- //
- USBWritePortW (UhcDev, StatusAddr, 0x003F);
-}
-
-/**
- Check whether the host controller operates well.
-
- @param UhcDev The UHCI device.
- @param StatusRegAddr The io address of status register.
-
- @retval TRUE Host controller is working.
- @retval FALSE Host controller is halted or system error.
-
-**/
-BOOLEAN
-IsStatusOK (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 StatusRegAddr
- )
-{
- UINT16 StatusValue;
-
- StatusValue = USBReadPortW (UhcDev, StatusRegAddr);
-
- if ((StatusValue & (USBSTS_HCPE | USBSTS_HSE | USBSTS_HCH)) != 0) {
- return FALSE;
- } else {
- return TRUE;
- }
-}
-
-/**
- Set Frame List Base Address.
-
- @param UhcDev The UHCI device.
- @param FrameListRegAddr The address of frame list register.
- @param Addr The address of frame list table.
-
-**/
-VOID
-SetFrameListBaseAddress (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 FrameListRegAddr,
- IN UINT32 Addr
- )
-{
- //
- // Sets value in the USB Frame List Base Address register.
- //
- USBWritePortDW (UhcDev, FrameListRegAddr, (UINT32)(Addr & 0xFFFFF000));
-}
-
-/**
- Create QH and initialize.
-
- @param UhcDev The UHCI device.
- @param PtrQH Place to store QH_STRUCT pointer.
-
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
- @retval EFI_SUCCESS Success.
-
-**/
-EFI_STATUS
-CreateQH (
- IN USB_UHC_DEV *UhcDev,
- OUT QH_STRUCT **PtrQH
- )
-{
- EFI_STATUS Status;
-
- //
- // allocate align memory for QH_STRUCT
- //
- Status = AllocateTDorQHStruct (UhcDev, sizeof (QH_STRUCT), (void **)PtrQH);
- if (EFI_ERROR (Status)) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- //
- // init each field of the QH_STRUCT
- //
- SetQHHorizontalValidorInvalid (*PtrQH, FALSE);
- SetQHVerticalValidorInvalid (*PtrQH, FALSE);
-
- return EFI_SUCCESS;
-}
-
-/**
- Set the horizontal link pointer in QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param PtrNext Place to the next QH_STRUCT.
-
-**/
-VOID
-SetQHHorizontalLinkPtr (
- IN QH_STRUCT *PtrQH,
- IN VOID *PtrNext
- )
-{
- //
- // Since the QH_STRUCT is aligned on 16-byte boundaries,
- // Only the highest 28bit of the address is valid
- // (take 32bit address as an example).
- //
- PtrQH->QueueHead.QHHorizontalPtr = (UINT32)(UINTN)PtrNext >> 4;
-}
-
-/**
- Set a QH or TD horizontally to be connected with a specific QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param IsQH Specify QH or TD is connected.
-
-**/
-VOID
-SetQHHorizontalQHorTDSelect (
- IN QH_STRUCT *PtrQH,
- IN BOOLEAN IsQH
- )
-{
- //
- // if QH is connected, the specified bit is set,
- // if TD is connected, the specified bit is cleared.
- //
- PtrQH->QueueHead.QHHorizontalQSelect = IsQH ? 1 : 0;
-}
-
-/**
- Set the horizontal validor bit in QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param IsValid Specify the horizontal linker is valid or not.
-
-**/
-VOID
-SetQHHorizontalValidorInvalid (
- IN QH_STRUCT *PtrQH,
- IN BOOLEAN IsValid
- )
-{
- //
- // Valid means the horizontal link pointer is valid,
- // else, it's invalid.
- //
- PtrQH->QueueHead.QHHorizontalTerminate = IsValid ? 0 : 1;
-}
-
-/**
- Set the vertical link pointer in QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param PtrNext Place to the next QH_STRUCT.
-
-**/
-VOID
-SetQHVerticalLinkPtr (
- IN QH_STRUCT *PtrQH,
- IN VOID *PtrNext
- )
-{
- //
- // Since the QH_STRUCT is aligned on 16-byte boundaries,
- // Only the highest 28bit of the address is valid
- // (take 32bit address as an example).
- //
- PtrQH->QueueHead.QHVerticalPtr = (UINT32)(UINTN)PtrNext >> 4;
-}
-
-/**
- Set a QH or TD vertically to be connected with a specific QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param IsQH Specify QH or TD is connected.
-
-**/
-VOID
-SetQHVerticalQHorTDSelect (
- IN QH_STRUCT *PtrQH,
- IN BOOLEAN IsQH
- )
-{
- //
- // Set the specified bit if the Vertical Link Pointer pointing to a QH,
- // Clear the specified bit if the Vertical Link Pointer pointing to a TD.
- //
- PtrQH->QueueHead.QHVerticalQSelect = IsQH ? 1 : 0;
-}
-
-/**
- Set the vertical validor bit in QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param IsValid Specify the vertical linker is valid or not.
-
-**/
-VOID
-SetQHVerticalValidorInvalid (
- IN QH_STRUCT *PtrQH,
- IN BOOLEAN IsValid
- )
-{
- //
- // If TRUE, meaning the Vertical Link Pointer field is valid,
- // else, the field is invalid.
- //
- PtrQH->QueueHead.QHVerticalTerminate = IsValid ? 0 : 1;
-}
-
-/**
- Allocate TD or QH Struct.
-
- @param UhcDev The UHCI device.
- @param Size The size of allocation.
- @param PtrStruct Place to store TD_STRUCT pointer.
-
- @return EFI_SUCCESS Allocate successfully.
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
-
-**/
-EFI_STATUS
-AllocateTDorQHStruct (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 Size,
- OUT VOID **PtrStruct
- )
-{
- EFI_STATUS Status;
-
- Status = EFI_SUCCESS;
- *PtrStruct = NULL;
-
- Status = UhcAllocatePool (
- UhcDev,
- (UINT8 **)PtrStruct,
- Size
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- ZeroMem (*PtrStruct, Size);
-
- return Status;
-}
-
-/**
- Create a TD Struct.
-
- @param UhcDev The UHCI device.
- @param PtrTD Place to store TD_STRUCT pointer.
-
- @return EFI_SUCCESS Allocate successfully.
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
-
-**/
-EFI_STATUS
-CreateTD (
- IN USB_UHC_DEV *UhcDev,
- OUT TD_STRUCT **PtrTD
- )
-{
- EFI_STATUS Status;
-
- //
- // create memory for TD_STRUCT, and align the memory.
- //
- Status = AllocateTDorQHStruct (UhcDev, sizeof (TD_STRUCT), (void **)PtrTD);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Make TD ready.
- //
- SetTDLinkPtrValidorInvalid (*PtrTD, FALSE);
-
- return EFI_SUCCESS;
-}
-
-/**
- Generate Setup Stage TD.
-
- @param UhcDev The UHCI device.
- @param DevAddr Device address.
- @param Endpoint Endpoint number.
- @param DeviceSpeed Device Speed.
- @param DevRequest CPU memory address of request structure buffer to transfer.
- @param RequestPhy PCI memory address of request structure buffer to transfer.
- @param RequestLen Request length.
- @param PtrTD TD_STRUCT generated.
-
- @return EFI_SUCCESS Generate setup stage TD successfully.
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
-
-**/
-EFI_STATUS
-GenSetupStageTD (
- IN USB_UHC_DEV *UhcDev,
- IN UINT8 DevAddr,
- IN UINT8 Endpoint,
- IN UINT8 DeviceSpeed,
- IN UINT8 *DevRequest,
- IN UINT8 *RequestPhy,
- IN UINT8 RequestLen,
- OUT TD_STRUCT **PtrTD
- )
-{
- TD_STRUCT *TdStruct;
- EFI_STATUS Status;
-
- Status = CreateTD (UhcDev, &TdStruct);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- SetTDLinkPtr (TdStruct, NULL);
-
- //
- // Depth first fashion
- //
- SetTDLinkPtrDepthorBreadth (TdStruct, TRUE);
-
- //
- // initialize as the last TD in the QH context,
- // this field will be updated in the TD linkage process.
- //
- SetTDLinkPtrValidorInvalid (TdStruct, FALSE);
-
- //
- // Disable Short Packet Detection by default
- //
- EnableorDisableTDShortPacket (TdStruct, FALSE);
-
- //
- // Max error counter is 3, retry 3 times when error encountered.
- //
- SetTDControlErrorCounter (TdStruct, 3);
-
- //
- // set device speed attribute
- // (TRUE - Slow Device; FALSE - Full Speed Device)
- //
- switch (DeviceSpeed) {
- case USB_SLOW_SPEED_DEVICE:
- SetTDLoworFullSpeedDevice (TdStruct, TRUE);
- break;
-
- case USB_FULL_SPEED_DEVICE:
- SetTDLoworFullSpeedDevice (TdStruct, FALSE);
- break;
- }
-
- //
- // Non isochronous transfer TD
- //
- SetTDControlIsochronousorNot (TdStruct, FALSE);
-
- //
- // Interrupt On Complete bit be set to zero,
- // Disable IOC interrupt.
- //
- SetorClearTDControlIOC (TdStruct, FALSE);
-
- //
- // Set TD Active bit
- //
- SetTDStatusActiveorInactive (TdStruct, TRUE);
-
- SetTDTokenMaxLength (TdStruct, RequestLen);
-
- SetTDTokenDataToggle0 (TdStruct);
-
- SetTDTokenEndPoint (TdStruct, Endpoint);
-
- SetTDTokenDeviceAddress (TdStruct, DevAddr);
-
- SetTDTokenPacketID (TdStruct, SETUP_PACKET_ID);
-
- TdStruct->PtrTDBuffer = (UINT8 *)DevRequest;
- TdStruct->TDBufferLength = RequestLen;
- //
- // Set the beginning address of the buffer that will be used
- // during the transaction.
- //
- TdStruct->TDData.TDBufferPtr = (UINT32)(UINTN)RequestPhy;
-
- *PtrTD = TdStruct;
-
- return EFI_SUCCESS;
-}
-
-/**
- Generate Data Stage TD.
-
- @param UhcDev The UHCI device.
- @param DevAddr Device address.
- @param Endpoint Endpoint number.
- @param PtrData CPU memory address of user data buffer to transfer.
- @param DataPhy PCI memory address of user data buffer to transfer.
- @param Len Data length.
- @param PktID PacketID.
- @param Toggle Data toggle value.
- @param DeviceSpeed Device Speed.
- @param PtrTD TD_STRUCT generated.
-
- @return EFI_SUCCESS Generate data stage TD successfully.
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
-
-**/
-EFI_STATUS
-GenDataTD (
- IN USB_UHC_DEV *UhcDev,
- IN UINT8 DevAddr,
- IN UINT8 Endpoint,
- IN UINT8 *PtrData,
- IN UINT8 *DataPhy,
- IN UINT8 Len,
- IN UINT8 PktID,
- IN UINT8 Toggle,
- IN UINT8 DeviceSpeed,
- OUT TD_STRUCT **PtrTD
- )
-{
- TD_STRUCT *TdStruct;
- EFI_STATUS Status;
-
- Status = CreateTD (UhcDev, &TdStruct);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- SetTDLinkPtr (TdStruct, NULL);
-
- //
- // Depth first fashion
- //
- SetTDLinkPtrDepthorBreadth (TdStruct, TRUE);
-
- //
- // Link pointer pointing to TD struct
- //
- SetTDLinkPtrQHorTDSelect (TdStruct, FALSE);
-
- //
- // initialize as the last TD in the QH context,
- // this field will be updated in the TD linkage process.
- //
- SetTDLinkPtrValidorInvalid (TdStruct, FALSE);
-
- //
- // Disable short packet detect
- //
- EnableorDisableTDShortPacket (TdStruct, FALSE);
- //
- // Max error counter is 3
- //
- SetTDControlErrorCounter (TdStruct, 3);
-
- //
- // set device speed attribute
- // (TRUE - Slow Device; FALSE - Full Speed Device)
- //
- switch (DeviceSpeed) {
- case USB_SLOW_SPEED_DEVICE:
- SetTDLoworFullSpeedDevice (TdStruct, TRUE);
- break;
-
- case USB_FULL_SPEED_DEVICE:
- SetTDLoworFullSpeedDevice (TdStruct, FALSE);
- break;
- }
-
- //
- // Non isochronous transfer TD
- //
- SetTDControlIsochronousorNot (TdStruct, FALSE);
-
- //
- // Disable Interrupt On Complete
- // Disable IOC interrupt.
- //
- SetorClearTDControlIOC (TdStruct, FALSE);
-
- //
- // Set Active bit
- //
- SetTDStatusActiveorInactive (TdStruct, TRUE);
-
- SetTDTokenMaxLength (TdStruct, Len);
-
- if (Toggle != 0) {
- SetTDTokenDataToggle1 (TdStruct);
- } else {
- SetTDTokenDataToggle0 (TdStruct);
- }
-
- SetTDTokenEndPoint (TdStruct, Endpoint);
-
- SetTDTokenDeviceAddress (TdStruct, DevAddr);
-
- SetTDTokenPacketID (TdStruct, PktID);
-
- TdStruct->PtrTDBuffer = (UINT8 *)PtrData;
- TdStruct->TDBufferLength = Len;
- //
- // Set the beginning address of the buffer that will be used
- // during the transaction.
- //
- TdStruct->TDData.TDBufferPtr = (UINT32)(UINTN)DataPhy;
-
- *PtrTD = TdStruct;
-
- return EFI_SUCCESS;
-}
-
-/**
- Generate Status Stage TD.
-
- @param UhcDev The UHCI device.
- @param DevAddr Device address.
- @param Endpoint Endpoint number.
- @param PktID PacketID.
- @param DeviceSpeed Device Speed.
- @param PtrTD TD_STRUCT generated.
-
- @return EFI_SUCCESS Generate status stage TD successfully.
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
-
-**/
-EFI_STATUS
-CreateStatusTD (
- IN USB_UHC_DEV *UhcDev,
- IN UINT8 DevAddr,
- IN UINT8 Endpoint,
- IN UINT8 PktID,
- IN UINT8 DeviceSpeed,
- OUT TD_STRUCT **PtrTD
- )
-{
- TD_STRUCT *PtrTDStruct;
- EFI_STATUS Status;
-
- Status = CreateTD (UhcDev, &PtrTDStruct);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- SetTDLinkPtr (PtrTDStruct, NULL);
-
- //
- // Depth first fashion
- //
- SetTDLinkPtrDepthorBreadth (PtrTDStruct, TRUE);
-
- //
- // initialize as the last TD in the QH context,
- // this field will be updated in the TD linkage process.
- //
- SetTDLinkPtrValidorInvalid (PtrTDStruct, FALSE);
-
- //
- // Disable short packet detect
- //
- EnableorDisableTDShortPacket (PtrTDStruct, FALSE);
-
- //
- // Max error counter is 3
- //
- SetTDControlErrorCounter (PtrTDStruct, 3);
-
- //
- // set device speed attribute
- // (TRUE - Slow Device; FALSE - Full Speed Device)
- //
- switch (DeviceSpeed) {
- case USB_SLOW_SPEED_DEVICE:
- SetTDLoworFullSpeedDevice (PtrTDStruct, TRUE);
- break;
-
- case USB_FULL_SPEED_DEVICE:
- SetTDLoworFullSpeedDevice (PtrTDStruct, FALSE);
- break;
- }
-
- //
- // Non isochronous transfer TD
- //
- SetTDControlIsochronousorNot (PtrTDStruct, FALSE);
-
- //
- // Disable Interrupt On Complete
- // Disable IOC interrupt.
- //
- SetorClearTDControlIOC (PtrTDStruct, FALSE);
-
- //
- // Set TD Active bit
- //
- SetTDStatusActiveorInactive (PtrTDStruct, TRUE);
-
- SetTDTokenMaxLength (PtrTDStruct, 0);
-
- SetTDTokenDataToggle1 (PtrTDStruct);
-
- SetTDTokenEndPoint (PtrTDStruct, Endpoint);
-
- SetTDTokenDeviceAddress (PtrTDStruct, DevAddr);
-
- SetTDTokenPacketID (PtrTDStruct, PktID);
-
- PtrTDStruct->PtrTDBuffer = NULL;
- PtrTDStruct->TDBufferLength = 0;
- //
- // Set the beginning address of the buffer that will be used
- // during the transaction.
- //
- PtrTDStruct->TDData.TDBufferPtr = 0;
-
- *PtrTD = PtrTDStruct;
-
- return EFI_SUCCESS;
-}
-
-/**
- Set the link pointer validor bit in TD.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsValid Specify the linker pointer is valid or not.
-
-**/
-VOID
-SetTDLinkPtrValidorInvalid (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsValid
- )
-{
- //
- // Valid means the link pointer is valid,
- // else, it's invalid.
- //
- PtrTDStruct->TDData.TDLinkPtrTerminate = (IsValid ? 0 : 1);
-}
-
-/**
- Set the Link Pointer pointing to a QH or TD.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsQH Specify QH or TD is connected.
-
-**/
-VOID
-SetTDLinkPtrQHorTDSelect (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsQH
- )
-{
- //
- // Indicate whether the Link Pointer pointing to a QH or TD
- //
- PtrTDStruct->TDData.TDLinkPtrQSelect = (IsQH ? 1 : 0);
-}
-
-/**
- Set the traverse is depth-first or breadth-first.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsDepth Specify the traverse is depth-first or breadth-first.
-
-**/
-VOID
-SetTDLinkPtrDepthorBreadth (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsDepth
- )
-{
- //
- // If TRUE, indicating the host controller should process in depth first fashion,
- // else, the host controller should process in breadth first fashion
- //
- PtrTDStruct->TDData.TDLinkPtrDepthSelect = (IsDepth ? 1 : 0);
-}
-
-/**
- Set TD Link Pointer in TD.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param PtrNext Place to the next TD_STRUCT.
-
-**/
-VOID
-SetTDLinkPtr (
- IN TD_STRUCT *PtrTDStruct,
- IN VOID *PtrNext
- )
-{
- //
- // Set TD Link Pointer. Since QH,TD align on 16-byte boundaries,
- // only the highest 28 bits are valid. (if take 32bit address as an example)
- //
- PtrTDStruct->TDData.TDLinkPtr = (UINT32)(UINTN)PtrNext >> 4;
-}
-
-/**
- Get TD Link Pointer.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval Get TD Link Pointer in TD.
-
-**/
-VOID *
-GetTDLinkPtr (
- IN TD_STRUCT *PtrTDStruct
- )
-{
- //
- // Get TD Link Pointer. Restore it back to 32bit
- // (if take 32bit address as an example)
- //
- return (VOID *)(UINTN)((PtrTDStruct->TDData.TDLinkPtr) << 4);
-}
-
-/**
- Enable/Disable short packet detection mechanism.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsEnable Enable or disable short packet detection mechanism.
-
-**/
-VOID
-EnableorDisableTDShortPacket (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsEnable
- )
-{
- //
- // TRUE means enable short packet detection mechanism.
- //
- PtrTDStruct->TDData.TDStatusSPD = (IsEnable ? 1 : 0);
-}
-
-/**
- Set the max error counter in TD.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param MaxErrors The number of allowable error.
-
-**/
-VOID
-SetTDControlErrorCounter (
- IN TD_STRUCT *PtrTDStruct,
- IN UINT8 MaxErrors
- )
-{
- //
- // valid value of MaxErrors is 0,1,2,3
- //
- if (MaxErrors > 3) {
- MaxErrors = 3;
- }
-
- PtrTDStruct->TDData.TDStatusErr = MaxErrors;
-}
-
-/**
- Set the TD is targeting a low-speed device or not.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsLowSpeedDevice Whether The device is low-speed.
-
-**/
-VOID
-SetTDLoworFullSpeedDevice (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsLowSpeedDevice
- )
-{
- //
- // TRUE means the TD is targeting at a Low-speed device
- //
- PtrTDStruct->TDData.TDStatusLS = (IsLowSpeedDevice ? 1 : 0);
-}
-
-/**
- Set the TD is isochronous transfer type or not.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsIsochronous Whether the transaction isochronous transfer type.
-
-**/
-VOID
-SetTDControlIsochronousorNot (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsIsochronous
- )
-{
- //
- // TRUE means the TD belongs to Isochronous transfer type.
- //
- PtrTDStruct->TDData.TDStatusIOS = (IsIsochronous ? 1 : 0);
-}
-
-/**
- Set if UCHI should issue an interrupt on completion of the frame
- in which this TD is executed
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsSet Whether HC should issue an interrupt on completion.
-
-**/
-VOID
-SetorClearTDControlIOC (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsSet
- )
-{
- //
- // If this bit is set, it indicates that the host controller should issue
- // an interrupt on completion of the frame in which this TD is executed.
- //
- PtrTDStruct->TDData.TDStatusIOC = IsSet ? 1 : 0;
-}
-
-/**
- Set if the TD is active and can be executed.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsActive Whether the TD is active and can be executed.
-
-**/
-VOID
-SetTDStatusActiveorInactive (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsActive
- )
-{
- //
- // If this bit is set, it indicates that the TD is active and can be
- // executed.
- //
- if (IsActive) {
- PtrTDStruct->TDData.TDStatus |= 0x80;
- } else {
- PtrTDStruct->TDData.TDStatus &= 0x7F;
- }
-}
-
-/**
- Specifies the maximum number of data bytes allowed for the transfer.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param MaxLen The maximum number of data bytes allowed.
-
- @retval The allowed maximum number of data.
-**/
-UINT16
-SetTDTokenMaxLength (
- IN TD_STRUCT *PtrTDStruct,
- IN UINT16 MaxLen
- )
-{
- //
- // Specifies the maximum number of data bytes allowed for the transfer.
- // the legal value extent is 0 ~ 0x500.
- //
- if (MaxLen > 0x500) {
- MaxLen = 0x500;
- }
-
- PtrTDStruct->TDData.TDTokenMaxLen = MaxLen - 1;
-
- return MaxLen;
-}
-
-/**
- Set the data toggle bit to DATA1.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
-**/
-VOID
-SetTDTokenDataToggle1 (
- IN TD_STRUCT *PtrTDStruct
- )
-{
- //
- // Set the data toggle bit to DATA1
- //
- PtrTDStruct->TDData.TDTokenDataToggle = 1;
-}
-
-/**
- Set the data toggle bit to DATA0.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
-**/
-VOID
-SetTDTokenDataToggle0 (
- IN TD_STRUCT *PtrTDStruct
- )
-{
- //
- // Set the data toggle bit to DATA0
- //
- PtrTDStruct->TDData.TDTokenDataToggle = 0;
-}
-
-/**
- Set EndPoint Number the TD is targeting at.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param EndPoint The Endport number of the target.
-
-**/
-VOID
-SetTDTokenEndPoint (
- IN TD_STRUCT *PtrTDStruct,
- IN UINTN EndPoint
- )
-{
- //
- // Set EndPoint Number the TD is targeting at.
- //
- PtrTDStruct->TDData.TDTokenEndPt = (UINT8)EndPoint;
-}
-
-/**
- Set Device Address the TD is targeting at.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param DevAddr The Device Address of the target.
-
-**/
-VOID
-SetTDTokenDeviceAddress (
- IN TD_STRUCT *PtrTDStruct,
- IN UINTN DevAddr
- )
-{
- //
- // Set Device Address the TD is targeting at.
- //
- PtrTDStruct->TDData.TDTokenDevAddr = (UINT8)DevAddr;
-}
-
-/**
- Set Packet Identification the TD is targeting at.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param PacketID The Packet Identification of the target.
-
-**/
-VOID
-SetTDTokenPacketID (
- IN TD_STRUCT *PtrTDStruct,
- IN UINT8 PacketID
- )
-{
- //
- // Set the Packet Identification to be used for this transaction.
- //
- PtrTDStruct->TDData.TDTokenPID = PacketID;
-}
-
-/**
- Detect whether the TD is active.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The TD is active or not.
-
-**/
-BOOLEAN
-IsTDStatusActive (
- IN TD_STRUCT *PtrTDStruct
- )
-{
- UINT8 TDStatus;
-
- //
- // Detect whether the TD is active.
- //
- TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
- return (BOOLEAN)(TDStatus & 0x80);
-}
-
-/**
- Detect whether the TD is stalled.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The TD is stalled or not.
-
-**/
-BOOLEAN
-IsTDStatusStalled (
- IN TD_STRUCT *PtrTDStruct
- )
-{
- UINT8 TDStatus;
-
- //
- // Detect whether the device/endpoint addressed by this TD is stalled.
- //
- TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
- return (BOOLEAN)(TDStatus & 0x40);
-}
-
-/**
- Detect whether Data Buffer Error is happened.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The Data Buffer Error is happened or not.
-
-**/
-BOOLEAN
-IsTDStatusBufferError (
- IN TD_STRUCT *PtrTDStruct
- )
-{
- UINT8 TDStatus;
-
- //
- // Detect whether Data Buffer Error is happened.
- //
- TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
- return (BOOLEAN)(TDStatus & 0x20);
-}
-
-/**
- Detect whether Babble Error is happened.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The Babble Error is happened or not.
-
-**/
-BOOLEAN
-IsTDStatusBabbleError (
- IN TD_STRUCT *PtrTDStruct
- )
-{
- UINT8 TDStatus;
-
- //
- // Detect whether Babble Error is happened.
- //
- TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
- return (BOOLEAN)(TDStatus & 0x10);
-}
-
-/**
- Detect whether NAK is received.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The NAK is received or not.
-
-**/
-BOOLEAN
-IsTDStatusNAKReceived (
- IN TD_STRUCT *PtrTDStruct
- )
-{
- UINT8 TDStatus;
-
- //
- // Detect whether NAK is received.
- //
- TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
- return (BOOLEAN)(TDStatus & 0x08);
-}
-
-/**
- Detect whether CRC/Time Out Error is encountered.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The CRC/Time Out Error is encountered or not.
-
-**/
-BOOLEAN
-IsTDStatusCRCTimeOutError (
- IN TD_STRUCT *PtrTDStruct
- )
-{
- UINT8 TDStatus;
-
- //
- // Detect whether CRC/Time Out Error is encountered.
- //
- TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
- return (BOOLEAN)(TDStatus & 0x04);
-}
-
-/**
- Detect whether Bitstuff Error is received.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The Bitstuff Error is received or not.
-
-**/
-BOOLEAN
-IsTDStatusBitStuffError (
- IN TD_STRUCT *PtrTDStruct
- )
-{
- UINT8 TDStatus;
-
- //
- // Detect whether Bitstuff Error is received.
- //
- TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
- return (BOOLEAN)(TDStatus & 0x02);
-}
-
-/**
- Retrieve the actual number of bytes that were tansferred.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The actual number of bytes that were tansferred.
-
-**/
-UINT16
-GetTDStatusActualLength (
- IN TD_STRUCT *PtrTDStruct
- )
-{
- //
- // Retrieve the actual number of bytes that were tansferred.
- // the value is encoded as n-1. so return the decoded value.
- //
- return (UINT16)((PtrTDStruct->TDData.TDStatusActualLength) + 1);
-}
-
-/**
- Retrieve the information of whether the Link Pointer field is valid or not.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The linker pointer field is valid or not.
-
-**/
-BOOLEAN
-GetTDLinkPtrValidorInvalid (
- IN TD_STRUCT *PtrTDStruct
- )
-{
- //
- // Retrieve the information of whether the Link Pointer field
- // is valid or not.
- //
- if ((PtrTDStruct->TDData.TDLinkPtrTerminate & BIT0) != 0) {
- return FALSE;
- } else {
- return TRUE;
- }
-}
-
-/**
- Count TD Number from PtrFirstTD.
-
- @param PtrFirstTD Place to store TD_STRUCT pointer.
-
- @retval The queued TDs number.
-
-**/
-UINTN
-CountTDsNumber (
- IN TD_STRUCT *PtrFirstTD
- )
-{
- UINTN Number;
- TD_STRUCT *Ptr;
-
- //
- // Count the queued TDs number.
- //
- Number = 0;
- Ptr = PtrFirstTD;
- while (Ptr != 0) {
- Ptr = (TD_STRUCT *)Ptr->PtrNextTD;
- Number++;
- }
-
- return Number;
-}
-
-/**
- Link TD To QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param PtrTD Place to store TD_STRUCT pointer.
-
-**/
-VOID
-LinkTDToQH (
- IN QH_STRUCT *PtrQH,
- IN TD_STRUCT *PtrTD
- )
-{
- if ((PtrQH == NULL) || (PtrTD == NULL)) {
- return;
- }
-
- //
- // Validate QH Vertical Ptr field
- //
- SetQHVerticalValidorInvalid (PtrQH, TRUE);
-
- //
- // Vertical Ptr pointing to TD structure
- //
- SetQHVerticalQHorTDSelect (PtrQH, FALSE);
-
- SetQHVerticalLinkPtr (PtrQH, (VOID *)PtrTD);
-
- PtrQH->PtrDown = (VOID *)PtrTD;
-}
-
-/**
- Link TD To TD.
-
- @param PtrPreTD Place to store TD_STRUCT pointer.
- @param PtrTD Place to store TD_STRUCT pointer.
-
-**/
-VOID
-LinkTDToTD (
- IN TD_STRUCT *PtrPreTD,
- IN TD_STRUCT *PtrTD
- )
-{
- if ((PtrPreTD == NULL) || (PtrTD == NULL)) {
- return;
- }
-
- //
- // Depth first fashion
- //
- SetTDLinkPtrDepthorBreadth (PtrPreTD, TRUE);
-
- //
- // Link pointer pointing to TD struct
- //
- SetTDLinkPtrQHorTDSelect (PtrPreTD, FALSE);
-
- //
- // Validate the link pointer valid bit
- //
- SetTDLinkPtrValidorInvalid (PtrPreTD, TRUE);
-
- SetTDLinkPtr (PtrPreTD, PtrTD);
-
- PtrPreTD->PtrNextTD = (VOID *)PtrTD;
-
- PtrTD->PtrNextTD = NULL;
-}
-
-/**
- Execute Control Transfer.
-
- @param UhcDev The UCHI device.
- @param PtrTD A pointer to TD_STRUCT data.
- @param ActualLen Actual transfer Length.
- @param TimeOut TimeOut value.
- @param TransferResult Transfer Result.
-
- @return EFI_DEVICE_ERROR The transfer failed due to transfer error.
- @return EFI_TIMEOUT The transfer failed due to time out.
- @return EFI_SUCCESS The transfer finished OK.
-
-**/
-EFI_STATUS
-ExecuteControlTransfer (
- IN USB_UHC_DEV *UhcDev,
- IN TD_STRUCT *PtrTD,
- OUT UINTN *ActualLen,
- IN UINTN TimeOut,
- OUT UINT32 *TransferResult
- )
-{
- UINTN ErrTDPos;
- UINTN Delay;
- BOOLEAN InfiniteLoop;
-
- ErrTDPos = 0;
- *TransferResult = EFI_USB_NOERROR;
- *ActualLen = 0;
- InfiniteLoop = FALSE;
-
- Delay = TimeOut * STALL_1_MILLI_SECOND;
- //
- // If Timeout is 0, then the caller must wait for the function to be completed
- // until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.
- //
- if (TimeOut == 0) {
- InfiniteLoop = TRUE;
- }
-
- do {
- CheckTDsResults (PtrTD, TransferResult, &ErrTDPos, ActualLen);
-
- //
- // TD is inactive, means the control transfer is end.
- //
- if ((*TransferResult & EFI_USB_ERR_NOTEXECUTE) != EFI_USB_ERR_NOTEXECUTE) {
- break;
- }
-
- MicroSecondDelay (STALL_1_MICRO_SECOND);
- Delay--;
- } while (InfiniteLoop || (Delay != 0));
-
- if (*TransferResult != EFI_USB_NOERROR) {
- return EFI_DEVICE_ERROR;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Execute Bulk Transfer.
-
- @param UhcDev The UCHI device.
- @param PtrTD A pointer to TD_STRUCT data.
- @param ActualLen Actual transfer Length.
- @param DataToggle DataToggle value.
- @param TimeOut TimeOut value.
- @param TransferResult Transfer Result.
-
- @return EFI_DEVICE_ERROR The transfer failed due to transfer error.
- @return EFI_TIMEOUT The transfer failed due to time out.
- @return EFI_SUCCESS The transfer finished OK.
-
-**/
-EFI_STATUS
-ExecBulkTransfer (
- IN USB_UHC_DEV *UhcDev,
- IN TD_STRUCT *PtrTD,
- IN OUT UINTN *ActualLen,
- IN UINT8 *DataToggle,
- IN UINTN TimeOut,
- OUT UINT32 *TransferResult
- )
-{
- UINTN ErrTDPos;
- UINTN ScrollNum;
- UINTN Delay;
- BOOLEAN InfiniteLoop;
-
- ErrTDPos = 0;
- *TransferResult = EFI_USB_NOERROR;
- *ActualLen = 0;
- InfiniteLoop = FALSE;
-
- Delay = TimeOut * STALL_1_MILLI_SECOND;
- //
- // If Timeout is 0, then the caller must wait for the function to be completed
- // until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.
- //
- if (TimeOut == 0) {
- InfiniteLoop = TRUE;
- }
-
- do {
- CheckTDsResults (PtrTD, TransferResult, &ErrTDPos, ActualLen);
- //
- // TD is inactive, thus meaning bulk transfer's end.
- //
- if ((*TransferResult & EFI_USB_ERR_NOTEXECUTE) != EFI_USB_ERR_NOTEXECUTE) {
- break;
- }
-
- MicroSecondDelay (STALL_1_MICRO_SECOND);
- Delay--;
- } while (InfiniteLoop || (Delay != 0));
-
- //
- // has error
- //
- if (*TransferResult != EFI_USB_NOERROR) {
- //
- // scroll the Data Toggle back to the last success TD
- //
- ScrollNum = CountTDsNumber (PtrTD) - ErrTDPos;
- if ((ScrollNum % 2) != 0) {
- *DataToggle ^= 1;
- }
-
- //
- // If error, wait 100ms to retry by upper layer
- //
- MicroSecondDelay (100 * 1000);
- return EFI_DEVICE_ERROR;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Delete Queued TDs.
-
- @param UhcDev The UCHI device.
- @param PtrFirstTD Place to store TD_STRUCT pointer.
-
-**/
-VOID
-DeleteQueuedTDs (
- IN USB_UHC_DEV *UhcDev,
- IN TD_STRUCT *PtrFirstTD
- )
-{
- TD_STRUCT *Tptr1;
-
- TD_STRUCT *Tptr2;
-
- Tptr1 = PtrFirstTD;
- //
- // Delete all the TDs in a queue.
- //
- while (Tptr1 != NULL) {
- Tptr2 = Tptr1;
-
- if (!GetTDLinkPtrValidorInvalid (Tptr2)) {
- Tptr1 = NULL;
- } else {
- //
- // has more than one TD in the queue.
- //
- Tptr1 = GetTDLinkPtr (Tptr2);
- }
-
- UhcFreePool (UhcDev, (UINT8 *)Tptr2, sizeof (TD_STRUCT));
- }
-
- return;
-}
-
-/**
- Check TDs Results.
-
- @param PtrTD A pointer to TD_STRUCT data.
- @param Result The result to return.
- @param ErrTDPos The Error TD position.
- @param ActualTransferSize Actual transfer size.
-
- @retval The TD is executed successfully or not.
-
-**/
-BOOLEAN
-CheckTDsResults (
- IN TD_STRUCT *PtrTD,
- OUT UINT32 *Result,
- OUT UINTN *ErrTDPos,
- OUT UINTN *ActualTransferSize
- )
-{
- UINTN Len;
-
- *Result = EFI_USB_NOERROR;
- *ErrTDPos = 0;
-
- //
- // Init to zero.
- //
- *ActualTransferSize = 0;
-
- while (PtrTD != NULL) {
- if (IsTDStatusActive (PtrTD)) {
- *Result |= EFI_USB_ERR_NOTEXECUTE;
- }
-
- if (IsTDStatusStalled (PtrTD)) {
- *Result |= EFI_USB_ERR_STALL;
- }
-
- if (IsTDStatusBufferError (PtrTD)) {
- *Result |= EFI_USB_ERR_BUFFER;
- }
-
- if (IsTDStatusBabbleError (PtrTD)) {
- *Result |= EFI_USB_ERR_BABBLE;
- }
-
- if (IsTDStatusNAKReceived (PtrTD)) {
- *Result |= EFI_USB_ERR_NAK;
- }
-
- if (IsTDStatusCRCTimeOutError (PtrTD)) {
- *Result |= EFI_USB_ERR_TIMEOUT;
- }
-
- if (IsTDStatusBitStuffError (PtrTD)) {
- *Result |= EFI_USB_ERR_BITSTUFF;
- }
-
- //
- // Accumulate actual transferred data length in each TD.
- //
- Len = GetTDStatusActualLength (PtrTD) & 0x7FF;
- *ActualTransferSize += Len;
-
- //
- // if any error encountered, stop processing the left TDs.
- //
- if ((*Result) != 0) {
- return FALSE;
- }
-
- PtrTD = (TD_STRUCT *)(PtrTD->PtrNextTD);
- //
- // Record the first Error TD's position in the queue,
- // this value is zero-based.
- //
- (*ErrTDPos)++;
- }
-
- return TRUE;
-}
-
-/**
- Create Memory Block.
-
- @param UhcDev The UCHI device.
- @param MemoryHeader The Pointer to allocated memory block.
- @param MemoryBlockSizeInPages The page size of memory block to be allocated.
-
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
- @retval EFI_SUCCESS Success.
-
-**/
-EFI_STATUS
-CreateMemoryBlock (
- IN USB_UHC_DEV *UhcDev,
- OUT MEMORY_MANAGE_HEADER **MemoryHeader,
- IN UINTN MemoryBlockSizeInPages
- )
-{
- EFI_STATUS Status;
- UINT8 *TempPtr;
- UINTN MemPages;
- UINT8 *Ptr;
- VOID *Mapping;
- EFI_PHYSICAL_ADDRESS MappedAddr;
-
- //
- // Memory Block uses MemoryBlockSizeInPages pages,
- // memory management header and bit array use 1 page
- //
- MemPages = MemoryBlockSizeInPages + 1;
- Status = IoMmuAllocateBuffer (
- UhcDev->IoMmu,
- MemPages,
- (VOID **)&TempPtr,
- &MappedAddr,
- &Mapping
- );
- if (EFI_ERROR (Status) || (TempPtr == NULL)) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- Ptr = TempPtr;
-
- ZeroMem (Ptr, MemPages * EFI_PAGE_SIZE);
-
- *MemoryHeader = (MEMORY_MANAGE_HEADER *)Ptr;
- //
- // adjust Ptr pointer to the next empty memory
- //
- Ptr += sizeof (MEMORY_MANAGE_HEADER);
- //
- // Set Bit Array initial address
- //
- (*MemoryHeader)->BitArrayPtr = Ptr;
-
- (*MemoryHeader)->Next = NULL;
-
- //
- // Memory block initial address
- //
- Ptr = TempPtr;
- Ptr += EFI_PAGE_SIZE;
- (*MemoryHeader)->MemoryBlockPtr = Ptr;
- //
- // set Memory block size
- //
- (*MemoryHeader)->MemoryBlockSizeInBytes = MemoryBlockSizeInPages * EFI_PAGE_SIZE;
- //
- // each bit in Bit Array will manage 32byte memory in memory block
- //
- (*MemoryHeader)->BitArraySizeInBytes = ((*MemoryHeader)->MemoryBlockSizeInBytes / 32) / 8;
-
- return EFI_SUCCESS;
-}
-
-/**
- Initialize UHCI memory management.
-
- @param UhcDev The UCHI device.
-
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
- @retval EFI_SUCCESS Success.
-
-**/
-EFI_STATUS
-InitializeMemoryManagement (
- IN USB_UHC_DEV *UhcDev
- )
-{
- MEMORY_MANAGE_HEADER *MemoryHeader;
- EFI_STATUS Status;
- UINTN MemPages;
-
- MemPages = NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES;
- Status = CreateMemoryBlock (UhcDev, &MemoryHeader, MemPages);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- UhcDev->Header1 = MemoryHeader;
-
- return EFI_SUCCESS;
-}
-
-/**
- Initialize UHCI memory management.
-
- @param UhcDev The UCHI device.
- @param Pool Buffer pointer to store the buffer pointer.
- @param AllocSize The size of the pool to be allocated.
-
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
- @retval EFI_SUCCESS Success.
-
-**/
-EFI_STATUS
-UhcAllocatePool (
- IN USB_UHC_DEV *UhcDev,
- OUT UINT8 **Pool,
- IN UINTN AllocSize
- )
-{
- MEMORY_MANAGE_HEADER *MemoryHeader;
- MEMORY_MANAGE_HEADER *TempHeaderPtr;
- MEMORY_MANAGE_HEADER *NewMemoryHeader;
- UINTN RealAllocSize;
- UINTN MemoryBlockSizeInPages;
- EFI_STATUS Status;
-
- *Pool = NULL;
-
- MemoryHeader = UhcDev->Header1;
-
- //
- // allocate unit is 32 byte (align on 32 byte)
- //
- if ((AllocSize & 0x1F) != 0) {
- RealAllocSize = (AllocSize / 32 + 1) * 32;
- } else {
- RealAllocSize = AllocSize;
- }
-
- Status = EFI_NOT_FOUND;
- for (TempHeaderPtr = MemoryHeader; TempHeaderPtr != NULL; TempHeaderPtr = TempHeaderPtr->Next) {
- Status = AllocMemInMemoryBlock (
- TempHeaderPtr,
- (VOID **)Pool,
- RealAllocSize / 32
- );
- if (!EFI_ERROR (Status)) {
- return EFI_SUCCESS;
- }
- }
-
- //
- // There is no enough memory,
- // Create a new Memory Block
- //
- //
- // if pool size is larger than NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES,
- // just allocate a large enough memory block.
- //
- if (RealAllocSize > (NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES * EFI_PAGE_SIZE)) {
- MemoryBlockSizeInPages = RealAllocSize / EFI_PAGE_SIZE + 1;
- } else {
- MemoryBlockSizeInPages = NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES;
- }
-
- Status = CreateMemoryBlock (UhcDev, &NewMemoryHeader, MemoryBlockSizeInPages);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Link the new Memory Block to the Memory Header list
- //
- InsertMemoryHeaderToList (MemoryHeader, NewMemoryHeader);
-
- Status = AllocMemInMemoryBlock (
- NewMemoryHeader,
- (VOID **)Pool,
- RealAllocSize / 32
- );
- return Status;
-}
-
-/**
- Alloc Memory In MemoryBlock.
-
- @param MemoryHeader The pointer to memory manage header.
- @param Pool Buffer pointer to store the buffer pointer.
- @param NumberOfMemoryUnit The size of the pool to be allocated.
-
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
- @retval EFI_SUCCESS Success.
-
-**/
-EFI_STATUS
-AllocMemInMemoryBlock (
- IN MEMORY_MANAGE_HEADER *MemoryHeader,
- OUT VOID **Pool,
- IN UINTN NumberOfMemoryUnit
- )
-{
- UINTN TempBytePos;
- UINTN FoundBytePos;
- UINT8 Index;
- UINT8 FoundBitPos;
- UINT8 ByteValue;
- UINT8 BitValue;
- UINTN NumberOfZeros;
- UINTN Count;
-
- FoundBytePos = 0;
- FoundBitPos = 0;
-
- ByteValue = MemoryHeader->BitArrayPtr[0];
- NumberOfZeros = 0;
- Index = 0;
- for (TempBytePos = 0; TempBytePos < MemoryHeader->BitArraySizeInBytes;) {
- //
- // Pop out BitValue from a byte in TempBytePos.
- //
- BitValue = (UINT8)(ByteValue & 0x1);
-
- if (BitValue == 0) {
- //
- // Found a free bit, the NumberOfZeros only record the number of those consecutive zeros
- //
- NumberOfZeros++;
- //
- // Found enough consecutive free space, break the loop
- //
- if (NumberOfZeros >= NumberOfMemoryUnit) {
- break;
- }
- } else {
- //
- // Encountering a '1', meant the bit is ocupied.
- //
- if (NumberOfZeros >= NumberOfMemoryUnit) {
- //
- // Found enough consecutive free space,break the loop
- //
- break;
- } else {
- //
- // the NumberOfZeros only record the number of those consecutive zeros,
- // so reset the NumberOfZeros to 0 when encountering '1' before finding
- // enough consecutive '0's
- //
- NumberOfZeros = 0;
- //
- // reset the (FoundBytePos,FoundBitPos) to the position of '1'
- //
- FoundBytePos = TempBytePos;
- FoundBitPos = Index;
- }
- }
-
- //
- // right shift the byte
- //
- ByteValue /= 2;
-
- //
- // step forward a bit
- //
- Index++;
- if (Index == 8) {
- //
- // step forward a byte, getting the byte value,
- // and reset the bit pos.
- //
- TempBytePos += 1;
- ByteValue = MemoryHeader->BitArrayPtr[TempBytePos];
- Index = 0;
- }
- }
-
- if (NumberOfZeros < NumberOfMemoryUnit) {
- return EFI_NOT_FOUND;
- }
-
- //
- // Found enough free space.
- //
- //
- // The values recorded in (FoundBytePos,FoundBitPos) have two conditions:
- // 1)(FoundBytePos,FoundBitPos) record the position
- // of the last '1' before the consecutive '0's, it must
- // be adjusted to the start position of the consecutive '0's.
- // 2)the start address of the consecutive '0's is just the start of
- // the bitarray. so no need to adjust the values of (FoundBytePos,FoundBitPos).
- //
- if ((MemoryHeader->BitArrayPtr[0] & BIT0) != 0) {
- FoundBitPos += 1;
- }
-
- //
- // Have the (FoundBytePos,FoundBitPos) make sense.
- //
- if (FoundBitPos > 7) {
- FoundBytePos += 1;
- FoundBitPos -= 8;
- }
-
- //
- // Set the memory as allocated
- //
- for (TempBytePos = FoundBytePos, Index = FoundBitPos, Count = 0; Count < NumberOfMemoryUnit; Count++) {
- MemoryHeader->BitArrayPtr[TempBytePos] = (UINT8)(MemoryHeader->BitArrayPtr[TempBytePos] | (1 << Index));
- Index++;
- if (Index == 8) {
- TempBytePos += 1;
- Index = 0;
- }
- }
-
- *Pool = MemoryHeader->MemoryBlockPtr + (FoundBytePos * 8 + FoundBitPos) * 32;
-
- return EFI_SUCCESS;
-}
-
-/**
- Uhci Free Pool.
-
- @param UhcDev The UHCI device.
- @param Pool A pointer to store the buffer address.
- @param AllocSize The size of the pool to be freed.
-
-**/
-VOID
-UhcFreePool (
- IN USB_UHC_DEV *UhcDev,
- IN UINT8 *Pool,
- IN UINTN AllocSize
- )
-{
- MEMORY_MANAGE_HEADER *MemoryHeader;
- MEMORY_MANAGE_HEADER *TempHeaderPtr;
- UINTN StartBytePos;
- UINTN Index;
- UINT8 StartBitPos;
- UINT8 Index2;
- UINTN Count;
- UINTN RealAllocSize;
-
- MemoryHeader = UhcDev->Header1;
-
- //
- // allocate unit is 32 byte (align on 32 byte)
- //
- if ((AllocSize & 0x1F) != 0) {
- RealAllocSize = (AllocSize / 32 + 1) * 32;
- } else {
- RealAllocSize = AllocSize;
- }
-
- for (TempHeaderPtr = MemoryHeader; TempHeaderPtr != NULL;
- TempHeaderPtr = TempHeaderPtr->Next)
- {
- if ((Pool >= TempHeaderPtr->MemoryBlockPtr) &&
- ((Pool + RealAllocSize) <= (TempHeaderPtr->MemoryBlockPtr +
- TempHeaderPtr->MemoryBlockSizeInBytes)))
- {
- //
- // Pool is in the Memory Block area,
- // find the start byte and bit in the bit array
- //
- StartBytePos = ((Pool - TempHeaderPtr->MemoryBlockPtr) / 32) / 8;
- StartBitPos = (UINT8)(((Pool - TempHeaderPtr->MemoryBlockPtr) / 32) % 8);
-
- //
- // reset associated bits in bit array
- //
- for (Index = StartBytePos, Index2 = StartBitPos, Count = 0; Count < (RealAllocSize / 32); Count++) {
- TempHeaderPtr->BitArrayPtr[Index] = (UINT8)(TempHeaderPtr->BitArrayPtr[Index] ^ (1 << Index2));
- Index2++;
- if (Index2 == 8) {
- Index += 1;
- Index2 = 0;
- }
- }
-
- //
- // break the loop
- //
- break;
- }
- }
-}
-
-/**
- Insert a new memory header into list.
-
- @param MemoryHeader A pointer to the memory header list.
- @param NewMemoryHeader A new memory header to be inserted into the list.
-
-**/
-VOID
-InsertMemoryHeaderToList (
- IN MEMORY_MANAGE_HEADER *MemoryHeader,
- IN MEMORY_MANAGE_HEADER *NewMemoryHeader
- )
-{
- MEMORY_MANAGE_HEADER *TempHeaderPtr;
-
- for (TempHeaderPtr = MemoryHeader; TempHeaderPtr != NULL; TempHeaderPtr = TempHeaderPtr->Next) {
- if (TempHeaderPtr->Next == NULL) {
- TempHeaderPtr->Next = NewMemoryHeader;
- break;
- }
- }
-}
-
-/**
- Map address of request structure buffer.
-
- @param Uhc The UHCI device.
- @param Request The user request buffer.
- @param MappedAddr Mapped address of request.
- @param Map Identificaion of this mapping to return.
-
- @return EFI_SUCCESS Success.
- @return EFI_DEVICE_ERROR Fail to map the user request.
-
-**/
-EFI_STATUS
-UhciMapUserRequest (
- IN USB_UHC_DEV *Uhc,
- IN OUT VOID *Request,
- OUT UINT8 **MappedAddr,
- OUT VOID **Map
- )
-{
- EFI_STATUS Status;
- UINTN Len;
- EFI_PHYSICAL_ADDRESS PhyAddr;
-
- Len = sizeof (EFI_USB_DEVICE_REQUEST);
- Status = IoMmuMap (
- Uhc->IoMmu,
- EdkiiIoMmuOperationBusMasterRead,
- Request,
- &Len,
- &PhyAddr,
- Map
- );
-
- if (!EFI_ERROR (Status)) {
- *MappedAddr = (UINT8 *)(UINTN)PhyAddr;
- }
-
- return Status;
-}
-
-/**
- Map address of user data buffer.
-
- @param Uhc The UHCI device.
- @param Direction Direction of the data transfer.
- @param Data The user data buffer.
- @param Len Length of the user data.
- @param PktId Packet identificaion.
- @param MappedAddr Mapped address to return.
- @param Map Identificaion of this mapping to return.
-
- @return EFI_SUCCESS Success.
- @return EFI_DEVICE_ERROR Fail to map the user data.
-
-**/
-EFI_STATUS
-UhciMapUserData (
- IN USB_UHC_DEV *Uhc,
- IN EFI_USB_DATA_DIRECTION Direction,
- IN VOID *Data,
- IN OUT UINTN *Len,
- OUT UINT8 *PktId,
- OUT UINT8 **MappedAddr,
- OUT VOID **Map
- )
-{
- EFI_STATUS Status;
- EFI_PHYSICAL_ADDRESS PhyAddr;
-
- Status = EFI_SUCCESS;
-
- switch (Direction) {
- case EfiUsbDataIn:
- //
- // BusMasterWrite means cpu read
- //
- *PktId = INPUT_PACKET_ID;
- Status = IoMmuMap (
- Uhc->IoMmu,
- EdkiiIoMmuOperationBusMasterWrite,
- Data,
- Len,
- &PhyAddr,
- Map
- );
-
- if (EFI_ERROR (Status)) {
- goto EXIT;
- }
-
- *MappedAddr = (UINT8 *)(UINTN)PhyAddr;
- break;
-
- case EfiUsbDataOut:
- *PktId = OUTPUT_PACKET_ID;
- Status = IoMmuMap (
- Uhc->IoMmu,
- EdkiiIoMmuOperationBusMasterRead,
- Data,
- Len,
- &PhyAddr,
- Map
- );
-
- if (EFI_ERROR (Status)) {
- goto EXIT;
- }
-
- *MappedAddr = (UINT8 *)(UINTN)PhyAddr;
- break;
-
- case EfiUsbNoData:
- if ((Len != NULL) && (*Len != 0)) {
- Status = EFI_INVALID_PARAMETER;
- goto EXIT;
- }
-
- *PktId = OUTPUT_PACKET_ID;
- *MappedAddr = NULL;
- *Map = NULL;
- break;
-
- default:
- Status = EFI_INVALID_PARAMETER;
- }
-
-EXIT:
- return Status;
-}
diff --git a/MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.h b/MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.h
deleted file mode 100644
index 5b135f2..0000000
--- a/MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.h
+++ /dev/null
@@ -1,1383 +0,0 @@
-/** @file
-Private Header file for Usb Host Controller PEIM
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef _RECOVERY_UHC_H_
-#define _RECOVERY_UHC_H_
-
-#include <PiPei.h>
-
-#include <Ppi/UsbController.h>
-#include <Ppi/UsbHostController.h>
-#include <Ppi/IoMmu.h>
-#include <Ppi/EndOfPeiPhase.h>
-
-#include <Library/DebugLib.h>
-#include <Library/PeimEntryPoint.h>
-#include <Library/PeiServicesLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/TimerLib.h>
-#include <Library/IoLib.h>
-#include <Library/PeiServicesLib.h>
-
-#define USB_SLOW_SPEED_DEVICE 0x01
-#define USB_FULL_SPEED_DEVICE 0x02
-
-//
-// One memory block uses 16 page
-//
-#define NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES 16
-
-#define USBCMD 0 /* Command Register Offset 00-01h */
-#define USBCMD_RS BIT0 /* Run/Stop */
-#define USBCMD_HCRESET BIT1 /* Host reset */
-#define USBCMD_GRESET BIT2 /* Global reset */
-#define USBCMD_EGSM BIT3 /* Global Suspend Mode */
-#define USBCMD_FGR BIT4 /* Force Global Resume */
-#define USBCMD_SWDBG BIT5 /* SW Debug mode */
-#define USBCMD_CF BIT6 /* Config Flag (sw only) */
-#define USBCMD_MAXP BIT7 /* Max Packet (0 = 32, 1 = 64) */
-
-/* Status register */
-#define USBSTS 2 /* Status Register Offset 02-03h */
-#define USBSTS_USBINT BIT0 /* Interrupt due to IOC */
-#define USBSTS_ERROR BIT1 /* Interrupt due to error */
-#define USBSTS_RD BIT2 /* Resume Detect */
-#define USBSTS_HSE BIT3 /* Host System Error - basically PCI problems */
-#define USBSTS_HCPE BIT4 /* Host Controller Process Error - the scripts were buggy */
-#define USBSTS_HCH BIT5 /* HC Halted */
-
-/* Interrupt enable register */
-#define USBINTR 4 /* Interrupt Enable Register 04-05h */
-#define USBINTR_TIMEOUT BIT0 /* Timeout/CRC error enable */
-#define USBINTR_RESUME BIT1 /* Resume interrupt enable */
-#define USBINTR_IOC BIT2 /* Interrupt On Complete enable */
-#define USBINTR_SP BIT3 /* Short packet interrupt enable */
-
-/* Frame Number Register Offset 06-08h */
-#define USBFRNUM 6
-
-/* Frame List Base Address Register Offset 08-0Bh */
-#define USBFLBASEADD 8
-
-/* Start of Frame Modify Register Offset 0Ch */
-#define USBSOF 0x0c
-
-/* USB port status and control registers */
-#define USBPORTSC1 0x10 /*Port 1 offset 10-11h */
-#define USBPORTSC2 0x12 /*Port 2 offset 12-13h */
-
-#define USBPORTSC_CCS BIT0 /* Current Connect Status ("device present") */
-#define USBPORTSC_CSC BIT1 /* Connect Status Change */
-#define USBPORTSC_PED BIT2 /* Port Enable / Disable */
-#define USBPORTSC_PEDC BIT3 /* Port Enable / Disable Change */
-#define USBPORTSC_LSL BIT4 /* Line Status Low bit*/
-#define USBPORTSC_LSH BIT5 /* Line Status High bit*/
-#define USBPORTSC_RD BIT6 /* Resume Detect */
-#define USBPORTSC_LSDA BIT8 /* Low Speed Device Attached */
-#define USBPORTSC_PR BIT9 /* Port Reset */
-#define USBPORTSC_SUSP BIT12 /* Suspend */
-
-#define SETUP_PACKET_ID 0x2D
-#define INPUT_PACKET_ID 0x69
-#define OUTPUT_PACKET_ID 0xE1
-#define ERROR_PACKET_ID 0x55
-
-#define STALL_1_MICRO_SECOND 1
-#define STALL_1_MILLI_SECOND 1000
-
-#pragma pack(1)
-
-typedef struct {
- UINT32 FrameListPtrTerminate : 1;
- UINT32 FrameListPtrQSelect : 1;
- UINT32 FrameListRsvd : 2;
- UINT32 FrameListPtr : 28;
-} FRAMELIST_ENTRY;
-
-typedef struct {
- UINT32 QHHorizontalTerminate : 1;
- UINT32 QHHorizontalQSelect : 1;
- UINT32 QHHorizontalRsvd : 2;
- UINT32 QHHorizontalPtr : 28;
- UINT32 QHVerticalTerminate : 1;
- UINT32 QHVerticalQSelect : 1;
- UINT32 QHVerticalRsvd : 2;
- UINT32 QHVerticalPtr : 28;
-} QUEUE_HEAD;
-
-typedef struct {
- QUEUE_HEAD QueueHead;
- UINT32 Reserved1;
- UINT32 Reserved2;
- VOID *PtrNext;
- VOID *PtrDown;
- VOID *Reserved3;
- UINT32 Reserved4;
-} QH_STRUCT;
-
-typedef struct {
- UINT32 TDLinkPtrTerminate : 1;
- UINT32 TDLinkPtrQSelect : 1;
- UINT32 TDLinkPtrDepthSelect : 1;
- UINT32 TDLinkPtrRsvd : 1;
- UINT32 TDLinkPtr : 28;
- UINT32 TDStatusActualLength : 11;
- UINT32 TDStatusRsvd : 5;
- UINT32 TDStatus : 8;
- UINT32 TDStatusIOC : 1;
- UINT32 TDStatusIOS : 1;
- UINT32 TDStatusLS : 1;
- UINT32 TDStatusErr : 2;
- UINT32 TDStatusSPD : 1;
- UINT32 TDStatusRsvd2 : 2;
- UINT32 TDTokenPID : 8;
- UINT32 TDTokenDevAddr : 7;
- UINT32 TDTokenEndPt : 4;
- UINT32 TDTokenDataToggle : 1;
- UINT32 TDTokenRsvd : 1;
- UINT32 TDTokenMaxLen : 11;
- UINT32 TDBufferPtr;
-} TD;
-
-typedef struct {
- TD TDData;
- UINT8 *PtrTDBuffer;
- VOID *PtrNextTD;
- VOID *PtrNextQH;
- UINT16 TDBufferLength;
- UINT16 Reserved;
-} TD_STRUCT;
-
-#pragma pack()
-
-typedef struct _MEMORY_MANAGE_HEADER MEMORY_MANAGE_HEADER;
-
-struct _MEMORY_MANAGE_HEADER {
- UINT8 *BitArrayPtr;
- UINTN BitArraySizeInBytes;
- UINT8 *MemoryBlockPtr;
- UINTN MemoryBlockSizeInBytes;
- MEMORY_MANAGE_HEADER *Next;
-};
-
-#define USB_UHC_DEV_SIGNATURE SIGNATURE_32 ('p', 'u', 'h', 'c')
-typedef struct {
- UINTN Signature;
- PEI_USB_HOST_CONTROLLER_PPI UsbHostControllerPpi;
- EDKII_IOMMU_PPI *IoMmu;
- EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
- //
- // EndOfPei callback is used to stop the UHC DMA operation
- // after exit PEI phase.
- //
- EFI_PEI_NOTIFY_DESCRIPTOR EndOfPeiNotifyList;
-
- UINT32 UsbHostControllerBaseAddress;
- FRAMELIST_ENTRY *FrameListEntry;
- QH_STRUCT *ConfigQH;
- QH_STRUCT *BulkQH;
- //
- // Header1 used for QH,TD memory blocks management
- //
- MEMORY_MANAGE_HEADER *Header1;
-} USB_UHC_DEV;
-
-#define PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS(a) CR (a, USB_UHC_DEV, UsbHostControllerPpi, USB_UHC_DEV_SIGNATURE)
-#define PEI_RECOVERY_USB_UHC_DEV_FROM_THIS_NOTIFY(a) CR (a, USB_UHC_DEV, EndOfPeiNotifyList, USB_UHC_DEV_SIGNATURE)
-
-/**
- Submits control transfer to a target USB device.
-
- @param PeiServices The pointer of EFI_PEI_SERVICES.
- @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
- @param DeviceAddress The target device address.
- @param DeviceSpeed Target device speed.
- @param MaximumPacketLength Maximum packet size the default control transfer
- endpoint is capable of sending or receiving.
- @param Request USB device request to send.
- @param TransferDirection Specifies the data direction for the data stage.
- @param Data Data buffer to be transmitted or received from USB device.
- @param DataLength The size (in bytes) of the data buffer.
- @param TimeOut Indicates the maximum timeout, in millisecond.
- @param TransferResult Return the result of this control transfer.
-
- @retval EFI_SUCCESS Transfer was completed successfully.
- @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resources.
- @retval EFI_INVALID_PARAMETER Some parameters are invalid.
- @retval EFI_TIMEOUT Transfer failed due to timeout.
- @retval EFI_DEVICE_ERROR Transfer failed due to host controller or device error.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcControlTransfer (
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 DeviceAddress,
- IN UINT8 DeviceSpeed,
- IN UINT8 MaximumPacketLength,
- IN EFI_USB_DEVICE_REQUEST *Request,
- IN EFI_USB_DATA_DIRECTION TransferDirection,
- IN OUT VOID *Data OPTIONAL,
- IN OUT UINTN *DataLength OPTIONAL,
- IN UINTN TimeOut,
- OUT UINT32 *TransferResult
- );
-
-/**
- Submits bulk transfer to a bulk endpoint of a USB device.
-
- @param PeiServices The pointer of EFI_PEI_SERVICES.
- @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
- @param DeviceAddress Target device address.
- @param EndPointAddress Endpoint number and its direction in bit 7.
- @param MaximumPacketLength Maximum packet size the endpoint is capable of
- sending or receiving.
- @param Data Array of pointers to the buffers of data to transmit
- from or receive into.
- @param DataLength The lenght of the data buffer.
- @param DataToggle On input, the initial data toggle for the transfer;
- On output, it is updated to to next data toggle to use of
- the subsequent bulk transfer.
- @param TimeOut Indicates the maximum time, in millisecond, which the
- transfer is allowed to complete.
- @param TransferResult A pointer to the detailed result information of the
- bulk transfer.
-
- @retval EFI_SUCCESS The transfer was completed successfully.
- @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource.
- @retval EFI_INVALID_PARAMETER Parameters are invalid.
- @retval EFI_TIMEOUT The transfer failed due to timeout.
- @retval EFI_DEVICE_ERROR The transfer failed due to host controller error.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcBulkTransfer (
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 DeviceAddress,
- IN UINT8 EndPointAddress,
- IN UINT8 MaximumPacketLength,
- IN OUT VOID *Data,
- IN OUT UINTN *DataLength,
- IN OUT UINT8 *DataToggle,
- IN UINTN TimeOut,
- OUT UINT32 *TransferResult
- );
-
-/**
- Retrieves the number of root hub ports.
-
- @param[in] PeiServices The pointer to the PEI Services Table.
- @param[in] This The pointer to this instance of the
- PEI_USB_HOST_CONTROLLER_PPI.
- @param[out] PortNumber The pointer to the number of the root hub ports.
-
- @retval EFI_SUCCESS The port number was retrieved successfully.
- @retval EFI_INVALID_PARAMETER PortNumber is NULL.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcGetRootHubPortNumber (
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- OUT UINT8 *PortNumber
- );
-
-/**
- Retrieves the current status of a USB root hub port.
-
- @param PeiServices The pointer of EFI_PEI_SERVICES.
- @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
- @param PortNumber The root hub port to retrieve the state from.
- @param PortStatus Variable to receive the port state.
-
- @retval EFI_SUCCESS The status of the USB root hub port specified.
- by PortNumber was returned in PortStatus.
- @retval EFI_INVALID_PARAMETER PortNumber is invalid.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcGetRootHubPortStatus (
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 PortNumber,
- OUT EFI_USB_PORT_STATUS *PortStatus
- );
-
-/**
- Sets a feature for the specified root hub port.
-
- @param PeiServices The pointer of EFI_PEI_SERVICES
- @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI
- @param PortNumber Root hub port to set.
- @param PortFeature Feature to set.
-
- @retval EFI_SUCCESS The feature specified by PortFeature was set.
- @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
- @retval EFI_TIMEOUT The time out occurred.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcSetRootHubPortFeature (
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 PortNumber,
- IN EFI_USB_PORT_FEATURE PortFeature
- );
-
-/**
- Clears a feature for the specified root hub port.
-
- @param PeiServices The pointer of EFI_PEI_SERVICES.
- @param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
- @param PortNumber Specifies the root hub port whose feature
- is requested to be cleared.
- @param PortFeature Indicates the feature selector associated with the
- feature clear request.
-
- @retval EFI_SUCCESS The feature specified by PortFeature was cleared
- for the USB root hub port specified by PortNumber.
- @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
-
-**/
-EFI_STATUS
-EFIAPI
-UhcClearRootHubPortFeature (
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 PortNumber,
- IN EFI_USB_PORT_FEATURE PortFeature
- );
-
-/**
- Initialize UHCI.
-
- @param UhcDev UHCI Device.
-
- @retval EFI_SUCCESS UHCI successfully initialized.
- @retval EFI_OUT_OF_RESOURCES Resource can not be allocated.
-
-**/
-EFI_STATUS
-InitializeUsbHC (
- IN USB_UHC_DEV *UhcDev
- );
-
-/**
- Create Frame List Structure.
-
- @param UhcDev UHCI device.
-
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
- @retval EFI_SUCCESS Success.
-
-**/
-EFI_STATUS
-CreateFrameList (
- USB_UHC_DEV *UhcDev
- );
-
-/**
- Read a 16bit width data from Uhc HC IO space register.
-
- @param UhcDev The UHCI device.
- @param Port The IO space address of the register.
-
- @retval the register content read.
-
-**/
-UINT16
-USBReadPortW (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 Port
- );
-
-/**
- Write a 16bit width data into Uhc HC IO space register.
-
- @param UhcDev The UHCI device.
- @param Port The IO space address of the register.
- @param Data The data written into the register.
-
-**/
-VOID
-USBWritePortW (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 Port,
- IN UINT16 Data
- );
-
-/**
- Write a 32bit width data into Uhc HC IO space register.
-
- @param UhcDev The UHCI device.
- @param Port The IO space address of the register.
- @param Data The data written into the register.
-
-**/
-VOID
-USBWritePortDW (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 Port,
- IN UINT32 Data
- );
-
-/**
- Clear the content of UHCI's Status Register.
-
- @param UhcDev The UHCI device.
- @param StatusAddr The IO space address of the register.
-
-**/
-VOID
-ClearStatusReg (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 StatusAddr
- );
-
-/**
- Check whether the host controller operates well.
-
- @param UhcDev The UHCI device.
- @param StatusRegAddr The io address of status register.
-
- @retval TRUE Host controller is working.
- @retval FALSE Host controller is halted or system error.
-
-**/
-BOOLEAN
-IsStatusOK (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 StatusRegAddr
- );
-
-/**
- Set Frame List Base Address.
-
- @param UhcDev The UHCI device.
- @param FrameListRegAddr The address of frame list register.
- @param Addr The address of frame list table.
-
-**/
-VOID
-SetFrameListBaseAddress (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 FrameListRegAddr,
- IN UINT32 Addr
- );
-
-/**
- Create QH and initialize.
-
- @param UhcDev The UHCI device.
- @param PtrQH Place to store QH_STRUCT pointer.
-
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
- @retval EFI_SUCCESS Success.
-
-**/
-EFI_STATUS
-CreateQH (
- IN USB_UHC_DEV *UhcDev,
- OUT QH_STRUCT **PtrQH
- );
-
-/**
- Set the horizontal link pointer in QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param PtrNext Place to the next QH_STRUCT.
-
-**/
-VOID
-SetQHHorizontalLinkPtr (
- IN QH_STRUCT *PtrQH,
- IN VOID *PtrNext
- );
-
-/**
- Set a QH or TD horizontally to be connected with a specific QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param IsQH Specify QH or TD is connected.
-
-**/
-VOID
-SetQHHorizontalQHorTDSelect (
- IN QH_STRUCT *PtrQH,
- IN BOOLEAN IsQH
- );
-
-/**
- Set the horizontal validor bit in QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param IsValid Specify the horizontal linker is valid or not.
-
-**/
-VOID
-SetQHHorizontalValidorInvalid (
- IN QH_STRUCT *PtrQH,
- IN BOOLEAN IsValid
- );
-
-/**
- Set the vertical link pointer in QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param PtrNext Place to the next QH_STRUCT.
-
-**/
-VOID
-SetQHVerticalLinkPtr (
- IN QH_STRUCT *PtrQH,
- IN VOID *PtrNext
- );
-
-/**
- Set a QH or TD vertically to be connected with a specific QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param IsQH Specify QH or TD is connected.
-
-**/
-VOID
-SetQHVerticalQHorTDSelect (
- IN QH_STRUCT *PtrQH,
- IN BOOLEAN IsQH
- );
-
-/**
- Set the vertical validor bit in QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param IsValid Specify the vertical linker is valid or not.
-
-**/
-VOID
-SetQHVerticalValidorInvalid (
- IN QH_STRUCT *PtrQH,
- IN BOOLEAN IsValid
- );
-
-/**
- Allocate TD or QH Struct.
-
- @param UhcDev The UHCI device.
- @param Size The size of allocation.
- @param PtrStruct Place to store TD_STRUCT pointer.
-
- @return EFI_SUCCESS Allocate successfully.
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
-
-**/
-EFI_STATUS
-AllocateTDorQHStruct (
- IN USB_UHC_DEV *UhcDev,
- IN UINT32 Size,
- OUT VOID **PtrStruct
- );
-
-/**
- Create a TD Struct.
-
- @param UhcDev The UHCI device.
- @param PtrTD Place to store TD_STRUCT pointer.
-
- @return EFI_SUCCESS Allocate successfully.
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
-
-**/
-EFI_STATUS
-CreateTD (
- IN USB_UHC_DEV *UhcDev,
- OUT TD_STRUCT **PtrTD
- );
-
-/**
- Generate Setup Stage TD.
-
- @param UhcDev The UHCI device.
- @param DevAddr Device address.
- @param Endpoint Endpoint number.
- @param DeviceSpeed Device Speed.
- @param DevRequest CPU memory address of request structure buffer to transfer.
- @param RequestPhy PCI memory address of request structure buffer to transfer.
- @param RequestLen Request length.
- @param PtrTD TD_STRUCT generated.
-
- @return EFI_SUCCESS Generate setup stage TD successfully.
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
-
-**/
-EFI_STATUS
-GenSetupStageTD (
- IN USB_UHC_DEV *UhcDev,
- IN UINT8 DevAddr,
- IN UINT8 Endpoint,
- IN UINT8 DeviceSpeed,
- IN UINT8 *DevRequest,
- IN UINT8 *RequestPhy,
- IN UINT8 RequestLen,
- OUT TD_STRUCT **PtrTD
- );
-
-/**
- Generate Data Stage TD.
-
- @param UhcDev The UHCI device.
- @param DevAddr Device address.
- @param Endpoint Endpoint number.
- @param PtrData CPU memory address of user data buffer to transfer.
- @param DataPhy PCI memory address of user data buffer to transfer.
- @param Len Data length.
- @param PktID PacketID.
- @param Toggle Data toggle value.
- @param DeviceSpeed Device Speed.
- @param PtrTD TD_STRUCT generated.
-
- @return EFI_SUCCESS Generate data stage TD successfully.
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
-
-**/
-EFI_STATUS
-GenDataTD (
- IN USB_UHC_DEV *UhcDev,
- IN UINT8 DevAddr,
- IN UINT8 Endpoint,
- IN UINT8 *PtrData,
- IN UINT8 *DataPhy,
- IN UINT8 Len,
- IN UINT8 PktID,
- IN UINT8 Toggle,
- IN UINT8 DeviceSpeed,
- OUT TD_STRUCT **PtrTD
- );
-
-/**
- Generate Status Stage TD.
-
- @param UhcDev The UHCI device.
- @param DevAddr Device address.
- @param Endpoint Endpoint number.
- @param PktID PacketID.
- @param DeviceSpeed Device Speed.
- @param PtrTD TD_STRUCT generated.
-
- @return EFI_SUCCESS Generate status stage TD successfully.
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
-
-**/
-EFI_STATUS
-CreateStatusTD (
- IN USB_UHC_DEV *UhcDev,
- IN UINT8 DevAddr,
- IN UINT8 Endpoint,
- IN UINT8 PktID,
- IN UINT8 DeviceSpeed,
- OUT TD_STRUCT **PtrTD
- );
-
-/**
- Set the link pointer validor bit in TD.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsValid Specify the linker pointer is valid or not.
-
-**/
-VOID
-SetTDLinkPtrValidorInvalid (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsValid
- );
-
-/**
- Set the Link Pointer pointing to a QH or TD.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsQH Specify QH or TD is connected.
-
-**/
-VOID
-SetTDLinkPtrQHorTDSelect (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsQH
- );
-
-/**
- Set the traverse is depth-first or breadth-first.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsDepth Specify the traverse is depth-first or breadth-first.
-
-**/
-VOID
-SetTDLinkPtrDepthorBreadth (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsDepth
- );
-
-/**
- Set TD Link Pointer in TD.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param PtrNext Place to the next TD_STRUCT.
-
-**/
-VOID
-SetTDLinkPtr (
- IN TD_STRUCT *PtrTDStruct,
- IN VOID *PtrNext
- );
-
-/**
- Get TD Link Pointer.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval Get TD Link Pointer in TD.
-
-**/
-VOID *
-GetTDLinkPtr (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Enable/Disable short packet detection mechanism.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsEnable Enable or disable short packet detection mechanism.
-
-**/
-VOID
-EnableorDisableTDShortPacket (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsEnable
- );
-
-/**
- Set the max error counter in TD.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param MaxErrors The number of allowable error.
-
-**/
-VOID
-SetTDControlErrorCounter (
- IN TD_STRUCT *PtrTDStruct,
- IN UINT8 MaxErrors
- );
-
-/**
- Set the TD is targeting a low-speed device or not.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsLowSpeedDevice Whether The device is low-speed.
-
-**/
-VOID
-SetTDLoworFullSpeedDevice (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsLowSpeedDevice
- );
-
-/**
- Set the TD is isochronous transfer type or not.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsIsochronous Whether the transaction isochronous transfer type.
-
-**/
-VOID
-SetTDControlIsochronousorNot (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsIsochronous
- );
-
-/**
- Set if UCHI should issue an interrupt on completion of the frame
- in which this TD is executed
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsSet Whether HC should issue an interrupt on completion.
-
-**/
-VOID
-SetorClearTDControlIOC (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsSet
- );
-
-/**
- Set if the TD is active and can be executed.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param IsActive Whether the TD is active and can be executed.
-
-**/
-VOID
-SetTDStatusActiveorInactive (
- IN TD_STRUCT *PtrTDStruct,
- IN BOOLEAN IsActive
- );
-
-/**
- Specifies the maximum number of data bytes allowed for the transfer.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param MaxLen The maximum number of data bytes allowed.
-
- @retval The allowed maximum number of data.
-**/
-UINT16
-SetTDTokenMaxLength (
- IN TD_STRUCT *PtrTDStruct,
- IN UINT16 MaxLen
- );
-
-/**
- Set the data toggle bit to DATA1.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
-**/
-VOID
-SetTDTokenDataToggle1 (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Set the data toggle bit to DATA0.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
-**/
-VOID
-SetTDTokenDataToggle0 (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Set EndPoint Number the TD is targeting at.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param EndPoint The Endport number of the target.
-
-**/
-VOID
-SetTDTokenEndPoint (
- IN TD_STRUCT *PtrTDStruct,
- IN UINTN EndPoint
- );
-
-/**
- Set Device Address the TD is targeting at.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param DevAddr The Device Address of the target.
-
-**/
-VOID
-SetTDTokenDeviceAddress (
- IN TD_STRUCT *PtrTDStruct,
- IN UINTN DevAddr
- );
-
-/**
- Set Packet Identification the TD is targeting at.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
- @param PacketID The Packet Identification of the target.
-
-**/
-VOID
-SetTDTokenPacketID (
- IN TD_STRUCT *PtrTDStruct,
- IN UINT8 PacketID
- );
-
-/**
- Set the beginning address of the data buffer that will be used
- during the transaction.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
-**/
-VOID
-SetTDDataBuffer (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Detect whether the TD is active.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The TD is active or not.
-
-**/
-BOOLEAN
-IsTDStatusActive (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Detect whether the TD is stalled.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The TD is stalled or not.
-
-**/
-BOOLEAN
-IsTDStatusStalled (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Detect whether Data Buffer Error is happened.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The Data Buffer Error is happened or not.
-
-**/
-BOOLEAN
-IsTDStatusBufferError (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Detect whether Babble Error is happened.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The Babble Error is happened or not.
-
-**/
-BOOLEAN
-IsTDStatusBabbleError (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Detect whether NAK is received.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The NAK is received or not.
-
-**/
-BOOLEAN
-IsTDStatusNAKReceived (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Detect whether CRC/Time Out Error is encountered.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The CRC/Time Out Error is encountered or not.
-
-**/
-BOOLEAN
-IsTDStatusCRCTimeOutError (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Detect whether Bitstuff Error is received.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The Bitstuff Error is received or not.
-
-**/
-BOOLEAN
-IsTDStatusBitStuffError (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Retrieve the actual number of bytes that were tansferred.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The actual number of bytes that were tansferred.
-
-**/
-UINT16
-GetTDStatusActualLength (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Retrieve the information of whether the Link Pointer field is valid or not.
-
- @param PtrTDStruct Place to store TD_STRUCT pointer.
-
- @retval The linker pointer field is valid or not.
-
-**/
-BOOLEAN
-GetTDLinkPtrValidorInvalid (
- IN TD_STRUCT *PtrTDStruct
- );
-
-/**
- Count TD Number from PtrFirstTD.
-
- @param PtrFirstTD Place to store TD_STRUCT pointer.
-
- @retval The queued TDs number.
-
-**/
-UINTN
-CountTDsNumber (
- IN TD_STRUCT *PtrFirstTD
- );
-
-/**
- Link TD To QH.
-
- @param PtrQH Place to store QH_STRUCT pointer.
- @param PtrTD Place to store TD_STRUCT pointer.
-
-**/
-VOID
-LinkTDToQH (
- IN QH_STRUCT *PtrQH,
- IN TD_STRUCT *PtrTD
- );
-
-/**
- Link TD To TD.
-
- @param PtrPreTD Place to store TD_STRUCT pointer.
- @param PtrTD Place to store TD_STRUCT pointer.
-
-**/
-VOID
-LinkTDToTD (
- IN TD_STRUCT *PtrPreTD,
- IN TD_STRUCT *PtrTD
- );
-
-/**
- Execute Control Transfer.
-
- @param UhcDev The UCHI device.
- @param PtrTD A pointer to TD_STRUCT data.
- @param ActualLen Actual transfer Length.
- @param TimeOut TimeOut value.
- @param TransferResult Transfer Result.
-
- @return EFI_DEVICE_ERROR The transfer failed due to transfer error.
- @return EFI_TIMEOUT The transfer failed due to time out.
- @return EFI_SUCCESS The transfer finished OK.
-
-**/
-EFI_STATUS
-ExecuteControlTransfer (
- IN USB_UHC_DEV *UhcDev,
- IN TD_STRUCT *PtrTD,
- OUT UINTN *ActualLen,
- IN UINTN TimeOut,
- OUT UINT32 *TransferResult
- );
-
-/**
- Execute Bulk Transfer.
-
- @param UhcDev The UCHI device.
- @param PtrTD A pointer to TD_STRUCT data.
- @param ActualLen Actual transfer Length.
- @param DataToggle DataToggle value.
- @param TimeOut TimeOut value.
- @param TransferResult Transfer Result.
-
- @return EFI_DEVICE_ERROR The transfer failed due to transfer error.
- @return EFI_TIMEOUT The transfer failed due to time out.
- @return EFI_SUCCESS The transfer finished OK.
-
-**/
-EFI_STATUS
-ExecBulkTransfer (
- IN USB_UHC_DEV *UhcDev,
- IN TD_STRUCT *PtrTD,
- IN OUT UINTN *ActualLen,
- IN UINT8 *DataToggle,
- IN UINTN TimeOut,
- OUT UINT32 *TransferResult
- );
-
-/**
- Delete Queued TDs.
-
- @param UhcDev The UCHI device.
- @param PtrFirstTD Place to store TD_STRUCT pointer.
-
-**/
-VOID
-DeleteQueuedTDs (
- IN USB_UHC_DEV *UhcDev,
- IN TD_STRUCT *PtrFirstTD
- );
-
-/**
- Check TDs Results.
-
- @param PtrTD A pointer to TD_STRUCT data.
- @param Result The result to return.
- @param ErrTDPos The Error TD position.
- @param ActualTransferSize Actual transfer size.
-
- @retval The TD is executed successfully or not.
-
-**/
-BOOLEAN
-CheckTDsResults (
- IN TD_STRUCT *PtrTD,
- OUT UINT32 *Result,
- OUT UINTN *ErrTDPos,
- OUT UINTN *ActualTransferSize
- );
-
-/**
- Create Memory Block.
-
- @param UhcDev The UCHI device.
- @param MemoryHeader The Pointer to allocated memory block.
- @param MemoryBlockSizeInPages The page size of memory block to be allocated.
-
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
- @retval EFI_SUCCESS Success.
-
-**/
-EFI_STATUS
-CreateMemoryBlock (
- IN USB_UHC_DEV *UhcDev,
- OUT MEMORY_MANAGE_HEADER **MemoryHeader,
- IN UINTN MemoryBlockSizeInPages
- );
-
-/**
- Initialize UHCI memory management.
-
- @param UhcDev The UCHI device.
-
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
- @retval EFI_SUCCESS Success.
-
-**/
-EFI_STATUS
-InitializeMemoryManagement (
- IN USB_UHC_DEV *UhcDev
- );
-
-/**
- Initialize UHCI memory management.
-
- @param UhcDev The UCHI device.
- @param Pool Buffer pointer to store the buffer pointer.
- @param AllocSize The size of the pool to be allocated.
-
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
- @retval EFI_SUCCESS Success.
-
-**/
-EFI_STATUS
-UhcAllocatePool (
- IN USB_UHC_DEV *UhcDev,
- OUT UINT8 **Pool,
- IN UINTN AllocSize
- );
-
-/**
- Alloc Memory In MemoryBlock.
-
- @param MemoryHeader The pointer to memory manage header.
- @param Pool Buffer pointer to store the buffer pointer.
- @param NumberOfMemoryUnit The size of the pool to be allocated.
-
- @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
- @retval EFI_SUCCESS Success.
-
-**/
-EFI_STATUS
-AllocMemInMemoryBlock (
- IN MEMORY_MANAGE_HEADER *MemoryHeader,
- OUT VOID **Pool,
- IN UINTN NumberOfMemoryUnit
- );
-
-/**
- Uhci Free Pool.
-
- @param UhcDev The UHCI device.
- @param Pool A pointer to store the buffer address.
- @param AllocSize The size of the pool to be freed.
-
-**/
-VOID
-UhcFreePool (
- IN USB_UHC_DEV *UhcDev,
- IN UINT8 *Pool,
- IN UINTN AllocSize
- );
-
-/**
- Insert a new memory header into list.
-
- @param MemoryHeader A pointer to the memory header list.
- @param NewMemoryHeader A new memory header to be inserted into the list.
-
-**/
-VOID
-InsertMemoryHeaderToList (
- IN MEMORY_MANAGE_HEADER *MemoryHeader,
- IN MEMORY_MANAGE_HEADER *NewMemoryHeader
- );
-
-/**
- Map address of request structure buffer.
-
- @param Uhc The UHCI device.
- @param Request The user request buffer.
- @param MappedAddr Mapped address of request.
- @param Map Identificaion of this mapping to return.
-
- @return EFI_SUCCESS Success.
- @return EFI_DEVICE_ERROR Fail to map the user request.
-
-**/
-EFI_STATUS
-UhciMapUserRequest (
- IN USB_UHC_DEV *Uhc,
- IN OUT VOID *Request,
- OUT UINT8 **MappedAddr,
- OUT VOID **Map
- );
-
-/**
- Map address of user data buffer.
-
- @param Uhc The UHCI device.
- @param Direction Direction of the data transfer.
- @param Data The user data buffer.
- @param Len Length of the user data.
- @param PktId Packet identificaion.
- @param MappedAddr Mapped address to return.
- @param Map Identificaion of this mapping to return.
-
- @return EFI_SUCCESS Success.
- @return EFI_DEVICE_ERROR Fail to map the user data.
-
-**/
-EFI_STATUS
-UhciMapUserData (
- IN USB_UHC_DEV *Uhc,
- IN EFI_USB_DATA_DIRECTION Direction,
- IN VOID *Data,
- IN OUT UINTN *Len,
- OUT UINT8 *PktId,
- OUT UINT8 **MappedAddr,
- OUT VOID **Map
- );
-
-/**
- Provides the controller-specific addresses required to access system memory from a
- DMA bus master.
-
- @param IoMmu Pointer to IOMMU PPI.
- @param Operation Indicates if the bus master is going to read or write to system memory.
- @param HostAddress The system memory address to map to the PCI controller.
- @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
- that were mapped.
- @param DeviceAddress The resulting map address for the bus master PCI controller to use to
- access the hosts HostAddress.
- @param Mapping A resulting value to pass to Unmap().
-
- @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
- @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
- @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
-
-**/
-EFI_STATUS
-IoMmuMap (
- IN EDKII_IOMMU_PPI *IoMmu,
- IN EDKII_IOMMU_OPERATION Operation,
- IN VOID *HostAddress,
- IN OUT UINTN *NumberOfBytes,
- OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
- OUT VOID **Mapping
- );
-
-/**
- Completes the Map() operation and releases any corresponding resources.
-
- @param IoMmu Pointer to IOMMU PPI.
- @param Mapping The mapping value returned from Map().
-
-**/
-VOID
-IoMmuUnmap (
- IN EDKII_IOMMU_PPI *IoMmu,
- IN VOID *Mapping
- );
-
-/**
- Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
- OperationBusMasterCommonBuffer64 mapping.
-
- @param IoMmu Pointer to IOMMU PPI.
- @param Pages The number of pages to allocate.
- @param HostAddress A pointer to store the base system memory address of the
- allocated range.
- @param DeviceAddress The resulting map address for the bus master PCI controller to use to
- access the hosts HostAddress.
- @param Mapping A resulting value to pass to Unmap().
-
- @retval EFI_SUCCESS The requested memory pages were allocated.
- @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
- MEMORY_WRITE_COMBINE and MEMORY_CACHED.
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
- @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
-
-**/
-EFI_STATUS
-IoMmuAllocateBuffer (
- IN EDKII_IOMMU_PPI *IoMmu,
- IN UINTN Pages,
- OUT VOID **HostAddress,
- OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
- OUT VOID **Mapping
- );
-
-/**
- Initialize IOMMU.
-
- @param IoMmu Pointer to pointer to IOMMU PPI.
-
-**/
-VOID
-IoMmuInit (
- OUT EDKII_IOMMU_PPI **IoMmu
- );
-
-#endif
diff --git a/MdeModulePkg/Bus/Pci/UhciPei/UhciPei.inf b/MdeModulePkg/Bus/Pci/UhciPei/UhciPei.inf
deleted file mode 100644
index 06515b7..0000000
--- a/MdeModulePkg/Bus/Pci/UhciPei/UhciPei.inf
+++ /dev/null
@@ -1,60 +0,0 @@
-## @file
-# The UhcPeim driver is responsible for managing the behavior of UHCI controller at PEI phase.
-#
-# It produces gPeiUsbHostControllerPpiGuid based on gPeiUsbControllerPpiGuid which is used
-# to enable recovery function from USB Drivers.
-#
-# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-#
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-##
-
-[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = UhciPei
- MODULE_UNI_FILE = UhciPei.uni
- FILE_GUID = C463CEAC-FC57-4f36-88B7-356C750C3BCA
- MODULE_TYPE = PEIM
- VERSION_STRING = 1.0
-
- ENTRY_POINT = UhcPeimEntry
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = IA32 X64 EBC
-#
-
-[Sources]
- UhcPeim.c
- UhcPeim.h
- DmaMem.c
-
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
-
-
-[LibraryClasses]
- IoLib
- TimerLib
- BaseMemoryLib
- PeiServicesLib
- PeimEntryPoint
- DebugLib
-
-
-[Ppis]
- gPeiUsbHostControllerPpiGuid ## PRODUCES
- gPeiUsbControllerPpiGuid ## CONSUMES
- gEdkiiIoMmuPpiGuid ## CONSUMES
- gEfiEndOfPeiSignalPpiGuid ## CONSUMES
-
-
-[Depex]
- gEfiPeiMemoryDiscoveredPpiGuid AND gPeiUsbControllerPpiGuid
-
-[UserExtensions.TianoCore."ExtraFiles"]
- UhciPeiExtra.uni
diff --git a/MdeModulePkg/Bus/Pci/UhciPei/UhciPei.uni b/MdeModulePkg/Bus/Pci/UhciPei/UhciPei.uni
deleted file mode 100644
index 04bdb8a..0000000
--- a/MdeModulePkg/Bus/Pci/UhciPei/UhciPei.uni
+++ /dev/null
@@ -1,17 +0,0 @@
-// /** @file
-// The UhcPeim driver is responsible for managing the behavior of UHCI controller at PEI phase.
-//
-// It produces gPeiUsbHostControllerPpiGuid based on gPeiUsbControllerPpiGuid which is used
-// to enable recovery function from USB Drivers.
-//
-// Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-
-#string STR_MODULE_ABSTRACT #language en-US "Responsible for managing the behavior of UHCI controller at PEI phase"
-
-#string STR_MODULE_DESCRIPTION #language en-US "It produces gPeiUsbHostControllerPpiGuid based on gPeiUsbControllerPpiGuid, which is used to enable recovery function from USB Drivers."
-
diff --git a/MdeModulePkg/Bus/Pci/UhciPei/UhciPeiExtra.uni b/MdeModulePkg/Bus/Pci/UhciPei/UhciPeiExtra.uni
deleted file mode 100644
index 4641a7b..0000000
--- a/MdeModulePkg/Bus/Pci/UhciPei/UhciPeiExtra.uni
+++ /dev/null
@@ -1,14 +0,0 @@
-// /** @file
-// UhciPei Localized Strings and Content
-//
-// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-#string STR_PROPERTIES_MODULE_NAME
-#language en-US
-"UHCI PEI Module for Recovery"
-
-
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
index c830db6..c337f15 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
@@ -837,6 +837,10 @@ XhcTransfer (
}
Xhc->PciIo->Flush (Xhc->PciIo);
+ //
+ // Do not free URB data, since it is passed in as an external argument
+ // and allocated and managed by the caller.
+ //
XhcFreeUrb (Xhc, Urb);
return Status;
}
@@ -1227,8 +1231,9 @@ ON_EXIT:
sending or receiving.
@param DataBuffersNumber Number of data buffers prepared for the transfer.
@param Data Array of pointers to the buffers of data to transmit
- from or receive into.
- @param DataLength The lenght of the data buffer.
+ from or receive into. The caller is responsible for freeing
+ the buffers after the transfers are completed.
+ @param DataLength The length of the data buffer.
@param DataToggle On input, the initial data toggle for the transfer;
On output, it is updated to to next data toggle to
use of the subsequent bulk transfer.
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
index 50d7d4b..52551a3 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
@@ -107,6 +107,10 @@ XhcCmdTransfer (
Status = EFI_SUCCESS;
}
+ //
+ // Do not free URB data, since `XhcCreateCmdTrb` does not allocate any data
+ // and the `Data` field is not used in command transfers.
+ //
XhcFreeUrb (Xhc, Urb);
ON_EXIT:
@@ -184,6 +188,9 @@ XhcCreateUrb (
/**
Free an allocated URB.
+ The `Data` field of the URB is not owned by the URB and is not freed here.
+ The caller is which allocates `Data` is responsible for freeing it.
+ Freeing `Data` must be done AFTER calling `XhcFreeUrb`, since this function may unmap the `DataMap` field.
@param Xhc The XHCI device.
@param Urb The URB to free.
@@ -1388,6 +1395,7 @@ XhciDelAsyncIntTransfer (
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
URB *Urb;
+ VOID *UrbData;
EFI_USB_DATA_DIRECTION Direction;
EFI_STATUS Status;
@@ -1412,8 +1420,16 @@ XhciDelAsyncIntTransfer (
}
RemoveEntryList (&Urb->UrbList);
- FreePool (Urb->Data);
+ //
+ // For `XhciDelAsyncIntTransfer`, the URB is created through `XhciInsertAsyncIntTransfer`
+ // and allocates and manages its own data buffer, so free it here.
+ //
+ UrbData = Urb->Data;
XhcFreeUrb (Xhc, Urb);
+ if (UrbData != NULL) {
+ FreePool (UrbData);
+ }
+
return EFI_SUCCESS;
}
}
@@ -1435,6 +1451,7 @@ XhciDelAllAsyncIntTransfers (
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
URB *Urb;
+ VOID *UrbData;
EFI_STATUS Status;
BASE_LIST_FOR_EACH_SAFE (Entry, Next, &Xhc->AsyncIntTransfers) {
@@ -1450,8 +1467,15 @@ XhciDelAllAsyncIntTransfers (
}
RemoveEntryList (&Urb->UrbList);
- FreePool (Urb->Data);
+ //
+ // For `XhciDelAllAsyncIntTransfers`, the URB is created through `XhciInsertAsyncIntTransfer`
+ // and allocates and manages its own data buffer, so free it here.
+ //
+ UrbData = Urb->Data;
XhcFreeUrb (Xhc, Urb);
+ if (UrbData != NULL) {
+ FreePool (UrbData);
+ }
}
}
@@ -1631,6 +1655,17 @@ XhcMonitorAsyncRequests (
Xhc = (USB_XHCI_INSTANCE *)Context;
BASE_LIST_FOR_EACH_SAFE (Entry, Next, &Xhc->AsyncIntTransfers) {
+ //
+ // Save values passed into the callback.
+ // `XhcUpdateAsyncRequest` must be called before the callback
+ // since the callback may free the URB, leading to a fault.
+ // However, the callback depends on values of the URB *before*
+ // `XhcUpdateAsyncRequest` is called, so we must save a copy.
+ //
+ UINTN cbCompleted;
+ UINT32 cbResult;
+ VOID *cbContext;
+
Urb = EFI_LIST_CONTAINER (Entry, URB, UrbList);
//
@@ -1683,6 +1718,19 @@ XhcMonitorAsyncRequests (
}
//
+ // Store values of URB before `XhcUpdateAsyncRequest`, since the callback depends on these values.
+ //
+ cbCompleted = Urb->Completed;
+ cbResult = Urb->Result;
+ cbContext = Urb->Context;
+
+ //
+ // The update call must occur before the callback since the callback
+ // may remove and free the URB, leading to a fault.
+ //
+ XhcUpdateAsyncRequest (Xhc, Urb);
+
+ //
// Leave error recovery to its related device driver. A
// common case of the error recovery is to re-submit the
// interrupt transfer which is linked to the head of the
@@ -1694,19 +1742,17 @@ XhcMonitorAsyncRequests (
//
if (Urb->Callback != NULL) {
//
- // Restore the old TPL, USB bus maybe connect device in
- // his callback. Some drivers may has a lower TPL restriction.
+ // Restore the previous TPL. The USB bus may connect a device in its callback,
+ // and some drivers require a lower TPL to run correctly.
//
gBS->RestoreTPL (OldTpl);
- (Urb->Callback)(ProcBuf, Urb->Completed, Urb->Context, Urb->Result);
+ (Urb->Callback)(ProcBuf, cbCompleted, cbContext, cbResult);
OldTpl = gBS->RaiseTPL (XHC_TPL);
}
if (ProcBuf != NULL) {
gBS->FreePool (ProcBuf);
}
-
- XhcUpdateAsyncRequest (Xhc, Urb);
}
gBS->RestoreTPL (OldTpl);
}
diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
index a03b2ce..c1072af 100644
--- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
+++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
@@ -1862,43 +1862,47 @@ UfsEnableHostController (
}
}
- //
- // UFS 2.0 spec section 7.1.1 - Host Controller Initialization
- //
- // Reinitialize the UFS host controller if HCE bit of HC register is set.
- //
- Status = UfsMmioRead32 (Private, UFS_HC_ENABLE_OFFSET, &Data);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- if ((Data & UFS_HC_HCE_EN) == UFS_HC_HCE_EN) {
+ if ((mUfsHcPlatform == NULL) ||
+ ((mUfsHcPlatform->Version >= 3) && !mUfsHcPlatform->SkipHceReenable))
+ {
//
- // Write a 0 to the HCE register at first to disable the host controller.
+ // UFS 2.0 spec section 7.1.1 - Host Controller Initialization
//
- Status = UfsMmioWrite32 (Private, UFS_HC_ENABLE_OFFSET, 0);
+ // Reinitialize the UFS host controller if HCE bit of HC register is set.
+ //
+ Status = UfsMmioRead32 (Private, UFS_HC_ENABLE_OFFSET, &Data);
if (EFI_ERROR (Status)) {
return Status;
}
+ if ((Data & UFS_HC_HCE_EN) == UFS_HC_HCE_EN) {
+ //
+ // Write a 0 to the HCE register at first to disable the host controller.
+ //
+ Status = UfsMmioWrite32 (Private, UFS_HC_ENABLE_OFFSET, 0);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Wait until HCE is read as '0' before continuing.
+ //
+ Status = UfsWaitMemSet (Private, UFS_HC_ENABLE_OFFSET, UFS_HC_HCE_EN, 0, UFS_TIMEOUT);
+ if (EFI_ERROR (Status)) {
+ return EFI_DEVICE_ERROR;
+ }
+ }
+
//
- // Wait until HCE is read as '0' before continuing.
+ // Write a 1 to the HCE register to enable the UFS host controller.
//
- Status = UfsWaitMemSet (Private, UFS_HC_ENABLE_OFFSET, UFS_HC_HCE_EN, 0, UFS_TIMEOUT);
+ Status = UfsMmioWrite32 (Private, UFS_HC_ENABLE_OFFSET, UFS_HC_HCE_EN);
if (EFI_ERROR (Status)) {
- return EFI_DEVICE_ERROR;
+ return Status;
}
}
//
- // Write a 1 to the HCE register to enable the UFS host controller.
- //
- Status = UfsMmioWrite32 (Private, UFS_HC_ENABLE_OFFSET, UFS_HC_HCE_EN);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
// Wait until HCE is read as '1' before continuing.
//
Status = UfsWaitMemSet (Private, UFS_HC_ENABLE_OFFSET, UFS_HC_HCE_EN, UFS_HC_HCE_EN, UFS_TIMEOUT);
@@ -1945,6 +1949,10 @@ UfsDeviceDetection (
}
}
+ if ((mUfsHcPlatform != NULL) && (mUfsHcPlatform->Version >= 3) && mUfsHcPlatform->SkipLinkStartup) {
+ return EFI_SUCCESS;
+ }
+
//
// Start UFS device detection.
// Try up to 3 times for establishing data link with device.
diff --git a/MdeModulePkg/Bus/Usb/UsbBotPei/BotPeim.h b/MdeModulePkg/Bus/Usb/UsbBotPei/BotPeim.h
index 54d149e..505bf3f 100644
--- a/MdeModulePkg/Bus/Usb/UsbBotPei/BotPeim.h
+++ b/MdeModulePkg/Bus/Usb/UsbBotPei/BotPeim.h
@@ -13,7 +13,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <PiPei.h>
#include <Ppi/UsbIo.h>
-#include <Ppi/UsbHostController.h>
#include <Ppi/BlockIo.h>
// #include <Library/DebugLib.h>
diff --git a/MdeModulePkg/Bus/Usb/UsbBotPei/UsbBotPeim.h b/MdeModulePkg/Bus/Usb/UsbBotPei/UsbBotPeim.h
index 1819784..8af6796 100644
--- a/MdeModulePkg/Bus/Usb/UsbBotPei/UsbBotPeim.h
+++ b/MdeModulePkg/Bus/Usb/UsbBotPei/UsbBotPeim.h
@@ -13,7 +13,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <PiPei.h>
#include <Ppi/UsbIo.h>
-#include <Ppi/UsbHostController.h>
#include <Ppi/BlockIo.h>
#include <Ppi/BlockIo2.h>
diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
index 3f24371..0438638 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
@@ -739,7 +739,7 @@ UsbIoGetStringDescriptor (
EFI_USB_STRING_DESCRIPTOR *StrDesc;
EFI_TPL OldTpl;
UINT8 *Buf;
- UINT8 Index;
+ UINT16 Index;
EFI_STATUS Status;
if ((StringIndex == 0) || (LangID == 0)) {
diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
index 713415d..4b8d01d 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
@@ -330,7 +330,7 @@ UsbSelectSetting (
}
}
- if (Index == IfDesc->NumOfSetting) {
+ if ((Index == IfDesc->NumOfSetting) || (Setting == NULL)) {
return EFI_NOT_FOUND;
}
@@ -393,7 +393,7 @@ UsbSelectConfig (
}
}
- if (Index == DevDesc->Desc.NumConfigurations) {
+ if ((Index == DevDesc->Desc.NumConfigurations) || (ConfigDesc == NULL)) {
return EFI_NOT_FOUND;
}
diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c
index 1a473d0..c4abf12 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c
@@ -596,7 +596,7 @@ UsbHubInit (
}
}
- if (Index == NumEndpoints) {
+ if ((Index == NumEndpoints) || (EpDesc == NULL)) {
DEBUG ((DEBUG_ERROR, "UsbHubInit: no interrupt endpoint found for hub %d\n", HubDev->Address));
return EFI_DEVICE_ERROR;
}
diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c
index eaffb8f..61cddf0 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c
@@ -850,6 +850,7 @@ UsbBusAddWantedUsbIoDP (
EFI_STATUS Status;
EFI_DEVICE_PATH_PROTOCOL *DevicePathPtr;
+ DevicePathPtr = NULL;
//
// Check whether remaining device path is valid
//
@@ -894,9 +895,12 @@ UsbBusAddWantedUsbIoDP (
}
ASSERT (DevicePathPtr != NULL);
- Status = AddUsbDPToList (DevicePathPtr, &Bus->WantedUsbIoDPList);
- ASSERT (!EFI_ERROR (Status));
- FreePool (DevicePathPtr);
+ if (DevicePathPtr != NULL) {
+ Status = AddUsbDPToList (DevicePathPtr, &Bus->WantedUsbIoDPList);
+ ASSERT (!EFI_ERROR (Status));
+ FreePool (DevicePathPtr);
+ }
+
return EFI_SUCCESS;
}
@@ -953,7 +957,9 @@ UsbBusIsWantedUsbIO (
// Create new Usb device path according to the usb part in UsbIo full device path
//
DevicePathPtr = GetUsbDPFromFullDP (UsbIf->DevicePath);
- ASSERT (DevicePathPtr != NULL);
+ if (DevicePathPtr == NULL) {
+ return FALSE;
+ }
DoConvert = FALSE;
WantedListIndex = WantedUsbIoDPListPtr->ForwardLink;
diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbBusPei.inf b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbBusPei.inf
index 31d7c2e..45fa54d 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbBusPei.inf
+++ b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbBusPei.inf
@@ -50,11 +50,10 @@
[Ppis]
gPeiUsbIoPpiGuid ## PRODUCES
- gPeiUsbHostControllerPpiGuid ## SOMETIMES_CONSUMES
- gPeiUsb2HostControllerPpiGuid ## SOMETIMES_CONSUMES
+ gPeiUsb2HostControllerPpiGuid ## CONSUMES
[Depex]
- gEfiPeiMemoryDiscoveredPpiGuid AND gPeiUsb2HostControllerPpiGuid OR gPeiUsbHostControllerPpiGuid
+ gEfiPeiMemoryDiscoveredPpiGuid AND gPeiUsb2HostControllerPpiGuid
[UserExtensions.TianoCore."ExtraFiles"]
UsbBusPeiExtra.uni
diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbIoPeim.c b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbIoPeim.c
index c428352..42fc563 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbIoPeim.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbIoPeim.c
@@ -78,36 +78,20 @@ PeiUsbControlTransfer (
}
}
- if (PeiUsbDev->Usb2HcPpi != NULL) {
- Status = PeiUsbDev->Usb2HcPpi->ControlTransfer (
- PeiServices,
- PeiUsbDev->Usb2HcPpi,
- PeiUsbDev->DeviceAddress,
- PeiUsbDev->DeviceSpeed,
- PeiUsbDev->MaxPacketSize0,
- Request,
- Direction,
- Data,
- &DataLength,
- Timeout,
- &(PeiUsbDev->Translator),
- &TransferResult
- );
- } else {
- Status = PeiUsbDev->UsbHcPpi->ControlTransfer (
- PeiServices,
- PeiUsbDev->UsbHcPpi,
- PeiUsbDev->DeviceAddress,
- PeiUsbDev->DeviceSpeed,
- (UINT8)PeiUsbDev->MaxPacketSize0,
- Request,
- Direction,
- Data,
- &DataLength,
- Timeout,
- &TransferResult
- );
- }
+ Status = PeiUsbDev->Usb2HcPpi->ControlTransfer (
+ PeiServices,
+ PeiUsbDev->Usb2HcPpi,
+ PeiUsbDev->DeviceAddress,
+ PeiUsbDev->DeviceSpeed,
+ PeiUsbDev->MaxPacketSize0,
+ Request,
+ Direction,
+ Data,
+ &DataLength,
+ Timeout,
+ &(PeiUsbDev->Translator),
+ &TransferResult
+ );
//
// Reset the endpoint toggle when endpoint stall is cleared
@@ -200,35 +184,20 @@ PeiUsbBulkTransfer (
OldToggle = DataToggle;
- if (PeiUsbDev->Usb2HcPpi != NULL) {
- Status = PeiUsbDev->Usb2HcPpi->BulkTransfer (
- PeiServices,
- PeiUsbDev->Usb2HcPpi,
- PeiUsbDev->DeviceAddress,
- DeviceEndpoint,
- PeiUsbDev->DeviceSpeed,
- MaxPacketLength,
- Data2,
- DataLength,
- &DataToggle,
- Timeout,
- &(PeiUsbDev->Translator),
- &TransferResult
- );
- } else {
- Status = PeiUsbDev->UsbHcPpi->BulkTransfer (
- PeiServices,
- PeiUsbDev->UsbHcPpi,
- PeiUsbDev->DeviceAddress,
- DeviceEndpoint,
- (UINT8)MaxPacketLength,
- Data,
- DataLength,
- &DataToggle,
- Timeout,
- &TransferResult
- );
- }
+ Status = PeiUsbDev->Usb2HcPpi->BulkTransfer (
+ PeiServices,
+ PeiUsbDev->Usb2HcPpi,
+ PeiUsbDev->DeviceAddress,
+ DeviceEndpoint,
+ PeiUsbDev->DeviceSpeed,
+ MaxPacketLength,
+ Data2,
+ DataLength,
+ &DataToggle,
+ Timeout,
+ &(PeiUsbDev->Translator),
+ &TransferResult
+ );
if (OldToggle != DataToggle) {
PeiUsbDev->DataToggle = (UINT16)(PeiUsbDev->DataToggle ^ (1 << EndpointIndex));
@@ -332,7 +301,6 @@ PeiUsbPortReset (
ResetRootPort (
PeiServices,
- PeiUsbDev->UsbHcPpi,
PeiUsbDev->Usb2HcPpi,
PeiUsbDev->DeviceAddress,
0
diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c
index 159cd19..9390053 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c
@@ -33,7 +33,6 @@ EFI_PEI_PPI_DESCRIPTOR mUsbIoPpiList = {
The enumeration routine to detect device change.
@param PeiServices Describes the list of possible PEI Services.
- @param UsbHcPpi The pointer of PEI_USB_HOST_CONTROLLER_PPI instance.
@param Usb2HcPpi The pointer of PEI_USB2_HOST_CONTROLLER_PPI instance.
@retval EFI_SUCCESS The usb is enumerated successfully.
@@ -44,7 +43,6 @@ EFI_PEI_PPI_DESCRIPTOR mUsbIoPpiList = {
EFI_STATUS
PeiUsbEnumeration (
IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi,
IN PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi
);
@@ -128,27 +126,19 @@ PeimInitializeUsb (
{
EFI_STATUS Status;
UINTN Index;
- PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi;
PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi;
if (!EFI_ERROR (PeiServicesRegisterForShadow (FileHandle))) {
return EFI_SUCCESS;
}
- //
- // gPeiUsbHostControllerPpiGuid and gPeiUsb2HostControllerPpiGuid should not
- // be produced at the same time
- //
Index = 0;
while (TRUE) {
- //
- // Get UsbHcPpi at first.
- //
Status = PeiServicesLocatePpi (
- &gPeiUsbHostControllerPpiGuid,
+ &gPeiUsb2HostControllerPpiGuid,
Index,
NULL,
- (VOID **)&UsbHcPpi
+ (VOID **)&Usb2HcPpi
);
if (EFI_ERROR (Status)) {
//
@@ -157,34 +147,11 @@ PeimInitializeUsb (
break;
}
- PeiUsbEnumeration ((EFI_PEI_SERVICES **)PeiServices, UsbHcPpi, NULL);
+ PeiUsbEnumeration ((EFI_PEI_SERVICES **)PeiServices, Usb2HcPpi);
Index++;
}
if (Index == 0) {
- //
- // Then try to get Usb2HcPpi.
- //
- while (TRUE) {
- Status = PeiServicesLocatePpi (
- &gPeiUsb2HostControllerPpiGuid,
- Index,
- NULL,
- (VOID **)&Usb2HcPpi
- );
- if (EFI_ERROR (Status)) {
- //
- // No more host controller, break out
- //
- break;
- }
-
- PeiUsbEnumeration ((EFI_PEI_SERVICES **)PeiServices, NULL, Usb2HcPpi);
- Index++;
- }
- }
-
- if (Index == 0) {
return EFI_UNSUPPORTED;
}
@@ -277,7 +244,6 @@ PeiHubEnumeration (
);
NewPeiUsbDevice->UsbIoPpiList.Ppi = &NewPeiUsbDevice->UsbIoPpi;
NewPeiUsbDevice->AllocateAddress = (UINTN)AllocateAddress;
- NewPeiUsbDevice->UsbHcPpi = PeiUsbDevice->UsbHcPpi;
NewPeiUsbDevice->Usb2HcPpi = PeiUsbDevice->Usb2HcPpi;
NewPeiUsbDevice->Tier = (UINT8)(PeiUsbDevice->Tier + 1);
NewPeiUsbDevice->IsHub = 0x0;
@@ -404,7 +370,6 @@ PeiHubEnumeration (
The enumeration routine to detect device change.
@param PeiServices Describes the list of possible PEI Services.
- @param UsbHcPpi The pointer of PEI_USB_HOST_CONTROLLER_PPI instance.
@param Usb2HcPpi The pointer of PEI_USB2_HOST_CONTROLLER_PPI instance.
@retval EFI_SUCCESS The usb is enumerated successfully.
@@ -415,7 +380,6 @@ PeiHubEnumeration (
EFI_STATUS
PeiUsbEnumeration (
IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi,
IN PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi
)
{
@@ -438,12 +402,6 @@ PeiUsbEnumeration (
Usb2HcPpi,
(UINT8 *)&NumOfRootPort
);
- } else if (UsbHcPpi != NULL) {
- UsbHcPpi->GetRootHubPortNumber (
- PeiServices,
- UsbHcPpi,
- (UINT8 *)&NumOfRootPort
- );
} else {
ASSERT (FALSE);
return EFI_INVALID_PARAMETER;
@@ -461,21 +419,12 @@ PeiUsbEnumeration (
//
// First get root port status to detect changes happen
//
- if (Usb2HcPpi != NULL) {
- Usb2HcPpi->GetRootHubPortStatus (
- PeiServices,
- Usb2HcPpi,
- (UINT8)Index,
- &PortStatus
- );
- } else {
- UsbHcPpi->GetRootHubPortStatus (
- PeiServices,
- UsbHcPpi,
- (UINT8)Index,
- &PortStatus
- );
- }
+ Usb2HcPpi->GetRootHubPortStatus (
+ PeiServices,
+ Usb2HcPpi,
+ (UINT8)Index,
+ &PortStatus
+ );
DEBUG ((DEBUG_INFO, "USB Status --- Port: %x ConnectChange[%04x] Status[%04x]\n", Index, PortStatus.PortChangeStatus, PortStatus.PortStatus));
//
@@ -514,7 +463,6 @@ PeiUsbEnumeration (
);
PeiUsbDevice->UsbIoPpiList.Ppi = &PeiUsbDevice->UsbIoPpi;
PeiUsbDevice->AllocateAddress = (UINTN)AllocateAddress;
- PeiUsbDevice->UsbHcPpi = UsbHcPpi;
PeiUsbDevice->Usb2HcPpi = Usb2HcPpi;
PeiUsbDevice->IsHub = 0x0;
PeiUsbDevice->DownStreamPortNo = 0x0;
@@ -527,43 +475,24 @@ PeiUsbEnumeration (
//
ResetRootPort (
PeiServices,
- PeiUsbDevice->UsbHcPpi,
PeiUsbDevice->Usb2HcPpi,
Index,
0
);
- if (Usb2HcPpi != NULL) {
- Usb2HcPpi->GetRootHubPortStatus (
- PeiServices,
- Usb2HcPpi,
- (UINT8)Index,
- &PortStatus
- );
- } else {
- UsbHcPpi->GetRootHubPortStatus (
- PeiServices,
- UsbHcPpi,
- (UINT8)Index,
- &PortStatus
- );
- }
+ Usb2HcPpi->GetRootHubPortStatus (
+ PeiServices,
+ Usb2HcPpi,
+ (UINT8)Index,
+ &PortStatus
+ );
} else {
- if (Usb2HcPpi != NULL) {
- Usb2HcPpi->ClearRootHubPortFeature (
- PeiServices,
- Usb2HcPpi,
- (UINT8)Index,
- EfiUsbPortResetChange
- );
- } else {
- UsbHcPpi->ClearRootHubPortFeature (
- PeiServices,
- UsbHcPpi,
- (UINT8)Index,
- EfiUsbPortResetChange
- );
- }
+ Usb2HcPpi->ClearRootHubPortFeature (
+ PeiServices,
+ Usb2HcPpi,
+ (UINT8)Index,
+ EfiUsbPortResetChange
+ );
}
PeiUsbDevice->DeviceSpeed = (UINT8)PeiUsbGetDeviceSpeed (PortStatus.PortStatus);
@@ -1032,7 +961,6 @@ GetExpectedDescriptor (
Send reset signal over the given root hub port.
@param PeiServices Describes the list of possible PEI Services.
- @param UsbHcPpi The pointer of PEI_USB_HOST_CONTROLLER_PPI instance.
@param Usb2HcPpi The pointer of PEI_USB2_HOST_CONTROLLER_PPI instance.
@param PortNum The port to be reset.
@param RetryIndex The retry times.
@@ -1041,7 +969,6 @@ GetExpectedDescriptor (
VOID
ResetRootPort (
IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi,
IN PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi,
IN UINT8 PortNum,
IN UINT8 RetryIndex
@@ -1051,211 +978,105 @@ ResetRootPort (
UINTN Index;
EFI_USB_PORT_STATUS PortStatus;
- if (Usb2HcPpi != NULL) {
- MicroSecondDelay (200 * 1000);
-
- //
- // reset root port
- //
- Status = Usb2HcPpi->SetRootHubPortFeature (
- PeiServices,
- Usb2HcPpi,
- PortNum,
- EfiUsbPortReset
- );
-
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "SetRootHubPortFeature EfiUsbPortReset Failed\n"));
- return;
- }
-
- //
- // Drive the reset signal for at least 50ms. Check USB 2.0 Spec
- // section 7.1.7.5 for timing requirements.
- //
- MicroSecondDelay (USB_SET_ROOT_PORT_RESET_STALL);
-
- //
- // clear reset root port
- //
- Status = Usb2HcPpi->ClearRootHubPortFeature (
- PeiServices,
- Usb2HcPpi,
- PortNum,
- EfiUsbPortReset
- );
-
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "ClearRootHubPortFeature EfiUsbPortReset Failed\n"));
- return;
- }
-
- MicroSecondDelay (USB_CLR_ROOT_PORT_RESET_STALL);
-
- //
- // USB host controller won't clear the RESET bit until
- // reset is actually finished.
- //
- ZeroMem (&PortStatus, sizeof (EFI_USB_PORT_STATUS));
-
- for (Index = 0; Index < USB_WAIT_PORT_STS_CHANGE_LOOP; Index++) {
- Status = Usb2HcPpi->GetRootHubPortStatus (
- PeiServices,
- Usb2HcPpi,
- PortNum,
- &PortStatus
- );
- if (EFI_ERROR (Status)) {
- return;
- }
-
- if (!USB_BIT_IS_SET (PortStatus.PortStatus, USB_PORT_STAT_RESET)) {
- break;
- }
+ MicroSecondDelay (200 * 1000);
- MicroSecondDelay (USB_WAIT_PORT_STS_CHANGE_STALL);
- }
-
- if (Index == USB_WAIT_PORT_STS_CHANGE_LOOP) {
- DEBUG ((DEBUG_ERROR, "ResetRootPort: reset not finished in time on port %d\n", PortNum));
- return;
- }
+ //
+ // reset root port
+ //
+ Status = Usb2HcPpi->SetRootHubPortFeature (
+ PeiServices,
+ Usb2HcPpi,
+ PortNum,
+ EfiUsbPortReset
+ );
- Usb2HcPpi->ClearRootHubPortFeature (
- PeiServices,
- Usb2HcPpi,
- PortNum,
- EfiUsbPortResetChange
- );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "SetRootHubPortFeature EfiUsbPortReset Failed\n"));
+ return;
+ }
- Usb2HcPpi->ClearRootHubPortFeature (
- PeiServices,
- Usb2HcPpi,
- PortNum,
- EfiUsbPortConnectChange
- );
+ //
+ // Drive the reset signal for at least 50ms. Check USB 2.0 Spec
+ // section 7.1.7.5 for timing requirements.
+ //
+ MicroSecondDelay (USB_SET_ROOT_PORT_RESET_STALL);
- //
- // Set port enable
- //
- Usb2HcPpi->SetRootHubPortFeature (
- PeiServices,
- Usb2HcPpi,
- PortNum,
- EfiUsbPortEnable
- );
+ //
+ // clear reset root port
+ //
+ Status = Usb2HcPpi->ClearRootHubPortFeature (
+ PeiServices,
+ Usb2HcPpi,
+ PortNum,
+ EfiUsbPortReset
+ );
- Usb2HcPpi->ClearRootHubPortFeature (
- PeiServices,
- Usb2HcPpi,
- PortNum,
- EfiUsbPortEnableChange
- );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "ClearRootHubPortFeature EfiUsbPortReset Failed\n"));
+ return;
+ }
- MicroSecondDelay ((RetryIndex + 1) * 50 * 1000);
- } else {
- MicroSecondDelay (200 * 1000);
+ MicroSecondDelay (USB_CLR_ROOT_PORT_RESET_STALL);
- //
- // reset root port
- //
- Status = UsbHcPpi->SetRootHubPortFeature (
- PeiServices,
- UsbHcPpi,
- PortNum,
- EfiUsbPortReset
- );
+ //
+ // USB host controller won't clear the RESET bit until
+ // reset is actually finished.
+ //
+ ZeroMem (&PortStatus, sizeof (EFI_USB_PORT_STATUS));
+ for (Index = 0; Index < USB_WAIT_PORT_STS_CHANGE_LOOP; Index++) {
+ Status = Usb2HcPpi->GetRootHubPortStatus (
+ PeiServices,
+ Usb2HcPpi,
+ PortNum,
+ &PortStatus
+ );
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "SetRootHubPortFeature EfiUsbPortReset Failed\n"));
return;
}
- //
- // Drive the reset signal for at least 50ms. Check USB 2.0 Spec
- // section 7.1.7.5 for timing requirements.
- //
- MicroSecondDelay (USB_SET_ROOT_PORT_RESET_STALL);
-
- //
- // clear reset root port
- //
- Status = UsbHcPpi->ClearRootHubPortFeature (
- PeiServices,
- UsbHcPpi,
- PortNum,
- EfiUsbPortReset
- );
-
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "ClearRootHubPortFeature EfiUsbPortReset Failed\n"));
- return;
+ if (!USB_BIT_IS_SET (PortStatus.PortStatus, USB_PORT_STAT_RESET)) {
+ break;
}
- MicroSecondDelay (USB_CLR_ROOT_PORT_RESET_STALL);
-
- //
- // USB host controller won't clear the RESET bit until
- // reset is actually finished.
- //
- ZeroMem (&PortStatus, sizeof (EFI_USB_PORT_STATUS));
-
- for (Index = 0; Index < USB_WAIT_PORT_STS_CHANGE_LOOP; Index++) {
- Status = UsbHcPpi->GetRootHubPortStatus (
- PeiServices,
- UsbHcPpi,
- PortNum,
- &PortStatus
- );
- if (EFI_ERROR (Status)) {
- return;
- }
-
- if (!USB_BIT_IS_SET (PortStatus.PortStatus, USB_PORT_STAT_RESET)) {
- break;
- }
+ MicroSecondDelay (USB_WAIT_PORT_STS_CHANGE_STALL);
+ }
- MicroSecondDelay (USB_WAIT_PORT_STS_CHANGE_STALL);
- }
+ if (Index == USB_WAIT_PORT_STS_CHANGE_LOOP) {
+ DEBUG ((DEBUG_ERROR, "ResetRootPort: reset not finished in time on port %d\n", PortNum));
+ return;
+ }
- if (Index == USB_WAIT_PORT_STS_CHANGE_LOOP) {
- DEBUG ((DEBUG_ERROR, "ResetRootPort: reset not finished in time on port %d\n", PortNum));
- return;
- }
+ Usb2HcPpi->ClearRootHubPortFeature (
+ PeiServices,
+ Usb2HcPpi,
+ PortNum,
+ EfiUsbPortResetChange
+ );
- UsbHcPpi->ClearRootHubPortFeature (
- PeiServices,
- UsbHcPpi,
- PortNum,
- EfiUsbPortResetChange
- );
+ Usb2HcPpi->ClearRootHubPortFeature (
+ PeiServices,
+ Usb2HcPpi,
+ PortNum,
+ EfiUsbPortConnectChange
+ );
- UsbHcPpi->ClearRootHubPortFeature (
- PeiServices,
- UsbHcPpi,
- PortNum,
- EfiUsbPortConnectChange
- );
+ //
+ // Set port enable
+ //
+ Usb2HcPpi->SetRootHubPortFeature (
+ PeiServices,
+ Usb2HcPpi,
+ PortNum,
+ EfiUsbPortEnable
+ );
- //
- // Set port enable
- //
- UsbHcPpi->SetRootHubPortFeature (
- PeiServices,
- UsbHcPpi,
- PortNum,
- EfiUsbPortEnable
- );
-
- UsbHcPpi->ClearRootHubPortFeature (
- PeiServices,
- UsbHcPpi,
- PortNum,
- EfiUsbPortEnableChange
- );
-
- MicroSecondDelay ((RetryIndex + 1) * 50 * 1000);
- }
+ Usb2HcPpi->ClearRootHubPortFeature (
+ PeiServices,
+ Usb2HcPpi,
+ PortNum,
+ EfiUsbPortEnableChange
+ );
- return;
+ MicroSecondDelay ((RetryIndex + 1) * 50 * 1000);
}
diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h
index 69d1126..83ee2ec 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h
+++ b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h
@@ -12,7 +12,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <PiPei.h>
-#include <Ppi/UsbHostController.h>
#include <Ppi/Usb2HostController.h>
#include <Ppi/UsbIo.h>
@@ -51,7 +50,6 @@ typedef struct {
UINT8 IsHub;
UINT8 DownStreamPortNo;
UINTN AllocateAddress;
- PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi;
PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi;
UINT8 ConfigurationData[1024];
EFI_USB_CONFIG_DESCRIPTOR *ConfigDesc;
@@ -238,7 +236,6 @@ PeiUsbPortReset (
Send reset signal over the given root hub port.
@param PeiServices Describes the list of possible PEI Services.
- @param UsbHcPpi The pointer of PEI_USB_HOST_CONTROLLER_PPI instance.
@param Usb2HcPpi The pointer of PEI_USB2_HOST_CONTROLLER_PPI instance.
@param PortNum The port to be reset.
@param RetryIndex The retry times.
@@ -247,7 +244,6 @@ PeiUsbPortReset (
VOID
ResetRootPort (
IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi,
IN PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi,
IN UINT8 PortNum,
IN UINT8 RetryIndex
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
index b5a6459..9360863 100644
--- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
+++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
@@ -437,16 +437,17 @@ GetCurrentKeyboardLayout (
if (Status == EFI_BUFFER_TOO_SMALL) {
KeyboardLayout = AllocatePool (Length);
ASSERT (KeyboardLayout != NULL);
-
- Status = HiiDatabase->GetKeyboardLayout (
- HiiDatabase,
- NULL,
- &Length,
- KeyboardLayout
- );
- if (EFI_ERROR (Status)) {
- FreePool (KeyboardLayout);
- KeyboardLayout = NULL;
+ if (KeyboardLayout != NULL) {
+ Status = HiiDatabase->GetKeyboardLayout (
+ HiiDatabase,
+ NULL,
+ &Length,
+ KeyboardLayout
+ );
+ if (EFI_ERROR (Status)) {
+ FreePool (KeyboardLayout);
+ KeyboardLayout = NULL;
+ }
}
}
@@ -683,7 +684,10 @@ SetKeyboardLayoutEvent (
//
TableEntry = GetKeyDescriptor (UsbKeyboardDevice, 0x58);
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, 0x28);
- CopyMem (TableEntry, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR));
+
+ if ((TableEntry != NULL) && (KeyDescriptor != NULL)) {
+ CopyMem (TableEntry, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR));
+ }
FreePool (KeyboardLayout);
}
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c b/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c
index 5706ccd..c75ce8a 100644
--- a/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c
+++ b/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c
@@ -160,7 +160,11 @@ USBMouseAbsolutePointerDriverBindingStart (
}
UsbMouseAbsolutePointerDevice = AllocateZeroPool (sizeof (USB_MOUSE_ABSOLUTE_POINTER_DEV));
- ASSERT (UsbMouseAbsolutePointerDevice != NULL);
+ if (UsbMouseAbsolutePointerDevice == NULL) {
+ ASSERT (UsbMouseAbsolutePointerDevice != NULL);
+ Status = EFI_OUT_OF_RESOURCES;
+ goto ErrorExit;
+ }
UsbMouseAbsolutePointerDevice->UsbIo = UsbIo;
UsbMouseAbsolutePointerDevice->Signature = USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE;
@@ -631,7 +635,11 @@ InitializeUsbMouseDevice (
}
ReportDesc = AllocateZeroPool (MouseHidDesc->HidClassDesc[0].DescriptorLength);
- ASSERT (ReportDesc != NULL);
+ if (ReportDesc == NULL) {
+ ASSERT (ReportDesc != NULL);
+ FreePool (Buf);
+ return EFI_OUT_OF_RESOURCES;
+ }
Status = UsbGetReportDescriptor (
UsbIo,
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c b/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c
index 451d4b9..13c5b22 100644
--- a/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c
+++ b/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c
@@ -732,7 +732,7 @@ InitializeUsbMouseDevice (
@param Data A pointer to a buffer that is filled with key data which is
retrieved via asynchronous interrupt transfer.
@param DataLength Indicates the size of the data buffer.
- @param Context Pointing to USB_KB_DEV instance.
+ @param Context Pointing to USB_MOUSE_DEV instance.
@param Result Indicates the result of the asynchronous interrupt transfer.
@retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.h b/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.h
index 3ddd765..6766831 100644
--- a/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.h
+++ b/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.h
@@ -402,7 +402,7 @@ InitializeUsbMouseDevice (
@param Data A pointer to a buffer that is filled with key data which is
retrieved via asynchronous interrupt transfer.
@param DataLength Indicates the size of the data buffer.
- @param Context Pointing to USB_KB_DEV instance.
+ @param Context Pointing to USB_MOUSE_DEV instance.
@param Result Indicates the result of the asynchronous interrupt transfer.
@retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
diff --git a/MdeModulePkg/Core/Pei/FwVol/FwVol.c b/MdeModulePkg/Core/Pei/FwVol/FwVol.c
index 04bec98..1c0aa9d 100644
--- a/MdeModulePkg/Core/Pei/FwVol/FwVol.c
+++ b/MdeModulePkg/Core/Pei/FwVol/FwVol.c
@@ -2,7 +2,7 @@
Pei Core Firmware File System service routines.
Copyright (c) 2015 HP Development Company, L.P.
-Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2025, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -456,6 +456,29 @@ FindFileEx (
}
/**
+ Return the pointer to the Firmware Volume GUID name in the FV header.
+
+ @param[in] FvHeader Pointer to the header of the Firmware Volume.
+
+ @retval Pointer to the Firmware Volume GUID name in the FV header.
+ NULL if the FV is anonymous without an extended header.
+**/
+EFI_GUID *
+GetFvName (
+ IN CONST EFI_FIRMWARE_VOLUME_HEADER *FvHeader
+ )
+{
+ EFI_FIRMWARE_VOLUME_EXT_HEADER *FvExtHeader;
+
+ if (FvHeader->ExtHeaderOffset == 0) {
+ return NULL;
+ }
+
+ FvExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)((UINT8 *)FvHeader + FvHeader->ExtHeaderOffset);
+ return &FvExtHeader->FvName;
+}
+
+/**
Initialize PeiCore FV List.
@param PrivateData - Pointer to PEI_CORE_INSTANCE.
@@ -519,8 +542,9 @@ PeiInitializeFv (
PrivateData->Fv[PrivateData->FvCount].AuthenticationStatus = 0;
DEBUG ((
DEBUG_INFO,
- "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
+ "The %dth FV[%g] start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
(UINT32)PrivateData->FvCount,
+ GetFvName (BfvHeader),
(VOID *)BfvHeader,
(UINT32)BfvHeader->FvLength,
FvHandle
@@ -661,8 +685,9 @@ FirmwareVolumeInfoPpiNotifyCallback (
CurFvCount = PrivateData->FvCount;
DEBUG ((
DEBUG_INFO,
- "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
+ "The %dth FV[%g] start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
(UINT32)CurFvCount,
+ GetFvName ((EFI_FIRMWARE_VOLUME_HEADER *)FvInfo2Ppi.FvInfo),
(VOID *)FvInfo2Ppi.FvInfo,
FvInfo2Ppi.FvInfoSize,
FvHandle
@@ -696,7 +721,7 @@ FirmwareVolumeInfoPpiNotifyCallback (
}
}
- DEBUG ((DEBUG_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, CurFvCount, FvHandle));
+ DEBUG ((DEBUG_INFO, "Found firmware volume Image File[%g] %p in FV[%d] %p\n", FileHandle, FileHandle, CurFvCount, FvHandle));
ProcessFvFile (PrivateData, &PrivateData->Fv[CurFvCount], FileHandle);
}
} while (FileHandle != NULL);
@@ -2434,8 +2459,9 @@ ThirdPartyFvPpiNotifyCallback (
CurFvCount = PrivateData->FvCount;
DEBUG ((
DEBUG_INFO,
- "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
+ "The %dth FV[%g] start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",
(UINT32)CurFvCount,
+ GetFvName ((EFI_FIRMWARE_VOLUME_HEADER *)FvInfo),
(VOID *)FvInfo,
FvInfoSize,
FvHandle
@@ -2469,7 +2495,7 @@ ThirdPartyFvPpiNotifyCallback (
}
}
- DEBUG ((DEBUG_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, CurFvCount, FvHandle));
+ DEBUG ((DEBUG_INFO, "Found firmware volume Image File[%g] %p in FV[%d] %p\n", FileHandle, FileHandle, CurFvCount, FvHandle));
ProcessFvFile (PrivateData, &PrivateData->Fv[CurFvCount], FileHandle);
}
} while (FileHandle != NULL);
diff --git a/MdeModulePkg/Include/Ppi/UsbHostController.h b/MdeModulePkg/Include/Ppi/UsbHostController.h
deleted file mode 100644
index cf468f9..0000000
--- a/MdeModulePkg/Include/Ppi/UsbHostController.h
+++ /dev/null
@@ -1,249 +0,0 @@
-/** @file
- Defines the USB Host Controller PPI that provides I/O services for a USB Host
- Controller that may be used to access recovery devices. These interfaces are
- modeled on the UEFI 2.3 specification EFI_USB2_HOST_CONTROLLER_PROTOCOL.
- Refer to section 16.1 of the UEFI 2.3 Specification for more information on
- these interfaces.
-
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef _PEI_USB_HOST_CONTROLLER_PPI_H_
-#define _PEI_USB_HOST_CONTROLLER_PPI_H_
-
-#include <Protocol/Usb2HostController.h>
-
-///
-/// Global ID for the PEI_USB_HOST_CONTROLLER_PPI.
-///
-#define PEI_USB_HOST_CONTROLLER_PPI_GUID \
- { \
- 0x652b38a9, 0x77f4, 0x453f, { 0x89, 0xd5, 0xe7, 0xbd, 0xc3, 0x52, 0xfc, 0x53} \
- }
-
-///
-/// Forward declaration for the PEI_USB_HOST_CONTROLLER_PPI.
-///
-typedef struct _PEI_USB_HOST_CONTROLLER_PPI PEI_USB_HOST_CONTROLLER_PPI;
-
-/**
- Initiate a USB control transfer using a specific USB Host controller on the USB bus.
-
- @param[in] PeiServices The pointer to the PEI Services Table.
- @param[in] This The pointer to this instance of the
- PEI_USB_HOST_CONTROLLER_PPI.
- @param[in] DeviceAddress Represents the address of the target device
- on the USB.
- @param[in] DeviceSpeed Indicates device speed.
- @param[in] MaximumPacketLength Indicates the maximum packet size that the
- default control transfer
- endpoint is capable of sending or receiving.
- @param[in] Request A pointer to the USB device request that
- will be sent to the USB device.
- @param[in] TransferDirection Specifies the data direction for the transfer.
- There are three values available:
- EfiUsbDataIn, EfiUsbDataOut and EfiUsbNoData.
- @param[in,out] Data A pointer to the buffer of data that will
- be transmitted to USB device or
- received from USB device.
- @param[in,out] DataLength On input, indicates the size, in bytes, of
- the data buffer specified by Data.
- On output, indicates the amount of data
- actually transferred.
- @param[in] TimeOut Indicates the maximum time, in milliseconds,
- that the transfer is allowed to complete.
- If Timeout is 0, then the caller must wait for
- the function to be completed until EFI_SUCCESS
- or EFI_DEVICE_ERROR is returned.
- @param[out] TransferResult A pointer to the detailed result information
- generated by this control transfer.
-
- @retval EFI_DEVICE_ERROR The control transfer failed due to host controller
- or device error.
- @retval EFI_SUCCESS The control transfer was completed successfully.
-
-**/
-typedef
-EFI_STATUS
-(EFIAPI *PEI_USB_HOST_CONTROLLER_CONTROL_TRANSFER)(
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 DeviceAddress,
- IN UINT8 DeviceSpeed,
- IN UINT8 MaximumPacketLength,
- IN USB_DEVICE_REQUEST *Request,
- IN EFI_USB_DATA_DIRECTION TransferDirection,
- IN OUT VOID *Data OPTIONAL,
- IN OUT UINTN *DataLength OPTIONAL,
- IN UINTN TimeOut,
- OUT UINT32 *TransferResult
- );
-
-/**
- Initiate a USB bulk transfer using a specific USB Host controller on the USB bus.
-
- @param[in] PeiServices The pointer to the PEI Services Table.
- @param[in] This The pointer to this instance of the
- PEI_USB_HOST_CONTROLLER_PPI.
- @param[in] DeviceAddress Represents the address of the target device
- on the USB.
- @param[in] EndPointAddress The combination of an endpoint number and
- an endpoint direction of the target USB device.
- @param[in] MaximumPacketLength Indicates the maximum packet size the target
- endpoint is capable of sending or receiving.
- @param[in,out] Data Array of pointers to the buffers of data
- that will be transmitted to USB device or
- received from USB device.
- @param[in,out] DataLength When input, indicates the size, in bytes, of
- the data buffers specified by Data. When output,
- indicates the data size actually transferred.
- @param[in,out] DataToggle A pointer to the data toggle value.
- @param[in] TimeOut Indicates the maximum time, in milliseconds,
- in which the transfer is allowed to complete.
- If Timeout is 0, then the caller must wait for
- the function to be completed until EFI_SUCCESS
- or EFI_DEVICE_ERROR is returned.
- @param[out] TransferResult A pointer to the detailed result information
- of the bulk transfer.
-
- @retval EFI_SUCCESS The bulk transfer was completed successfully.
- @retval EFI_DEVICE_ERROR The bulk transfer failed due to host controller or device error.
- Caller should check TransferResult for detailed error information.
-
-**/
-typedef
-EFI_STATUS
-(EFIAPI *PEI_USB_HOST_CONTROLLER_BULK_TRANSFER)(
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 DeviceAddress,
- IN UINT8 EndPointAddress,
- IN UINT8 MaximumPacketLength,
- IN OUT VOID *Data,
- IN OUT UINTN *DataLength,
- IN OUT UINT8 *DataToggle,
- IN UINTN TimeOut,
- OUT UINT32 *TransferResult
- );
-
-/**
- Retrieves the number of root hub ports.
-
- @param[in] PeiServices The pointer to the PEI Services Table.
- @param[in] This The pointer to this instance of the
- PEI_USB_HOST_CONTROLLER_PPI.
- @param[out] PortNumber The pointer to the number of the root hub ports.
-
- @retval EFI_SUCCESS The port number was retrieved successfully.
- @retval EFI_DEVICE_ERROR An error was encountered while attempting to retrieve
- the port number.
- @retval EFI_INVALID_PARAMETER PortNumber is NULL.
-
-**/
-typedef
-EFI_STATUS
-(EFIAPI *PEI_USB_HOST_CONTROLLER_GET_ROOTHUB_PORT_NUMBER)(
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- OUT UINT8 *PortNumber
- );
-
-/**
- Retrieves the current status of a USB root hub port.
-
- @param[in] PeiServices The pointer to the PEI Services Table.
- @param[in] This The pointer to this instance of the
- PEI_USB_HOST_CONTROLLER_PPI.
- @param[in] PortNumber Specifies the root hub port from which the status is
- to be retrieved.
- This value is zero based.
- @param[out] PortStatus A pointer to the current port status bits and port
- status change bits.
-
- @retval EFI_SUCCESS The status of the USB root hub port specified by
- PortNumber was returned in PortStatus.
- @retval EFI_INVALID_PARAMETER PortNumber is invalid.
-
-**/
-typedef
-EFI_STATUS
-(EFIAPI *PEI_USB_HOST_CONTROLLER_GET_ROOTHUB_PORT_STATUS)(
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 PortNumber,
- OUT EFI_USB_PORT_STATUS *PortStatus
- );
-
-/**
- Sets a feature for the specified root hub port.
-
- @param[in] PeiServices The pointer to the PEI Services Table.
- @param[in] This The pointer to this instance of the
- PEI_USB_HOST_CONTROLLER_PPI.
- @param[in] PortNumber Specifies the root hub port whose feature is requested
- to be set. This value is zero based.
- @param[in] PortFeature Indicates the feature selector associated with the feature
- set request.
-
- @retval EFI_SUCCESS The feature specified by PortFeature was set for
- the USB root hub port specified by PortNumber.
- @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid
- for this function.
-
-**/
-typedef
-EFI_STATUS
-(EFIAPI *PEI_USB_HOST_CONTROLLER_SET_ROOTHUB_PORT_FEATURE)(
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 PortNumber,
- IN EFI_USB_PORT_FEATURE PortFeature
- );
-
-/**
- Clears a feature for the specified root hub port.
-
- @param[in] PeiServices The pointer to the PEI Services Table.
- @param[in] This The pointer to this instance of the
- PEI_USB_HOST_CONTROLLER_PPI.
- @param[in] PortNumber Specifies the root hub port whose feature is
- requested to be cleared.
- @param[in] PortFeature Indicates the feature selector associated with the
- feature clear request.
-
- @return EFI_SUCCESS The feature specified by PortFeature was cleared
- for the USB root hub port specified by PortNumber.
- @return EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
- @return EFI_DEVICE_ERROR Can't read the register.
-
-**/
-typedef
-EFI_STATUS
-(EFIAPI *PEI_USB_HOST_CONTROLLER_CLEAR_ROOTHUB_PORT_FEATURE)(
- IN EFI_PEI_SERVICES **PeiServices,
- IN PEI_USB_HOST_CONTROLLER_PPI *This,
- IN UINT8 PortNumber,
- IN EFI_USB_PORT_FEATURE PortFeature
- );
-
-///
-/// This PPI contains a set of services to interact with the USB host controller.
-/// These interfaces are modeled on the UEFI 2.3 specification protocol
-/// EFI_USB2_HOST_CONTROLLER_PROTOCOL. Refer to section 16.1 of the UEFI 2.3
-/// Specification for more information on these interfaces.
-///
-struct _PEI_USB_HOST_CONTROLLER_PPI {
- PEI_USB_HOST_CONTROLLER_CONTROL_TRANSFER ControlTransfer;
- PEI_USB_HOST_CONTROLLER_BULK_TRANSFER BulkTransfer;
- PEI_USB_HOST_CONTROLLER_GET_ROOTHUB_PORT_NUMBER GetRootHubPortNumber;
- PEI_USB_HOST_CONTROLLER_GET_ROOTHUB_PORT_STATUS GetRootHubPortStatus;
- PEI_USB_HOST_CONTROLLER_SET_ROOTHUB_PORT_FEATURE SetRootHubPortFeature;
- PEI_USB_HOST_CONTROLLER_CLEAR_ROOTHUB_PORT_FEATURE ClearRootHubPortFeature;
-};
-
-extern EFI_GUID gPeiUsbHostControllerPpiGuid;
-
-#endif
diff --git a/MdeModulePkg/Include/Protocol/UfsHostControllerPlatform.h b/MdeModulePkg/Include/Protocol/UfsHostControllerPlatform.h
index 32e9f64..b5b3160 100644
--- a/MdeModulePkg/Include/Protocol/UfsHostControllerPlatform.h
+++ b/MdeModulePkg/Include/Protocol/UfsHostControllerPlatform.h
@@ -11,7 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Protocol/UfsHostController.h>
-#define EDKII_UFS_HC_PLATFORM_PROTOCOL_VERSION 2
+#define EDKII_UFS_HC_PLATFORM_PROTOCOL_VERSION 3
extern EFI_GUID gEdkiiUfsHcPlatformProtocolGuid;
@@ -129,6 +129,14 @@ struct _EDKII_UFS_HC_PLATFORM_PROTOCOL {
/// Reference Clock Frequency Ufs Card Attribute that need to be set in this Ufs Host Environment.
///
EDKII_UFS_CARD_REF_CLK_FREQ_ATTRIBUTE RefClkFreq;
+ ///
+ /// Flag to skip HCE re-enable.
+ ///
+ BOOLEAN SkipHceReenable;
+ ///
+ /// Flag to skip link startup.
+ ///
+ BOOLEAN SkipLinkStartup;
};
#endif
diff --git a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c
index 2d807bf..bd5b8f5 100644
--- a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c
+++ b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c
@@ -3,6 +3,7 @@
This library class defines a set of interfaces to customize Display module
Copyright (c) 2013-2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2025, Loongson Technology Corporation Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -859,10 +860,7 @@ PrintInternal (
)
{
CHAR16 *Buffer;
- CHAR16 *BackupBuffer;
UINTN Index;
- UINTN PreviousIndex;
- UINTN Count;
UINTN TotalCount;
UINTN PrintWidth;
UINTN CharWidth;
@@ -870,10 +868,8 @@ PrintInternal (
//
// For now, allocate an arbitrarily long buffer
//
- Buffer = AllocateZeroPool (0x10000);
- BackupBuffer = AllocateZeroPool (0x10000);
+ Buffer = AllocateZeroPool (0x10000);
ASSERT (Buffer);
- ASSERT (BackupBuffer);
if (Column != (UINTN)-1) {
Out->SetCursorPosition (Out, Column, Row);
@@ -884,73 +880,42 @@ PrintInternal (
Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
Out->SetAttribute (Out, Out->Mode->Attribute);
+ Out->OutputString (Out, Buffer);
- Index = 0;
- PreviousIndex = 0;
- Count = 0;
- TotalCount = 0;
- PrintWidth = 0;
- CharWidth = 1;
+ Index = 0;
+ TotalCount = 0;
+ PrintWidth = 0;
+ CharWidth = 1;
do {
- for ( ; (Buffer[Index] != NARROW_CHAR) && (Buffer[Index] != WIDE_CHAR) && (Buffer[Index] != 0); Index++) {
- BackupBuffer[Index] = Buffer[Index];
- }
-
if (Buffer[Index] == 0) {
break;
}
- //
- // Print this out, we are about to switch widths
- //
- Out->OutputString (Out, &BackupBuffer[PreviousIndex]);
- Count = StrLen (&BackupBuffer[PreviousIndex]);
- PrintWidth += Count * CharWidth;
- TotalCount += Count;
-
- //
- // Preserve the current index + 1, since this is where we will start printing from next
- //
- PreviousIndex = Index + 1;
-
- //
- // We are at a narrow or wide character directive. Set attributes and strip it and print it
- //
- if (Buffer[Index] == NARROW_CHAR) {
- //
- // Preserve bits 0 - 6 and zero out the rest
- //
- Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
- Out->SetAttribute (Out, Out->Mode->Attribute);
- CharWidth = 1;
- } else {
- //
- // Must be wide, set bit 7 ON
- //
- Out->Mode->Attribute = Out->Mode->Attribute | EFI_WIDE_ATTRIBUTE;
- Out->SetAttribute (Out, Out->Mode->Attribute);
- CharWidth = 2;
+ switch (Buffer[Index]) {
+ case NARROW_CHAR:
+ CharWidth = 1;
+ break;
+ case WIDE_CHAR:
+ CharWidth = 2;
+ break;
+ default:
+ PrintWidth += CharWidth;
+ TotalCount += 1;
+ break;
}
Index++;
} while (Buffer[Index] != 0);
//
- // We hit the end of the string - print it
+ // We hit the end of the string - fill remaining space with SPACE.
//
- Out->OutputString (Out, &BackupBuffer[PreviousIndex]);
- Count = StrLen (&BackupBuffer[PreviousIndex]);
- PrintWidth += Count * CharWidth;
- TotalCount += Count;
if (PrintWidth < Width) {
- Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
- Out->SetAttribute (Out, Out->Mode->Attribute);
Out->OutputString (Out, &mSpaceBuffer[SPACE_BUFFER_SIZE - Width + PrintWidth]);
}
FreePool (Buffer);
- FreePool (BackupBuffer);
return TotalCount;
}
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 0c0b1c6..8820059 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -504,9 +504,6 @@
## Include/Ppi/AtaController.h
gPeiAtaControllerPpiGuid = { 0xa45e60d1, 0xc719, 0x44aa, { 0xb0, 0x7a, 0xaa, 0x77, 0x7f, 0x85, 0x90, 0x6d }}
- ## Include/Ppi/UsbHostController.h
- gPeiUsbHostControllerPpiGuid = { 0x652B38A9, 0x77F4, 0x453F, { 0x89, 0xD5, 0xE7, 0xBD, 0xC3, 0x52, 0xFC, 0x53 }}
-
## Include/Ppi/Usb2HostController.h
gPeiUsb2HostControllerPpiGuid = { 0xfedd6305, 0xe2d7, 0x4ed5, { 0x9f, 0xaa, 0xda, 0x8, 0xe, 0x33, 0x6c, 0x22 }}
@@ -1677,6 +1674,14 @@
# @Prompt Maximum Number of PEI Reset Filters, Reset Notifications or Reset Handlers.
gEfiMdeModulePkgTokenSpaceGuid.PcdMaximumPeiResetNotifies|0x10|UINT32|0x0000010A
+ ## Whether to report support of FMP capsules in OsIndicationSupport.<BR><BR>
+ # This PCD indicates if support of FMP capsules should be advertised.<BR>
+ # TRUE - support of FMP capsules is advertised.<BR>
+ # FALSE - support of FMP capsules is not advertised.<BR>
+ # If platform does not use this feature, this PCD should be set to FALSE.<BR><BR>
+ # @Prompt Enable advertising support of FMP capsules.
+ gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleFmpSupport|FALSE|BOOLEAN|0x00000028
+
## Capsule On Disk is to deliver capsules via files on Mass Storage device.<BR><BR>
# This PCD indicates if the Capsule On Disk is supported.<BR>
# TRUE - Capsule On Disk is supported.<BR>
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 2e0c665..62ece76 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -250,7 +250,6 @@
MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf
MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf
MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf
- MdeModulePkg/Bus/Pci/UhciPei/UhciPei.inf
MdeModulePkg/Bus/Pci/EhciPei/EhciPei.inf
MdeModulePkg/Bus/Pci/XhciPei/XhciPei.inf
MdeModulePkg/Bus/Pci/IdeBusPei/IdeBusPei.inf
diff --git a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
index 5bac635..95d2607 100644
--- a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
+++ b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
@@ -97,6 +97,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleOnDiskSupport ## CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleFmpSupport ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport ## CONSUMES
[Depex]
diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
index 72de8d3..7856491 100644
--- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
+++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
@@ -580,6 +580,10 @@ BdsFormalizeOSIndicationVariable (
OsIndicationSupport |= EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED;
}
+ if (PcdGetBool (PcdCapsuleFmpSupport)) {
+ OsIndicationSupport |= EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED;
+ }
+
Status = gRT->SetVariable (
EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME,
&gEfiGlobalVariableGuid,
diff --git a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
index 50a88f5..981844c 100644
--- a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
+++ b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
@@ -2,6 +2,7 @@
This is the main routine for initializing the Graphics Console support routines.
Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2025, Loongson Technology Corporation Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -1095,6 +1096,14 @@ GraphicsConsoleConOutTestString (
Count = 0;
while (WString[Count] != 0) {
+ //
+ // In TerminalConOutOutputString(), WIDE_CHAR/NARROW_CHAR will be ignored.
+ // So, WString contains WIDE_CHAR/NARROW_CHAR is also valid.
+ //
+ if ((WString[Count] == WIDE_CHAR) || (WString[Count] == NARROW_CHAR)) {
+ continue;
+ }
+
Status = mHiiFont->GetGlyph (
mHiiFont,
WString[Count],
diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
index 66438be..7a7aa5b 100644
--- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
+++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
@@ -4,6 +4,7 @@
Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.<BR>
Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
Copyright (C) 2016 Silicon Graphics, Inc. All rights reserved.<BR>
+Copyright (c) 2025, Loongson Technology Corporation Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -17,6 +18,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Guid/PcAnsi.h>
#include <Guid/TtyTerm.h>
#include <Guid/StatusCodeDataTypeVariable.h>
+#include <Guid/MdeModuleHii.h>
#include <Protocol/SimpleTextOut.h>
#include <Protocol/SerialIo.h>
@@ -161,7 +163,7 @@ typedef union {
#define FOREGROUND_CONTROL_OFFSET 6
#define BACKGROUND_CONTROL_OFFSET 11
#define ROW_OFFSET 2
-#define COLUMN_OFFSET 5
+#define COLUMN_OFFSET 6
#define FW_BACK_OFFSET 2
#define RESIZE_ROW_OFFSET 4
#define RESIZE_COLUMN_OFFSET 8
diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
index eb8658c..54539c3 100644
--- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
+++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
@@ -4,6 +4,7 @@
Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.<BR>
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
Copyright (C) 2016 Silicon Graphics, Inc. All rights reserved.<BR>
+Copyright (c) 2025, Loongson Technology Corporation Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -75,12 +76,12 @@ UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = {
};
CHAR16 mSetModeString[] = { ESC, '[', '=', '3', 'h', 0 };
-CHAR16 mSetModeStringResize[] = { ESC, '[', '8', ';', '0', '0', '0', ';', '0', '0', '0', 't', '0', 0 };
+CHAR16 mSetModeStringResize[] = { ESC, '[', '8', ';', '0', '0', '0', ';', '0', '0', '0', 't', 0 };
CHAR16 mSetAttributeString[] = { ESC, '[', '0', 'm', ESC, '[', '4', '0', 'm', ESC, '[', '4', '0', 'm', 0 };
CHAR16 mClearScreenString[] = { ESC, '[', '2', 'J', 0 };
-CHAR16 mSetCursorPositionString[] = { ESC, '[', '0', '0', ';', '0', '0', 'H', 0 };
-CHAR16 mCursorForwardString[] = { ESC, '[', '0', '0', 'C', 0 };
-CHAR16 mCursorBackwardString[] = { ESC, '[', '0', '0', 'D', 0 };
+CHAR16 mSetCursorPositionString[] = { ESC, '[', '0', '0', '0', ';', '0', '0', '0', 'H', 0 };
+CHAR16 mCursorForwardString[] = { ESC, '[', '0', '0', '0', 'C', 0 };
+CHAR16 mCursorBackwardString[] = { ESC, '[', '0', '0', '0', 'D', 0 };
//
// Body of the ConOut functions
@@ -216,6 +217,13 @@ TerminalConOutOutputString (
);
for ( ; *WString != CHAR_NULL; WString++) {
+ //
+ // Skip WIDE_CHAR/NARROW_CHAR, because they are not displayable.
+ //
+ if ((*WString == WIDE_CHAR) || (*WString == NARROW_CHAR)) {
+ continue;
+ }
+
switch (TerminalDevice->TerminalType) {
case TerminalTypePcAnsi:
case TerminalTypeVt100:
@@ -497,10 +505,10 @@ TerminalConOutSetMode (
Rows = TerminalDevice->TerminalConsoleModeData[ModeNumber].Rows;
mSetModeStringResize[RESIZE_ROW_OFFSET + 0] = (CHAR16)('0' + (Rows / 100));
- mSetModeStringResize[RESIZE_ROW_OFFSET + 1] = (CHAR16)('0' + ((Rows - ((Rows / 100) * 100)) / 10));
+ mSetModeStringResize[RESIZE_ROW_OFFSET + 1] = (CHAR16)('0' + ((Rows % 100) / 10));
mSetModeStringResize[RESIZE_ROW_OFFSET + 2] = (CHAR16)('0' + (Rows % 10));
mSetModeStringResize[RESIZE_COLUMN_OFFSET + 0] = (CHAR16)('0' + (Columns / 100));
- mSetModeStringResize[RESIZE_COLUMN_OFFSET + 1] = (CHAR16)('0' + ((Columns - ((Columns / 100) * 100)) / 10));
+ mSetModeStringResize[RESIZE_COLUMN_OFFSET + 1] = (CHAR16)('0' + ((Columns % 100) / 10));
mSetModeStringResize[RESIZE_COLUMN_OFFSET + 2] = (CHAR16)('0' + (Columns % 10));
String = mSetModeStringResize;
@@ -804,21 +812,25 @@ TerminalConOutSetCursorPosition (
((UINTN)Mode->CursorRow == Row))
{
if ((UINTN)Mode->CursorColumn > Column) {
- mCursorBackwardString[FW_BACK_OFFSET + 0] = (CHAR16)('0' + ((Mode->CursorColumn - Column) / 10));
- mCursorBackwardString[FW_BACK_OFFSET + 1] = (CHAR16)('0' + ((Mode->CursorColumn - Column) % 10));
+ mCursorBackwardString[FW_BACK_OFFSET + 0] = (CHAR16)('0' + ((Mode->CursorColumn - Column) / 100));
+ mCursorBackwardString[FW_BACK_OFFSET + 1] = (CHAR16)('0' + (((Mode->CursorColumn - Column) % 100) / 10));
+ mCursorBackwardString[FW_BACK_OFFSET + 2] = (CHAR16)('0' + ((Mode->CursorColumn - Column) % 10));
String = mCursorBackwardString;
} else if (Column > (UINTN)Mode->CursorColumn) {
- mCursorForwardString[FW_BACK_OFFSET + 0] = (CHAR16)('0' + ((Column - Mode->CursorColumn) / 10));
- mCursorForwardString[FW_BACK_OFFSET + 1] = (CHAR16)('0' + ((Column - Mode->CursorColumn) % 10));
+ mCursorForwardString[FW_BACK_OFFSET + 0] = (CHAR16)('0' + ((Column - Mode->CursorColumn) / 100));
+ mCursorForwardString[FW_BACK_OFFSET + 1] = (CHAR16)('0' + (((Column - Mode->CursorColumn) % 100) / 10));
+ mCursorForwardString[FW_BACK_OFFSET + 2] = (CHAR16)('0' + ((Column - Mode->CursorColumn) % 10));
String = mCursorForwardString;
} else {
String = L""; // No cursor motion necessary
}
} else {
- mSetCursorPositionString[ROW_OFFSET + 0] = (CHAR16)('0' + ((Row + 1) / 10));
- mSetCursorPositionString[ROW_OFFSET + 1] = (CHAR16)('0' + ((Row + 1) % 10));
- mSetCursorPositionString[COLUMN_OFFSET + 0] = (CHAR16)('0' + ((Column + 1) / 10));
- mSetCursorPositionString[COLUMN_OFFSET + 1] = (CHAR16)('0' + ((Column + 1) % 10));
+ mSetCursorPositionString[ROW_OFFSET + 0] = (CHAR16)('0' + ((Row + 1) / 100));
+ mSetCursorPositionString[ROW_OFFSET + 1] = (CHAR16)('0' + (((Row + 1) % 100) / 10));
+ mSetCursorPositionString[ROW_OFFSET + 2] = (CHAR16)('0' + ((Row + 1) % 10));
+ mSetCursorPositionString[COLUMN_OFFSET + 0] = (CHAR16)('0' + ((Column + 1) / 100));
+ mSetCursorPositionString[COLUMN_OFFSET + 1] = (CHAR16)('0' + (((Column + 1) % 100) / 10));
+ mSetCursorPositionString[COLUMN_OFFSET + 2] = (CHAR16)('0' + ((Column + 1) % 10));
String = mSetCursorPositionString;
}
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
index c9aabaa..a282f6d 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
@@ -2,6 +2,7 @@
Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2025, Loongson Technology Corporation Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -4265,7 +4266,7 @@ GenerateAltConfigResp (
// Convert Value to a hex string in "%x" format
// NOTE: This is in the opposite byte that GUID and PATH use
//
- if (BlockData->OpCode == EFI_IFR_STRING_OP) {
+ if ((BlockData->OpCode == EFI_IFR_STRING_OP) && (DefaultValueData->Value.string != 0)) {
DefaultString = InternalGetString (HiiHandle, DefaultValueData->Value.string);
TmpBuffer = AllocateZeroPool (Width);
ASSERT (TmpBuffer != NULL);
diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c
index 9f3d434..8bd72f0 100644
--- a/MdeModulePkg/Universal/Variable/Pei/Variable.c
+++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c
@@ -913,7 +913,7 @@ FindVariableEx (
}
}
- if (MaxIndex != NULL) {
+ if ((MaxIndex != NULL) && (VariableHeader != NULL)) {
//
// HOB exists but the variable cannot be found in HOB
// If not found in HOB, then let's start from the MaxIndex we've found.
@@ -1164,7 +1164,7 @@ PeiGetNextVariableName (
VariableHeader = NULL;
Status = FindVariable (VariableName, VariableGuid, &Variable, &StoreInfo);
- if ((Variable.CurrPtr == NULL) || (Status != EFI_SUCCESS)) {
+ if ((Status != EFI_SUCCESS) || (Variable.CurrPtr == NULL)) {
return Status;
}
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
index 1c76590..10fb4a3 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -1549,39 +1549,40 @@ AutoUpdateLangVariable (
// Get the corresponding ISO639 language tag according to RFC4646 language tag.
//
BestLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->LangCodes, Index, TRUE);
-
- //
- // Check the variable space for both Lang and PlatformLang variable.
- //
- VariableEntry[0].VariableSize = ISO_639_2_ENTRY_SIZE + 1;
- VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
- VariableEntry[0].Name = EFI_LANG_VARIABLE_NAME;
-
- VariableEntry[1].VariableSize = AsciiStrSize (BestPlatformLang);
- VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
- VariableEntry[1].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;
- if (!CheckRemainingSpaceForConsistency (VARIABLE_ATTRIBUTE_NV_BS_RT, &VariableEntry[0], &VariableEntry[1], NULL)) {
- //
- // No enough variable space to set both Lang and PlatformLang successfully.
- //
- Status = EFI_OUT_OF_RESOURCES;
- } else {
+ if (BestLang != NULL) {
//
- // Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.
+ // Check the variable space for both Lang and PlatformLang variable.
//
- FindVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
-
- Status = UpdateVariable (
- EFI_LANG_VARIABLE_NAME,
- &gEfiGlobalVariableGuid,
- BestLang,
- ISO_639_2_ENTRY_SIZE + 1,
- Attributes,
- 0,
- 0,
- &Variable,
- NULL
- );
+ VariableEntry[0].VariableSize = ISO_639_2_ENTRY_SIZE + 1;
+ VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
+ VariableEntry[0].Name = EFI_LANG_VARIABLE_NAME;
+
+ VariableEntry[1].VariableSize = AsciiStrSize (BestPlatformLang);
+ VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
+ VariableEntry[1].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;
+ if (!CheckRemainingSpaceForConsistency (VARIABLE_ATTRIBUTE_NV_BS_RT, &VariableEntry[0], &VariableEntry[1], NULL)) {
+ //
+ // No enough variable space to set both Lang and PlatformLang successfully.
+ //
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ //
+ // Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.
+ //
+ FindVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
+
+ Status = UpdateVariable (
+ EFI_LANG_VARIABLE_NAME,
+ &gEfiGlobalVariableGuid,
+ BestLang,
+ ISO_639_2_ENTRY_SIZE + 1,
+ Attributes,
+ 0,
+ 0,
+ &Variable,
+ NULL
+ );
+ }
}
DEBUG ((DEBUG_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a Status: %r\n", BestPlatformLang, BestLang, Status));
@@ -1606,39 +1607,40 @@ AutoUpdateLangVariable (
// Get the corresponding RFC4646 language tag according to ISO639 language tag.
//
BestPlatformLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->PlatformLangCodes, Index, FALSE);
-
- //
- // Check the variable space for both PlatformLang and Lang variable.
- //
- VariableEntry[0].VariableSize = AsciiStrSize (BestPlatformLang);
- VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
- VariableEntry[0].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;
-
- VariableEntry[1].VariableSize = ISO_639_2_ENTRY_SIZE + 1;
- VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
- VariableEntry[1].Name = EFI_LANG_VARIABLE_NAME;
- if (!CheckRemainingSpaceForConsistency (VARIABLE_ATTRIBUTE_NV_BS_RT, &VariableEntry[0], &VariableEntry[1], NULL)) {
- //
- // No enough variable space to set both PlatformLang and Lang successfully.
- //
- Status = EFI_OUT_OF_RESOURCES;
- } else {
+ if (BestPlatformLang != NULL) {
//
- // Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.
+ // Check the variable space for both PlatformLang and Lang variable.
//
- FindVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
-
- Status = UpdateVariable (
- EFI_PLATFORM_LANG_VARIABLE_NAME,
- &gEfiGlobalVariableGuid,
- BestPlatformLang,
- AsciiStrSize (BestPlatformLang),
- Attributes,
- 0,
- 0,
- &Variable,
- NULL
- );
+ VariableEntry[0].VariableSize = AsciiStrSize (BestPlatformLang);
+ VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
+ VariableEntry[0].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;
+
+ VariableEntry[1].VariableSize = ISO_639_2_ENTRY_SIZE + 1;
+ VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
+ VariableEntry[1].Name = EFI_LANG_VARIABLE_NAME;
+ if (!CheckRemainingSpaceForConsistency (VARIABLE_ATTRIBUTE_NV_BS_RT, &VariableEntry[0], &VariableEntry[1], NULL)) {
+ //
+ // No enough variable space to set both PlatformLang and Lang successfully.
+ //
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ //
+ // Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.
+ //
+ FindVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
+
+ Status = UpdateVariable (
+ EFI_PLATFORM_LANG_VARIABLE_NAME,
+ &gEfiGlobalVariableGuid,
+ BestPlatformLang,
+ AsciiStrSize (BestPlatformLang),
+ Attributes,
+ 0,
+ 0,
+ &Variable,
+ NULL
+ );
+ }
}
DEBUG ((DEBUG_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a Status: %r\n", BestLang, BestPlatformLang, Status));
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c
index 984cae1..60d16e9 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c
@@ -477,6 +477,8 @@ InternalProtocolGetVariablePolicyInfo (
UINTN BufferSize;
UINTN VariableNameSize;
+ PolicyHeader = NULL;
+
if ((VariableName == NULL) || (VendorGuid == NULL) || (VariablePolicy == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -609,8 +611,11 @@ InternalProtocolGetVariablePolicyInfo (
Done:
ReleaseLockOnlyAtBootTime (&mMmCommunicationLock);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
- return (EFI_ERROR (Status)) ? Status : PolicyHeader->Result;
+ return (PolicyHeader != NULL) ? PolicyHeader->Result : EFI_SUCCESS;
}
/**
diff --git a/EmbeddedPkg/Include/Guid/Fdt.h b/MdePkg/Include/Guid/Fdt.h
index e009146..9f9270a 100644
--- a/EmbeddedPkg/Include/Guid/Fdt.h
+++ b/MdePkg/Include/Guid/Fdt.h
@@ -14,9 +14,4 @@
extern EFI_GUID gFdtTableGuid;
-#define FDT_VARIABLE_GUID \
- { 0x25a4fd4a, 0x9703, 0x4ba9, { 0xa1, 0x90, 0xb7, 0xc8, 0x4e, 0xfb, 0x3e, 0x57 } }
-
-extern EFI_GUID gFdtVariableGuid;
-
#endif /* __FDT_H__ */
diff --git a/MdePkg/Include/IndustryStandard/SmBios.h b/MdePkg/Include/IndustryStandard/SmBios.h
index 490ec43..ce0a8e3 100644
--- a/MdePkg/Include/IndustryStandard/SmBios.h
+++ b/MdePkg/Include/IndustryStandard/SmBios.h
@@ -1905,7 +1905,8 @@ typedef enum {
MemoryTypeHBM2 = 0x21,
MemoryTypeDdr5 = 0x22,
MemoryTypeLpddr5 = 0x23,
- MemoryTypeHBM3 = 0x24
+ MemoryTypeHBM3 = 0x24,
+ MemoryTypeMrDimm = 0x25
} MEMORY_DEVICE_TYPE;
///
@@ -1944,7 +1945,8 @@ typedef enum {
// This definition is updated to represent Intel
// Optane DC Persistent Memory in SMBIOS spec 3.4.0
//
- MemoryTechnologyIntelOptanePersistentMemory = 0x07
+ MemoryTechnologyIntelOptanePersistentMemory = 0x07,
+ MemoryTechnologyMrDimmDeprecated = 0x08
} MEMORY_DEVICE_TECHNOLOGY;
///
diff --git a/MdePkg/Include/Protocol/SimplePointer.h b/MdePkg/Include/Protocol/SimplePointer.h
index f8d45a6..313119f 100644
--- a/MdePkg/Include/Protocol/SimplePointer.h
+++ b/MdePkg/Include/Protocol/SimplePointer.h
@@ -54,12 +54,12 @@ typedef struct {
UINT64 ResolutionX;
///
/// The resolution of the pointer device on the y-axis in counts/mm.
- /// If 0, then the pointer device does not support an x-axis.
+ /// If 0, then the pointer device does not support a y-axis.
///
UINT64 ResolutionY;
///
/// The resolution of the pointer device on the z-axis in counts/mm.
- /// If 0, then the pointer device does not support an x-axis.
+ /// If 0, then the pointer device does not support a z-axis.
///
UINT64 ResolutionZ;
///
diff --git a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
index 05f758a..be7043b 100644
--- a/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
+++ b/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
@@ -3,6 +3,7 @@
libfdt library.
Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -54,12 +55,6 @@ memcmp (
size_t
);
-int
-strcmp (
- const char *,
- const char *
- );
-
char *
strchr (
const char *,
@@ -88,19 +83,15 @@ strcpy (
//
// Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
//
-#define memcpy(dest, source, count) CopyMem(dest,source, (UINTN)(count))
-#define memset(dest, ch, count) SetMem(dest, (UINTN)(count),(UINT8)(ch))
-#define memchr(buf, ch, count) ScanMem8(buf, (UINTN)(count),(UINT8)ch)
-#define memcmp(buf1, buf2, count) (int)(CompareMem(buf1, buf2, (UINTN)(count)))
-#define memmove(dest, source, count) CopyMem(dest, source, (UINTN)(count))
-#define strlen(str) (size_t)(AsciiStrLen(str))
-#define strnlen(str, count) (size_t)(AsciiStrnLenS(str, count))
-#define strncpy(strDest, strSource, count) AsciiStrnCpyS(strDest, MAX_STRING_SIZE, strSource, (UINTN)count)
-#define strcat(strDest, strSource) AsciiStrCatS(strDest, MAX_STRING_SIZE, strSource)
-#define strchr(str, ch) ScanMem8(str, AsciiStrSize (str), (UINT8)ch)
-#define strcmp(string1, string2, count) (int)(AsciiStrCmp(string1, string2))
-#define strncmp(string1, string2, count) (int)(AsciiStrnCmp(string1, string2, (UINTN)(count)))
-#define strrchr(str, ch) fdt_strrchr(str, ch)
-#define strtoul(ptr, end_ptr, base) fdt_strtoul(ptr, end_ptr, base)
+#define memcpy(dest, source, count) CopyMem(dest,source, (UINTN)(count))
+#define memset(dest, ch, count) SetMem(dest, (UINTN)(count),(UINT8)(ch))
+#define memchr(buf, ch, count) ScanMem8(buf, (UINTN)(count),(UINT8)ch)
+#define memcmp(buf1, buf2, count) (int)(CompareMem(buf1, buf2, (UINTN)(count)))
+#define memmove(dest, source, count) CopyMem(dest, source, (UINTN)(count))
+#define strlen(str) (size_t)(AsciiStrLen(str))
+#define strnlen(str, count) (size_t)(AsciiStrnLenS(str, count))
+#define strchr(str, ch) ScanMem8(str, AsciiStrSize (str), (UINT8)ch)
+#define strrchr(str, ch) fdt_strrchr(str, ch)
+#define strtoul(ptr, end_ptr, base) fdt_strtoul(ptr, end_ptr, base)
#endif /* FDT_LIB_SUPPORT_H_ */
diff --git a/MdePkg/Library/BaseRngLib/Riscv/Rng.c b/MdePkg/Library/BaseRngLib/Riscv/Rng.c
index 6a9b2ce..35b792f 100644
--- a/MdePkg/Library/BaseRngLib/Riscv/Rng.c
+++ b/MdePkg/Library/BaseRngLib/Riscv/Rng.c
@@ -19,75 +19,7 @@
#define SEED_RETRY_LOOPS 100
-// 64-bit Mersenne Twister implementation
-// A widely used pseudo random number generator. It performs bit shifts etc to
-// achieve the random number. It's output is determined by SEED value generated
-// by RISC-V SEED CSR"
-
-#define STATE_SIZE 312
-#define MIDDLE 156
-#define INIT_SHIFT 62
-#define TWIST_MASK 0xb5026f5aa96619e9ULL
-#define INIT_FACT 6364136223846793005ULL
-#define SHIFT1 29
-#define MASK1 0x5555555555555555ULL
-#define SHIFT2 17
-#define MASK2 0x71d67fffeda60000ULL
-#define SHIFT3 37
-#define MASK3 0xfff7eee000000000ULL
-#define SHIFT4 43
-
-#define LOWER_MASK 0x7fffffff
-#define UPPER_MASK (~(UINT64)LOWER_MASK)
-
-static UINT64 mState[STATE_SIZE];
-static UINTN mIndex = STATE_SIZE + 1;
-
-/**
- Initialize mState to defualt state.
-
- @param[in] S Input seed value
- **/
-STATIC
-VOID
-SeedRng (
- IN UINT64 S
- )
-{
- UINTN I;
-
- mIndex = STATE_SIZE;
- mState[0] = S;
-
- for (I = 1; I < STATE_SIZE; I++) {
- mState[I] = (INIT_FACT * (mState[I - 1] ^ (mState[I - 1] >> INIT_SHIFT))) + I;
- }
-}
-
-/**
- Initializes mState with entropy values. The initialization is based on the
- Seed value populated in mState[0] which then influences all the other values
- in the mState array. Later values are retrieved from the same array instead
- of calling trng instruction every time.
-
- **/
-STATIC
-VOID
-TwistRng (
- VOID
- )
-{
- UINTN I;
- UINT64 X;
-
- for (I = 0; I < STATE_SIZE; I++) {
- X = (mState[I] & UPPER_MASK) | (mState[(I + 1) % STATE_SIZE] & LOWER_MASK);
- X = (X >> 1) ^ (X & 1 ? TWIST_MASK : 0);
- mState[I] = mState[(I + MIDDLE) % STATE_SIZE] ^ X;
- }
-
- mIndex = 0;
-}
+// 64-bit CPU-based RNG using risc-v Zkr instruction
// Defined in Seed.S
extern UINT64
@@ -164,14 +96,7 @@ BaseRngLibConstructor (
VOID
)
{
- UINT64 Seed;
-
- if (Get64BitSeed (&Seed)) {
- SeedRng (Seed);
- return EFI_SUCCESS;
- } else {
- return EFI_UNSUPPORTED;
- }
+ return EFI_SUCCESS;
}
/**
@@ -241,24 +166,10 @@ ArchGetRandomNumber64 (
{
UINT64 Y;
- // Never initialized.
- if (mIndex > STATE_SIZE) {
+ if (!Get64BitSeed (&Y)) {
return FALSE;
}
- // Mersenne Twister
- if (mIndex == STATE_SIZE) {
- TwistRng ();
- }
-
- Y = mState[mIndex];
- Y ^= (Y >> SHIFT1) & MASK1;
- Y ^= (Y << SHIFT2) & MASK2;
- Y ^= (Y << SHIFT3) & MASK3;
- Y ^= Y >> SHIFT4;
-
- mIndex++;
-
*Rand = Y;
return TRUE;
}
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 842abaa..ed22a67 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -615,6 +615,10 @@
## Include/Guid/FdtHob.h
gFdtHobGuid = { 0x16958446, 0x19B7, 0x480B, { 0xB0, 0x47, 0x74, 0x85, 0xAD, 0x3F, 0x71, 0x6D } }
+ ## FDT Configuration Table
+ # Include/Guid/Fdt.h
+ gFdtTableGuid = { 0xb1b621d5, 0xf19c, 0x41a5, { 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 } }
+
## Include/Guid/ImageAuthentication.h
gEfiImageSecurityDatabaseGuid = { 0xd719b2cb, 0x3d3a, 0x4596, {0xa3, 0xbc, 0xda, 0xd0, 0xe, 0x67, 0x65, 0x6f }}
gEfiCertSha256Guid = { 0xc1c41626, 0x504c, 0x4092, {0xac, 0xa9, 0x41, 0xf9, 0x36, 0x93, 0x43, 0x28 }}
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
index 3b2ac0d..072707f 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
@@ -1490,7 +1490,7 @@ WifiMgrOnTimerTick (
}
Nic = (WIFI_MGR_DEVICE_DATA *)Context;
- if (Nic->ConnectPendingNetwork == NULL) {
+ if ((Nic->ConnectPendingNetwork == NULL) && !Nic->HasDisconnectPendingNetwork) {
DEBUG ((DEBUG_VERBOSE, "[WiFi Connection Manager] No profile for connection, no scan triggered!\n"));
gBS->SetTimer (Nic->TickTimer, TimerCancel, 0);
return;
diff --git a/OvmfPkg/Library/MemDebugLogLib/MemDebugLogPei.c b/OvmfPkg/Library/MemDebugLogLib/MemDebugLogPei.c
index cbdab6c..05e32da 100644
--- a/OvmfPkg/Library/MemDebugLogLib/MemDebugLogPei.c
+++ b/OvmfPkg/Library/MemDebugLogLib/MemDebugLogPei.c
@@ -12,9 +12,6 @@
#include <Library/QemuFwCfgSimpleParserLib.h>
#include <Library/MemDebugLogLib.h>
-EFI_PHYSICAL_ADDRESS mMemDebugLogBufAddr;
-BOOLEAN mMemDebugLogBufAddrInit;
-
EFI_STATUS
EFIAPI
MemDebugLogWrite (
@@ -22,23 +19,21 @@ MemDebugLogWrite (
IN UINTN Length
)
{
- EFI_STATUS Status;
+ EFI_PHYSICAL_ADDRESS MemDebugLogBufAddr;
+ EFI_STATUS Status;
- if (!mMemDebugLogBufAddrInit) {
- //
- // Obtain the Memory Debug Log buffer addr from HOB
- // NOTE: This is expected to fail until the HOB is created.
- //
- Status = MemDebugLogAddrFromHOB (&mMemDebugLogBufAddr);
- if (EFI_ERROR (Status)) {
- mMemDebugLogBufAddr = 0;
- } else {
- mMemDebugLogBufAddrInit = TRUE;
- }
+ //
+ // Obtain the Memory Debug Log buffer addr from HOB
+ // NOTE: This is expected to fail until the HOB is created.
+ //
+ Status = MemDebugLogAddrFromHOB (&MemDebugLogBufAddr);
+
+ if (EFI_ERROR (Status)) {
+ MemDebugLogBufAddr = 0;
}
- if (mMemDebugLogBufAddr) {
- Status = MemDebugLogWriteBuffer (mMemDebugLogBufAddr, Buffer, Length);
+ if (MemDebugLogBufAddr != 0) {
+ Status = MemDebugLogWriteBuffer (MemDebugLogBufAddr, Buffer, Length);
} else {
//
// HOB has not yet been created, so
diff --git a/OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiCore.c b/OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiCore.c
index 1e95d65..c8de40d 100644
--- a/OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiCore.c
+++ b/OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiCore.c
@@ -11,9 +11,6 @@
#include <Library/PeiServicesLib.h>
#include <Library/MemDebugLogLib.h>
-EFI_PHYSICAL_ADDRESS mMemDebugLogBufAddr;
-BOOLEAN mMemDebugLogBufAddrInit;
-
EFI_STATUS
EFIAPI
MemDebugLogWrite (
@@ -21,23 +18,20 @@ MemDebugLogWrite (
IN UINTN Length
)
{
- EFI_STATUS Status;
-
- if (!mMemDebugLogBufAddrInit) {
- //
- // Obtain the Memory Debug Log buffer addr from HOB
- // NOTE: This is expected to fail until the HOB is created.
- //
- Status = MemDebugLogAddrFromHOB (&mMemDebugLogBufAddr);
- if (EFI_ERROR (Status)) {
- mMemDebugLogBufAddr = 0;
- } else {
- mMemDebugLogBufAddrInit = TRUE;
- }
+ EFI_PHYSICAL_ADDRESS MemDebugLogBufAddr;
+ EFI_STATUS Status;
+
+ //
+ // Obtain the Memory Debug Log buffer addr from HOB
+ // NOTE: This is expected to fail until the HOB is created.
+ //
+ Status = MemDebugLogAddrFromHOB (&MemDebugLogBufAddr);
+ if (EFI_ERROR (Status)) {
+ MemDebugLogBufAddr = 0;
}
- if (mMemDebugLogBufAddr) {
- Status = MemDebugLogWriteBuffer (mMemDebugLogBufAddr, Buffer, Length);
+ if (MemDebugLogBufAddr != 0) {
+ Status = MemDebugLogWriteBuffer (MemDebugLogBufAddr, Buffer, Length);
} else {
//
// HOB has not yet been created, so
diff --git a/OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiLib.inf b/OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiLib.inf
index 18f06e4..b6b407c 100644
--- a/OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiLib.inf
+++ b/OvmfPkg/Library/MemDebugLogLib/MemDebugLogPeiLib.inf
@@ -29,11 +29,6 @@
[LibraryClasses]
SynchronizationLib
PcdLib
-
-[LibraryClasses.Ia32]
- QemuFwCfgSimpleParserLib
-
-[LibraryClasses.X64]
QemuFwCfgSimpleParserLib
[Guids]
diff --git a/OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootDefaultKeysInit/SecureBootDefaultKeysInit.c b/OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootDefaultKeysInit/SecureBootDefaultKeysInit.c
new file mode 100644
index 0000000..037174d
--- /dev/null
+++ b/OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootDefaultKeysInit/SecureBootDefaultKeysInit.c
@@ -0,0 +1,643 @@
+/** @file
+ This driver init default Secure Boot variables
+
+ Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+ (C) Copyright 2018 Hewlett Packard Enterprise Development LP<BR>
+ Copyright (c) 2021, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2021, Semihalf All rights reserved.<BR>
+ Copyright (c) 2021, Ampere Computing LLC. All rights reserved.<BR>
+ Copyright (C) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <UefiSecureBoot.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/DxeServicesLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/UefiLib.h>
+#include <Guid/AuthenticatedVariableFormat.h>
+#include <Guid/ImageAuthentication.h>
+#include <Library/SecureBootVariableLib.h>
+#include <Library/SecureBootVariableProvisionLib.h>
+
+/**
+ Set PKDefault Variable.
+
+ @param[in] X509Data X509 Certificate data.
+ @param[in] X509DataSize X509 Certificate data size.
+
+ @retval EFI_SUCCESS PKDefault is set successfully.
+
+**/
+EFI_STATUS
+SetPkDefault (
+ IN UINT8 *X509Data,
+ IN UINTN X509DataSize
+ )
+{
+ EFI_STATUS Status;
+ UINT32 Attr;
+ UINTN DataSize;
+ EFI_SIGNATURE_LIST *PkCert;
+ EFI_SIGNATURE_DATA *PkCertData;
+
+ PkCert = NULL;
+
+ //
+ // Allocate space for PK certificate list and initialize it.
+ // Create PK database entry with SignatureHeaderSize equals 0.
+ //
+ PkCert = (EFI_SIGNATURE_LIST *)AllocateZeroPool (
+ sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1
+ + X509DataSize
+ );
+ if (PkCert == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ DEBUG ((DEBUG_ERROR, "%a: Cannot initialize PKDefault: %r\n", __func__, Status));
+ goto ON_EXIT;
+ }
+
+ PkCert->SignatureListSize = (UINT32)(sizeof (EFI_SIGNATURE_LIST)
+ + sizeof (EFI_SIGNATURE_DATA) - 1
+ + X509DataSize);
+ PkCert->SignatureSize = (UINT32)(sizeof (EFI_SIGNATURE_DATA) - 1 + X509DataSize);
+ PkCert->SignatureHeaderSize = 0;
+ CopyGuid (&PkCert->SignatureType, &gEfiCertX509Guid);
+ PkCertData = (EFI_SIGNATURE_DATA *)((UINTN)PkCert
+ + sizeof (EFI_SIGNATURE_LIST)
+ + PkCert->SignatureHeaderSize);
+ CopyGuid (&PkCertData->SignatureOwner, &gEfiGlobalVariableGuid);
+ //
+ // Fill the PK database with PKpub data from X509 certificate file.
+ //
+ CopyMem (&(PkCertData->SignatureData[0]), X509Data, X509DataSize);
+
+ Attr = EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS;
+ DataSize = PkCert->SignatureListSize;
+
+ Status = gRT->SetVariable (
+ EFI_PK_DEFAULT_VARIABLE_NAME,
+ &gEfiGlobalVariableGuid,
+ Attr,
+ DataSize,
+ PkCert
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Cannot initialize PKDefault: %r\n", __func__, Status));
+ goto ON_EXIT;
+ }
+
+ON_EXIT:
+
+ if (PkCert != NULL) {
+ FreePool (PkCert);
+ }
+
+ return Status;
+}
+
+/**
+ Set KDKDefault Variable.
+
+ @param[in] X509Data X509 Certificate data.
+ @param[in] X509DataSize X509 Certificate data size.
+
+ @retval EFI_SUCCESS KEKDefault is set successfully.
+
+**/
+EFI_STATUS
+SetKekDefault (
+ IN UINT8 *X509Data,
+ IN UINTN X509DataSize
+ )
+{
+ EFI_STATUS Status;
+ EFI_SIGNATURE_DATA *KEKSigData;
+ EFI_SIGNATURE_LIST *KekSigList;
+ UINTN DataSize;
+ UINTN KekSigListSize;
+ UINT32 Attr;
+
+ KekSigList = NULL;
+ KekSigListSize = 0;
+ DataSize = 0;
+ KEKSigData = NULL;
+
+ KekSigListSize = sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + X509DataSize;
+ KekSigList = (EFI_SIGNATURE_LIST *)AllocateZeroPool (KekSigListSize);
+ if (KekSigList == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ DEBUG ((DEBUG_ERROR, "%a: Cannot initialize KEKDefault: %r\n", __func__, Status));
+ goto ON_EXIT;
+ }
+
+ //
+ // Fill Certificate Database parameters.
+ //
+ KekSigList->SignatureListSize = (UINT32)KekSigListSize;
+ KekSigList->SignatureHeaderSize = 0;
+ KekSigList->SignatureSize = (UINT32)(sizeof (EFI_SIGNATURE_DATA) - 1 + X509DataSize);
+ CopyGuid (&KekSigList->SignatureType, &gEfiCertX509Guid);
+
+ KEKSigData = (EFI_SIGNATURE_DATA *)((UINT8 *)KekSigList + sizeof (EFI_SIGNATURE_LIST));
+ CopyGuid (&KEKSigData->SignatureOwner, &gEfiGlobalVariableGuid);
+ CopyMem (KEKSigData->SignatureData, X509Data, X509DataSize);
+
+ //
+ // Check if KEK been already existed.
+ // If true, use EFI_VARIABLE_APPEND_WRITE attribute to append the
+ // new kek to original variable
+ //
+ Attr = EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS;
+
+ Status = gRT->GetVariable (
+ EFI_KEK_DEFAULT_VARIABLE_NAME,
+ &gEfiGlobalVariableGuid,
+ NULL,
+ &DataSize,
+ NULL
+ );
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ Attr |= EFI_VARIABLE_APPEND_WRITE;
+ } else if (Status != EFI_NOT_FOUND) {
+ DEBUG ((DEBUG_ERROR, "%a: Cannot get the value of KEK: %r\n", __func__, Status));
+ goto ON_EXIT;
+ }
+
+ Status = gRT->SetVariable (
+ EFI_KEK_DEFAULT_VARIABLE_NAME,
+ &gEfiGlobalVariableGuid,
+ Attr,
+ KekSigListSize,
+ KekSigList
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Cannot initialize KEKDefault: %r\n", __func__, Status));
+ goto ON_EXIT;
+ }
+
+ON_EXIT:
+
+ if (KekSigList != NULL) {
+ FreePool (KekSigList);
+ }
+
+ return Status;
+}
+
+/**
+ Checks if the file content complies with EFI_VARIABLE_AUTHENTICATION_2 format
+
+ @param[in] Data Data.
+ @param[in] DataSize Data size.
+
+ @retval TRUE The content is EFI_VARIABLE_AUTHENTICATION_2 format.
+ @retval FALSE The content is NOT a EFI_VARIABLE_AUTHENTICATION_2 format.
+
+**/
+BOOLEAN
+IsAuthentication2Format (
+ IN UINT8 *Data,
+ IN UINTN DataSize
+ )
+{
+ EFI_VARIABLE_AUTHENTICATION_2 *Auth2;
+ BOOLEAN IsAuth2Format;
+
+ IsAuth2Format = FALSE;
+
+ Auth2 = (EFI_VARIABLE_AUTHENTICATION_2 *)Data;
+ if (Auth2->AuthInfo.Hdr.wCertificateType != WIN_CERT_TYPE_EFI_GUID) {
+ goto ON_EXIT;
+ }
+
+ if (CompareGuid (&gEfiCertPkcs7Guid, &Auth2->AuthInfo.CertType)) {
+ IsAuth2Format = TRUE;
+ }
+
+ON_EXIT:
+
+ return IsAuth2Format;
+}
+
+/**
+ Set signature database with the data of EFI_VARIABLE_AUTHENTICATION_2 format.
+
+ @param[in] AuthData AUTHENTICATION_2 data.
+ @param[in] AuthDataSize AUTHENTICATION_2 data size.
+ @param[in] VariableName Variable name of signature database, must be
+ EFI_DB_DEFAULT_VARIABLE_NAME or EFI_DBX_DEFAULT_VARIABLE_NAME or EFI_DBT_DEFAULT_VARIABLE_NAME.
+
+ @retval EFI_SUCCESS New signature is set successfully.
+ @retval EFI_INVALID_PARAMETER The parameter is invalid.
+ @retval EFI_UNSUPPORTED Unsupported command.
+ @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
+
+**/
+EFI_STATUS
+SetAuthentication2ToSigDb (
+ IN UINT8 *AuthData,
+ IN UINTN AuthDataSize,
+ IN CHAR16 *VariableName
+ )
+{
+ EFI_STATUS Status;
+ UINTN DataSize;
+ UINT32 Attr;
+ UINT8 *Data;
+
+ Attr = EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS;
+
+ //
+ // Check if SigDB variable has been already existed.
+ // If true, use EFI_VARIABLE_APPEND_WRITE attribute to append the
+ // new signature data to original variable
+ //
+ DataSize = 0;
+ Status = gRT->GetVariable (
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ NULL,
+ &DataSize,
+ NULL
+ );
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ Attr |= EFI_VARIABLE_APPEND_WRITE;
+ } else if (Status != EFI_NOT_FOUND) {
+ DEBUG ((DEBUG_ERROR, "%a: Cannot get the value of signature database: %r\n", __func__, Status));
+ return Status;
+ }
+
+ //
+ // Ignore AUTHENTICATION_2 region. Only the actual certificate is needed.
+ //
+ DataSize = AuthDataSize - ((EFI_VARIABLE_AUTHENTICATION_2 *)AuthData)->AuthInfo.Hdr.dwLength - sizeof (EFI_TIME);
+ Data = AuthData + (AuthDataSize - DataSize);
+
+ Status = gRT->SetVariable (
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ Attr,
+ DataSize,
+ Data
+ );
+
+ return Status;
+}
+
+/**
+
+ Set signature database with the data of X509 format.
+
+ @param[in] X509Data X509 Certificate data.
+ @param[in] X509DataSize X509 Certificate data size.
+ @param[in] VariableName Variable name of signature database, must be
+ EFI_DB_DEFAULT_VARIABLE_NAME or EFI_DBX_DEFAULT_VARIABLE_NAME or EFI_DBT_DEFAULT_VARIABLE_NAME.
+ @param[in] SignatureOwnerGuid Guid of the signature owner.
+
+ @retval EFI_SUCCESS New X509 is enrolled successfully.
+ @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
+
+**/
+EFI_STATUS
+SetX509ToSigDb (
+ IN UINT8 *X509Data,
+ IN UINTN X509DataSize,
+ IN CHAR16 *VariableName,
+ IN EFI_GUID *SignatureOwnerGuid
+ )
+{
+ EFI_STATUS Status;
+ EFI_SIGNATURE_LIST *SigDBCert;
+ EFI_SIGNATURE_DATA *SigDBCertData;
+ VOID *Data;
+ UINTN DataSize;
+ UINTN SigDBSize;
+ UINT32 Attr;
+
+ SigDBSize = 0;
+ DataSize = 0;
+ SigDBCert = NULL;
+ SigDBCertData = NULL;
+ Data = NULL;
+
+ SigDBSize = sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + X509DataSize;
+ Data = AllocateZeroPool (SigDBSize);
+ if (Data == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory: %r\n", __func__, Status));
+ goto ON_EXIT;
+ }
+
+ //
+ // Fill Certificate Database parameters.
+ //
+ SigDBCert = (EFI_SIGNATURE_LIST *)Data;
+ SigDBCert->SignatureListSize = (UINT32)SigDBSize;
+ SigDBCert->SignatureHeaderSize = 0;
+ SigDBCert->SignatureSize = (UINT32)(sizeof (EFI_SIGNATURE_DATA) - 1 + X509DataSize);
+ CopyGuid (&SigDBCert->SignatureType, &gEfiCertX509Guid);
+
+ SigDBCertData = (EFI_SIGNATURE_DATA *)((UINT8 *)SigDBCert + sizeof (EFI_SIGNATURE_LIST));
+ CopyGuid (&SigDBCertData->SignatureOwner, SignatureOwnerGuid);
+ CopyMem ((UINT8 *)(SigDBCertData->SignatureData), X509Data, X509DataSize);
+
+ //
+ // Check if signature database entry has been already existed.
+ // If true, use EFI_VARIABLE_APPEND_WRITE attribute to append the
+ // new signature data to original variable
+ //
+ Attr = EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS;
+
+ Status = gRT->GetVariable (
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ NULL,
+ &DataSize,
+ NULL
+ );
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ Attr |= EFI_VARIABLE_APPEND_WRITE;
+ } else if (Status != EFI_NOT_FOUND) {
+ goto ON_EXIT;
+ }
+
+ Status = gRT->SetVariable (
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ Attr,
+ SigDBSize,
+ Data
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Cannot set signature database: %r\n", __func__, Status));
+ goto ON_EXIT;
+ }
+
+ON_EXIT:
+
+ if (Data != NULL) {
+ FreePool (Data);
+ }
+
+ return Status;
+}
+
+/**
+
+ Set signature database.
+
+ @param[in] Data Data.
+ @param[in] DataSize Data size.
+ @param[in] VariableName Variable name of signature database, must be
+ EFI_DB_DEFAULT_VARIABLE_NAME or EFI_DBX_DEFAULT_VARIABLE_NAME or EFI_DBT_DEFAULT_VARIABLE_NAME.
+ @param[in] SignatureOwnerGuid Guid of the signature owner.
+
+ @retval EFI_SUCCESS Signature is set successfully.
+ @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
+
+**/
+EFI_STATUS
+SetSignatureDatabase (
+ IN UINT8 *Data,
+ IN UINTN DataSize,
+ IN CHAR16 *VariableName,
+ IN EFI_GUID *SignatureOwnerGuid
+ )
+{
+ if (IsAuthentication2Format (Data, DataSize)) {
+ return SetAuthentication2ToSigDb (Data, DataSize, VariableName);
+ } else {
+ return SetX509ToSigDb (Data, DataSize, VariableName, SignatureOwnerGuid);
+ }
+}
+
+/** Initializes PKDefault variable with data from FFS section.
+
+ @retval EFI_SUCCESS Variable was initialized successfully.
+ @retval EFI_UNSUPPORTED Variable already exists.
+**/
+EFI_STATUS
+InitPkDefault (
+ IN VOID
+ )
+{
+ EFI_STATUS Status;
+ UINT8 *Data;
+ UINTN DataSize;
+
+ //
+ // Check if variable exists, if so do not change it
+ //
+ Status = GetVariable2 (EFI_PK_DEFAULT_VARIABLE_NAME, &gEfiGlobalVariableGuid, (VOID **)&Data, &DataSize);
+ if (Status == EFI_SUCCESS) {
+ DEBUG ((DEBUG_INFO, "Variable %s exists. Old value is preserved\n", EFI_PK_DEFAULT_VARIABLE_NAME));
+ FreePool (Data);
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Variable does not exist, can be initialized
+ //
+ DEBUG ((DEBUG_INFO, "Variable %s does not exist.\n", EFI_PK_DEFAULT_VARIABLE_NAME));
+
+ //
+ // Enroll default PK.
+ //
+ Status = GetSectionFromFv (
+ &gDefaultPKFileGuid,
+ EFI_SECTION_RAW,
+ 0,
+ (VOID **)&Data,
+ &DataSize
+ );
+ if (!EFI_ERROR (Status)) {
+ SetPkDefault (Data, DataSize);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/** Initializes KEKDefault variable with data from FFS section.
+
+ @retval EFI_SUCCESS Variable was initialized successfully.
+ @retval EFI_UNSUPPORTED Variable already exists.
+**/
+EFI_STATUS
+InitKekDefault (
+ IN VOID
+ )
+{
+ EFI_STATUS Status;
+ UINTN Index;
+ UINT8 *Data;
+ UINTN DataSize;
+
+ //
+ // Check if variable exists, if so do not change it
+ //
+ Status = GetVariable2 (EFI_KEK_DEFAULT_VARIABLE_NAME, &gEfiGlobalVariableGuid, (VOID **)&Data, &DataSize);
+ if (Status == EFI_SUCCESS) {
+ DEBUG ((DEBUG_INFO, "Variable %s exists. Old value is preserved\n", EFI_KEK_DEFAULT_VARIABLE_NAME));
+ FreePool (Data);
+ return EFI_UNSUPPORTED;
+ }
+
+ Index = 0;
+ do {
+ Status = GetSectionFromFv (
+ &gDefaultKEKFileGuid,
+ EFI_SECTION_RAW,
+ Index,
+ (VOID **)&Data,
+ &DataSize
+ );
+ if (!EFI_ERROR (Status)) {
+ SetKekDefault (Data, DataSize);
+ Index++;
+ }
+ } while (Status == EFI_SUCCESS);
+
+ return EFI_SUCCESS;
+}
+
+/** Initializes dbDefault variable with data from FFS section.
+
+ @retval EFI_SUCCESS Variable was initialized successfully.
+ @retval EFI_UNSUPPORTED Variable already exists.
+**/
+EFI_STATUS
+InitDbDefault (
+ IN VOID
+ )
+{
+ EFI_STATUS Status;
+ UINTN Index;
+ UINT8 *Data;
+ UINTN DataSize;
+
+ Status = GetVariable2 (EFI_DB_DEFAULT_VARIABLE_NAME, &gEfiGlobalVariableGuid, (VOID **)&Data, &DataSize);
+ if (Status == EFI_SUCCESS) {
+ DEBUG ((DEBUG_INFO, "Variable %s exists. Old value is preserved\n", EFI_DB_DEFAULT_VARIABLE_NAME));
+ FreePool (Data);
+ return EFI_UNSUPPORTED;
+ }
+
+ DEBUG ((DEBUG_INFO, "Variable %s does not exist.\n", EFI_DB_DEFAULT_VARIABLE_NAME));
+
+ Index = 0;
+ do {
+ Status = GetSectionFromFv (
+ &gDefaultdbFileGuid,
+ EFI_SECTION_RAW,
+ Index,
+ (VOID **)&Data,
+ &DataSize
+ );
+ if (!EFI_ERROR (Status)) {
+ SetSignatureDatabase (Data, DataSize, EFI_DB_DEFAULT_VARIABLE_NAME, &gEfiGlobalVariableGuid);
+ Index++;
+ }
+ } while (Status == EFI_SUCCESS);
+
+ return EFI_SUCCESS;
+}
+
+/** Initializes dbxDefault variable with data from FFS section.
+
+ @retval EFI_SUCCESS Variable was initialized successfully.
+ @retval EFI_UNSUPPORTED Variable already exists.
+**/
+EFI_STATUS
+InitDbxDefault (
+ IN VOID
+ )
+{
+ EFI_STATUS Status;
+ UINTN Index;
+ UINT8 *Data;
+ UINTN DataSize;
+
+ //
+ // Check if variable exists, if so do not change it
+ //
+ Status = GetVariable2 (EFI_DBX_DEFAULT_VARIABLE_NAME, &gEfiGlobalVariableGuid, (VOID **)&Data, &DataSize);
+ if (Status == EFI_SUCCESS) {
+ DEBUG ((DEBUG_INFO, "Variable %s exists. Old value is preserved\n", EFI_DBX_DEFAULT_VARIABLE_NAME));
+ FreePool (Data);
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Variable does not exist, can be initialized
+ //
+ DEBUG ((DEBUG_INFO, "Variable %s does not exist.\n", EFI_DBX_DEFAULT_VARIABLE_NAME));
+
+ Index = 0;
+ do {
+ Status = GetSectionFromFv (
+ &gDefaultdbxFileGuid,
+ EFI_SECTION_RAW,
+ Index,
+ (VOID **)&Data,
+ &DataSize
+ );
+ if (!EFI_ERROR (Status)) {
+ SetSignatureDatabase (Data, DataSize, EFI_DBX_DEFAULT_VARIABLE_NAME, &gEfiGlobalVariableGuid);
+ Index++;
+ }
+ } while (Status == EFI_SUCCESS);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Initializes default SecureBoot certificates with data from FFS section.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS Variable was initialized successfully.
+**/
+EFI_STATUS
+EFIAPI
+SecureBootDefaultKeysInitEntry (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = InitPkDefault ();
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Cannot initialize PKDefault: %r\n", __func__, Status));
+ return Status;
+ }
+
+ Status = InitKekDefault ();
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Cannot initialize KEKDefault: %r\n", __func__, Status));
+ return Status;
+ }
+
+ Status = InitDbDefault ();
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Cannot initialize dbDefault: %r\n", __func__, Status));
+ return Status;
+ }
+
+ Status = InitDbxDefault ();
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Cannot initialize dbxDefault: %r\n", __func__, Status));
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootDefaultKeysInit/SecureBootDefaultKeysInit.inf b/OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootDefaultKeysInit/SecureBootDefaultKeysInit.inf
new file mode 100644
index 0000000..0127841
--- /dev/null
+++ b/OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootDefaultKeysInit/SecureBootDefaultKeysInit.inf
@@ -0,0 +1,49 @@
+## @file
+# Initializes Secure Boot default keys
+#
+# Copyright (c) 2021, ARM Ltd. All rights reserved.<BR>
+# Copyright (c) 2021, Semihalf All rights reserved.<BR>
+# Copyright (C) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 1.29
+ BASE_NAME = SecureBootDefaultKeysInit
+ FILE_GUID = 384D1860-7306-11F0-B8B4-F53A5CB787AC
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = SecureBootDefaultKeysInitEntry
+
+[Sources]
+ SecureBootDefaultKeysInit.c
+
+[Packages]
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ SecurityPkg/SecurityPkg.dec
+
+[LibraryClasses]
+ DebugLib
+ DxeServicesLib
+ SecureBootVariableLib
+ SecureBootVariableProvisionLib
+ UefiBootServicesTableLib
+ UefiDriverEntryPoint
+
+[Guids]
+ gDefaultdbFileGuid
+ gDefaultdbxFileGuid
+ gDefaultKEKFileGuid
+ gDefaultPKFileGuid
+ gEfiCertPkcs7Guid
+ gEfiCertX509Guid
+ gEfiCustomModeEnableGuid
+ gEfiImageSecurityDatabaseGuid
+ gEfiSecureBootEnableDisableGuid
+
+[Depex]
+ gEfiVariableArchProtocolGuid AND
+ gEfiVariableWriteArchProtocolGuid
diff --git a/OvmfPkg/RiscVVirt/PlatformPei/PlatformPeim.c b/OvmfPkg/RiscVVirt/PlatformPei/PlatformPeim.c
index 54b5d33..3da71aa 100644
--- a/OvmfPkg/RiscVVirt/PlatformPei/PlatformPeim.c
+++ b/OvmfPkg/RiscVVirt/PlatformPei/PlatformPeim.c
@@ -1,6 +1,7 @@
/** @file
- Copyright (c) 2011, ARM Limited. All rights reserved.<BR>
+ Copyright (c) 2011-2014, ARM Limited. All rights reserved.<BR>
+ Copyright (c) 2014-2020, Linaro Limited. All rights reserved.<BR>
Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -45,6 +46,12 @@ CONST EFI_PEI_PPI_DESCRIPTOR mPpiListBootMode = {
NULL
};
+CONST EFI_PEI_PPI_DESCRIPTOR mTpm2DiscoveredPpi = {
+ (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+ &gOvmfTpmDiscoveredPpiGuid,
+ NULL
+};
+
/*
Install PEI memory.
@@ -89,6 +96,126 @@ FindInstallPeiMemory (
ASSERT_EFI_ERROR (PeiServicesInstallPeiMemory (PeiMemoryBase, PEI_MEMORY_SIZE));
}
+/**
+ Set up TPM resources from FDT.
+
+ @param FdtBase Fdt base address
+
+**/
+STATIC
+VOID
+SetupTPMResources (
+ VOID *FdtBase
+ )
+{
+ INT32 Node, Prev;
+ INT32 Parent, Depth;
+ CONST CHAR8 *Compatible;
+ CONST CHAR8 *CompItem;
+ INT32 Len;
+ INT32 RangesLen;
+ CONST UINT8 *RegProp;
+ CONST UINT32 *RangesProp;
+ UINT64 TpmBase;
+ UINT64 TpmBaseSize;
+
+ //
+ // Set Parent to suppress incorrect compiler/analyzer warnings.
+ //
+ Parent = 0;
+
+ for (Prev = Depth = 0; ; Prev = Node) {
+ Node = FdtNextNode (FdtBase, Prev, &Depth);
+ if (Node < 0) {
+ break;
+ }
+
+ if (Depth == 1) {
+ Parent = Node;
+ }
+
+ Compatible = FdtGetProp (FdtBase, Node, "compatible", &Len);
+
+ //
+ // Iterate over the NULL-separated items in the compatible string
+ //
+ for (CompItem = Compatible; CompItem != NULL && CompItem < Compatible + Len;
+ CompItem += 1 + AsciiStrLen (CompItem))
+ {
+ if (AsciiStrCmp (CompItem, "tcg,tpm-tis-mmio") == 0) {
+ RegProp = FdtGetProp (FdtBase, Node, "reg", &Len);
+ ASSERT (Len == 8 || Len == 16);
+ if (Len == 8) {
+ TpmBase = Fdt32ToCpu (*(UINT32 *)RegProp);
+ TpmBaseSize = Fdt32ToCpu (*(UINT32 *)((UINT8 *)RegProp + 4));
+ } else if (Len == 16) {
+ TpmBase = Fdt64ToCpu (ReadUnaligned64 ((UINT64 *)RegProp));
+ TpmBaseSize = Fdt64ToCpu (ReadUnaligned64 ((UINT64 *)((UINT8 *)RegProp + 8)));
+ }
+
+ if (Depth > 1) {
+ //
+ // QEMU/mach-virt may put the TPM on the platform bus, in which case
+ // we have to take its 'ranges' property into account to translate the
+ // MMIO address. This consists of a <child base, parent base, size>
+ // tuple, where the child base and the size use the same number of
+ // cells as the 'reg' property above, and the parent base uses 2 cells
+ //
+ RangesProp = FdtGetProp (FdtBase, Parent, "ranges", &RangesLen);
+ ASSERT (RangesProp != NULL);
+
+ //
+ // a plain 'ranges' attribute without a value implies a 1:1 mapping
+ //
+ if (RangesLen != 0) {
+ //
+ // assume a single translated range with 2 cells for the parent base
+ //
+ if (RangesLen != Len + 2 * sizeof (UINT32)) {
+ DEBUG ((
+ DEBUG_WARN,
+ "%a: 'ranges' property has unexpected size %d\n",
+ __func__,
+ RangesLen
+ ));
+ break;
+ }
+
+ if (Len == 8) {
+ TpmBase -= Fdt32ToCpu (RangesProp[0]);
+ } else {
+ TpmBase -= Fdt64ToCpu (ReadUnaligned64 ((UINT64 *)RangesProp));
+ }
+
+ //
+ // advance RangesProp to the parent bus address
+ //
+ RangesProp = (UINT32 *)((UINT8 *)RangesProp + Len / 2);
+ TpmBase += Fdt64ToCpu (ReadUnaligned64 ((UINT64 *)RangesProp));
+ }
+ }
+
+ break;
+ }
+ }
+ }
+
+ if (TpmBase) {
+ BuildResourceDescriptorHob (
+ EFI_RESOURCE_MEMORY_MAPPED_IO,
+ EFI_RESOURCE_ATTRIBUTE_PRESENT |
+ EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
+ EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
+ EFI_RESOURCE_ATTRIBUTE_TESTED,
+ TpmBase,
+ ALIGN_VALUE (TpmBaseSize, EFI_PAGE_SIZE)
+ );
+
+ ASSERT_EFI_ERROR ((EFI_STATUS)PcdSet64S (PcdTpmBaseAddress, TpmBase));
+ PeiServicesInstallPpi (&mTpm2DiscoveredPpi);
+ }
+}
+
/*
Entry point of this module.
@@ -125,6 +252,7 @@ InitializePlatformPeim (
MemoryInitialization (SecData->FdtPointer);
CpuInitialization (SecData->FdtPointer);
PlatformInitialization (SecData->FdtPointer);
+ SetupTPMResources (SecData->FdtPointer);
//
// Install PEI memory
diff --git a/OvmfPkg/RiscVVirt/PlatformPei/PlatformPeim.inf b/OvmfPkg/RiscVVirt/PlatformPei/PlatformPeim.inf
index 9be96dd..6ca005b 100644
--- a/OvmfPkg/RiscVVirt/PlatformPei/PlatformPeim.inf
+++ b/OvmfPkg/RiscVVirt/PlatformPei/PlatformPeim.inf
@@ -25,17 +25,24 @@
MdeModulePkg/MdeModulePkg.dec
UefiCpuPkg/UefiCpuPkg.dec
OvmfPkg/OvmfPkg.dec
+ SecurityPkg/SecurityPkg.dec
[LibraryClasses]
PeimEntryPoint
DebugLib
+ FdtLib
HobLib
+ PcdLib
PeiServicesLib
PlatformSecLib
+[Pcd]
+ gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress
+
[Ppis]
gEfiPeiMasterBootModePpiGuid # PPI ALWAYS_PRODUCED
gEfiSecHobDataPpiGuid # ALWAYS_CONSUMED
+ gOvmfTpmDiscoveredPpiGuid # SOMETIMES_PRODUCES
[Depex]
TRUE
diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc
index bc4935e..c23130a 100644
--- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc
+++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc
@@ -193,13 +193,14 @@
[PcdsFixedAtBuild.common]
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800
-!if $(NETWORK_TLS_ENABLE) == TRUE
+!if $(NETWORK_TLS_ENABLE) == TRUE || $(SECURE_BOOT_ENABLE) == TRUE
#
# The cumulative and individual VOLATILE variable size limits should be set
# high enough for accommodating several and/or large CA certificates.
#
gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x80000
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize|0x40000
+ gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x8400
!endif
gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"2.7"
@@ -290,6 +291,8 @@
[LibraryClasses.common.PEI_CORE, LibraryClasses.common.PEIM]
!if $(TPM2_ENABLE) == TRUE
PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
+ BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
+ Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
!else
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
!endif
@@ -317,6 +320,24 @@
<LibraryClasses>
NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
}
+!if $(TPM2_ENABLE) == TRUE
+ OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
+ SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf {
+ <LibraryClasses>
+ Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterPei.inf
+ NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
+ HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf
+ NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf
+ NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf
+ NULL|SecurityPkg/Library/HashInstanceLibSha384/HashInstanceLibSha384.inf
+ NULL|SecurityPkg/Library/HashInstanceLibSha512/HashInstanceLibSha512.inf
+ NULL|SecurityPkg/Library/HashInstanceLibSm3/HashInstanceLibSm3.inf
+ }
+ SecurityPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.inf {
+ <LibraryClasses>
+ TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLib/PeiDxeTpmPlatformHierarchyLib.inf
+ }
+!endif
!else
UefiCpuPkg/SecCore/SecCoreNative.inf {
<LibraryClasses>
@@ -370,7 +391,7 @@
!endif
}
SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
- OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.inf
+ OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootDefaultKeysInit/SecureBootDefaultKeysInit.inf
!else
MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
!endif
diff --git a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf
index 3470b18..1f37eb6 100644
--- a/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf
+++ b/OvmfPkg/RiscVVirt/RiscVVirtQemu.fdf
@@ -89,6 +89,24 @@ INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
!endif
!if $(SECURE_BOOT_ENABLE) == TRUE
INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
+ INF OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootDefaultKeysInit/SecureBootDefaultKeysInit.inf
+
+ FILE FREEFORM = 85254ea7-4759-4fc4-82d4-5eed5fb0a4a0 {
+ SECTION RAW = OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootKeys/PK/PK.cer
+ }
+
+ FILE FREEFORM = 6f64916e-9f7a-4c35-b952-cd041efb05a3 {
+ SECTION RAW = OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootKeys/KEK/MicCorKEKCA2011_2011-06-24.crt
+ }
+
+ FILE FREEFORM = c491d352-7623-4843-accc-2791a7574421 {
+ SECTION RAW = OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootKeys/db/MicWinProPCA2011_2011-10-19.crt
+ SECTION RAW = OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootKeys/db/MicCorUEFCA2011_2011-06-27.crt
+ }
+
+ FILE FREEFORM = 5740766a-718e-4dc0-9935-c36f7d3f884f {
+ SECTION RAW = OvmfPkg/RiscVVirt/Feature/SecureBoot/SecureBootKeys/dbx/dbxupdate_x64.bin
+ }
!endif
INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
INF MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf
@@ -212,6 +230,16 @@ INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
#
+# TPM2 support
+#
+!if $(TPM2_ENABLE) == TRUE
+ INF SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf
+!if $(TPM2_CONFIG_ENABLE) == TRUE
+ INF SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDxe.inf
+!endif
+!endif
+
+#
# TianoCore logo (splash screen)
#
INF MdeModulePkg/Logo/LogoDxe.inf
diff --git a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf b/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
index 51078c9..0355df9 100644
--- a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
+++ b/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
@@ -52,3 +52,6 @@
[Depex.ARM, Depex.AARCH64]
gOvmfTpmDiscoveredPpiGuid
+
+[Depex.RISCV64]
+ gOvmfTpmDiscoveredPpiGuid
diff --git a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c
index f759df9..c6a9804 100644
--- a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c
+++ b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c
@@ -542,8 +542,19 @@ OneOfStatementToAttributeValues (
}
if (Option->Text != 0) {
- Values->ValueArray[Index].ValueName = HiiGetRedfishAsciiString (HiiHandle, SchemaName, Option->Text);
Values->ValueArray[Index].ValueDisplayName = HiiGetEnglishAsciiString (HiiHandle, Option->Text);
+ Values->ValueArray[Index].ValueName = HiiGetRedfishAsciiString (HiiHandle, SchemaName, Option->Text);
+ if (Values->ValueArray[Index].ValueName == NULL) {
+ DEBUG ((DEBUG_MANAGEABILITY, "%a: Redfish x-UEFI string is not found.\n", __func__));
+ //
+ // No x-UEFI-redfish string defined. Try to get string in English.
+ //
+ Values->ValueArray[Index].ValueName =
+ AllocateCopyPool (AsciiStrSize (Values->ValueArray[Index].ValueDisplayName), (VOID *)Values->ValueArray[Index].ValueDisplayName);
+ if (Values->ValueArray[Index].ValueName == NULL) {
+ DEBUG ((DEBUG_MANAGEABILITY, "%a: Both Redfish and English string are not found.\n", __func__));
+ }
+ }
}
Index += 1;
@@ -1309,8 +1320,16 @@ HiiValueToRedfishValue (
RedfishValue->Value.Buffer = HiiGetRedfishAsciiString (HiiHandle, FullSchema, StringId);
if (RedfishValue->Value.Buffer == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
- break;
+ DEBUG ((DEBUG_MANAGEABILITY, "%a: Redfish x-UEFI string is not found.\n", __func__));
+ //
+ // No x-UEFI-redfish string defined. Try to get string in English.
+ //
+ RedfishValue->Value.Buffer = HiiGetEnglishAsciiString (HiiHandle, StringId);
+ if (RedfishValue->Value.Buffer == NULL) {
+ DEBUG ((DEBUG_MANAGEABILITY, "%a: Both Redfish and English string are not found.\n", __func__));
+ Status = EFI_OUT_OF_RESOURCES;
+ break;
+ }
}
RedfishValue->Type = RedfishValueTypeString;
@@ -1399,6 +1418,18 @@ HiiValueToRedfishValue (
}
RedfishValue->Value.StringArray[Index] = HiiGetRedfishAsciiString (HiiHandle, FullSchema, StringIdArray[Index]);
+ if (RedfishValue->Value.StringArray[Index] == NULL) {
+ DEBUG ((DEBUG_MANAGEABILITY, "%a: Redfish x-UEFI string is not found.\n", __func__));
+ //
+ // No x-UEFI-redfish string defined. Try to get string in English.
+ //
+ RedfishValue->Value.StringArray[Index] = HiiGetEnglishAsciiString (HiiHandle, StringIdArray[Index]);
+ if (RedfishValue->Value.StringArray[Index] == NULL) {
+ DEBUG ((DEBUG_MANAGEABILITY, "%a: Both Redfish and English string are not found.\n", __func__));
+ Status = EFI_OUT_OF_RESOURCES;
+ }
+ }
+
ASSERT (RedfishValue->Value.StringArray[Index] != NULL);
}
@@ -1418,6 +1449,7 @@ HiiValueToRedfishValue (
RedfishValue->Value.Buffer = HiiGetRedfishAsciiString (HiiHandle, FullSchema, HiiStatement->ExtraData.TextTwo);
if (RedfishValue->Value.Buffer == NULL) {
+ DEBUG ((DEBUG_MANAGEABILITY, "%a: Redfish x-UEFI string is not found.\n", __func__));
//
// No x-UEFI-redfish string defined. Try to get string in English.
//
@@ -1666,7 +1698,7 @@ RedfishPlatformConfigProtocolGetValue (
goto RELEASE_RESOURCE;
}
- if (TargetStatement->Suppressed) {
+ if (TargetStatement->Suppressed && !RedfishPlatformConfigFeatureProp (REDFISH_PLATFORM_CONFIG_ALLOW_SUPPRESSED)) {
Status = EFI_ACCESS_DENIED;
goto RELEASE_RESOURCE;
}
@@ -2289,7 +2321,7 @@ RedfishPlatformConfigProtocolGetDefaultValue (
goto RELEASE_RESOURCE;
}
- if (TargetStatement->Suppressed) {
+ if (TargetStatement->Suppressed && !RedfishPlatformConfigFeatureProp (REDFISH_PLATFORM_CONFIG_ALLOW_SUPPRESSED)) {
Status = EFI_ACCESS_DENIED;
goto RELEASE_RESOURCE;
}
diff --git a/SecurityPkg/FvReportPei/FvReportPei.c b/SecurityPkg/FvReportPei/FvReportPei.c
index 4376f52..6c92e73 100644
--- a/SecurityPkg/FvReportPei/FvReportPei.c
+++ b/SecurityPkg/FvReportPei/FvReportPei.c
@@ -71,10 +71,7 @@ InstallPreHashFvPpi (
+ HashSize;
PreHashedFvPpi = AllocatePool (PpiSize);
- if (PreHashedFvPpi == NULL) {
- ASSERT (PreHashedFvPpi != NULL);
- return;
- }
+ ASSERT (PreHashedFvPpi != NULL);
PreHashedFvPpi->FvBase = (UINT32)(UINTN)FvBuffer;
PreHashedFvPpi->FvLength = (UINT32)FvLength;
@@ -86,11 +83,7 @@ InstallPreHashFvPpi (
CopyMem (HASH_VALUE_PTR (HashInfo), HashValue, HashSize);
FvInfoPpiDescriptor = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
- if (FvInfoPpiDescriptor == NULL) {
- ASSERT (FvInfoPpiDescriptor != NULL);
- FreePool (PreHashedFvPpi);
- return;
- }
+ ASSERT (FvInfoPpiDescriptor != NULL);
FvInfoPpiDescriptor->Guid = &gEdkiiPeiFirmwareVolumeInfoPrehashedFvPpiGuid;
FvInfoPpiDescriptor->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
@@ -209,11 +202,8 @@ VerifyHashedFv (
// Copy FV to permanent memory to avoid potential TOC/TOU.
//
FvBuffer = AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)FvInfo[FvIndex].Length));
- if (FvBuffer == NULL) {
- ASSERT (FvBuffer != NULL);
- Status = EFI_OUT_OF_RESOURCES;
- goto Done;
- }
+
+ ASSERT (FvBuffer != NULL);
if (FvShadowPpi != NULL) {
Status = FvShadowPpi->FirmwareVolumeShadow (
@@ -353,17 +343,38 @@ GetHashInfo (
}
/**
- Verify and report pre-hashed FVs.
+ Verifies and reports pre-hashed Firmware Volumes (FVs).
- Doing this must be at post-memory to make sure there's enough memory to hold
- all FVs to be verified. This is necessary for mitigating TOCTOU issue.
+ This function should be called after memory initialization (post-memory phase)
+ to ensure sufficient memory is available to hold all FVs for verification.
- This function will never return if the verification is failed.
+ Verifying FVs at this stage is critical to mitigate Time-of-Check to Time-of-Use (TOCTOU) vulnerabilities.
+
+ FV Verification Step:
+
+ This function relies upon an instance of gEdkiiPeiFirmwareVolumeInfoStoredHashFvPpiGuid being installed. If
+ an instance of the PPI is not found, EFI_NOT_FOUND is returned.
+
+ If the gEdkiiPeiFirmwareVolumeInfoStoredHashFvPpiGuid PPI instance does not have valid hash information for the
+ current boot mode (hash info is NULL), verification is treated as successful.
+
+ FV Reporting Step:
+
+ If FV verification is successful, the function reports the FVs to PEI and/or DXE core for further processing by:
+
+ 1. Installing a FV HOB.
+ 2. Installing a FV Info PPI.
+ 3. Reporting a status code with the value from PcdStatusCodeFvVerificationPass to indicate that FV verification
+ passed.
+
+ If FV verification fails, the function reports a status code with the value from PcdStatusCodeFvVerificationFail
+ and returns a failure status code.
@param[in] PeiServices General purpose services available to every PEIM.
@param[in] BootMode Current boot mode.
@retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_NOT_FOUND No valid gEdkiiPeiFirmwareVolumeInfoStoredHashFvPpiGuid PPI instance found.
**/
STATIC
EFI_STATUS
@@ -389,17 +400,12 @@ CheckStoredHashFv (
);
if (!EFI_ERROR (Status) && (StoredHashFvPpi != NULL) && (StoredHashFvPpi->FvNumber > 0)) {
HashInfo = GetHashInfo (StoredHashFvPpi, BootMode);
- if (HashInfo != NULL) {
- Status = VerifyHashedFv (
+ Status = VerifyHashedFv (
HashInfo,
StoredHashFvPpi->FvInfo,
StoredHashFvPpi->FvNumber,
BootMode
);
- } else {
- Status = EFI_NOT_FOUND;
- }
-
if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OBB verification passed (%r)\r\n", Status));
diff --git a/SecurityPkg/HddPassword/HddPasswordDxe.c b/SecurityPkg/HddPassword/HddPasswordDxe.c
index 228a9f4..6f36b5a 100644
--- a/SecurityPkg/HddPassword/HddPasswordDxe.c
+++ b/SecurityPkg/HddPassword/HddPasswordDxe.c
@@ -149,10 +149,7 @@ BuildHddPasswordDeviceInfo (
S3InitDevicesExist = FALSE;
} else if (Status == EFI_BUFFER_TOO_SMALL) {
S3InitDevices = AllocatePool (S3InitDevicesLength);
- if (S3InitDevices == NULL) {
- ASSERT (S3InitDevices != NULL);
- return;
- }
+ ASSERT (S3InitDevices != NULL);
Status = RestoreLockBox (
&gS3StorageDeviceInitListGuid,
@@ -187,10 +184,7 @@ BuildHddPasswordDeviceInfo (
FreePool (S3InitDevicesBak);
}
- if (S3InitDevices == NULL) {
- ASSERT (S3InitDevices != NULL);
- return;
- }
+ ASSERT (S3InitDevices != NULL);
TempDevInfo = (HDD_PASSWORD_DEVICE_INFO *)((UINTN)TempDevInfo +
sizeof (HDD_PASSWORD_DEVICE_INFO) +
@@ -2201,14 +2195,8 @@ HddPasswordFormExtractConfig (
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
//
ConfigRequestHdr = HiiConstructConfigHdr (&mHddPasswordVendorGuid, mHddPasswordVendorStorageName, Private->DriverHandle);
- if (ConfigRequestHdr == NULL) {
- ASSERT (ConfigRequestHdr != NULL);
- FreePool (IfrData);
- return EFI_OUT_OF_RESOURCES;
- }
-
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
ASSERT (ConfigRequest != NULL);
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
@@ -2398,11 +2386,7 @@ HddPasswordFormCallback (
// In case goto the device configuration form, update the device form title.
//
ConfigFormEntry = HddPasswordGetConfigFormEntryByIndex ((UINT32)(QuestionId - KEY_HDD_DEVICE_ENTRY_BASE));
- if (ConfigFormEntry == NULL) {
- ASSERT (ConfigFormEntry != NULL);
- FreePool (IfrData);
- return EFI_NOT_FOUND;
- }
+ ASSERT (ConfigFormEntry != NULL);
DeviceFormTitleToken = (EFI_STRING_ID)STR_HDD_SECURITY_HD;
HiiSetString (Private->HiiHandle, DeviceFormTitleToken, ConfigFormEntry->HddString, NULL);
diff --git a/SecurityPkg/Library/AuthVariableLib/AuthService.c b/SecurityPkg/Library/AuthVariableLib/AuthService.c
index 2d79cc1..706cb67 100644
--- a/SecurityPkg/Library/AuthVariableLib/AuthService.c
+++ b/SecurityPkg/Library/AuthVariableLib/AuthService.c
@@ -553,7 +553,7 @@ CheckSignatureListFormat (
// Walk through the input signature list and check the data format.
// If any signature is incorrectly formed, the whole check will fail.
//
- while ((SigDataSize > 0) && (SigDataSize >= (UINTN)SigList->SignatureListSize)) {
+ while ((SigDataSize > 0) && (SigDataSize >= SigList->SignatureListSize)) {
for (Index = 0; Index < (sizeof (mSupportSigItem) / sizeof (EFI_SIGNATURE_ITEM)); Index++ ) {
if (CompareGuid (&SigList->SignatureType, &mSupportSigItem[Index].SigType)) {
//
@@ -1088,7 +1088,7 @@ FilterSignatureList (
Tail = TempData;
NewCertList = (EFI_SIGNATURE_LIST *)NewData;
- while ((*NewDataSize > 0) && (*NewDataSize >= (UINTN)NewCertList->SignatureListSize)) {
+ while ((*NewDataSize > 0) && (*NewDataSize >= NewCertList->SignatureListSize)) {
NewCert = (EFI_SIGNATURE_DATA *)((UINT8 *)NewCertList + sizeof (EFI_SIGNATURE_LIST) + NewCertList->SignatureHeaderSize);
NewCertCount = (NewCertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - NewCertList->SignatureHeaderSize) / NewCertList->SignatureSize;
@@ -1098,7 +1098,7 @@ FilterSignatureList (
Size = DataSize;
CertList = (EFI_SIGNATURE_LIST *)Data;
- while ((Size > 0) && (Size >= (UINTN)CertList->SignatureListSize)) {
+ while ((Size > 0) && (Size >= CertList->SignatureListSize)) {
if (CompareGuid (&CertList->SignatureType, &NewCertList->SignatureType) &&
(CertList->SignatureSize == NewCertList->SignatureSize))
{
diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
index 5ac6dda..46d39cd 100644
--- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
+++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
@@ -883,7 +883,7 @@ IsCertHashFoundInDbx (
return Status;
}
- while ((DbxSize > 0) && (SignatureListSize >= (UINTN)DbxList->SignatureListSize)) {
+ while ((DbxSize > 0) && (SignatureListSize >= DbxList->SignatureListSize)) {
//
// Determine Hash Algorithm of Certificate in the forbidden database.
//
@@ -1028,7 +1028,7 @@ IsSignatureFoundInDatabase (
// Enumerate all signature data in SigDB to check if signature exists for executable.
//
CertList = (EFI_SIGNATURE_LIST *)Data;
- while ((DataSize > 0) && (DataSize >= (UINTN)CertList->SignatureListSize)) {
+ while ((DataSize > 0) && (DataSize >= CertList->SignatureListSize)) {
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
if ((CertList->SignatureSize == sizeof (EFI_SIGNATURE_DATA) - 1 + SignatureSize) && (CompareGuid (&CertList->SignatureType, CertType))) {
@@ -1193,7 +1193,7 @@ PassTimestampCheck (
}
CertList = (EFI_SIGNATURE_LIST *)DbtData;
- while ((DbtDataSize > 0) && (DbtDataSize >= (UINTN)CertList->SignatureListSize)) {
+ while ((DbtDataSize > 0) && (DbtDataSize >= CertList->SignatureListSize)) {
if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) {
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
@@ -1319,7 +1319,7 @@ IsForbiddenByDbx (
//
CertList = (EFI_SIGNATURE_LIST *)Data;
CertListSize = DataSize;
- while ((CertListSize > 0) && (CertListSize >= (UINTN)CertList->SignatureListSize)) {
+ while ((CertListSize > 0) && (CertListSize >= CertList->SignatureListSize)) {
if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) {
CertData = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
@@ -1524,7 +1524,7 @@ IsAllowedByDb (
// Find X509 certificate in Signature List to verify the signature in pkcs7 signed data.
//
CertList = (EFI_SIGNATURE_LIST *)Data;
- while ((DataSize > 0) && (DataSize >= (UINTN)CertList->SignatureListSize)) {
+ while ((DataSize > 0) && (DataSize >= CertList->SignatureListSize)) {
if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) {
CertData = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
@@ -2057,9 +2057,8 @@ Failed:
// executable information table in either case.
//
NameStr = ConvertDevicePathToText (File, FALSE, TRUE);
-
+ AddImageExeInfo (Action, NameStr, File, SignatureList, SignatureListSize);
if (NameStr != NULL) {
- AddImageExeInfo (Action, NameStr, File, SignatureList, SignatureListSize);
DEBUG ((DEBUG_INFO, "The image doesn't pass verification: %s\n", NameStr));
FreePool (NameStr);
}
diff --git a/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c b/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c
index f81519d..de4f5e5 100644
--- a/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c
+++ b/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c
@@ -387,10 +387,7 @@ Tcg2UserConfirm (
NoPpiInfo = FALSE;
BufSize = CONFIRM_BUFFER_SIZE;
ConfirmText = AllocateZeroPool (BufSize);
- if (ConfirmText == NULL) {
- ASSERT (ConfirmText != NULL);
- return FALSE;
- }
+ ASSERT (ConfirmText != NULL);
mTcg2PpStringPackHandle = HiiAddPackages (&gEfiTcg2PhysicalPresenceGuid, gImageHandle, DxeTcg2PhysicalPresenceLibStrings, NULL);
ASSERT (mTcg2PpStringPackHandle != NULL);
@@ -404,20 +401,10 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
- if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR));
- if (TmpStr1 == NULL) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
@@ -430,29 +417,14 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEAD_STR));
- if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_CLEAR));
- if (TmpStr1 == NULL) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR));
- if (TmpStr1 == NULL) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
@@ -480,29 +452,14 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_SET_PCR_BANKS));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
- if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_SET_PCR_BANKS_1));
- if (TmpStr1 == NULL) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_SET_PCR_BANKS_2));
- if (TmpStr1 == NULL) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
@@ -510,11 +467,7 @@ Tcg2UserConfirm (
Tcg2FillBufferWithBootHashAlg (TempBuffer2, sizeof (TempBuffer2), CurrentPCRBanks);
TmpStr1 = AllocateZeroPool (BufSize);
- if (TmpStr1 == NULL) {
- ASSERT (TmpStr1 != NULL);
- return FALSE;
- }
-
+ ASSERT (TmpStr1 != NULL);
UnicodeSPrint (TmpStr1, BufSize, L"Current PCRBanks is 0x%x. (%s)\nNew PCRBanks is 0x%x. (%s)\n", CurrentPCRBanks, TempBuffer2, TpmPpCommandParameter, TempBuffer);
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
@@ -528,29 +481,14 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CHANGE_EPS));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
- if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CHANGE_EPS_1));
- if (TmpStr1 == NULL) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CHANGE_EPS_2));
- if (TmpStr1 == NULL) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
@@ -560,11 +498,6 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_ENABLE_BLOCK_SID));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_HEAD_STR));
- if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
break;
@@ -573,11 +506,6 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_DISABLE_BLOCK_SID));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_HEAD_STR));
- if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
break;
@@ -587,11 +515,6 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PP_ENABLE_BLOCK_SID));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PPI_HEAD_STR));
- if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
break;
@@ -601,11 +524,6 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PP_DISABLE_BLOCK_SID));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PPI_HEAD_STR));
- if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
break;
@@ -626,21 +544,11 @@ Tcg2UserConfirm (
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
}
- if (TmpStr1 == NULL) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
if (NoPpiInfo) {
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_INFO));
- if (TmpStr1 == NULL) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
}
@@ -653,21 +561,11 @@ Tcg2UserConfirm (
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_ACCEPT_KEY));
}
- if (TmpStr1 == NULL) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
if (NoPpiInfo) {
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_NO_PPI_INFO));
- if (TmpStr1 == NULL) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
}
@@ -675,11 +573,6 @@ Tcg2UserConfirm (
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_REJECT_KEY));
}
- if (TmpStr1 == NULL) {
- FreePool (ConfirmText);
- return FALSE;
- }
-
BufSize -= StrSize (ConfirmText);
UnicodeSPrint (ConfirmText + StrLen (ConfirmText), BufSize, TmpStr1, TmpStr2);
diff --git a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
index d38a607..597ce77 100644
--- a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
+++ b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
@@ -540,7 +540,7 @@ UserConfirm (
CHAR16 *TmpStr2;
UINTN BufSize;
BOOLEAN CautionKey;
- UINTN Index;
+ UINT16 Index;
CHAR16 DstStr[81];
TmpStr2 = NULL;
diff --git a/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c b/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c
index b8eb5d6..acba11d 100644
--- a/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c
+++ b/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c
@@ -615,9 +615,6 @@ GetMeasureBootProtocols (
@retval EFI_SUCCESS The file specified by DevicePath and non-NULL
FileBuffer did authenticate, and the platform policy dictates
that the DXE Foundation may use the file.
-
- @retval EFI_OUT_OF_RESOURCES A necessary memory buffer could not be allocated.
-
@retval other error value
**/
EFI_STATUS
@@ -711,16 +708,9 @@ DxeTpm2MeasureBootHandler (
}
}
- if (OrigDevicePathNode != NULL) {
- FreePool (OrigDevicePathNode);
- }
-
+ FreePool (OrigDevicePathNode);
OrigDevicePathNode = DuplicateDevicePath (File);
- if (OrigDevicePathNode == NULL) {
- ASSERT (OrigDevicePathNode != NULL);
- return EFI_OUT_OF_RESOURCES;
- }
-
+ ASSERT (OrigDevicePathNode != NULL);
break;
}
}
diff --git a/SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c b/SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c
index 7b00833..c786c21 100644
--- a/SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c
+++ b/SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c
@@ -56,10 +56,7 @@ Sha1HashInit (
CtxSize = Sha1GetContextSize ();
Sha1Ctx = AllocatePool (CtxSize);
- if (Sha1Ctx == NULL) {
- ASSERT (Sha1Ctx != NULL);
- return EFI_OUT_OF_RESOURCES;
- }
+ ASSERT (Sha1Ctx != NULL);
Sha1Init (Sha1Ctx);
diff --git a/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c b/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c
index 4fdc5a8..4387740 100644
--- a/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c
+++ b/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c
@@ -56,10 +56,7 @@ Sha256HashInit (
CtxSize = Sha256GetContextSize ();
Sha256Ctx = AllocatePool (CtxSize);
- if (Sha256Ctx == NULL) {
- ASSERT (Sha256Ctx != NULL);
- return EFI_OUT_OF_RESOURCES;
- }
+ ASSERT (Sha256Ctx != NULL);
Sha256Init (Sha256Ctx);
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c
index 5e0bbe5..2169c5e 100644
--- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c
+++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c
@@ -80,11 +80,6 @@ HashStart (
for (Index = 0; Index < mHashInterfaceCount; Index++) {
HashMask = Tpm2GetHashMaskFromAlgo (&mHashInterface[Index].HashGuid);
- if (HashCtx == NULL) {
- // If we fail to get the hash mask we don't have resources.
- return EFI_OUT_OF_RESOURCES;
- }
-
if ((HashMask & PcdGet32 (PcdTpm2HashMask)) != 0) {
mHashInterface[Index].HashInit (&HashCtx[Index]);
}
@@ -283,16 +278,8 @@ HashAndExtend (
CheckSupportedHashMaskMismatch ();
- Status = HashStart (&HashHandle);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- Status = HashUpdate (HashHandle, DataToHash, DataToHashLen);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
+ HashStart (&HashHandle);
+ HashUpdate (HashHandle, DataToHash, DataToHashLen);
Status = HashCompleteAndExtend (HashHandle, PcrIndex, NULL, 0, DigestList);
return Status;
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c
index 156dc04..eeb424b 100644
--- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c
+++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c
@@ -106,10 +106,7 @@ CheckSupportedHashMaskMismatch (
HASH_INTERFACE_HOB *HashInterfaceHobLast;
HashInterfaceHobLast = InternalGetHashInterfaceHob (&gZeroGuid);
- if (HashInterfaceHobLast == NULL) {
- ASSERT (HashInterfaceHobLast != NULL);
- return;
- }
+ ASSERT (HashInterfaceHobLast != NULL);
if ((HashInterfaceHobLast->SupportedHashMask != 0) &&
(HashInterfaceHobCurrent->SupportedHashMask != HashInterfaceHobLast->SupportedHashMask))
@@ -155,10 +152,7 @@ HashStart (
CheckSupportedHashMaskMismatch (HashInterfaceHob);
HashCtx = AllocatePool (sizeof (*HashCtx) * HashInterfaceHob->HashInterfaceCount);
- if (HashCtx == NULL) {
- ASSERT (HashCtx != NULL);
- return EFI_OUT_OF_RESOURCES;
- }
+ ASSERT (HashCtx != NULL);
for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {
HashMask = Tpm2GetHashMaskFromAlgo (&HashInterfaceHob->HashInterface[Index].HashGuid);
@@ -311,16 +305,8 @@ HashAndExtend (
CheckSupportedHashMaskMismatch (HashInterfaceHob);
- Status = HashStart (&HashHandle);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- Status = HashUpdate (HashHandle, DataToHash, DataToHashLen);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
+ HashStart (&HashHandle);
+ HashUpdate (HashHandle, DataToHash, DataToHashLen);
Status = HashCompleteAndExtend (HashHandle, PcrIndex, NULL, 0, DigestList);
return Status;
diff --git a/SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c b/SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c
index e45e975..7f9fdd2 100644
--- a/SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c
+++ b/SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c
@@ -59,11 +59,7 @@ SecureBootFetchData (
*SigListOut = NULL;
*SigListsSize = 0;
CertInfo = AllocatePool (sizeof (SECURE_BOOT_CERTIFICATE_INFO));
- if (CertInfo == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- NewCertInfo = CertInfo;
+ NewCertInfo = CertInfo;
while (1) {
if (NewCertInfo == NULL) {
Status = EFI_OUT_OF_RESOURCES;
@@ -97,9 +93,6 @@ SecureBootFetchData (
sizeof (SECURE_BOOT_CERTIFICATE_INFO) * (KeyIndex + 1),
CertInfo
);
- if (NewCertInfo == NULL) {
- goto Cleanup;
- }
}
if (Status == EFI_NOT_FOUND) {
diff --git a/SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c b/SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c
index cbe1da3..e1e0f99 100644
--- a/SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c
+++ b/SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c
@@ -106,7 +106,7 @@ MeasureFirmwareBlob (
{
if (Description != NULL) {
AsciiSPrint ((CHAR8 *)FvBlob2.BlobDescription, sizeof (FvBlob2.BlobDescription), "%a", Description);
- } else if (FvName != NULL) {
+ } else {
AsciiSPrint ((CHAR8 *)FvBlob2.BlobDescription, sizeof (FvBlob2.BlobDescription), "Fv(%g)", FvName);
}
diff --git a/SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c b/SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c
index 5eb1a0b..64bea73 100644
--- a/SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c
+++ b/SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c
@@ -270,7 +270,7 @@ Tpm12TisTpmCommand (
{
EFI_STATUS Status;
UINT16 BurstCount;
- UINTN Index;
+ UINT32 Index;
UINT32 TpmOutSize;
UINT16 Data16;
UINT32 Data32;
diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c
index f11f769..7ca8927 100644
--- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c
+++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c
@@ -229,6 +229,7 @@ Tpm2NvReadPublic (
case TPM_RC_SUCCESS:
// return data
break;
+ case TPM_RC_HANDLE:
case TPM_RC_HANDLE + RC_NV_ReadPublic_nvIndex: // TPM_RC_NV_DEFINED:
return EFI_NOT_FOUND;
case TPM_RC_VALUE + RC_NV_ReadPublic_nvIndex:
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c
index 1b2cddf..3ac20e8 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c
@@ -230,8 +230,6 @@ AesEncrypt (
UINTN NbIndex;
UINTN Round;
- EFI_STATUS Status;
-
if ((Key == NULL) || (InData == NULL) || (OutData == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -239,10 +237,7 @@ AesEncrypt (
//
// Expands AES Key for encryption.
//
- Status = AesExpandKey (Key, 128, &AesKey);
- if (EFI_ERROR (Status)) {
- return Status;
- }
+ AesExpandKey (Key, 128, &AesKey);
Nr = AesKey.Nk + 6;
Ek = AesKey.EncKey;
diff --git a/SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c b/SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c
index 068c3c7..7b48002 100644
--- a/SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c
+++ b/SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c
@@ -2224,7 +2224,7 @@ ProcessOpalRequest (
//
TempVariable = Variable;
while ((VariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&
- (VariableSize >= (UINTN)TempVariable->Length) &&
+ (VariableSize >= TempVariable->Length) &&
(TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE)))
{
DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
@@ -2329,7 +2329,7 @@ RemoveDevice (
}
if (mOpalDriver.DeviceList == Dev) {
- mOpalDriver.DeviceList = NULL;
+ mOpalDriver.DeviceList = Dev->Next;
return;
}
@@ -2339,6 +2339,8 @@ RemoveDevice (
TmpDev->Next = Dev->Next;
break;
}
+
+ TmpDev = TmpDev->Next;
}
}
diff --git a/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c b/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c
index c5f1121..1e0b00b 100644
--- a/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c
+++ b/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c
@@ -113,7 +113,7 @@ GetSavedOpalRequest (
TempVariable = Variable;
while ((VariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&
- (VariableSize >= (UINTN)TempVariable->Length) &&
+ (VariableSize >= TempVariable->Length) &&
(TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE)))
{
DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
@@ -193,7 +193,7 @@ SaveOpalRequest (
TempVariable = Variable;
TempVariableSize = VariableSize;
while ((TempVariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&
- (TempVariableSize >= (UINTN)TempVariable->Length) &&
+ (TempVariableSize >= TempVariable->Length) &&
(TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE)))
{
DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
@@ -226,11 +226,7 @@ SaveOpalRequest (
DevicePathSize = GetDevicePathSize (DevicePath);
NewVariableSize = VariableSize + sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize;
NewVariable = AllocatePool (NewVariableSize);
- if (NewVariable == NULL) {
- ASSERT (NewVariable != NULL);
- return;
- }
-
+ ASSERT (NewVariable != NULL);
CopyMem (NewVariable, Variable, VariableSize);
TempVariable = (OPAL_REQUEST_VARIABLE *)((UINTN)NewVariable + VariableSize);
TempVariable->Length = (UINT32)(sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize);
@@ -243,11 +239,7 @@ SaveOpalRequest (
DevicePathSize = GetDevicePathSize (DevicePath);
NewVariableSize = sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize;
NewVariable = AllocatePool (NewVariableSize);
- if (NewVariable == NULL) {
- ASSERT (NewVariable != NULL);
- return;
- }
-
+ ASSERT (NewVariable != NULL);
NewVariable->Length = (UINT32)(sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize);
CopyMem (&NewVariable->OpalRequest, &OpalRequest, sizeof (OPAL_REQUEST));
DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)NewVariable + sizeof (OPAL_REQUEST_VARIABLE));
@@ -1119,13 +1111,8 @@ ExtractConfig (
//
DriverHandle = HiiGetDriverImageHandleCB ();
ConfigRequestHdr = HiiConstructConfigHdr (&gHiiSetupVariableGuid, OpalPasswordStorageName, DriverHandle);
- if (ConfigRequestHdr == NULL) {
- ASSERT (ConfigRequestHdr != NULL);
- return EFI_OUT_OF_RESOURCES;
- }
-
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
if (ConfigRequest == NULL) {
return EFI_OUT_OF_RESOURCES;
}
diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c
index 2b93733..edf5f0f 100644
--- a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c
+++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c
@@ -103,11 +103,7 @@ InitializeTcg2VersionInfo (
TCG2_VERSION_NAME,
PrivateData->DriverHandle
);
- if (ConfigRequestHdr == NULL) {
- ASSERT (ConfigRequestHdr != NULL);
- return;
- }
-
+ ASSERT (ConfigRequestHdr != NULL);
DataSize = sizeof (Tcg2Version);
Status = gRT->GetVariable (
TCG2_VERSION_NAME,
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
index 2a0307c..85a8528 100644
--- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
+++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
@@ -626,7 +626,7 @@ DumpEventLog (
TCG_PCR_EVENT_HDR *EventHdr;
TCG_PCR_EVENT2 *TcgPcrEvent2;
TCG_EfiSpecIDEventStruct *TcgEfiSpecIdEventStruct;
- UINT64 NumberOfEvents;
+ UINTN NumberOfEvents;
if (!DebugPrintLevelEnabled (DEBUG_SECURITY)) {
return;
@@ -637,7 +637,7 @@ DumpEventLog (
switch (EventLogFormat) {
case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2:
EventHdr = (TCG_PCR_EVENT_HDR *)(UINTN)EventLogLocation;
- while ((EFI_PHYSICAL_ADDRESS)(UINTN)EventHdr <= EventLogLastEntry) {
+ while ((UINTN)EventHdr <= EventLogLastEntry) {
DumpEvent (EventHdr);
EventHdr = (TCG_PCR_EVENT_HDR *)((UINTN)EventHdr + sizeof (TCG_PCR_EVENT_HDR) + EventHdr->EventSize);
}
@@ -668,7 +668,7 @@ DumpEventLog (
DumpTcgEfiSpecIdEventStruct (TcgEfiSpecIdEventStruct);
TcgPcrEvent2 = (TCG_PCR_EVENT2 *)((UINTN)TcgEfiSpecIdEventStruct + GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct));
- while ((EFI_PHYSICAL_ADDRESS)(UINTN)TcgPcrEvent2 <= EventLogLastEntry) {
+ while ((UINTN)TcgPcrEvent2 <= EventLogLastEntry) {
DumpEvent2 (TcgPcrEvent2);
TcgPcrEvent2 = (TCG_PCR_EVENT2 *)((UINTN)TcgPcrEvent2 + GetPcrEvent2Size (TcgPcrEvent2));
}
diff --git a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
index 2b4164c..52ea1ac 100644
--- a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
+++ b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
@@ -193,19 +193,9 @@ TcgExtractConfig (
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
//
ConfigRequestHdr = HiiConstructConfigHdr (&gTcgConfigFormSetGuid, mTcgStorageName, PrivateData->DriverHandle);
- if (ConfigRequestHdr == NULL) {
- ASSERT (ConfigRequestHdr != NULL);
- return EFI_OUT_OF_RESOURCES;
- }
-
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
- if (ConfigRequest == NULL) {
- ASSERT (ConfigRequest != NULL);
- FreePool (ConfigRequestHdr);
- return EFI_OUT_OF_RESOURCES;
- }
-
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
+ ASSERT (ConfigRequest != NULL);
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, sizeof (TCG_CONFIGURATION));
FreePool (ConfigRequestHdr);
diff --git a/SecurityPkg/Tcg/TcgDxe/TcgDxe.c b/SecurityPkg/Tcg/TcgDxe/TcgDxe.c
index ea4516a..ee6c627 100644
--- a/SecurityPkg/Tcg/TcgDxe/TcgDxe.c
+++ b/SecurityPkg/Tcg/TcgDxe/TcgDxe.c
@@ -286,10 +286,7 @@ TpmCommHashAll (
CtxSize = Sha1GetContextSize ();
Sha1Ctx = AllocatePool (CtxSize);
- if (Sha1Ctx == NULL) {
- ASSERT (Sha1Ctx != NULL);
- return EFI_OUT_OF_RESOURCES;
- }
+ ASSERT (Sha1Ctx != NULL);
Sha1Init (Sha1Ctx);
Sha1Update (Sha1Ctx, Data, DataLen);
diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
index 65b3f81..5a23dc5 100644
--- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
+++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
@@ -98,11 +98,7 @@ ExtractFileNameFromDevicePath (
ASSERT (DevicePath != NULL);
- String = DevicePathToStr (DevicePath);
- if (String == NULL) {
- return NULL;
- }
-
+ String = DevicePathToStr (DevicePath);
MatchString = String;
LastMatch = String;
FileName = NULL;
diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c
index e79932d..d262904 100644
--- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c
+++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c
@@ -1095,7 +1095,7 @@ IsSignatureFoundInDatabase (
// Enumerate all signature data in SigDB to check if signature exists for executable.
//
CertList = (EFI_SIGNATURE_LIST *)Data;
- while ((DataSize > 0) && (DataSize >= (UINTN)CertList->SignatureListSize)) {
+ while ((DataSize > 0) && (DataSize >= CertList->SignatureListSize)) {
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
if ((CertList->SignatureSize == sizeof (EFI_SIGNATURE_DATA) - 1 + SignatureSize) && (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid))) {
@@ -1173,10 +1173,7 @@ CalculateCertHash (
//
CtxSize = mHash[HashAlg].GetContextSize ();
HashCtx = AllocatePool (CtxSize);
- if (HashCtx == NULL) {
- ASSERT (HashCtx != NULL);
- return FALSE;
- }
+ ASSERT (HashCtx != NULL);
//
// 2. Initialize a hash context.
@@ -1264,7 +1261,7 @@ IsCertHashFoundInDbx (
// Check whether the certificate hash exists in the forbidden database.
//
DbxList = (EFI_SIGNATURE_LIST *)Data;
- while ((DataSize > 0) && (DataSize >= (UINTN)DbxList->SignatureListSize)) {
+ while ((DataSize > 0) && (DataSize >= DbxList->SignatureListSize)) {
//
// Determine Hash Algorithm of Certificate in the forbidden database.
//
@@ -1351,7 +1348,7 @@ GetSignaturelistOffset (
SigList = Database;
SiglistSize = DatabaseSize;
- while ((SiglistSize > 0) && (SiglistSize >= (UINTN)SigList->SignatureListSize)) {
+ while ((SiglistSize > 0) && (SiglistSize >= SigList->SignatureListSize)) {
if (CompareGuid (&SigList->SignatureType, SignatureType)) {
*Offset = DatabaseSize - SiglistSize;
return TRUE;
@@ -1891,10 +1888,7 @@ HashPeImage (
CtxSize = mHash[HashAlg].GetContextSize ();
HashCtx = AllocatePool (CtxSize);
- if (HashCtx == NULL) {
- ASSERT (HashCtx != NULL);
- goto Done;
- }
+ ASSERT (HashCtx != NULL);
// 1. Load the image header into memory.
@@ -2546,7 +2540,7 @@ UpdateDeletePage (
)
{
EFI_STATUS Status;
- UINTN Index;
+ UINT32 Index;
UINTN CertCount;
UINTN GuidIndex;
VOID *StartOpCodeHandle;
@@ -2730,7 +2724,7 @@ DeleteKeyExchangeKey (
UINT8 *Data;
UINT8 *OldData;
UINT32 Attr;
- UINTN Index;
+ UINT32 Index;
EFI_SIGNATURE_LIST *CertList;
EFI_SIGNATURE_LIST *NewCertList;
EFI_SIGNATURE_DATA *Cert;
@@ -2934,7 +2928,7 @@ DeleteSignature (
UINT8 *Data;
UINT8 *OldData;
UINT32 Attr;
- UINTN Index;
+ UINT32 Index;
EFI_SIGNATURE_LIST *CertList;
EFI_SIGNATURE_LIST *NewCertList;
EFI_SIGNATURE_DATA *Cert;
@@ -3212,7 +3206,7 @@ DeleteSignatureEx (
//
// Traverse to target EFI_SIGNATURE_LIST but others will be skipped.
//
- while ((RemainingSize > 0) && (RemainingSize >= (UINTN)ListWalker->SignatureListSize) && ListIndex < PrivateData->ListIndex) {
+ while ((RemainingSize > 0) && (RemainingSize >= ListWalker->SignatureListSize) && ListIndex < PrivateData->ListIndex) {
CopyMem ((UINT8 *)NewVariableData + Offset, ListWalker, ListWalker->SignatureListSize);
Offset += ListWalker->SignatureListSize;
@@ -3519,19 +3513,9 @@ SecureBootExtractConfig (
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
//
ConfigRequestHdr = HiiConstructConfigHdr (&gSecureBootConfigFormSetGuid, mSecureBootStorageName, PrivateData->DriverHandle);
- if (ConfigRequestHdr == NULL) {
- ASSERT (ConfigRequestHdr != NULL);
- return EFI_OUT_OF_RESOURCES;
- }
-
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
- if (ConfigRequest == NULL) {
- ASSERT (ConfigRequest != NULL);
- FreePool (ConfigRequestHdr);
- return EFI_OUT_OF_RESOURCES;
- }
-
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
+ ASSERT (ConfigRequest != NULL);
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
FreePool (ConfigRequestHdr);
@@ -3810,7 +3794,7 @@ LoadSignatureList (
RemainingSize = DataSize;
ListWalker = (EFI_SIGNATURE_LIST *)VariableData;
- while ((RemainingSize > 0) && (RemainingSize >= (UINTN)ListWalker->SignatureListSize)) {
+ while ((RemainingSize > 0) && (RemainingSize >= ListWalker->SignatureListSize)) {
if (CompareGuid (&ListWalker->SignatureType, &gEfiCertRsa2048Guid)) {
ListType = STRING_TOKEN (STR_LIST_TYPE_RSA2048_SHA256);
} else if (CompareGuid (&ListWalker->SignatureType, &gEfiCertX509Guid)) {
@@ -4226,7 +4210,7 @@ LoadSignatureData (
VOID *EndOpCodeHandle;
UINTN DataSize;
UINTN RemainingSize;
- UINT64 Index;
+ UINT16 Index;
UINT8 *VariableData;
CHAR16 VariableName[BUFFER_MAX_SIZE];
CHAR16 NameBuffer[BUFFER_MAX_SIZE];
@@ -4310,7 +4294,7 @@ LoadSignatureData (
//
// Skip signature list.
//
- while ((RemainingSize > 0) && (RemainingSize >= (UINTN)ListWalker->SignatureListSize) && ListIndex-- > 0) {
+ while ((RemainingSize > 0) && (RemainingSize >= ListWalker->SignatureListSize) && ListIndex-- > 0) {
RemainingSize -= ListWalker->SignatureListSize;
ListWalker = (EFI_SIGNATURE_LIST *)((UINT8 *)ListWalker + ListWalker->SignatureListSize);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c
index 30f4846..b8c6852 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c
@@ -2883,6 +2883,14 @@ TABLE_ITEM MemoryDeviceTypeTable[] = {
{
MemoryTypeLpddr5,
L" LPDDR5"
+ },
+ {
+ MemoryTypeHBM3,
+ L" HBM3 (High Bandwidth Memory Generation 3)"
+ },
+ {
+ MemoryTypeMrDimm,
+ L" MRDIMM (Multi-Channel RDIMM)"
}
};
@@ -2973,6 +2981,10 @@ TABLE_ITEM MemoryDeviceMemoryTechnologyTable[] = {
{
MemoryTechnologyIntelOptanePersistentMemory,
L" Intel Optane Persistent Memory"
+ },
+ {
+ MemoryTechnologyMrDimmDeprecated,
+ L" MRDIMM"
}
};
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
index 0f4068d..b6c5df7 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
@@ -96,7 +96,6 @@
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
MdeModulePkg/MdeModulePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
[LibraryClasses]
MemoryAllocationLib
diff --git a/ShellPkg/ShellPkg.ci.yaml b/ShellPkg/ShellPkg.ci.yaml
index 4f5c69d..2c3a70d 100644
--- a/ShellPkg/ShellPkg.ci.yaml
+++ b/ShellPkg/ShellPkg.ci.yaml
@@ -35,7 +35,6 @@
"MdePkg/MdePkg.dec",
"MdeModulePkg/MdeModulePkg.dec",
"ShellPkg/ShellPkg.dec",
- "EmbeddedPkg/EmbeddedPkg.dec",
"NetworkPkg/NetworkPkg.dec"
],
# For host based unit tests
diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.c b/StandaloneMmPkg/Core/StandaloneMmCore.c
index 154285f..2345f9a 100644
--- a/StandaloneMmPkg/Core/StandaloneMmCore.c
+++ b/StandaloneMmPkg/Core/StandaloneMmCore.c
@@ -298,7 +298,7 @@ MmEndOfPeiHandler (
DEBUG ((DEBUG_INFO, "MmEndOfPeiHandler\n"));
//
- // Install MM EndOfDxe protocol
+ // Install MM EndOfPei protocol
//
MmHandle = NULL;
Status = MmInstallProtocolInterface (
diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c
index 38837b9..1ab84ec 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c
@@ -383,7 +383,7 @@ LocateMmCoreFv (
it is pointed to fundation and platform HOB list.
**/
VOID *
-CreatMmHobList (
+CreateMmHobList (
OUT UINTN *HobSize,
IN MM_COMM_BUFFER *MmCommBuffer,
IN EFI_PHYSICAL_ADDRESS MmFvBase,
@@ -785,10 +785,10 @@ ExecuteMmCoreFromMmram (
InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
//
- // Get HOB list for Standalone MM Core.
+ // Create HOB list for Standalone MM Core.
//
MmHobSize = 0;
- MmHobList = CreatMmHobList (
+ MmHobList = CreateMmHobList (
&MmHobSize,
MmCommBuffer,
MmFvBase,
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c b/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c
index 080e229..bb07200 100644
--- a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c
+++ b/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c
@@ -8,6 +8,7 @@
**/
#include <Uefi.h>
+#include <Guid/RiscVSecHobData.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>
@@ -16,9 +17,12 @@
#include <Pi/PiHob.h>
#include <Library/HobLib.h>
#include <Library/FdtLib.h>
+#include <Library/TimerLib.h>
STATIC UINT64 mTimeBase;
+#define GET_TIME_BASE() (mTimeBase ?: GetPerformanceCounterProperties(NULL, NULL))
+
/**
Stalls the CPU for at least the given number of ticks.
@@ -63,7 +67,7 @@ MicroSecondDelay (
DivU64x32 (
MultU64x32 (
MicroSeconds,
- mTimeBase
+ GET_TIME_BASE ()
),
1000000u
)
@@ -91,7 +95,7 @@ NanoSecondDelay (
DivU64x32 (
MultU64x32 (
NanoSeconds,
- mTimeBase
+ GET_TIME_BASE ()
),
1000000000u
)
@@ -150,6 +154,12 @@ GetPerformanceCounterProperties (
OUT UINT64 *EndValue OPTIONAL
)
{
+ VOID *Hob;
+ RISCV_SEC_HANDOFF_DATA *SecData;
+ CONST EFI_GUID SecHobDataGuid = RISCV_SEC_HANDOFF_HOB_GUID;
+ UINT64 TimeBase;
+ CONST VOID *FdtBase;
+
if (StartValue != NULL) {
*StartValue = 0;
}
@@ -165,20 +175,27 @@ GetPerformanceCounterProperties (
//
// Locate the FDT HOB and validate header
//
- CONST EFI_HOB_GUID_TYPE *Hob = GetFirstGuidHob (&gFdtHobGuid);
-
- ASSERT (Hob != NULL);
-
- CONST VOID *DeviceTreeBase =
- (CONST VOID *)(UINTN)*(CONST UINT64 *)GET_GUID_HOB_DATA (Hob);
+ Hob = GetFirstGuidHob (&gFdtHobGuid);
+ if (Hob) {
+ FdtBase = (CONST VOID *)(UINTN)*(CONST UINT64 *)GET_GUID_HOB_DATA (Hob);
+ } else {
+ //
+ // Get the FDT address from the SEC HOB
+ //
+ Hob = GetFirstGuidHob (&SecHobDataGuid);
+ ASSERT (Hob != NULL);
+ SecData = (RISCV_SEC_HANDOFF_DATA *)GET_GUID_HOB_DATA (Hob);
+ FdtBase = (CONST VOID *)SecData->FdtPointer;
+ }
- ASSERT (FdtCheckHeader (DeviceTreeBase) == 0);
+ ASSERT (FdtBase != NULL);
+ ASSERT (FdtCheckHeader ((VOID *)(UINTN)FdtBase) == 0);
//
// /cpus node
//
INT32 Node = FdtSubnodeOffsetNameLen (
- DeviceTreeBase,
+ FdtBase,
0,
"cpus",
sizeof ("cpus") - 1
@@ -191,15 +208,23 @@ GetPerformanceCounterProperties (
//
INT32 Len;
CONST FDT_PROPERTY *Prop =
- FdtGetProperty (DeviceTreeBase, Node, "timebase-frequency", &Len);
+ FdtGetProperty (FdtBase, Node, "timebase-frequency", &Len);
ASSERT (Prop != NULL && Len == sizeof (UINT32));
//
// Device-tree cells are big-endian
//
- mTimeBase = SwapBytes32 (*(CONST UINT32 *)Prop->Data);
- return mTimeBase;
+ TimeBase = SwapBytes32 (*(CONST UINT32 *)Prop->Data);
+ ASSERT (TimeBase != 0);
+
+ //
+ // Save the time base for later use. Note that the mTimeBase maybe zero if
+ // this library is stored in read-only memory.
+ //
+ mTimeBase = TimeBase;
+
+ return TimeBase;
}
/**
@@ -227,13 +252,13 @@ GetTimeInNanoSecond (
// Time = --------- x 1,000,000,000
// Frequency
//
- NanoSeconds = MultU64x32 (DivU64x32Remainder (Ticks, mTimeBase, &Remainder), 1000000000u);
+ NanoSeconds = MultU64x32 (DivU64x32Remainder (Ticks, GET_TIME_BASE (), &Remainder), 1000000000u);
//
// Frequency < 0x100000000, so Remainder < 0x100000000, then (Remainder * 1,000,000,000)
// will not overflow 64-bit.
//
- NanoSeconds += DivU64x32 (MultU64x32 ((UINT64)Remainder, 1000000000u), mTimeBase);
+ NanoSeconds += DivU64x32 (MultU64x32 ((UINT64)Remainder, 1000000000u), GET_TIME_BASE ());
return NanoSeconds;
}
diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
index 2fd6f7d..866ca70 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
@@ -1,6 +1,6 @@
/** @file
- This driver will report some MMIO/IO resources to dxe core, extract smbios and acpi
- tables from bootloader.
+ This driver will setup PCDs for DXE phase from HOBs
+ and initialise architecture-specific settings and resources.
Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -29,8 +29,9 @@ BlDxeEntryPoint (
EFI_HOB_GUID_TYPE *GuidHob;
EFI_PEI_GRAPHICS_INFO_HOB *GfxInfo;
ACPI_BOARD_INFO *AcpiBoardInfo;
-
- Status = EFI_SUCCESS;
+ FIRMWARE_INFO *FirmwareInfo;
+ EFI_SYSTEM_RESOURCE_TABLE *Esrt;
+ EFI_SYSTEM_RESOURCE_ENTRY *Esre;
//
// Find the frame buffer information and update PCDs
@@ -63,5 +64,30 @@ BlDxeEntryPoint (
Status = BlArchAdditionalOps (ImageHandle, SystemTable);
ASSERT_EFI_ERROR (Status);
+ //
+ // Build and publish a single-entry ESRT if a bootloader provided us with
+ // details about currently running firmware
+ //
+ GuidHob = GetFirstGuidHob (&gEfiFirmwareInfoHobGuid);
+ if (GuidHob != NULL) {
+ FirmwareInfo = (FIRMWARE_INFO *)GET_GUID_HOB_DATA (GuidHob);
+
+ Esrt = AllocateZeroPool (sizeof (EFI_SYSTEM_RESOURCE_TABLE) + sizeof (EFI_SYSTEM_RESOURCE_ENTRY));
+ ASSERT (Esrt != NULL);
+
+ Esrt->FwResourceVersion = EFI_SYSTEM_RESOURCE_TABLE_FIRMWARE_RESOURCE_VERSION;
+ Esrt->FwResourceCount = 1;
+ Esrt->FwResourceCountMax = 1;
+
+ Esre = (EFI_SYSTEM_RESOURCE_ENTRY *)&Esrt[1];
+ CopyMem (&Esre->FwClass, &FirmwareInfo->Type, sizeof (EFI_GUID));
+ Esre->FwType = ESRT_FW_TYPE_SYSTEMFIRMWARE;
+ Esre->FwVersion = FirmwareInfo->Version;
+ Esre->LowestSupportedFwVersion = FirmwareInfo->LowestSupportedVersion;
+
+ Status = gBS->InstallConfigurationTable (&gEfiSystemResourceTableGuid, Esrt);
+ ASSERT_EFI_ERROR (Status);
+ }
+
return EFI_SUCCESS;
}
diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h
index ebae6f2..2a23547 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h
@@ -11,17 +11,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <PiDxe.h>
-#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
-#include <Library/DxeServicesTableLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
-#include <Library/UefiLib.h>
#include <Library/IoLib.h>
#include <Library/HobLib.h>
+#include <Library/MemoryAllocationLib.h>
-#include <Guid/SmBios.h>
+#include <Guid/SystemResourceTable.h>
#include <Guid/AcpiBoardInfoGuid.h>
+#include <Guid/FirmwareInfoGuid.h>
#include <Guid/GraphicsInfoHob.h>
EFI_STATUS
diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
index 4c15fd4..c1fe073 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
@@ -42,18 +42,19 @@
[LibraryClasses]
UefiDriverEntryPoint
UefiBootServicesTableLib
- DxeServicesTableLib
DebugLib
BaseMemoryLib
- UefiLib
HobLib
+ MemoryAllocationLib
[LibraryClasses.AARCH64]
ArmMmuLib
[Guids]
gUefiAcpiBoardInfoGuid
+ gEfiFirmwareInfoHobGuid
gEfiGraphicsInfoHobGuid
+ gEfiSystemResourceTableGuid
[Protocols]
gEfiCpuArchProtocolGuid
diff --git a/UefiPayloadPkg/BlSupportDxe/X86/BlSupport.c b/UefiPayloadPkg/BlSupportDxe/X86/BlSupport.c
index 56d4c71..a7bbd88 100644
--- a/UefiPayloadPkg/BlSupportDxe/X86/BlSupport.c
+++ b/UefiPayloadPkg/BlSupportDxe/X86/BlSupport.c
@@ -6,85 +6,8 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-#include "BlSupportDxe.h"
-
-/**
- Reserve MMIO/IO resource in GCD
-
- @param IsMMIO Flag of whether it is mmio resource or io resource.
- @param GcdType Type of the space.
- @param BaseAddress Base address of the space.
- @param Length Length of the space.
- @param Alignment Align with 2^Alignment
- @param ImageHandle Handle for the image of this driver.
-
- @retval EFI_SUCCESS Reserve successful
-**/
-EFI_STATUS
-ReserveResourceInGcd (
- IN BOOLEAN IsMMIO,
- IN UINTN GcdType,
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length,
- IN UINTN Alignment,
- IN EFI_HANDLE ImageHandle
- )
-{
- EFI_STATUS Status;
-
- if (IsMMIO) {
- Status = gDS->AddMemorySpace (
- GcdType,
- BaseAddress,
- Length,
- EFI_MEMORY_UC
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((
- DEBUG_WARN,
- "Failed to add memory space :0x%lx 0x%lx\n",
- BaseAddress,
- Length
- ));
- }
-
- Status = gDS->AllocateMemorySpace (
- EfiGcdAllocateAddress,
- GcdType,
- Alignment,
- Length,
- &BaseAddress,
- ImageHandle,
- NULL
- );
- } else {
- Status = gDS->AddIoSpace (
- GcdType,
- BaseAddress,
- Length
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((
- DEBUG_WARN,
- "Failed to add IO space :0x%lx 0x%lx\n",
- BaseAddress,
- Length
- ));
- }
-
- Status = gDS->AllocateIoSpace (
- EfiGcdAllocateAddress,
- GcdType,
- Alignment,
- Length,
- &BaseAddress,
- ImageHandle,
- NULL
- );
- }
- return Status;
-}
+#include "BlSupportDxe.h"
/**
Architecture level additional operation which needs to be performed before
@@ -104,12 +27,5 @@ BlArchAdditionalOps (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- //
- // Report MMIO/IO Resources
- //
- ReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFEC00000, SIZE_4KB, 0, ImageHandle); // IOAPIC
-
- ReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFED00000, SIZE_1KB, 0, ImageHandle); // HPET
-
return EFI_SUCCESS;
}
diff --git a/UefiPayloadPkg/Include/Coreboot.h b/UefiPayloadPkg/Include/Coreboot.h
index 1b05f15..4d0d2cc 100644
--- a/UefiPayloadPkg/Include/Coreboot.h
+++ b/UefiPayloadPkg/Include/Coreboot.h
@@ -263,6 +263,34 @@ struct cb_smmstorev2 {
UINT8 unused[3]; /* Set to zero */
} __attribute__ ((packed));
+/*
+ * Machine-friendly version of a system firmware component. A component is
+ * identified by a GUID. coreboot is an obvious main component but there could
+ * be others (like EC) which should get their own instances of the tag.
+ *
+ * The main consumer of this information is UEFI firmware but something else
+ * could reuse it too.
+ *
+ * Larger number in a version field corresponds to a more recent version.
+ */
+#define CB_TAG_FW_INFO 0x0045
+struct lb_efi_fw_info {
+ UINT32 tag;
+ UINT32 size;
+ UINT8 guid[16]; /* Called "firmware class" in UEFI */
+ UINT32 version; /* Current version */
+ UINT32 lowest_supported_version; /* Lowest allowed version */
+ UINT32 fw_size; /* Size of firmware in bytes */
+} __attribute__ ((packed));
+
+#define CB_TAG_CAPSULE 0x0046
+struct cb_range {
+ UINT32 tag;
+ UINT32 size;
+ UINT64 range_start;
+ UINT32 range_size;
+} __attribute__ ((packed));
+
/* Helpful macros */
#define MEM_RANGE_COUNT(_rec) \
diff --git a/UefiPayloadPkg/Include/Guid/FirmwareInfoGuid.h b/UefiPayloadPkg/Include/Guid/FirmwareInfoGuid.h
new file mode 100644
index 0000000..fa1d064
--- /dev/null
+++ b/UefiPayloadPkg/Include/Guid/FirmwareInfoGuid.h
@@ -0,0 +1,26 @@
+/** @file
+ This file defines the hob structure for firmware related information from a
+ bootloader
+
+ Copyright (c) 2025, 3mdeb Sp. z o.o.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef FIRMWARE_INFO_GUID_H_
+#define FIRMWARE_INFO_GUID_H_
+
+///
+/// Firmware information GUID
+///
+extern EFI_GUID gEfiFirmwareInfoHobGuid;
+
+typedef struct {
+ EFI_GUID Type;
+ CHAR8 VersionStr[64];
+ UINT32 Version;
+ UINT32 LowestSupportedVersion;
+ UINT32 ImageSize;
+} FIRMWARE_INFO;
+
+#endif // FIRMWARE_INFO_GUID_H_
diff --git a/UefiPayloadPkg/Include/Library/BlParseLib.h b/UefiPayloadPkg/Include/Library/BlParseLib.h
index 82be5a9..e86f03f 100644
--- a/UefiPayloadPkg/Include/Library/BlParseLib.h
+++ b/UefiPayloadPkg/Include/Library/BlParseLib.h
@@ -15,6 +15,7 @@
#include <Guid/MemoryMapInfoGuid.h>
#include <Guid/SerialPortInfoGuid.h>
#include <Guid/AcpiBoardInfoGuid.h>
+#include <Guid/FirmwareInfoGuid.h>
#include <UniversalPayload/AcpiTable.h>
#include <UniversalPayload/SmbiosTable.h>
@@ -26,6 +27,12 @@ typedef RETURN_STATUS \
VOID *Param
);
+typedef VOID \
+(*BL_CAPSULE_CALLBACK) (
+ EFI_PHYSICAL_ADDRESS BaseAddress,
+ UINT64 Length
+ );
+
/**
This function retrieves the parameter base address from boot loader.
@@ -148,4 +155,33 @@ ParseMiscInfo (
VOID
);
+/**
+ Parse firmware information passed in by bootloader
+
+ @param FwInfo Information about current firmware.
+
+ @retval RETURN_INVALID_PARAMETER The parameter is NULL.
+ @retval RETURN_SUCCESS Successfully parsed information.
+ @retval RETURN_NOT_FOUND The information is missing.
+**/
+RETURN_STATUS
+EFIAPI
+ParseFirmwareInfo (
+ OUT FIRMWARE_INFO *FwInfo
+ );
+
+/**
+ Parse update capsules passed in by bootloader
+
+ @param CapsuleCallback The callback routine invoked for each capsule.
+
+ @retval RETURN_SUCCESS Successfully parsed capsules.
+ @retval RETURN_NOT_FOUND Failed to look up the information.
+**/
+RETURN_STATUS
+EFIAPI
+ParseCapsules (
+ IN BL_CAPSULE_CALLBACK CapsuleCallback
+ );
+
#endif
diff --git a/UefiPayloadPkg/Include/Library/SmmStoreLib.h b/UefiPayloadPkg/Include/Library/SmmStoreLib.h
index bf0b8a0..13b51ee 100644
--- a/UefiPayloadPkg/Include/Library/SmmStoreLib.h
+++ b/UefiPayloadPkg/Include/Library/SmmStoreLib.h
@@ -1,6 +1,7 @@
/** @file SmmStoreLib.h
Copyright (c) 2022, 9elements GmbH<BR>
+ Copyright (c) 2025, 3mdeb Sp. z o.o.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -67,6 +68,25 @@ SmmStoreLibRead (
);
/**
+ Read from an arbitrary flash location. The whole flash is represented as a
+ sequence of blocks.
+
+ @param[in] Lba The starting logical block index to read from.
+ @param[in] Offset Offset into the block at which to begin reading.
+ @param[in] NumBytes On input, indicates the requested read size. On
+ output, indicates the actual number of bytes read
+ @param[in] Buffer Pointer to the buffer to read into.
+
+**/
+EFI_STATUS
+SmmStoreLibReadAnyBlock (
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN *NumBytes,
+ IN UINT8 *Buffer
+ );
+
+/**
Write to SmmStore
@param[in] Lba The starting logical block index to write to.
@@ -85,6 +105,25 @@ SmmStoreLibWrite (
);
/**
+ Write to an arbitrary flash location. The whole flash is represented as a
+ sequence of blocks.
+
+ @param[in] Lba The starting logical block index to write to.
+ @param[in] Offset Offset into the block at which to begin writing.
+ @param[in] NumBytes On input, indicates the requested write size. On
+ output, indicates the actual number of bytes written
+ @param[in] Buffer Pointer to the data to write.
+
+**/
+EFI_STATUS
+SmmStoreLibWriteAnyBlock (
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN *NumBytes,
+ IN UINT8 *Buffer
+ );
+
+/**
Erase a block using the SmmStore
@param Lba The logical block index to erase.
@@ -96,6 +135,18 @@ SmmStoreLibEraseBlock (
);
/**
+ Erase an arbitrary block of the flash. The whole flash is represented as a
+ sequence of blocks.
+
+ @param Lba The logical block index to erase.
+
+**/
+EFI_STATUS
+SmmStoreLibEraseAnyBlock (
+ IN EFI_LBA Lba
+ );
+
+/**
Function to update a pointer on virtual address change. Matches the signature
and operation of EfiConvertPointer.
diff --git a/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c b/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c
index d7282e0..0f6d1d5 100644
--- a/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c
+++ b/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c
@@ -14,6 +14,7 @@
#include <Library/PcdLib.h>
#include <Library/IoLib.h>
#include <Library/BlParseLib.h>
+#include <Library/PrintLib.h>
#include <Library/SmmStoreParseLib.h>
#include <IndustryStandard/Acpi.h>
#include <Coreboot.h>
@@ -638,3 +639,114 @@ ParseSmmStoreInfo (
return RETURN_SUCCESS;
}
+
+/**
+ Parse information in a string form identified by a number
+
+ @param Id String identifier.
+
+ @retval NULL The requested information wasn't found.
+ @retval Otherwise A pointer to a static string.
+**/
+STATIC
+CONST CHAR8 *
+EFIAPI
+ParseInfoString (
+ IN UINTN Id
+ )
+{
+ struct cb_string *CbString;
+
+ CbString = FindCbTag (Id);
+ if (CbString == NULL) {
+ return NULL;
+ }
+
+ return (CONST CHAR8 *)CbString->string;
+}
+
+/**
+ Parse firmware information passed in by bootloader
+
+ @param FwInfo Information about current firmware.
+
+ @retval RETURN_INVALID_PARAMETER The parameter is NULL.
+ @retval RETURN_SUCCESS Successfully parsed information.
+ @retval RETURN_NOT_FOUND The information is missing.
+**/
+RETURN_STATUS
+EFIAPI
+ParseFirmwareInfo (
+ OUT FIRMWARE_INFO *FwInfo
+ )
+{
+ CONST CHAR8 *Version;
+ CONST CHAR8 *ExtraVersion;
+ struct lb_efi_fw_info *Info;
+
+ if (FwInfo == NULL) {
+ return RETURN_INVALID_PARAMETER;
+ }
+
+ Info = FindCbTag (CB_TAG_FW_INFO);
+ if (Info == NULL) {
+ return RETURN_NOT_FOUND;
+ }
+
+ Version = ParseInfoString (CB_TAG_VERSION);
+ ExtraVersion = ParseInfoString (CB_TAG_EXTRA_VERSION);
+
+ /* No big deal if these aren't available. */
+ if ((Version == NULL) && (ExtraVersion == NULL)) {
+ Version = "coreboot+EDK2 (unknown version)";
+ ExtraVersion = "";
+ } else if (Version == NULL) {
+ Version = "";
+ } else if (ExtraVersion == NULL) {
+ ExtraVersion = "";
+ }
+
+ CopyMem (&FwInfo->Type, &Info->guid, sizeof (FwInfo->Type));
+ FwInfo->Version = Info->version;
+ FwInfo->LowestSupportedVersion = Info->lowest_supported_version;
+ FwInfo->ImageSize = Info->fw_size;
+ AsciiSPrint (FwInfo->VersionStr, sizeof (FwInfo->VersionStr), "%a%a", Version, ExtraVersion);
+ return RETURN_SUCCESS;
+}
+
+/**
+ Parse update capsules passed in by bootloader
+
+ @param CapsuleCallback The callback routine invoked for each capsule.
+
+ @retval RETURN_SUCCESS Successfully parsed capsules.
+ @retval RETURN_NOT_FOUND Failed to look up the information.
+**/
+RETURN_STATUS
+EFIAPI
+ParseCapsules (
+ IN BL_CAPSULE_CALLBACK CapsuleCallback
+ )
+{
+ struct cb_header *Header;
+ struct cb_range *Range;
+ UINT8 *TmpPtr;
+ UINTN Idx;
+
+ Header = GetParameterBase ();
+ if (Header == NULL) {
+ return RETURN_NOT_FOUND;
+ }
+
+ TmpPtr = (UINT8 *)Header + Header->header_bytes;
+ for (Idx = 0; Idx < Header->table_entries; Idx++) {
+ Range = (struct cb_range *)TmpPtr;
+ if (Range->tag == CB_TAG_CAPSULE) {
+ CapsuleCallback (Range->range_start, Range->range_size);
+ }
+
+ TmpPtr += Range->size;
+ }
+
+ return RETURN_SUCCESS;
+}
diff --git a/UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf b/UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf
index cf81697..7be238c 100644
--- a/UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf
+++ b/UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf
@@ -34,6 +34,7 @@
IoLib
DebugLib
PcdLib
+ PrintLib
[Pcd]
gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter
diff --git a/UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.c b/UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.c
new file mode 100644
index 0000000..ff85401
--- /dev/null
+++ b/UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.c
@@ -0,0 +1,1143 @@
+/** @file
+ Provides firmware device specific services to support updates of a firmware
+ image stored in a firmware device.
+
+ This implementation uses SmmStoreLib to update the whole flash chip. For
+ this to work correctly Intel ME or an equivalent need to be disabled and all
+ flash chip protections need to be lifted (rather, not applied) if coreboot
+ finds any capsules during initialization. It is done to allow updating ME or
+ changing chip's layout in a new firmware (e.g., to allocate more space for
+ the BIOS region). In the future, this can be made more flexible, say, by
+ parsing coreboot's FMAP and only updating some regions. Such functionality
+ probably need embedding more knowledge about specific firmware image via a
+ new library to be customized for specific use-cases.
+
+ Copyright (c) Microsoft Corporation.<BR>
+ Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2025, 3mdeb Sp. z o.o. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <PiDxe.h>
+#include <Guid/FirmwareInfoGuid.h>
+#include <Guid/SystemResourceTable.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/FmpDeviceLib.h>
+#include <Library/HobLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/SmmStoreLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Coreboot.h>
+
+/**
+ This function requests firmware information on the first call, caches it and
+ returns on all calls afterwards.
+
+ @param[out] Info Place to store a pointer to firmware information.
+
+ @retval EFI_SUCCESS Info points to firmware information.
+ @retval EFI_INVALID_PARAMETER Info is NULL.
+**/
+STATIC
+EFI_STATUS
+GetFwInfo (
+ OUT FIRMWARE_INFO **Info
+ )
+{
+ STATIC FIRMWARE_INFO Storage;
+ STATIC BOOLEAN Initialized;
+
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ if (Info == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (!Initialized) {
+ GuidHob = GetFirstGuidHob (&gEfiFirmwareInfoHobGuid);
+ if (GuidHob == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a(): failed to query firmware information\n", __func__));
+ return EFI_UNSUPPORTED;
+ }
+
+ Storage = *(FIRMWARE_INFO *)GET_GUID_HOB_DATA (GuidHob);
+ Initialized = TRUE;
+ }
+
+ *Info = &Storage;
+ return EFI_SUCCESS;
+}
+
+/**
+ Provide a function to install the Firmware Management Protocol instance onto a
+ device handle when the device is managed by a driver that follows the UEFI
+ Driver Model. If the device is not managed by a driver that follows the UEFI
+ Driver Model, then EFI_UNSUPPORTED is returned.
+
+ @param[in] FmpInstaller Function that installs the Firmware Management
+ Protocol.
+
+ @retval EFI_SUCCESS The device is managed by a driver that follows the
+ UEFI Driver Model. FmpInstaller must be called on
+ each Driver Binding Start().
+ @retval EFI_UNSUPPORTED The device is not managed by a driver that follows
+ the UEFI Driver Model.
+ @retval other The Firmware Management Protocol for this firmware
+ device is not installed. The firmware device is
+ still locked using FmpDeviceLock().
+**/
+EFI_STATUS
+EFIAPI
+RegisterFmpInstaller (
+ IN FMP_DEVICE_LIB_REGISTER_FMP_INSTALLER Function
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+/**
+ Provide a function to uninstall the Firmware Management Protocol instance from a
+ device handle when the device is managed by a driver that follows the UEFI
+ Driver Model. If the device is not managed by a driver that follows the UEFI
+ Driver Model, then EFI_UNSUPPORTED is returned.
+
+ @param[in] FmpUninstaller Function that installs the Firmware Management
+ Protocol.
+
+ @retval EFI_SUCCESS The device is managed by a driver that follows the
+ UEFI Driver Model. FmpUninstaller must be called on
+ each Driver Binding Stop().
+ @retval EFI_UNSUPPORTED The device is not managed by a driver that follows
+ the UEFI Driver Model.
+ @retval other The Firmware Management Protocol for this firmware
+ device is not installed. The firmware device is
+ still locked using FmpDeviceLock().
+**/
+EFI_STATUS
+EFIAPI
+RegisterFmpUninstaller (
+ IN FMP_DEVICE_LIB_REGISTER_FMP_UNINSTALLER Function
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+/**
+ Set the device context for the FmpDeviceLib services when the device is
+ managed by a driver that follows the UEFI Driver Model. If the device is not
+ managed by a driver that follows the UEFI Driver Model, then EFI_UNSUPPORTED
+ is returned. Once a device context is set, the FmpDeviceLib services
+ operate on the currently set device context.
+
+ @param[in] Handle Device handle for the FmpDeviceLib services.
+ If Handle is NULL, then Context is freed.
+ @param[in, out] Context Device context for the FmpDeviceLib services.
+ If Context is NULL, then a new context is allocated
+ for Handle and the current device context is set and
+ returned in Context. If Context is not NULL, then
+ the current device context is set.
+
+ @retval EFI_SUCCESS The device is managed by a driver that follows the
+ UEFI Driver Model.
+ @retval EFI_UNSUPPORTED The device is not managed by a driver that follows
+ the UEFI Driver Model.
+ @retval other The Firmware Management Protocol for this firmware
+ device is not installed. The firmware device is
+ still locked using FmpDeviceLock().
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceSetContext (
+ IN EFI_HANDLE Handle,
+ IN OUT VOID **Context
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+/**
+ Returns the size, in bytes, of the firmware image currently stored in the
+ firmware device. This function is used to by the GetImage() and
+ GetImageInfo() services of the Firmware Management Protocol. If the image
+ size can not be determined from the firmware device, then 0 must be returned.
+
+ @param[out] Size Pointer to the size, in bytes, of the firmware image
+ currently stored in the firmware device.
+
+ @retval EFI_SUCCESS The size of the firmware image currently
+ stored in the firmware device was returned.
+ @retval EFI_INVALID_PARAMETER Size is NULL.
+ @retval EFI_UNSUPPORTED The firmware device does not support reporting
+ the size of the currently stored firmware image.
+ @retval EFI_DEVICE_ERROR An error occurred attempting to determine the
+ size of the firmware image currently stored in
+ in the firmware device.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceGetSize (
+ OUT UINTN *Size
+ )
+{
+ EFI_STATUS Status;
+ FIRMWARE_INFO *FwInfo;
+
+ if (Size == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = GetFwInfo (&FwInfo);
+ if (!EFI_ERROR (Status)) {
+ *Size = FwInfo->ImageSize;
+ }
+
+ return Status;
+}
+
+/**
+ Returns the GUID value used to fill in the ImageTypeId field of the
+ EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
+ service of the Firmware Management Protocol. If EFI_UNSUPPORTED is returned,
+ then the ImageTypeId field is set to gEfiCallerIdGuid. If EFI_SUCCESS is
+ returned, then ImageTypeId is set to the Guid returned from this function.
+
+ @param[out] Guid Double pointer to a GUID value that is updated to point to
+ to a GUID value. The GUID value is not allocated and must
+ not be modified or freed by the caller.
+
+ @retval EFI_SUCCESS EFI_FIRMWARE_IMAGE_DESCRIPTOR ImageTypeId GUID is set
+ to the returned Guid value.
+ @retval EFI_UNSUPPORTED EFI_FIRMWARE_IMAGE_DESCRIPTOR ImageTypeId GUID is set
+ to gEfiCallerIdGuid.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceGetImageTypeIdGuidPtr (
+ OUT EFI_GUID **Guid
+ )
+{
+ EFI_STATUS Status;
+ FIRMWARE_INFO *FwInfo;
+
+ if (Guid == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = GetFwInfo (&FwInfo);
+ if (!EFI_ERROR (Status)) {
+ *Guid = &FwInfo->Type;
+ }
+
+ return Status;
+}
+
+/**
+ Returns values used to fill in the AttributesSupported and AttributesSettings
+ fields of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the
+ GetImageInfo() service of the Firmware Management Protocol. The following
+ bit values from the Firmware Management Protocol may be combined:
+ IMAGE_ATTRIBUTE_IMAGE_UPDATABLE
+ IMAGE_ATTRIBUTE_RESET_REQUIRED
+ IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED
+ IMAGE_ATTRIBUTE_IN_USE
+ IMAGE_ATTRIBUTE_UEFI_IMAGE
+
+ @param[out] Supported Attributes supported by this firmware device.
+ @param[out] Setting Attributes settings for this firmware device.
+
+ @retval EFI_SUCCESS The attributes supported by the firmware
+ device were returned.
+ @retval EFI_INVALID_PARAMETER Supported is NULL.
+ @retval EFI_INVALID_PARAMETER Setting is NULL.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceGetAttributes (
+ OUT UINT64 *Supported,
+ OUT UINT64 *Setting
+ )
+{
+ if ((Supported == NULL) || (Setting == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *Supported = IMAGE_ATTRIBUTE_IMAGE_UPDATABLE |
+ IMAGE_ATTRIBUTE_RESET_REQUIRED |
+ IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED |
+ IMAGE_ATTRIBUTE_IN_USE;
+ *Setting = *Supported;
+ return EFI_SUCCESS;
+}
+
+/**
+ Returns the value used to fill in the LowestSupportedVersion field of the
+ EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
+ service of the Firmware Management Protocol. If EFI_SUCCESS is returned, then
+ the firmware device supports a method to report the LowestSupportedVersion
+ value from the currently stored firmware image. If the value can not be
+ reported for the firmware image currently stored in the firmware device, then
+ EFI_UNSUPPORTED must be returned. EFI_DEVICE_ERROR is returned if an error
+ occurs attempting to retrieve the LowestSupportedVersion value for the
+ currently stored firmware image.
+
+ @note It is recommended that all firmware devices support a method to report
+ the LowestSupportedVersion value from the currently stored firmware
+ image.
+
+ @param[out] LowestSupportedVersion LowestSupportedVersion value retrieved
+ from the currently stored firmware image.
+
+ @retval EFI_SUCCESS The lowest supported version of currently stored
+ firmware image was returned in LowestSupportedVersion.
+ @retval EFI_UNSUPPORTED The firmware device does not support a method to
+ report the lowest supported version of the currently
+ stored firmware image.
+ @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the lowest
+ supported version of the currently stored firmware
+ image.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceGetLowestSupportedVersion (
+ OUT UINT32 *LowestSupportedVersion
+ )
+{
+ EFI_STATUS Status;
+ FIRMWARE_INFO *FwInfo;
+
+ if (LowestSupportedVersion == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = GetFwInfo (&FwInfo);
+ if (!EFI_ERROR (Status)) {
+ *LowestSupportedVersion = FwInfo->LowestSupportedVersion;
+ }
+
+ return Status;
+}
+
+/**
+ Returns the Null-terminated Unicode string that is used to fill in the
+ VersionName field of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is
+ returned by the GetImageInfo() service of the Firmware Management Protocol.
+ The returned string must be allocated using EFI_BOOT_SERVICES.AllocatePool().
+
+ @note It is recommended that all firmware devices support a method to report
+ the VersionName string from the currently stored firmware image.
+
+ @param[out] VersionString The version string retrieved from the currently
+ stored firmware image.
+
+ @retval EFI_SUCCESS The version string of currently stored
+ firmware image was returned in Version.
+ @retval EFI_INVALID_PARAMETER VersionString is NULL.
+ @retval EFI_UNSUPPORTED The firmware device does not support a method
+ to report the version string of the currently
+ stored firmware image.
+ @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the
+ version string of the currently stored
+ firmware image.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate the
+ buffer for the version string of the currently
+ stored firmware image.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceGetVersionString (
+ OUT CHAR16 **VersionString
+ )
+{
+ EFI_STATUS Status;
+ FIRMWARE_INFO *FwInfo;
+
+ if (VersionString == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = GetFwInfo (&FwInfo);
+ if (!EFI_ERROR (Status)) {
+ *VersionString = (CHAR16 *)AllocateCopyPool (
+ sizeof (FwInfo->VersionStr),
+ FwInfo->VersionStr
+ );
+ if (*VersionString == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ }
+ }
+
+ return Status;
+}
+
+/**
+ Returns the value used to fill in the Version field of the
+ EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
+ service of the Firmware Management Protocol. If EFI_SUCCESS is returned, then
+ the firmware device supports a method to report the Version value from the
+ currently stored firmware image. If the value can not be reported for the
+ firmware image currently stored in the firmware device, then EFI_UNSUPPORTED
+ must be returned. EFI_DEVICE_ERROR is returned if an error occurs attempting
+ to retrieve the LowestSupportedVersion value for the currently stored firmware
+ image.
+
+ @note It is recommended that all firmware devices support a method to report
+ the Version value from the currently stored firmware image.
+
+ @param[out] Version The version value retrieved from the currently stored
+ firmware image.
+
+ @retval EFI_SUCCESS The version of currently stored firmware image was
+ returned in Version.
+ @retval EFI_UNSUPPORTED The firmware device does not support a method to
+ report the version of the currently stored firmware
+ image.
+ @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the version
+ of the currently stored firmware image.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceGetVersion (
+ OUT UINT32 *Version
+ )
+{
+ EFI_STATUS Status;
+ FIRMWARE_INFO *FwInfo;
+
+ if (Version == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = GetFwInfo (&FwInfo);
+ if (!EFI_ERROR (Status)) {
+ *Version = FwInfo->Version;
+ }
+
+ return Status;
+}
+
+/**
+ Returns the value used to fill in the HardwareInstance field of the
+ EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
+ service of the Firmware Management Protocol. If EFI_SUCCESS is returned, then
+ the firmware device supports a method to report the HardwareInstance value.
+ If the value can not be reported for the firmware device, then EFI_UNSUPPORTED
+ must be returned. EFI_DEVICE_ERROR is returned if an error occurs attempting
+ to retrieve the HardwareInstance value for the firmware device.
+
+ @param[out] HardwareInstance The hardware instance value for the firmware
+ device.
+
+ @retval EFI_SUCCESS The hardware instance for the current firmware
+ device is returned in HardwareInstance.
+ @retval EFI_UNSUPPORTED The firmware device does not support a method to
+ report the hardware instance value.
+ @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the hardware
+ instance value.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceGetHardwareInstance (
+ OUT UINT64 *HardwareInstance
+ )
+{
+ if (HardwareInstance == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *HardwareInstance = 0;
+ return EFI_SUCCESS;
+}
+
+/**
+ Returns a copy of the firmware image currently stored in the firmware device.
+
+ @note It is recommended that all firmware devices support a method to retrieve
+ a copy currently stored firmware image. This can be used to support
+ features such as recovery and rollback.
+
+ @param[out] Image Pointer to a caller allocated buffer where the
+ currently stored firmware image is copied to.
+ @param[in, out] ImageSize Pointer the size, in bytes, of the Image buffer.
+ On return, points to the size, in bytes, of firmware
+ image currently stored in the firmware device.
+
+ @retval EFI_SUCCESS Image contains a copy of the firmware image
+ currently stored in the firmware device, and
+ ImageSize contains the size, in bytes, of the
+ firmware image currently stored in the
+ firmware device.
+ @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small
+ to hold the firmware image currently stored in
+ the firmware device. The buffer size required
+ is returned in ImageSize.
+ @retval EFI_INVALID_PARAMETER The Image is NULL.
+ @retval EFI_INVALID_PARAMETER The ImageSize is NULL.
+ @retval EFI_UNSUPPORTED The operation is not supported.
+ @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the
+ firmware image currently stored in the firmware
+ device.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceGetImage (
+ OUT VOID *Image,
+ IN OUT UINTN *ImageSize
+ )
+{
+ //
+ // This seems useful only if FMP device is part of the running firmware.
+ //
+ return EFI_UNSUPPORTED;
+}
+
+/**
+ Checks if a new firmware image is valid for the firmware device. This
+ function allows firmware update operation to validate the firmware image
+ before FmpDeviceSetImage() is called.
+
+ @param[in] Image Points to a new firmware image.
+ @param[in] ImageSize Size, in bytes, of a new firmware image.
+ @param[out] ImageUpdatable Indicates if a new firmware image is valid for
+ a firmware update to the firmware device. The
+ following values from the Firmware Management
+ Protocol are supported:
+ IMAGE_UPDATABLE_VALID
+ IMAGE_UPDATABLE_INVALID
+ IMAGE_UPDATABLE_INVALID_TYPE
+ IMAGE_UPDATABLE_INVALID_OLD
+ IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE
+
+ @retval EFI_SUCCESS The image was successfully checked. Additional
+ status information is returned in
+ ImageUpdatable.
+ @retval EFI_INVALID_PARAMETER Image is NULL.
+ @retval EFI_INVALID_PARAMETER ImageUpdatable is NULL.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceCheckImage (
+ IN CONST VOID *Image,
+ IN UINTN ImageSize,
+ OUT UINT32 *ImageUpdatable
+ )
+{
+ UINT32 LastAttemptStatus;
+
+ return FmpDeviceCheckImageWithStatus (Image, ImageSize, ImageUpdatable, &LastAttemptStatus);
+}
+
+/**
+ Checks if a new firmware image is valid for the firmware device. This
+ function allows firmware update operation to validate the firmware image
+ before FmpDeviceSetImage() is called.
+
+ @param[in] Image Points to a new firmware image.
+ @param[in] ImageSize Size, in bytes, of a new firmware image.
+ @param[out] ImageUpdatable Indicates if a new firmware image is valid for
+ a firmware update to the firmware device. The
+ following values from the Firmware Management
+ Protocol are supported:
+ IMAGE_UPDATABLE_VALID
+ IMAGE_UPDATABLE_INVALID
+ IMAGE_UPDATABLE_INVALID_TYPE
+ IMAGE_UPDATABLE_INVALID_OLD
+ IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE
+ @param[out] LastAttemptStatus A pointer to a UINT32 that holds the last attempt
+ status to report back to the ESRT table in case
+ of error.
+
+ The return status code must fall in the range of
+ LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE to
+ LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE.
+
+ If the value falls outside this range, it will be converted
+ to LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL.
+
+ @retval EFI_SUCCESS The image was successfully checked. Additional
+ status information is returned in
+ ImageUpdatable.
+ @retval EFI_INVALID_PARAMETER Image is NULL.
+ @retval EFI_INVALID_PARAMETER ImageUpdatable is NULL.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceCheckImageWithStatus (
+ IN CONST VOID *Image,
+ IN UINTN ImageSize,
+ OUT UINT32 *ImageUpdatable,
+ OUT UINT32 *LastAttemptStatus
+ )
+{
+ EFI_STATUS Status;
+ UINTN FwSize;
+ UINTN BlockSize;
+
+ if ((Image == NULL) || (ImageUpdatable == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
+ *ImageUpdatable = IMAGE_UPDATABLE_INVALID;
+
+ Status = FmpDeviceGetSize (&FwSize);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a(): FmpDeviceGetSize() failed with: %r\n", __func__, Status));
+ return Status;
+ }
+
+ if (ImageSize != FwSize) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a(): image size (0x%x) doesn't match firmware size (0x%x)\n",
+ __func__,
+ ImageSize,
+ FwSize
+ ));
+ return EFI_ABORTED;
+ }
+
+ Status = SmmStoreLibGetBlockSize (&BlockSize);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a(): SmmStoreLibGetBlockSize() failed with: %r\n", __func__, Status));
+ return Status;
+ }
+
+ if (FwSize % BlockSize != 0) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a(): firmware size (0x%x) is not a multiple of block size (0x%x)\n",
+ __func__,
+ FwSize,
+ BlockSize
+ ));
+ return EFI_ABORTED;
+ }
+
+ *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;
+ *ImageUpdatable = IMAGE_UPDATABLE_VALID;
+ return EFI_SUCCESS;
+}
+
+/**
+ Updates a firmware device with a new firmware image. This function returns
+ EFI_UNSUPPORTED if the firmware image is not updatable. If the firmware image
+ is updatable, the function should perform the following minimal validations
+ before proceeding to do the firmware image update.
+ - Validate that the image is a supported image for this firmware device.
+ Return EFI_ABORTED if the image is not supported. Additional details
+ on why the image is not a supported image may be returned in AbortReason.
+ - Validate the data from VendorCode if is not NULL. Firmware image
+ validation must be performed before VendorCode data validation.
+ VendorCode data is ignored or considered invalid if image validation
+ fails. Return EFI_ABORTED if the VendorCode data is invalid.
+
+ VendorCode enables vendor to implement vendor-specific firmware image update
+ policy. Null if the caller did not specify the policy or use the default
+ policy. As an example, vendor can implement a policy to allow an option to
+ force a firmware image update when the abort reason is due to the new firmware
+ image version is older than the current firmware image version or bad image
+ checksum. Sensitive operations such as those wiping the entire firmware image
+ and render the device to be non-functional should be encoded in the image
+ itself rather than passed with the VendorCode. AbortReason enables vendor to
+ have the option to provide a more detailed description of the abort reason to
+ the caller.
+
+ @param[in] Image Points to the new firmware image.
+ @param[in] ImageSize Size, in bytes, of the new firmware image.
+ @param[in] VendorCode This enables vendor to implement vendor-specific
+ firmware image update policy. NULL indicates
+ the caller did not specify the policy or use the
+ default policy.
+ @param[in] Progress A function used to report the progress of
+ updating the firmware device with the new
+ firmware image.
+ @param[in] CapsuleFwVersion The version of the new firmware image from the
+ update capsule that provided the new firmware
+ image.
+ @param[out] AbortReason A pointer to a pointer to a Null-terminated
+ Unicode string providing more details on an
+ aborted operation. The buffer is allocated by
+ this function with
+ EFI_BOOT_SERVICES.AllocatePool(). It is the
+ caller's responsibility to free this buffer with
+ EFI_BOOT_SERVICES.FreePool().
+
+ @retval EFI_SUCCESS The firmware device was successfully updated
+ with the new firmware image.
+ @retval EFI_ABORTED The operation is aborted. Additional details
+ are provided in AbortReason.
+ @retval EFI_INVALID_PARAMETER The Image was NULL.
+ @retval EFI_UNSUPPORTED The operation is not supported.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceSetImage (
+ IN CONST VOID *Image,
+ IN UINTN ImageSize,
+ IN CONST VOID *VendorCode OPTIONAL,
+ IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress OPTIONAL,
+ IN UINT32 CapsuleFwVersion,
+ OUT CHAR16 **AbortReason
+ )
+{
+ UINT32 LastAttemptStatus;
+
+ return FmpDeviceSetImageWithStatus (
+ Image,
+ ImageSize,
+ VendorCode,
+ Progress,
+ CapsuleFwVersion,
+ AbortReason,
+ &LastAttemptStatus
+ );
+}
+
+/**
+ Advances progress of the operation by a single step, converts the steps to
+ percents and invokes a callback if there is one.
+
+ @param[in] Callback External callback for progress reporting
+ or NULL if there is none.
+ @param[in] TotalSteps Total number of flashing steps.
+ @param[in, out] Step Current step number.
+ @param[in, out] ShouldReportProgress A flag indicating whether progress needs
+ to be reported.
+**/
+STATIC
+VOID
+IncrementProgress (
+ IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Callback OPTIONAL,
+ IN UINTN TotalSteps,
+ IN OUT UINTN *Step,
+ IN OUT BOOLEAN *ShouldReportProgress
+ )
+{
+ EFI_STATUS Status;
+ UINTN Progress;
+
+ if (!*ShouldReportProgress) {
+ return;
+ }
+
+ if (Callback == NULL) {
+ *ShouldReportProgress = FALSE;
+ return;
+ }
+
+ ++*Step;
+ Progress = (*Step * 100) / TotalSteps;
+
+ //
+ // Value of 0 means "progress reporting is not supported", so avoid using it.
+ //
+ if (Progress == 0) {
+ Progress = 1;
+ }
+
+ Status = Callback (Progress);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_WARN, "%a(): progress callback failed with: %r\n", __func__, Status));
+ *ShouldReportProgress = FALSE;
+ }
+}
+
+/**
+ This code finds variable in storage blocks (Volatile or Non-Volatile).
+
+ @param[in] VariableName Name of Variable to be found.
+ @param[in] VendorGuid Variable vendor GUID.
+ @param[out] Attributes Attribute value of the variable found.
+ @param[in, out] DataSize Size of Data found. If size is less than the
+ data, this value contains the required size.
+ @param[out] Data Data pointer.
+
+ @return EFI_INVALID_PARAMETER Invalid parameter.
+ @return EFI_SUCCESS Find the specified variable.
+ @return EFI_NOT_FOUND Not found.
+ @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GetVariableHook (
+ IN CHAR16 *VariableName,
+ IN EFI_GUID *VendorGuid,
+ OUT UINT32 *Attributes OPTIONAL,
+ IN OUT UINTN *DataSize,
+ OUT VOID *Data
+ )
+{
+ DEBUG ((DEBUG_INFO, "%a(): %g:%S\n", __func__, VendorGuid, VariableName));
+ return EFI_NOT_AVAILABLE_YET;
+}
+
+/**
+ This code Finds the Next available variable.
+
+ @param[in, out] VariableNameSize Size of the variable name.
+ @param[in, out] VariableName Pointer to variable name.
+ @param[in, out] VendorGuid Variable Vendor Guid.
+
+ @return EFI_INVALID_PARAMETER Invalid parameter.
+ @return EFI_SUCCESS Find the specified variable.
+ @return EFI_NOT_FOUND Not found.
+ @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GetNextVariableNameHook (
+ IN OUT UINTN *VariableNameSize,
+ IN OUT CHAR16 *VariableName,
+ IN OUT EFI_GUID *VendorGuid
+ )
+{
+ DEBUG ((DEBUG_INFO, "%a(): %g:%S\n", __func__, VendorGuid, VariableName));
+ return EFI_NOT_AVAILABLE_YET;
+}
+
+/**
+ This code sets variable in storage blocks (Volatile or Non-Volatile).
+
+ @param[in] VariableName Name of Variable to be found.
+ @param[in] VendorGuid Variable vendor GUID.
+ @param[in] Attributes Attribute value of the variable found
+ @param[in] DataSize Size of Data found. If size is less than the
+ data, this value contains the required size.
+ @param[in] Data Data pointer.
+
+ @return EFI_INVALID_PARAMETER Invalid parameter.
+ @return EFI_SUCCESS Set successfully.
+ @return EFI_OUT_OF_RESOURCES Resource not enough to set variable.
+ @return EFI_NOT_FOUND Not found.
+ @return EFI_WRITE_PROTECTED Variable is read-only.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+SetVariableHook (
+ IN CHAR16 *VariableName,
+ IN EFI_GUID *VendorGuid,
+ IN UINT32 Attributes,
+ IN UINTN DataSize,
+ IN VOID *Data
+ )
+{
+ DEBUG ((
+ DEBUG_INFO,
+ "%a(): %g:%S, 0x%x bytes, 0x%x\n",
+ __func__,
+ VendorGuid,
+ VariableName,
+ DataSize,
+ Attributes
+ ));
+ return EFI_NOT_AVAILABLE_YET;
+}
+
+/**
+ This code returns information about the EFI variables.
+
+ @param[in] Attributes Attributes bitmask to specify the type of variables
+ on which to return information.
+ @param[out] MaximumVariableStorageSize Pointer to the maximum size of the storage space available
+ for the EFI variables associated with the attributes specified.
+ @param[out] RemainingVariableStorageSize Pointer to the remaining size of the storage space available
+ for EFI variables associated with the attributes specified.
+ @param[out] MaximumVariableSize Pointer to the maximum size of an individual EFI variables
+ associated with the attributes specified.
+
+ @return EFI_SUCCESS Query successfully.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+QueryVariableInfoHook (
+ IN UINT32 Attributes,
+ OUT UINT64 *MaximumVariableStorageSize,
+ OUT UINT64 *RemainingVariableStorageSize,
+ OUT UINT64 *MaximumVariableSize
+ )
+{
+ DEBUG ((DEBUG_INFO, "%a(): 0x%x\n", __func__, Attributes));
+ return EFI_NOT_AVAILABLE_YET;
+}
+
+/**
+ Updates a firmware device with a new firmware image. This function returns
+ EFI_UNSUPPORTED if the firmware image is not updatable. If the firmware image
+ is updatable, the function should perform the following minimal validations
+ before proceeding to do the firmware image update.
+ - Validate that the image is a supported image for this firmware device.
+ Return EFI_ABORTED if the image is not supported. Additional details
+ on why the image is not a supported image may be returned in AbortReason.
+ - Validate the data from VendorCode if is not NULL. Firmware image
+ validation must be performed before VendorCode data validation.
+ VendorCode data is ignored or considered invalid if image validation
+ fails. Return EFI_ABORTED if the VendorCode data is invalid.
+
+ VendorCode enables vendor to implement vendor-specific firmware image update
+ policy. Null if the caller did not specify the policy or use the default
+ policy. As an example, vendor can implement a policy to allow an option to
+ force a firmware image update when the abort reason is due to the new firmware
+ image version is older than the current firmware image version or bad image
+ checksum. Sensitive operations such as those wiping the entire firmware image
+ and render the device to be non-functional should be encoded in the image
+ itself rather than passed with the VendorCode. AbortReason enables vendor to
+ have the option to provide a more detailed description of the abort reason to
+ the caller.
+
+ @param[in] Image Points to the new firmware image.
+ @param[in] ImageSize Size, in bytes, of the new firmware image.
+ @param[in] VendorCode This enables vendor to implement vendor-specific
+ firmware image update policy. NULL indicates
+ the caller did not specify the policy or use the
+ default policy.
+ @param[in] Progress A function used to report the progress of
+ updating the firmware device with the new
+ firmware image.
+ @param[in] CapsuleFwVersion The version of the new firmware image from the
+ update capsule that provided the new firmware
+ image.
+ @param[out] AbortReason A pointer to a pointer to a Null-terminated
+ Unicode string providing more details on an
+ aborted operation. The buffer is allocated by
+ this function with
+ EFI_BOOT_SERVICES.AllocatePool(). It is the
+ caller's responsibility to free this buffer with
+ EFI_BOOT_SERVICES.FreePool().
+ @param[out] LastAttemptStatus A pointer to a UINT32 that holds the last attempt
+ status to report back to the ESRT table in case
+ of error. This value will only be checked when this
+ function returns an error.
+
+ The return status code must fall in the range of
+ LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE to
+ LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE.
+
+ If the value falls outside this range, it will be converted
+ to LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL.
+
+ @retval EFI_SUCCESS The firmware device was successfully updated
+ with the new firmware image.
+ @retval EFI_ABORTED The operation is aborted. Additional details
+ are provided in AbortReason.
+ @retval EFI_INVALID_PARAMETER The Image was NULL.
+ @retval EFI_UNSUPPORTED The operation is not supported.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceSetImageWithStatus (
+ IN CONST VOID *Image,
+ IN UINTN ImageSize,
+ IN CONST VOID *VendorCode OPTIONAL,
+ IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress OPTIONAL,
+ IN UINT32 CapsuleFwVersion,
+ OUT CHAR16 **AbortReason,
+ OUT UINT32 *LastAttemptStatus
+ )
+{
+ EFI_STATUS Status;
+ UINTN BlockSize;
+ UINTN BlockCount;
+ UINTN Block;
+ UINTN NumBytes;
+ UINTN TotalSteps;
+ UINTN Step;
+ BOOLEAN ShouldReportProgress;
+ VOID *ReadBuffer;
+ CONST UINT8 *WriteNext;
+
+ *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
+
+ //
+ // FmpDeviceCheckImageWithStatus() has already validated the image, so not
+ // repeating the checks. However, could move the checks here to be able to
+ // report abort reason which can't be done in FmpDeviceCheckImageWithStatus().
+ //
+
+ Status = SmmStoreLibGetBlockSize (&BlockSize);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a(): SmmStoreLibGetBlockSize() failed with: %r\n",
+ __func__,
+ Status
+ ));
+ return Status;
+ }
+
+ ReadBuffer = AllocatePool (BlockSize);
+ if (ReadBuffer == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a(): failed to allocate read buffer\n", __func__));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ BlockCount = ImageSize / BlockSize;
+ DEBUG ((
+ DEBUG_INFO,
+ "%a(): 0x%x blocks of 0x%x bytes\n",
+ __func__,
+ BlockCount,
+ BlockSize
+ ));
+
+ ShouldReportProgress = TRUE;
+ TotalSteps = BlockCount * 2; // Erase and write of each block.
+ Step = 0;
+ WriteNext = Image;
+
+ for (Block = 0; Block < BlockCount; Block++, WriteNext += BlockSize) {
+ //
+ // Save the flash and time by only writing a block if new contents differs
+ // from the old one.
+ //
+ // This is an optimization, so ignore read errors (if they are indicative of
+ // a serious problem, erasing or writing will fail as well).
+ //
+ NumBytes = BlockSize;
+ Status = SmmStoreLibReadAnyBlock (Block, 0, &NumBytes, ReadBuffer);
+ if (!EFI_ERROR (Status) && (NumBytes == BlockSize)) {
+ if (CompareMem (ReadBuffer, WriteNext, BlockSize) == 0) {
+ // Erase step.
+ IncrementProgress (Progress, TotalSteps, &Step, &ShouldReportProgress);
+ // Write step.
+ IncrementProgress (Progress, TotalSteps, &Step, &ShouldReportProgress);
+ continue;
+ }
+ }
+
+ Status = SmmStoreLibEraseAnyBlock (Block);
+ if (EFI_ERROR (Status)) {
+ goto IoError;
+ }
+
+ IncrementProgress (Progress, TotalSteps, &Step, &ShouldReportProgress);
+
+ NumBytes = BlockSize;
+ Status = SmmStoreLibWriteAnyBlock (Block, 0, &NumBytes, (VOID *)WriteNext);
+ if (EFI_ERROR (Status) || (NumBytes != BlockSize)) {
+ goto IoError;
+ }
+
+ IncrementProgress (Progress, TotalSteps, &Step, &ShouldReportProgress);
+ }
+
+ FreePool (ReadBuffer);
+
+ *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;
+
+ //
+ // Updating the firmware on system flash overwrites SMMSTORE region which
+ // backs up EFI variables of the running firmware. At this point both SMI
+ // handler from coreboot and variable services of EDK can be mistaken in
+ // their assumptions about the location, size and contents of the region.
+ // Accessing flash where SMMSTORE used to be can lead to unexpected results
+ // including corruption of the new image outside of its SMMSTORE. Switch to
+ // the use of stubs for dealing with EFI variables that do nothing.
+ //
+ // New firmware will not report result of flashing in any way unless some
+ // kind of communication mechanism is implemented for this purpose.
+ //
+ // If there was an error, it's unclear whether these stubs would be of any
+ // help, so they are employed only on successful flashing.
+ //
+
+ gRT->GetVariable = GetVariableHook;
+ gRT->GetNextVariableName = GetNextVariableNameHook;
+ gRT->SetVariable = SetVariableHook;
+ gRT->QueryVariableInfo = QueryVariableInfoHook;
+
+ gRT->Hdr.CRC32 = 0;
+ gBS->CalculateCrc32 (
+ (UINT8 *)&gRT->Hdr,
+ gRT->Hdr.HeaderSize,
+ &gRT->Hdr.CRC32
+ );
+
+ return EFI_SUCCESS;
+
+IoError:
+ //
+ // There are several reasons why we might end up in here:
+ // - an actual issue with the flash chip which is unlikely to allow any
+ // recovery via software
+ // - a bug in SMMSTORE SMI handler of coreboot
+ // - any bug of the firmware or its configuration which has resulted in the
+ // system not being ready for a full flash update
+ //
+ // The last case can be caused at least by:
+ // - coreboot not lifting flash protections
+ // - Intel ME not being disabled
+ //
+ // This situation is atypical and can leave the flash chip in an
+ // unpredictable state which can be fully functional, unbootable or something
+ // in between.
+ //
+ // Being optimistic that the firmware is still functional, we're leaving
+ // variable services available under assumption that SMMSTORE region hasn't
+ // been moved withing the firmware image (most updates don't modify layout).
+ // Note that the store can even be recreated on the next boot depending on
+ // the damage that it has sustained. It's also possible that we hit
+ // protected range and nothing of any worth has been modified.
+ //
+ // If the firmware ends up unbootable, then, in general, external flashing
+ // via a programmer needs to be employed to recover the device.
+ //
+ FreePool (ReadBuffer);
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a(): flashing has failed at block 0x%x/0x%x: %r\n",
+ __func__,
+ Block,
+ BlockCount,
+ EFI_DEVICE_ERROR
+ ));
+ return EFI_DEVICE_ERROR;
+}
+
+/**
+ Lock the firmware device that contains a firmware image. Once a firmware
+ device is locked, any attempts to modify the firmware image contents in the
+ firmware device must fail.
+
+ @note It is recommended that all firmware devices support a lock method to
+ prevent modifications to a stored firmware image.
+
+ @note A firmware device lock mechanism is typically only cleared by a full
+ system reset (not just sleep state/low power mode).
+
+ @retval EFI_SUCCESS The firmware device was locked.
+ @retval EFI_UNSUPPORTED The firmware device does not support locking
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceLock (
+ VOID
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+/**
+ Constructor that performs required initialization.
+
+ @param ImageHandle The image handle of the process.
+ @param SystemTable The EFI System Table pointer.
+
+ @retval EFI_SUCCESS Initialization was successful.
+**/
+EFI_STATUS
+EFIAPI
+FmpDeviceSmmLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ SmmStoreLibInitialize ();
+ return EFI_SUCCESS;
+}
diff --git a/UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.inf b/UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.inf
new file mode 100644
index 0000000..893e361
--- /dev/null
+++ b/UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.inf
@@ -0,0 +1,47 @@
+## @file
+# Provides firmware device specific services to support updates of a firmware
+# image stored in a firmware device.
+#
+# Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
+# Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2025, 3mdeb Sp. z o.o. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = FmpDeviceSmmLib
+ MODULE_UNI_FILE = FmpDeviceSmmLib.uni
+ FILE_GUID = 979CF0F8-7214-4D12-89CE-F32112ED71C6
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = FmpDeviceLib|DXE_DRIVER UEFI_DRIVER
+ CONSTRUCTOR = FmpDeviceSmmLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+ FmpDeviceSmmLib.c
+
+[LibraryClasses]
+ BaseMemoryLib
+ DebugLib
+ HobLib
+ MemoryAllocationLib
+ SmmStoreLib
+ UefiBootServicesTableLib
+ UefiRuntimeServicesTableLib
+
+[Packages]
+ UefiPayloadPkg/UefiPayloadPkg.dec
+ FmpDevicePkg/FmpDevicePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+
+[Guids]
+ gEfiFirmwareInfoHobGuid
diff --git a/UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.uni b/UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.uni
new file mode 100644
index 0000000..37efb8c
--- /dev/null
+++ b/UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.uni
@@ -0,0 +1,13 @@
+// /** @file
+// Provides firmware device specific services to support updates of a firmware
+// image stored in a firmware device.
+//
+// Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Provides firmware device specific services to support updates of a firmware image stored in a firmware device."
+
+#string STR_MODULE_DESCRIPTION #language en-US "Provides firmware device specific services to support updates of a firmware image stored in a firmware device."
diff --git a/UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c b/UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c
index c2d4437..0e3bf29 100644
--- a/UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c
+++ b/UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c
@@ -558,6 +558,39 @@ BuildFv3Hob (
}
/**
+ Builds a Capsule Volume HOB.
+
+ This function builds a Capsule Volume HOB.
+ It can only be invoked during PEI phase;
+ for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
+
+ If the platform does not support Capsule Volume HOBs, then ASSERT().
+ If there is no additional space for HOB creation, then ASSERT().
+
+ @param BaseAddress The base address of the Capsule Volume.
+ @param Length The size of the Capsule Volume in bytes.
+
+**/
+VOID
+EFIAPI
+BuildCvHob (
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length
+ )
+{
+ EFI_HOB_UEFI_CAPSULE *Hob;
+
+ Hob = CreateHob (EFI_HOB_TYPE_UEFI_CAPSULE, sizeof (EFI_HOB_UEFI_CAPSULE));
+ ASSERT (Hob != NULL);
+ if (Hob == NULL) {
+ return;
+ }
+
+ Hob->BaseAddress = BaseAddress;
+ Hob->Length = Length;
+}
+
+/**
Builds a HOB for the CPU.
This function builds a HOB for the CPU.
diff --git a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
index a4a49da..0788d85 100644
--- a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
+++ b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
@@ -226,6 +226,7 @@ PlatformBootManagerBeforeConsole (
VOID
)
{
+ EFI_STATUS Status;
EFI_INPUT_KEY Enter;
EFI_INPUT_KEY CustomKey;
EFI_INPUT_KEY Down;
@@ -264,6 +265,17 @@ PlatformBootManagerBeforeConsole (
EfiBootManagerAddKeyOptionVariable (NULL, (UINT16)BootOption.OptionNumber, 0, &Down, NULL);
//
+ // Process update capsules that don't contain embedded drivers.
+ //
+ if (GetBootModeHob () == BOOT_ON_FLASH_UPDATE) {
+ // TODO: when enabling capsule support for laptops, add a battery check here
+ Status = ProcessCapsules ();
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a(): ProcessCapsule() failed with: %r\n", __func__, Status));
+ }
+ }
+
+ //
// Install ready to lock.
// This needs to be done before option rom dispatched.
//
@@ -312,6 +324,33 @@ PlatformBootManagerAfterConsole (
EfiBootManagerRefreshAllBootOption ();
//
+ // Active BOOT_ON_FLASH_UPDATE mode means that at least one capsule has been
+ // discovered by a bootloader and passed for further processing into EDK which
+ // created EFI_HOB_TYPE_UEFI_CAPSULE HOB(s).
+ //
+ // Process update capsules that weren't processed on the first call to
+ // ProcessCapsules() in PlatformBootManagerBeforeConsole().
+ //
+ if (GetBootModeHob () == BOOT_ON_FLASH_UPDATE) {
+ // TODO: when enabling capsule support for laptops, add a battery check here
+ Status = ProcessCapsules ();
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a(): ProcessCapsule() failed with: %r\n", __func__, Status));
+ }
+
+ //
+ // Reset the system to disable SMI handler in order to exclude the
+ // possibility of it being used outside of the firmware.
+ //
+ // In practice, this will rarely execute because even the first
+ // ProcessCapsules() invocation might do a reset if all capsules were
+ // processed and at least one of them needed a reset. This is just to catch
+ // a case when this doesn't happen which is possible on error.
+ //
+ gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
+ }
+
+ //
// Register UEFI Shell
//
PlatformRegisterFvBootOption (&gUefiShellFileGuid, L"UEFI Shell", LOAD_OPTION_ACTIVE);
diff --git a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.h b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.h
index 2110997..88a83af 100644
--- a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.h
+++ b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.h
@@ -26,6 +26,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/PrintLib.h>
#include <Library/DxeServicesLib.h>
#include <Library/BootLogoLib.h>
+#include <Library/CapsuleLib.h>
+#include <Library/HobLib.h>
#include <Protocol/SmmAccess2.h>
typedef struct {
diff --git a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
index 987c730..e803cc8 100644
--- a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+++ b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -47,6 +47,8 @@
HiiLib
PrintLib
PlatformHookLib
+ CapsuleLib
+ HobLib
[Guids]
gEfiEndOfDxeEventGroupGuid
diff --git a/UefiPayloadPkg/Library/SblParseLib/SblParseLib.c b/UefiPayloadPkg/Library/SblParseLib/SblParseLib.c
index de139a5..7cc615a 100644
--- a/UefiPayloadPkg/Library/SblParseLib/SblParseLib.c
+++ b/UefiPayloadPkg/Library/SblParseLib/SblParseLib.c
@@ -307,3 +307,41 @@ ParseSmmStoreInfo (
{
return RETURN_NOT_FOUND;
}
+
+/**
+ Parse firmware information passed in by bootloader
+
+ @param FwInfo Information about current firmware.
+
+ @retval RETURN_INVALID_PARAMETER The parameter is NULL.
+ @retval RETURN_SUCCESS Successfully parsed information.
+ @retval RETURN_NOT_FOUND The information is missing.
+**/
+RETURN_STATUS
+EFIAPI
+ParseFirmwareInfo (
+ OUT FIRMWARE_INFO *FwInfo
+ )
+{
+ return RETURN_NOT_FOUND;
+}
+
+/**
+ Parse update capsules passed in by bootloader
+
+ @param CapsuleCallback The callback routine invoked for each capsule.
+
+ @retval RETURN_SUCCESS Successfully parsed capsules.
+ @retval RETURN_NOT_FOUND Failed to look up the information.
+**/
+RETURN_STATUS
+EFIAPI
+ParseCapsules (
+ IN BL_CAPSULE_CALLBACK CapsuleCallback
+ )
+{
+ //
+ // Treat not supporting this function like reporting zero capsules.
+ //
+ return RETURN_SUCCESS;
+}
diff --git a/UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf b/UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf
index f83a10c..15fd1ca 100644
--- a/UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf
+++ b/UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf
@@ -41,6 +41,8 @@
gEfiGraphicsInfoHobGuid
gEfiGraphicsDeviceInfoHobGuid
gUniversalPayloadPciRootBridgeInfoGuid
+ gUniversalPayloadSmbiosTableGuid
+ gUniversalPayloadAcpiTableGuid
[Pcd]
gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter
diff --git a/UefiPayloadPkg/Library/SmmStoreLib/SmmStore.c b/UefiPayloadPkg/Library/SmmStoreLib/SmmStore.c
index 690bae0..f232b12 100644
--- a/UefiPayloadPkg/Library/SmmStoreLib/SmmStore.c
+++ b/UefiPayloadPkg/Library/SmmStoreLib/SmmStore.c
@@ -1,6 +1,7 @@
/** @file SmmStore.c
Copyright (c) 2022, 9elements GmbH<BR>
+ Copyright (c) 2025, 3mdeb Sp. z o.o.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -139,33 +140,31 @@ SmmStoreLibGetMmioAddress (
}
/**
- Read from SmmStore
+ Read a flash block. The whole flash is represented as a
+ sequence of blocks.
@param[in] Lba The starting logical block index to read from.
@param[in] Offset Offset into the block at which to begin reading.
@param[in] NumBytes On input, indicates the requested read size. On
- output, indicates the actual number of bytes read.
+ output, indicates the actual number of bytes read
@param[in] Buffer Pointer to the buffer to read into.
+ @param[in] ReadCmd Read command to use.
+
+ @note Validation of mSmmStoreInfo and Lba must be done by the calling code.
**/
+STATIC
EFI_STATUS
-SmmStoreLibRead (
+ReadBlock (
IN EFI_LBA Lba,
IN UINTN Offset,
IN UINTN *NumBytes,
- IN UINT8 *Buffer
+ IN UINT8 *Buffer,
+ IN UINT8 ReadCmd
)
{
EFI_STATUS Status;
- if (mSmmStoreInfo == NULL) {
- return EFI_NO_MEDIA;
- }
-
- if (Lba >= mSmmStoreInfo->NumBlocks) {
- return EFI_INVALID_PARAMETER;
- }
-
if (((*NumBytes + Offset) > mSmmStoreInfo->BlockSize) ||
((*NumBytes + Offset) > mSmmStoreInfo->ComBufferSize))
{
@@ -176,7 +175,7 @@ SmmStoreLibRead (
mArgComBuf->Read.BufOffset = Offset;
mArgComBuf->Read.BlockId = Lba;
- Status = CallSmm (mSmmStoreInfo->ApmCmd, SMMSTORE_CMD_RAW_READ, mArgComBufPhys);
+ Status = CallSmm (mSmmStoreInfo->ApmCmd, ReadCmd, mArgComBufPhys);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -187,17 +186,17 @@ SmmStoreLibRead (
}
/**
- Write to SmmStore
+ Read from SmmStore
- @param[in] Lba The starting logical block index to write to.
- @param[in] Offset Offset into the block at which to begin writing.
- @param[in] NumBytes On input, indicates the requested write size. On
- output, indicates the actual number of bytes written.
- @param[in] Buffer Pointer to the data to write.
+ @param[in] Lba The starting logical block index to read from.
+ @param[in] Offset Offset into the block at which to begin reading.
+ @param[in] NumBytes On input, indicates the requested read size. On
+ output, indicates the actual number of bytes read.
+ @param[in] Buffer Pointer to the buffer to read into.
**/
EFI_STATUS
-SmmStoreLibWrite (
+SmmStoreLibRead (
IN EFI_LBA Lba,
IN UINTN Offset,
IN UINTN *NumBytes,
@@ -212,6 +211,59 @@ SmmStoreLibWrite (
return EFI_INVALID_PARAMETER;
}
+ return ReadBlock (Lba, Offset, NumBytes, Buffer, SMMSTORE_CMD_RAW_READ);
+}
+
+/**
+ Read from an arbitrary flash location. The whole flash is represented as a
+ sequence of blocks.
+
+ @param[in] Lba The starting logical block index to read from.
+ @param[in] Offset Offset into the block at which to begin reading.
+ @param[in] NumBytes On input, indicates the requested read size. On
+ output, indicates the actual number of bytes read
+ @param[in] Buffer Pointer to the buffer to read into.
+
+**/
+EFI_STATUS
+SmmStoreLibReadAnyBlock (
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN *NumBytes,
+ IN UINT8 *Buffer
+ )
+{
+ if (mSmmStoreInfo == NULL) {
+ return EFI_NO_MEDIA;
+ }
+
+ return ReadBlock (Lba, Offset, NumBytes, Buffer, SMMSTORE_CMD_USE_FULL_FLASH | SMMSTORE_CMD_RAW_READ);
+}
+
+/**
+ Write a flash block. The whole flash is represented as a
+ sequence of blocks.
+
+ @param[in] Lba The starting logical block index to write to.
+ @param[in] Offset Offset into the block at which to begin writing.
+ @param[in] NumBytes On input, indicates the requested write size. On
+ output, indicates the actual number of bytes written
+ @param[in] Buffer Pointer to the data to write.
+ @param[in] WriteCmd Write command to use.
+
+ @note Validation of mSmmStoreInfo and Lba must be done by the calling code.
+
+**/
+STATIC
+EFI_STATUS
+WriteBlock (
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN *NumBytes,
+ IN UINT8 *Buffer,
+ IN UINT8 WriteCmd
+ )
+{
if (((*NumBytes + Offset) > mSmmStoreInfo->BlockSize) ||
((*NumBytes + Offset) > mSmmStoreInfo->ComBufferSize))
{
@@ -224,7 +276,62 @@ SmmStoreLibWrite (
CopyMem ((VOID *)(UINTN)(mSmmStoreInfo->ComBuffer + Offset), Buffer, *NumBytes);
- return CallSmm (mSmmStoreInfo->ApmCmd, SMMSTORE_CMD_RAW_WRITE, mArgComBufPhys);
+ return CallSmm (mSmmStoreInfo->ApmCmd, WriteCmd, mArgComBufPhys);
+}
+
+/**
+ Write to SmmStore
+
+ @param[in] Lba The starting logical block index to write to.
+ @param[in] Offset Offset into the block at which to begin writing.
+ @param[in] NumBytes On input, indicates the requested write size. On
+ output, indicates the actual number of bytes written.
+ @param[in] Buffer Pointer to the data to write.
+
+**/
+EFI_STATUS
+SmmStoreLibWrite (
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN *NumBytes,
+ IN UINT8 *Buffer
+ )
+{
+ if (mSmmStoreInfo == NULL) {
+ return EFI_NO_MEDIA;
+ }
+
+ if (Lba >= mSmmStoreInfo->NumBlocks) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return WriteBlock (Lba, Offset, NumBytes, Buffer, SMMSTORE_CMD_RAW_WRITE);
+}
+
+/**
+ Write to an arbitrary flash location. The whole flash is represented as a
+ sequence of blocks.
+
+ @param[in] Lba The starting logical block index to write to.
+ @param[in] Offset Offset into the block at which to begin writing.
+ @param[in] NumBytes On input, indicates the requested write size. On
+ output, indicates the actual number of bytes written
+ @param[in] Buffer Pointer to the data to write.
+
+**/
+EFI_STATUS
+SmmStoreLibWriteAnyBlock (
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN *NumBytes,
+ IN UINT8 *Buffer
+ )
+{
+ if (mSmmStoreInfo == NULL) {
+ return EFI_NO_MEDIA;
+ }
+
+ return WriteBlock (Lba, Offset, NumBytes, Buffer, SMMSTORE_CMD_USE_FULL_FLASH | SMMSTORE_CMD_RAW_WRITE);
}
/**
@@ -252,6 +359,31 @@ SmmStoreLibEraseBlock (
}
/**
+ Erase an arbitrary block of the flash. The whole flash is represented as a
+ sequence of blocks.
+
+ @param Lba The logical block index to erase.
+
+**/
+EFI_STATUS
+SmmStoreLibEraseAnyBlock (
+ IN EFI_LBA Lba
+ )
+{
+ if (mSmmStoreInfo == NULL) {
+ return EFI_NO_MEDIA;
+ }
+
+ mArgComBuf->Clear.BlockId = Lba;
+
+ return CallSmm (
+ mSmmStoreInfo->ApmCmd,
+ SMMSTORE_CMD_USE_FULL_FLASH | SMMSTORE_CMD_RAW_CLEAR,
+ mArgComBufPhys
+ );
+}
+
+/**
Fixup internal data so that EFI can be called in virtual mode.
Converts any pointers in lib to virtual mode. This function is meant to
be invoked on gEfiEventVirtualAddressChangeGuid event when the library is
diff --git a/UefiPayloadPkg/Library/SmmStoreLib/SmmStore.h b/UefiPayloadPkg/Library/SmmStoreLib/SmmStore.h
index d91b8e1..11a42a7 100644
--- a/UefiPayloadPkg/Library/SmmStoreLib/SmmStore.h
+++ b/UefiPayloadPkg/Library/SmmStoreLib/SmmStore.h
@@ -1,6 +1,7 @@
/** @file SmmStore.h
Copyright (c) 2022, 9elements GmbH<BR>
+ Copyright (c) 2025, 3mdeb Sp. z o.o.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -19,6 +20,9 @@
#define SMMSTORE_CMD_RAW_WRITE 6
#define SMMSTORE_CMD_RAW_CLEAR 7
+/* Used by capsule updates as a standalone command or modifier to v2 commands */
+#define SMMSTORE_CMD_USE_FULL_FLASH 0x80
+
/*
* This allows the payload to store raw data in the flash regions.
* This can be used by a FaultTolerantWrite implementation, that uses at least
diff --git a/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.c b/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.c
new file mode 100644
index 0000000..05b66c0
--- /dev/null
+++ b/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.c
@@ -0,0 +1,459 @@
+/** @file
+ Implementation of the gEfiPciPlatformProtocol to support loading
+ PCI Option ROMs when full PCI enumeration is skipped.
+
+Copyright (c) 2025, 9elements GmbH. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+
+**/
+
+#include "PciPlatformDxe.h"
+#include <Bus/Pci/PciBusDxe/PciBus.h>
+#include <Bus/Pci/PciBusDxe/PciOptionRomSupport.h>
+
+EFI_STATUS
+EFIAPI
+PciPlatformNotify (
+ IN EFI_PCI_PLATFORM_PROTOCOL *This,
+ IN EFI_HANDLE HostBridge,
+ IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase,
+ IN EFI_PCI_EXECUTION_PHASE ExecPhase
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+EFI_STATUS
+EFIAPI
+PciPlatformPrepController (
+ IN EFI_PCI_PLATFORM_PROTOCOL *This,
+ IN EFI_HANDLE HostBridge,
+ IN EFI_HANDLE RootBridge,
+ IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress,
+ IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase,
+ IN EFI_PCI_EXECUTION_PHASE ExecPhase
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+/**
+ Gets the PCI device's option ROM from a platform-specific location.
+
+ The GetPciRom() function gets the PCI device's option ROM from a platform-specific location.
+ The option ROM will be loaded into memory. This member function is used to return an image
+ that is packaged as a PCI 2.2 option ROM. The image may contain both legacy and EFI option
+ ROMs. See the UEFI 2.0 Specification for details. This member function can be used to return
+ option ROM images for embedded controllers. Option ROMs for embedded controllers are typically
+ stored in platform-specific storage, and this member function can retrieve it from that storage
+ and return it to the PCI bus driver. The PCI bus driver will call this member function before
+ scanning the ROM that is attached to any controller, which allows to scan the PCI card for
+ ROM image and retrieve it.
+
+ @param[in] This The pointer to the EFI_PCI_PLATFORM_PROTOCOL instance.
+ @param[in] PciHandle The handle of the PCI device.
+ @param[out] RomImage If the call succeeds, the pointer to the pointer to the option ROM image.
+ Otherwise, this field is undefined. The memory for RomImage is allocated
+ by EFI_PCI_PLATFORM_PROTOCOL.GetPciRom() using the EFI Boot Service AllocatePool().
+ It is the caller's responsibility to free the memory using the EFI Boot Service
+ FreePool(), when the caller is done with the option ROM.
+ @param[out] RomSize If the call succeeds, a pointer to the size of the option ROM size. Otherwise,
+ this field is undefined.
+
+ @retval EFI_SUCCESS The option ROM was available for this device and loaded into memory.
+ @retval EFI_NOT_FOUND No option ROM was available for this device.
+ @retval EFI_OUT_OF_RESOURCES No memory was available to load the option ROM.
+ @retval EFI_DEVICE_ERROR An error occurred in obtaining the option ROM.
+
+**/
+EFI_STATUS
+EFIAPI
+PciGetPciRom (
+ IN CONST EFI_PCI_PLATFORM_PROTOCOL *This,
+ IN EFI_HANDLE PciHandle,
+ OUT VOID **RomImage,
+ OUT UINTN *RomSize
+ )
+{
+ EFI_STATUS Status;
+ IN EFI_PCI_IO_PROTOCOL *PciIo;
+ UINTN PciSegment;
+ UINTN PciBus;
+ UINTN PciDevice;
+ UINTN PciFunction;
+ UINTN RomBarIndex;
+ UINT32 Buffer;
+ UINT32 AllOnes;
+ PCI_IO_DEVICE *PciIoDevice;
+ UINT8 Indicator;
+ UINT16 OffsetPcir;
+ UINT32 RomBarOffset;
+ UINT32 RomBar;
+ BOOLEAN FirstCheck;
+ UINT64 RomImageSize;
+ UINT32 LegacyImageLength;
+ UINT8 *RomInMemory;
+ UINT8 CodeType;
+ PCI_EXPANSION_ROM_HEADER RomHeader;
+ PCI_DATA_STRUCTURE RomPcir;
+
+ //
+ // Check to see if RomImage is NULL
+ //
+ if (RomImage == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Check to see if RomSize is NULL
+ //
+ if (RomSize == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *RomImage = NULL;
+ *RomSize = 0;
+
+ Status = gBS->HandleProtocol (
+ PciHandle,
+ &gEfiPciIoProtocolGuid,
+ (VOID **)&PciIo
+ );
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to open gEfiPciIoProtocolGuid\n", __func__));
+ return EFI_UNSUPPORTED;
+ }
+
+ PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (PciIo);
+
+ //
+ // Get the location of the PCI device
+ //
+ PciIo->GetLocation (
+ PciIo,
+ &PciSegment,
+ &PciBus,
+ &PciDevice,
+ &PciFunction
+ );
+
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: PCI @ [%02x|%02x|%02x|%02x] Searching Option ROM...\n",
+ __func__,
+ PciSegment,
+ PciBus,
+ PciDevice,
+ PciFunction
+ ));
+
+ //
+ // Default ROM is at 0x30
+ //
+ RomBarIndex = PCI_EXPANSION_ROM_BASE;
+
+ if (IS_PCI_BRIDGE (&PciIoDevice->Pci)) {
+ //
+ // If is ppb ROM is at 0x38
+ //
+ RomBarIndex = PCI_BRIDGE_ROMBAR;
+ }
+
+ //
+ // Backup ROM BAR
+ //
+ Status = PciIo->Pci.Read (
+ PciIo,
+ EfiPciWidthUint32,
+ RomBarIndex,
+ 1,
+ &Buffer
+ );
+ if (EFI_ERROR (Status)) {
+ goto CloseAndReturn;
+ }
+
+ //
+ // The bit0 is 0 to prevent the enabling of the Rom address decoder
+ //
+ AllOnes = 0xfffffffe;
+
+ Status = PciIo->Pci.Write (
+ PciIo,
+ EfiPciWidthUint32,
+ RomBarIndex,
+ 1,
+ &AllOnes
+ );
+ if (EFI_ERROR (Status)) {
+ goto CloseAndReturn;
+ }
+
+ //
+ // Read back
+ //
+ Status = PciIo->Pci.Read (
+ PciIo,
+ EfiPciWidthUint32,
+ RomBarIndex,
+ 1,
+ &AllOnes
+ );
+ if (EFI_ERROR (Status)) {
+ goto CloseAndReturn;
+ }
+
+ //
+ // Bits [1, 10] are reserved
+ //
+ AllOnes &= 0xFFFFF800;
+ if ((AllOnes == 0) || (AllOnes == 0xFFFFF800)) {
+ DEBUG ((DEBUG_VERBOSE, "%a: No Option ROM found\n", __func__));
+ return EFI_NOT_FOUND;
+ }
+
+ *RomSize = (~AllOnes) + 1;
+
+ //
+ // Restore BAR and enable it
+ //
+ RomBar = Buffer | 1;
+ Status = PciIo->Pci.Write (
+ PciIo,
+ EfiPciWidthUint32,
+ RomBarIndex,
+ 1,
+ &RomBar
+ );
+ if (EFI_ERROR (Status)) {
+ goto CloseAndReturn;
+ }
+
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: ROM BAR enabled at 0x%x with size %d\n",
+ __func__,
+ Buffer &~1,
+ *RomSize
+ ));
+
+ //
+ // Set pointer to ROM BAR
+ //
+ RomBar = Buffer & 0xFFFFF800;
+
+ RomBarOffset = RomBar;
+ FirstCheck = TRUE;
+ LegacyImageLength = 0;
+ RomImageSize = 0;
+
+ //
+ // Expect to find a PCI ROM header at offset 0.
+ // The ROM header contains a pointer to the PCI Data structure.
+ // The PCI Data structure holds the image size.
+ // At the end of the image another Option ROM might be found
+ // (one for legacy BIOS and one for EFI).
+ //
+ do {
+ Status = PciIoDevice->PciRootBridgeIo->Mem.Read (
+ PciIoDevice->PciRootBridgeIo,
+ EfiPciWidthUint8,
+ RomBarOffset,
+ sizeof (PCI_EXPANSION_ROM_HEADER),
+ (UINT8 *)&RomHeader
+ );
+ if (EFI_ERROR (Status)) {
+ goto RestoreBar;
+ }
+
+ if (RomHeader.Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {
+ RomBarOffset = RomBarOffset + 512;
+ if (FirstCheck) {
+ break;
+ } else {
+ RomImageSize = RomImageSize + 512;
+ continue;
+ }
+ }
+
+ FirstCheck = FALSE;
+ OffsetPcir = RomHeader.PcirOffset;
+ //
+ // If the pointer to the PCI Data Structure is invalid, no further images can be located.
+ // The PCI Data Structure must be DWORD aligned.
+ //
+ if ((OffsetPcir == 0) ||
+ ((OffsetPcir & 3) != 0) ||
+ (RomImageSize + OffsetPcir + sizeof (PCI_DATA_STRUCTURE) > *RomSize))
+ {
+ break;
+ }
+
+ Status = PciIoDevice->PciRootBridgeIo->Mem.Read (
+ PciIoDevice->PciRootBridgeIo,
+ EfiPciWidthUint8,
+ RomBarOffset + OffsetPcir,
+ sizeof (PCI_DATA_STRUCTURE),
+ (UINT8 *)&RomPcir
+ );
+ if (EFI_ERROR (Status)) {
+ goto RestoreBar;
+ }
+
+ //
+ // If a valid signature is not present in the PCI Data Structure, no further images can be located.
+ //
+ if (RomPcir.Signature != PCI_DATA_STRUCTURE_SIGNATURE) {
+ break;
+ }
+
+ if (RomImageSize + RomPcir.ImageLength * 512 > *RomSize) {
+ break;
+ }
+
+ if (RomPcir.CodeType == PCI_CODE_TYPE_PCAT_IMAGE) {
+ CodeType = PCI_CODE_TYPE_PCAT_IMAGE;
+ LegacyImageLength = ((UINT32)((EFI_LEGACY_EXPANSION_ROM_HEADER *)&RomHeader)->Size512) * 512;
+ }
+
+ Indicator = RomPcir.Indicator;
+ RomImageSize = RomImageSize + RomPcir.ImageLength * 512;
+ RomBarOffset = RomBarOffset + RomPcir.ImageLength * 512;
+ } while (((Indicator & 0x80) == 0x00) && ((RomBarOffset - RomBar) < *RomSize));
+
+ //
+ // Some Legacy Cards do not report the correct ImageLength so used the maximum
+ // of the legacy length and the PCIR Image Length
+ //
+ if (CodeType == PCI_CODE_TYPE_PCAT_IMAGE) {
+ RomImageSize = MAX (RomImageSize, LegacyImageLength);
+ }
+
+ if (RomImageSize > 0) {
+ //
+ // Allocate buffer to return
+ //
+ RomInMemory = (UINT8 *)AllocatePool ((UINT32)RomImageSize);
+ if (RomInMemory == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto RestoreBar;
+ }
+
+ //
+ // Copy ROM image into memory
+ //
+ Status = PciIoDevice->PciRootBridgeIo->Mem.Read (
+ PciIoDevice->PciRootBridgeIo,
+ EfiPciWidthUint8,
+ RomBar,
+ (UINT32)RomImageSize,
+ RomInMemory
+ );
+ if (EFI_ERROR (Status)) {
+ goto RestoreBar;
+ }
+ } else {
+ Status = EFI_NOT_FOUND;
+ goto RestoreBar;
+ }
+
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: PCI @ [%02x|%02x|%02x|%02x]: Found Option ROM at 0x%x, length 0x%x\n",
+ __func__,
+ PciSegment,
+ PciBus,
+ PciDevice,
+ PciFunction,
+ RomBar,
+ RomImageSize
+ ));
+
+ PciIoDevice->EmbeddedRom = TRUE;
+ PciIoDevice->PciIo.RomSize = RomImageSize;
+ PciIoDevice->PciIo.RomImage = RomInMemory;
+
+ *RomImage = RomInMemory;
+ *RomSize = RomImageSize;
+
+ Status = EFI_SUCCESS;
+
+RestoreBar:
+ //
+ // Restore BAR
+ //
+ PciIo->Pci.Write (
+ PciIo,
+ EfiPciWidthUint32,
+ RomBarIndex,
+ 1,
+ &RomBar
+ );
+
+CloseAndReturn:
+ //
+ // Close the I/O Abstraction(s) used to perform the supported test
+ //
+ gBS->CloseProtocol (
+ PciHandle,
+ &gEfiPciIoProtocolGuid,
+ PciIo,
+ PciHandle
+ );
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+PciGetPlatformPolicy (
+ IN CONST EFI_PCI_PLATFORM_PROTOCOL *This,
+ OUT EFI_PCI_PLATFORM_POLICY *PciPolicy
+ )
+{
+ if (PciPolicy == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *PciPolicy = 0;
+
+ return EFI_SUCCESS;
+}
+
+EFI_PCI_PLATFORM_PROTOCOL mPciPlatformProtocol = {
+ PciPlatformNotify,
+ PciPlatformPrepController,
+ PciGetPlatformPolicy,
+ PciGetPciRom,
+};
+
+/**
+ The Entry Point for Option ROM driver.
+
+ It installs DriverBinding.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+InstallPciPlatformProtocol (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ EFI_HANDLE DriverHandle = NULL;
+
+ Status = gBS->InstallProtocolInterface (
+ &DriverHandle,
+ &gEfiPciPlatformProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mPciPlatformProtocol
+ );
+
+ return Status;
+}
diff --git a/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.h b/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.h
new file mode 100644
index 0000000..322fc5f
--- /dev/null
+++ b/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.h
@@ -0,0 +1,20 @@
+/** @file
+ Header file for a gEfiPciPlatformProtocol driver.
+
+Copyright (c) 2025, 9elements GmbH. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+
+**/
+
+#ifndef _PCI_PLATFORM_DXE_H_
+#define _PCI_PLATFORM_DXE_H_
+#include <PiDxe.h>
+
+#include <IndustryStandard/Pci.h>
+#include <IndustryStandard/Acpi.h>
+#include <IndustryStandard/Pci22.h>
+#include <Protocol/PciIo.h>
+#include <Protocol/PciPlatform.h>
+
+#endif
diff --git a/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf b/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf
new file mode 100644
index 0000000..9e0ba63
--- /dev/null
+++ b/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf
@@ -0,0 +1,43 @@
+## @file
+# This driver produces gEfiPciPlatformProtocol to load PCI Option ROMs
+#
+# Copyright (c) 2025, 9elements Agency GmbH
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = PciPlatformDxe
+ FILE_GUID = 86D58F7B-6E7C-401F-BDD4-E32E6D582AAD
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = InstallPciPlatformProtocol
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
+#
+
+[Sources.common]
+ PciPlatformDxe.h
+ PciPlatformDxe.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UefiPayloadPkg/UefiPayloadPkg.dec
+
+[LibraryClasses]
+ UefiDriverEntryPoint
+ DxeServicesTableLib
+ DebugLib
+ MemoryAllocationLib
+ BaseMemoryLib
+
+[Protocols]
+ gEfiPciPlatformProtocolGuid ## PRODUCES
+ gEfiPciIoProtocolGuid ## COMSUMES
diff --git a/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c b/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c
index 3391da8..9840368 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c
@@ -358,7 +358,7 @@ HandOffToDxeCore (
DEBUG ((
DEBUG_INFO,
- "%a() Stack Base: 0x%lx, Stack Size: 0x%x\n",
+ "%a() Stack Base: 0x%llx, Stack Size: 0x%x\n",
__func__,
BaseOfStack,
STACK_SIZE
diff --git a/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFuncFit.c b/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFuncFit.c
index d0f3143..867765f 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFuncFit.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFuncFit.c
@@ -356,7 +356,7 @@ HandOffToDxeCore (
DEBUG ((
DEBUG_INFO,
- "%a() Stack Base: 0x%lx, Stack Size: 0x%x\n",
+ "%a() Stack Base: 0x%llx, Stack Size: 0x%x\n",
__func__,
BaseOfStack,
STACK_SIZE
diff --git a/UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFunc.c b/UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFunc.c
index ecd2493..ff4841b 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFunc.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFunc.c
@@ -60,7 +60,7 @@ HandOffToDxeCore (
//
UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE);
- DEBUG ((DEBUG_INFO, "DXE Core new stack at %x, stack pointer at %x\n", BaseOfStack, TopOfStack));
+ DEBUG ((DEBUG_INFO, "DXE Core new stack at %llx, stack pointer at %llx\n", BaseOfStack, TopOfStack));
//
// Transfer the control to the entry point of DxeCore.
diff --git a/UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFuncFit.c b/UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFuncFit.c
index e74c4fa..e92c4c3 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFuncFit.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFuncFit.c
@@ -1,8 +1,8 @@
/** @file
- x64-specifc functionality for DxeLoad.
+ RISC-V specific functionality for DxeLoad.
-Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
+ Copyright (C) 2023, Rivos Inc. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
index 468c366..343676d 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
@@ -342,6 +342,8 @@ BuildHobFromBl (
ACPI_BOARD_INFO *AcpiBoardInfo;
SMMSTORE_INFO SmmStoreInfo;
SMMSTORE_INFO *NewSmmStoreInfo;
+ FIRMWARE_INFO FirmwareInfo;
+ FIRMWARE_INFO *NewFirmwareInfo;
EFI_PEI_GRAPHICS_INFO_HOB GfxInfo;
EFI_PEI_GRAPHICS_INFO_HOB *NewGfxInfo;
EFI_PEI_GRAPHICS_DEVICE_INFO_HOB GfxDeviceInfo;
@@ -400,6 +402,17 @@ BuildHobFromBl (
}
//
+ // Create guid hob for firmware information
+ //
+ Status = ParseFirmwareInfo (&FirmwareInfo);
+ if (!EFI_ERROR (Status)) {
+ NewFirmwareInfo = BuildGuidHob (&gEfiFirmwareInfoHobGuid, sizeof (FirmwareInfo));
+ ASSERT (NewFirmwareInfo != NULL);
+ CopyMem (NewFirmwareInfo, &FirmwareInfo, sizeof (FirmwareInfo));
+ DEBUG ((DEBUG_INFO, "Created firmware info hob\n"));
+ }
+
+ //
// Create SmBios table Hob
//
SmBiosTableHob = BuildGuidHob (&gUniversalPayloadSmbiosTableGuid, sizeof (UNIVERSAL_PAYLOAD_SMBIOS_TABLE));
@@ -457,6 +470,15 @@ BuildHobFromBl (
return Status;
}
+ //
+ // Import update capsules, if there are any.
+ //
+ Status = ParseCapsules (BuildCvHob);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Error when importing update capsules, Status = %r\n", Status));
+ return Status;
+ }
+
return EFI_SUCCESS;
}
@@ -512,6 +534,7 @@ _ModuleEntryPoint (
EFI_PEI_HOB_POINTERS Hob;
SERIAL_PORT_INFO SerialPortInfo;
UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *UniversalSerialPort;
+ EFI_HOB_HANDOFF_INFO_TABLE *HobInfo;
Status = PcdSet64S (PcdBootloaderParameter, BootloaderParameter);
ASSERT_EFI_ERROR (Status);
@@ -535,7 +558,7 @@ _ModuleEntryPoint (
HobMemTop = HobMemBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);
- HobConstructor ((VOID *)MemBase, (VOID *)HobMemTop, (VOID *)HobMemBase, (VOID *)HobMemTop);
+ HobInfo = HobConstructor ((VOID *)MemBase, (VOID *)HobMemTop, (VOID *)HobMemBase, (VOID *)HobMemTop);
//
// Build serial port info
@@ -592,6 +615,13 @@ _ModuleEntryPoint (
DEBUG ((DEBUG_INFO, "DxeCoreEntryPoint = 0x%lx\n", DxeCoreEntryPoint));
//
+ // Switch to update mode if there is at least one capsule.
+ //
+ if (GetFirstHob (EFI_HOB_TYPE_UEFI_CAPSULE) != NULL) {
+ HobInfo->BootMode = BOOT_ON_FLASH_UPDATE;
+ }
+
+ //
// Mask off all legacy 8259 interrupt sources
//
IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, 0xFF);
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
index b6fe5ef..87e1564 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
@@ -38,6 +38,7 @@
#include <UniversalPayload/SerialPortInfo.h>
#include <UniversalPayload/DeviceTree.h>
#include <Guid/PcdDataBaseSignatureGuid.h>
+#include <Guid/FirmwareInfoGuid.h>
#include <Guid/SmmStoreInfoGuid.h>
#define LEGACY_8259_MASK_REGISTER_MASTER 0x21
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
index 702be0d..8795f1b 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
@@ -71,6 +71,7 @@
gUniversalPayloadSmbiosTableGuid
gUniversalPayloadAcpiTableGuid
gUniversalPayloadSerialPortInfoGuid
+ gEfiFirmwareInfoHobGuid
gEfiSmmStoreInfoHobGuid
[FeaturePcd.IA32]
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayloadPkg.dec
index 491e542..51ddcc5 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dec
+++ b/UefiPayloadPkg/UefiPayloadPkg.dec
@@ -46,6 +46,7 @@
gUplPciSegmentInfoHobGuid = {0x37e0e3a9, 0xb3fc, 0x4e85, { 0x97, 0x2b, 0x40, 0x82, 0xfc, 0x79, 0x40, 0x54 } }
gEfiSmmStoreInfoHobGuid = { 0xf585ca19, 0x881b, 0x44fb, { 0x3f, 0x3d, 0x81, 0x89, 0x7c, 0x57, 0xbb, 0x01 } }
+ gEfiFirmwareInfoHobGuid = { 0xe0653829, 0x274e, 0x4b1e, { 0x87, 0x2d, 0xa2, 0x20, 0xf5, 0xaf, 0x8f, 0x3d } }
[Ppis]
gEfiPayLoadHobBasePpiGuid = { 0xdbe23aa1, 0xa342, 0x4b97, {0x85, 0xb6, 0xb2, 0x26, 0xf1, 0x61, 0x73, 0x89} }
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 34de87f..db4875e 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -43,8 +43,17 @@
DEFINE USE_CBMEM_FOR_CONSOLE = FALSE
DEFINE BOOTSPLASH_IMAGE = FALSE
DEFINE NVME_ENABLE = TRUE
- DEFINE CAPSULE_SUPPORT = FALSE
DEFINE LOCKBOX_SUPPORT = FALSE
+ DEFINE LOAD_OPTION_ROMS = FALSE
+
+ #
+ # Capsule updates
+ #
+ # CAPSULE_MAIN_FW_GUID specifies GUID to be used by FmpDxe when
+ # CAPSULE_SUPPORT is set to TRUE
+ #
+ DEFINE CAPSULE_SUPPORT = FALSE
+ DEFINE CAPSULE_MAIN_FW_GUID =
#
# Crypto Support
@@ -277,8 +286,23 @@
UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf
!if $(CAPSULE_SUPPORT) == TRUE
- CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
+ CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf
+ !if $(BOOTSPLASH_IMAGE)
+ # Note, however, that DisplayUpdateProgressLibGraphics aborts firmware
+ # update if GOP is missing, so text progress works in more environments.
+ DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdateProgressLibGraphics.inf
+ !else
+ DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdateProgressLibText.inf
+ !endif
+ # If there are no specific checks to do, null-library suffices
+ CapsuleUpdatePolicyLib|FmpDevicePkg/Library/CapsuleUpdatePolicyLibNull/CapsuleUpdatePolicyLibNull.inf
+ FmpAuthenticationLib|SecurityPkg/Library/FmpAuthenticationLibPkcs7/FmpAuthenticationLibPkcs7.inf
+ FmpDependencyCheckLib|FmpDevicePkg/Library/FmpDependencyCheckLib/FmpDependencyCheckLib.inf
+ # No need to save/restore FMP dependencies unless they are utilized
+ FmpDependencyDeviceLib|FmpDevicePkg/Library/FmpDependencyDeviceLibNull/FmpDependencyDeviceLibNull.inf
+ FmpDependencyLib|FmpDevicePkg/Library/FmpDependencyLib/FmpDependencyLib.inf
+ FmpPayloadHeaderLib|FmpDevicePkg/Library/FmpPayloadHeaderLibV1/FmpPayloadHeaderLibV1.inf
!else
CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
!endif
@@ -345,7 +369,6 @@
!if $(VARIABLE_SUPPORT) == "EMU"
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
!elseif $(VARIABLE_SUPPORT) == "SMMSTORE"
- SmmStoreLib|UefiPayloadPkg/Library/SmmStoreLib/SmmStoreLib.inf
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
!elseif $(VARIABLE_SUPPORT) == "SPI"
PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecureLibNull.inf
@@ -353,6 +376,9 @@
S3BootScriptLib|MdePkg/Library/BaseS3BootScriptLibNull/BaseS3BootScriptLibNull.inf
MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf
!endif
+!if $(VARIABLE_SUPPORT) == "SMMSTORE" || ($(CAPSULE_SUPPORT) && $(BOOTLOADER) == "COREBOOT")
+ SmmStoreLib|UefiPayloadPkg/Library/SmmStoreLib/SmmStoreLib.inf
+!endif
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
@@ -495,6 +521,9 @@
!if $(PERFORMANCE_MEASUREMENT_ENABLE)
PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
!endif
+!if $(CAPSULE_SUPPORT) == TRUE
+ CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
+!endif
[LibraryClasses.common.UEFI_DRIVER,LibraryClasses.common.UEFI_APPLICATION]
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
@@ -553,6 +582,8 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol|TRUE
gEfiMdeModulePkgTokenSpaceGuid.PcdHiiOsRuntimeSupport|FALSE
gEfiMdeModulePkgTokenSpaceGuid.PcdPciDegradeResourceForOptionRom|FALSE
+ ## Whether capsules are allowed to persist across reset.
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSupportUpdateCapsuleReset|$(CAPSULE_SUPPORT)
[PcdsFeatureFlag.X64]
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|TRUE
@@ -591,6 +622,9 @@
gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1800000
+ ## Whether FMP capsules are enabled.
+ gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleFmpSupport|$(CAPSULE_SUPPORT)
+
!if $(CRYPTO_PROTOCOL_SUPPORT) == TRUE
!if $(CRYPTO_DRIVER_EXTERNAL_SUPPORT) == FALSE
gEfiCryptoPkgTokenSpaceGuid.PcdCryptoServiceFamilyEnable.HmacSha256.Family | PCD_CRYPTO_SERVICE_ENABLE_FAMILY
@@ -943,6 +977,31 @@
NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf
}
MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf
+!if $(CAPSULE_SUPPORT) == TRUE
+ # Build FmpDxe meant for the inclusion into an update capsule as an embedded driver.
+ FmpDevicePkg/FmpDxe/FmpDxe.inf {
+ <Defines>
+ # FmpDxe interprets its FILE_GUID as firmware GUID. This allows including
+ # multiple FmpDxe instances along each other targeting different
+ # components.
+ FILE_GUID = $(CAPSULE_MAIN_FW_GUID)
+ <PcdsFixedAtBuild>
+ gFmpDevicePkgTokenSpaceGuid.PcdFmpDeviceImageIdName|L"System Firmware"
+ # Public certificate used for validation of UEFI capsules
+ #
+ # See BaseTools/Source/Python/Pkcs7Sign/Readme.md for more details on such
+ # PCDs and include files.
+ !include BaseTools/Source/Python/Pkcs7Sign/TestRoot.cer.gFmpDevicePkgTokenSpaceGuid.PcdFmpDevicePkcs7CertBufferXdr.inc
+ <LibraryClasses>
+!if $(BOOTLOADER) == "COREBOOT"
+ FmpDeviceLib|UefiPayloadPkg/Library/FmpDeviceSmmLib/FmpDeviceSmmLib.inf
+!else
+ # TODO: provide platform-specific implementation of firmware flashing
+ FmpDeviceLib|FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLibNull.inf
+!endif
+ }
+ MdeModulePkg/Universal/EsrtDxe/EsrtDxe.inf
+!endif
MdeModulePkg/Universal/Metronome/Metronome.inf
@@ -1036,6 +1095,13 @@
!endif
#
+ # Support for loading Option ROMs from PCI-Express devices
+ #
+!if $(LOAD_OPTION_ROMS) == TRUE
+ UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf
+!endif
+
+ #
# Usb Support
#
MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf
diff --git a/UefiPayloadPkg/UefiPayloadPkg.fdf b/UefiPayloadPkg/UefiPayloadPkg.fdf
index 4264fa9..28afae7 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.fdf
+++ b/UefiPayloadPkg/UefiPayloadPkg.fdf
@@ -292,6 +292,10 @@ INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
!endif
INF UefiPayloadPkg/GraphicsOutputDxe/GraphicsOutputDxe.inf
+!if $(LOAD_OPTION_ROMS) == TRUE
+INF UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf
+!endif
+
#
# SCSI/ATA/IDE/DISK Support
#
@@ -365,6 +369,13 @@ INF ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.inf
INF ShellPkg/Application/Shell/Shell.inf
!endif
+#
+# Capsules
+#
+!if $(CAPSULE_SUPPORT) == TRUE
+INF MdeModulePkg/Universal/EsrtDxe/EsrtDxe.inf
+!endif
+
!if $(UNIVERSAL_PAYLOAD) == TRUE
!if $(SECURE_BOOT_ENABLE) == TRUE
diff --git a/pip-requirements.txt b/pip-requirements.txt
index d2365e7..ec5502e 100644
--- a/pip-requirements.txt
+++ b/pip-requirements.txt
@@ -17,3 +17,5 @@ edk2-pytool-extensions~=0.29.11
antlr4-python3-runtime==4.9
lcov-cobertura==2.1.1
regex==2024.11.6
+pylibfdt==1.7.2.post1
+pefile