diff options
Diffstat (limited to 'MdeModulePkg')
168 files changed, 5515 insertions, 7535 deletions
diff --git a/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c b/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c index 9e905e5..24f9f1e 100644 --- a/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c +++ b/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c @@ -452,7 +452,7 @@ UiCreateResetMenu ( StartOpCodeHandle,
FRONT_PAGE_KEY_RESET,
STRING_TOKEN (STR_RESET_STRING),
- STRING_TOKEN (STR_RESET_STRING),
+ STRING_TOKEN (STR_RESET_STRING_HELP),
EFI_IFR_FLAG_CALLBACK,
0
);
diff --git a/MdeModulePkg/Application/UiApp/FrontPageStrings.uni b/MdeModulePkg/Application/UiApp/FrontPageStrings.uni index a0ab9ab..bd6e377 100644 --- a/MdeModulePkg/Application/UiApp/FrontPageStrings.uni +++ b/MdeModulePkg/Application/UiApp/FrontPageStrings.uni @@ -51,9 +51,9 @@ #string STR_EMPTY_STRING #language en-US ""
#language fr-FR ""
#string STR_RESET_STRING #language en-US "Reset"
- #language fr-FR "Reset"
-#string STR_RESET_STRING_HELP #language en-US "Reset the current setting."
- #language fr-FR "Reset the current setting."
+ #language fr-FR "Réinitialiser"
+#string STR_RESET_STRING_HELP #language en-US "Cold reset (reboots the computer)."
+ #language fr-FR "Réinitialisation à froid (redémarre l'ordinateur)."
#string STR_CUSTOMIZE_BANNER_LINE4_LEFT #language en-US ""
#language fr-FR ""
#string STR_CUSTOMIZE_BANNER_LINE4_RIGHT #language en-US ""
diff --git a/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c b/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c index 3f5462c..8e21fd1 100644 --- a/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c +++ b/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c @@ -6,6 +6,7 @@ This PPI can be consumed by PEIM which produce gEfiPeiDeviceRecoveryModulePpiGui for Atapi CD ROM device.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -1198,7 +1199,7 @@ CheckErrorStatus ( }
/**
- Idendify Atapi devices.
+ Identify Atapi devices.
@param[in] AtapiBlkIoDev A pointer to atapi block IO device.
@param[in] DevicePosition An integer to signify device position.
diff --git a/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.h b/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.h index abc1dc6..4cff117 100644 --- a/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.h +++ b/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.h @@ -2,6 +2,7 @@ Private Include file for IdeBus PEIM.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -524,7 +525,7 @@ CheckErrorStatus ( );
/**
- Idendify Atapi devices.
+ Identify Atapi devices.
@param[in] AtapiBlkIoDev A pointer to atapi block IO device.
@param[in] DevicePosition An integer to signify device position.
diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c index 337b209..a21c94c 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c @@ -49,7 +49,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_PCI_HOTPLUG_REQUEST_PROTOCOL mPciHotPlugReque Installs driver module protocols and. Creates virtual device handles for ConIn,
ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,
Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.
- Installs Graphics Output protocol and/or UGA Draw protocol if needed.
+ Installs Graphics Output protocol if needed.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c index 6594b8e..5c4b215 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c @@ -59,19 +59,30 @@ PciDevicePresent ( Pci
);
- if (!EFI_ERROR (Status) && ((Pci->Hdr).VendorId != 0xffff)) {
- //
- // Read the entire config header for the device
- //
- Status = PciRootBridgeIo->Pci.Read (
- PciRootBridgeIo,
- EfiPciWidthUint32,
- Address,
- sizeof (PCI_TYPE00) / sizeof (UINT32),
- Pci
- );
+ //
+ // The host bridge may be programmed to accept Configuration Retry Status (CRS). If the PCI device
+ // is slow, and CRS is enabled, the VendorId may read as 0x0001 when not ready.
+ // This behavior is defined in PCI spec that VendorId is 0x0001.
+ // PCI EXPRESS BASE SPECIFICATION, REV. 3.1 section 2.3.1.
+ // Skip the device, as all the other data read will be invalid.
+ //
+ if (!EFI_ERROR (Status)) {
+ if (((Pci->Hdr).VendorId != 0xffff) && ((Pci->Hdr).VendorId != 0x0001)) {
+ //
+ // Read the entire config header for the device
+ //
+ Status = PciRootBridgeIo->Pci.Read (
+ PciRootBridgeIo,
+ EfiPciWidthUint32,
+ Address,
+ sizeof (PCI_TYPE00) / sizeof (UINT32),
+ Pci
+ );
- return EFI_SUCCESS;
+ return EFI_SUCCESS;
+ } else if ((Pci->Hdr).VendorId == 0x0001) {
+ DEBUG ((DEBUG_WARN, "CRS response detected. Devices that return a CRS response during enumeration are currently ignored\n"));
+ }
}
return EFI_NOT_FOUND;
@@ -2628,7 +2639,7 @@ PciEnumeratorLight ( **/
EFI_STATUS
PciGetBusRange (
- IN EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR **Descriptors,
+ IN OUT EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR **Descriptors,
OUT UINT16 *MinBus,
OUT UINT16 *MaxBus,
OUT UINT16 *BusRange
diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.h b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.h index 7daa6e0..89df989 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.h +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.h @@ -409,7 +409,7 @@ PciEnumeratorLight ( **/
EFI_STATUS
PciGetBusRange (
- IN EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR **Descriptors,
+ IN OUT EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR **Descriptors,
OUT UINT16 *MinBus,
OUT UINT16 *MaxBus,
OUT UINT16 *BusRange
diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c index 84fc016..28840de 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c @@ -1100,6 +1100,7 @@ PciScanBus ( EFI_HPC_STATE State;
UINT64 PciAddress;
EFI_HPC_PADDING_ATTRIBUTES Attributes;
+ VOID *DescriptorsBuffer;
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors;
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *NextDescriptors;
UINT16 BusRange;
@@ -1108,16 +1109,17 @@ PciScanBus ( UINT32 TempReservedBusNum;
BOOLEAN IsAriEnabled;
- PciRootBridgeIo = Bridge->PciRootBridgeIo;
- SecondBus = 0;
- Register = 0;
- State = 0;
- Attributes = (EFI_HPC_PADDING_ATTRIBUTES)0;
- BusRange = 0;
- BusPadding = FALSE;
- PciDevice = NULL;
- PciAddress = 0;
- IsAriEnabled = FALSE;
+ PciRootBridgeIo = Bridge->PciRootBridgeIo;
+ SecondBus = 0;
+ Register = 0;
+ State = 0;
+ Attributes = (EFI_HPC_PADDING_ATTRIBUTES)0;
+ BusRange = 0;
+ BusPadding = FALSE;
+ PciDevice = NULL;
+ PciAddress = 0;
+ IsAriEnabled = FALSE;
+ DescriptorsBuffer = NULL;
for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) {
if (!IsAriEnabled) {
@@ -1257,7 +1259,7 @@ PciScanBus ( PciDevice->DevicePath,
PciAddress,
&State,
- (VOID **)&Descriptors,
+ &DescriptorsBuffer,
&Attributes
);
@@ -1265,6 +1267,7 @@ PciScanBus ( return Status;
}
+ Descriptors = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)DescriptorsBuffer;
BusRange = 0;
NextDescriptors = Descriptors;
Status = PciGetBusRange (
@@ -1274,7 +1277,9 @@ PciScanBus ( &BusRange
);
- FreePool (Descriptors);
+ FreePool (DescriptorsBuffer);
+ DescriptorsBuffer = NULL;
+ Descriptors = NULL;
if (!EFI_ERROR (Status)) {
BusPadding = TRUE;
diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c index bd5ace1..8bb6c12 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c @@ -371,7 +371,7 @@ ContainEfiImage ( @param RomBase Base address of Option Rom.
@retval EFI_OUT_OF_RESOURCES No enough memory to hold image.
- @retval EFI_SUCESS Successfully loaded Option Rom.
+ @retval EFI_SUCCESS Successfully loaded Option Rom.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.h b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.h index 16998a4..0ddad05 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.h +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.h @@ -91,7 +91,7 @@ GetOpRomInfo ( @param RomBase Base address of Option Rom.
@retval EFI_OUT_OF_RESOURCES No enough memory to hold image.
- @retval EFI_SUCESS Successfully loaded Option Rom.
+ @retval EFI_SUCCESS Successfully loaded Option Rom.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c index 2e7497a..9e8a7f4 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c @@ -8,6 +8,7 @@ Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
+ Copyright (C) 2023, Apple Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -59,6 +60,7 @@ DumpCapabilityReg ( DEBUG ((DEBUG_INFO, " SDR50 Support %a\n", Capability->Sdr50 ? "TRUE" : "FALSE"));
DEBUG ((DEBUG_INFO, " SDR104 Support %a\n", Capability->Sdr104 ? "TRUE" : "FALSE"));
DEBUG ((DEBUG_INFO, " DDR50 Support %a\n", Capability->Ddr50 ? "TRUE" : "FALSE"));
+ DEBUG ((DEBUG_INFO, " UHS-II Support %a\n", Capability->UhsII ? "TRUE" : "FALSE"));
DEBUG ((DEBUG_INFO, " Driver Type A %a\n", Capability->DriverTypeA ? "TRUE" : "FALSE"));
DEBUG ((DEBUG_INFO, " Driver Type C %a\n", Capability->DriverTypeC ? "TRUE" : "FALSE"));
DEBUG ((DEBUG_INFO, " Driver Type D %a\n", Capability->DriverTypeD ? "TRUE" : "FALSE"));
@@ -72,6 +74,8 @@ DumpCapabilityReg ( DEBUG ((DEBUG_INFO, " SDR50 Tuning %a\n", Capability->TuningSDR50 ? "TRUE" : "FALSE"));
DEBUG ((DEBUG_INFO, " Retuning Mode Mode %d\n", Capability->RetuningMod + 1));
DEBUG ((DEBUG_INFO, " Clock Multiplier M = %d\n", Capability->ClkMultiplier + 1));
+ DEBUG ((DEBUG_INFO, " ADMA3 Support %a\n", Capability->Adma3 ? "TRUE" : "FALSE"));
+ DEBUG ((DEBUG_INFO, " 1.8V VDD2 %a\n", Capability->Vdd2Voltage18 ? "TRUE" : "FALSE"));
DEBUG ((DEBUG_INFO, " HS 400 %a\n", Capability->Hs400 ? "TRUE" : "FALSE"));
return;
}
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h index 9115577..e436a7d 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h @@ -2,10 +2,13 @@ Provides some data structure definitions used by the SD/MMC host controller driver.
-Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
+ Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
+ Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (C) 2023, Apple Inc. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+ @par Specification Reference:
+ - SD Host Controller Simplified Specification, Version 4.20, July 25, 2018
**/
#ifndef _SD_MMC_PCI_HCI_H_
@@ -174,7 +177,7 @@ typedef struct { UINT32 Sdr50 : 1; // bit 32
UINT32 Sdr104 : 1; // bit 33
UINT32 Ddr50 : 1; // bit 34
- UINT32 Reserved3 : 1; // bit 35
+ UINT32 UhsII : 1; // bit 35
UINT32 DriverTypeA : 1; // bit 36
UINT32 DriverTypeC : 1; // bit 37
UINT32 DriverTypeD : 1; // bit 38
@@ -184,7 +187,10 @@ typedef struct { UINT32 TuningSDR50 : 1; // bit 45
UINT32 RetuningMod : 2; // bit 46:47
UINT32 ClkMultiplier : 8; // bit 48:55
- UINT32 Reserved5 : 7; // bit 56:62
+ UINT32 Reserved5 : 3; // bit 56:58
+ UINT32 Adma3 : 1; // bit 59
+ UINT32 Vdd2Voltage18 : 1; // bit 60
+ UINT32 Reserved6 : 2; // bit 61:62
UINT32 Hs400 : 1; // bit 63
} SD_MMC_HC_SLOT_CAP;
diff --git a/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c b/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c index 66915cc..8e6bd1b 100644 --- a/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c +++ b/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c @@ -875,7 +875,7 @@ Uhci2BulkTransfer ( //
// Link the TDs to bulk queue head. According to the platfore
- // defintion of UHCI_NO_BW_RECLAMATION, BulkQh is either configured
+ // definition of UHCI_NO_BW_RECLAMATION, BulkQh is either configured
// to do full speed bandwidth reclamation or not.
//
BulkQh = Uhc->BulkQh;
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/Spi/SpiBus/SpiBus.c b/MdeModulePkg/Bus/Spi/SpiBus/SpiBus.c index b183ca1..61ddbe5 100644 --- a/MdeModulePkg/Bus/Spi/SpiBus/SpiBus.c +++ b/MdeModulePkg/Bus/Spi/SpiBus/SpiBus.c @@ -329,8 +329,17 @@ Transaction ( ((SpiChip->SpiHc->Attributes & HC_SUPPORTS_WRITE_THEN_READ_OPERATIONS) != HC_SUPPORTS_WRITE_THEN_READ_OPERATIONS))
{
// Convert to full duplex transaction
- DummyReadBuffer = AllocateZeroPool (WriteBytes);
- DummyWriteBuffer = AllocateZeroPool (ReadBytes);
+ DummyReadBuffer = AllocateZeroPool (WriteBytes);
+ if (DummyReadBuffer == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ DummyWriteBuffer = AllocateZeroPool (ReadBytes);
+ if (DummyWriteBuffer == NULL) {
+ FreePool (DummyReadBuffer);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
SpiChip->BusTransaction.ReadBuffer = DummyReadBuffer;
SpiChip->BusTransaction.ReadBytes = WriteBytes;
diff --git a/MdeModulePkg/Bus/Spi/SpiBus/SpiBusDxe.c b/MdeModulePkg/Bus/Spi/SpiBus/SpiBusDxe.c index cd0a2c9..a38db47 100644 --- a/MdeModulePkg/Bus/Spi/SpiBus/SpiBusDxe.c +++ b/MdeModulePkg/Bus/Spi/SpiBus/SpiBusDxe.c @@ -59,8 +59,7 @@ SpiBusEntry ( if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_VERBOSE, "No SpiHcProtocol is found\n"));
- Status = EFI_NOT_FOUND;
- goto Exit;
+ return EFI_NOT_FOUND;
}
// Locate the SPI Configuration Protocol
@@ -108,7 +107,7 @@ SpiBusEntry ( // Get SpiHc from the SpiHcHandles
Status = gBS->HandleProtocol (
SpiHcHandles[HcIndex],
- &gEfiDevicePathProtocolGuid,
+ &gEfiSpiHcProtocolGuid,
(VOID **)&SpiHc
);
@@ -193,6 +192,9 @@ SpiBusEntry ( }
Exit:
+
+ gBS->FreePool (SpiHcHandles);
+
DEBUG ((DEBUG_VERBOSE, "%a - EXIT (Status = %r)\n", __func__, Status));
return Status;
}
diff --git a/MdeModulePkg/Bus/Spi/SpiNorFlashJedecSfdp/SpiNorFlash.c b/MdeModulePkg/Bus/Spi/SpiNorFlashJedecSfdp/SpiNorFlash.c index 3ac5420..ae8abda 100644 --- a/MdeModulePkg/Bus/Spi/SpiNorFlashJedecSfdp/SpiNorFlash.c +++ b/MdeModulePkg/Bus/Spi/SpiNorFlashJedecSfdp/SpiNorFlash.c @@ -48,11 +48,22 @@ FillWriteBuffer ( UINT32 Index;
UINT8 SfdpAddressBytes;
- SfdpAddressBytes = (UINT8)Instance->SfdpBasicFlash->AddressBytes;
+ if ((Instance == NULL) || ((WriteBytes != 0) && (WriteBuffer == NULL))) {
+ ASSERT (Instance != NULL);
+ ASSERT (WriteBytes == 0 || WriteBuffer != NULL);
+ return 0;
+ }
+
+ if (Instance->SfdpBasicFlash == NULL) {
+ SfdpAddressBytes = 0;
+ } else {
+ SfdpAddressBytes = (UINT8)Instance->SfdpBasicFlash->AddressBytes;
+ }
// Copy Opcode into Write Buffer
Instance->SpiTransactionWriteBuffer[0] = Opcode;
Index = 1;
+ AddressSize = 0;
if (UseAddress) {
if (AddressBytesSupported == SPI_ADDR_3BYTE_ONLY) {
if (SfdpAddressBytes != 0) {
diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c index 4a9fa01..c1072af 100644 --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c @@ -1808,7 +1808,7 @@ UfsAllocateAlignCommonBuffer ( if (EFI_ERROR (Status) || (Bytes != EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (Size)))) {
UfsHc->FreeBuffer (
UfsHc,
- EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (Size)),
+ EFI_SIZE_TO_PAGES (Size),
*CmdDescHost
);
*CmdDescHost = NULL;
@@ -1825,7 +1825,7 @@ UfsAllocateAlignCommonBuffer ( );
UfsHc->FreeBuffer (
UfsHc,
- EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (Size)),
+ EFI_SIZE_TO_PAGES (Size),
*CmdDescHost
);
*CmdDescMapping = NULL;
@@ -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 b3a4063..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;
}
@@ -900,12 +900,17 @@ UsbEnumeratePort ( Child = NULL;
HubApi = HubIf->HubApi;
+ // Zero out PortState in case GetPortStatus does not set
+ // it and we continue on the EFI_DEVICE_ERROR path
+ PortState.PortStatus = 0;
+ PortState.PortChangeStatus = 0;
+
//
// Host learns of the new device by polling the hub for port changes.
//
Status = HubApi->GetPortStatus (HubIf, Port, &PortState);
- if (EFI_ERROR (Status)) {
+ if (EFI_ERROR (Status) && (Status != EFI_DEVICE_ERROR)) {
DEBUG ((DEBUG_ERROR, "UsbEnumeratePort: failed to get state of port %d\n", Port));
return Status;
}
@@ -987,7 +992,9 @@ UsbEnumeratePort ( // Now, new device connected, enumerate and configure the device
//
DEBUG ((DEBUG_INFO, "UsbEnumeratePort: new device connected at port %d\n", Port));
- if (USB_BIT_IS_SET (PortState.PortChangeStatus, USB_PORT_STAT_C_RESET)) {
+ if (USB_BIT_IS_SET (PortState.PortChangeStatus, USB_PORT_STAT_C_RESET) &&
+ (Status != EFI_DEVICE_ERROR))
+ {
Status = UsbEnumerateNewDev (HubIf, Port, FALSE);
} else {
Status = UsbEnumerateNewDev (HubIf, Port, TRUE);
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/UsbMassStorageDxe/UsbMassBoot.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c index f648187..8c09831 100644 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c @@ -210,7 +210,7 @@ UsbBootExecCmd ( //
// If command execution failed, then retrieve error info via sense request.
//
- DEBUG ((DEBUG_ERROR, "UsbBootExecCmd: %r to Exec 0x%x Cmd (Result = %x)\n", Status, *(UINT8 *)Cmd, CmdResult));
+ DEBUG ((DEBUG_INFO, "UsbBootExecCmd: %r to Exec 0x%x Cmd (Result = %x)\n", Status, *(UINT8 *)Cmd, CmdResult));
return UsbBootRequestSense (UsbMass);
}
diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c index 55c239d..c4efa6b 100644 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c @@ -449,8 +449,7 @@ UsbBotExecCommand ( @param Context The context of the BOT protocol, that is,
USB_BOT_PROTOCOL.
- @param ExtendedVerification If FALSE, just issue Bulk-Only Mass Storage Reset request.
- If TRUE, additionally reset parent hub port.
+ @param ExtendedVerification ExtendedVerification is ignored in this implementation.
@retval EFI_SUCCESS The device is reset.
@retval Others Failed to reset the device..
@@ -470,16 +469,6 @@ UsbBotResetDevice ( UsbBot = (USB_BOT_PROTOCOL *)Context;
- if (ExtendedVerification) {
- //
- // If we need to do strictly reset, reset its parent hub port
- //
- Status = UsbBot->UsbIo->UsbPortReset (UsbBot->UsbIo);
- if (EFI_ERROR (Status)) {
- return EFI_DEVICE_ERROR;
- }
- }
-
//
// Issue a class specific Bulk-Only Mass Storage Reset request,
// according to section 3.1 of USB Mass Storage Class Bulk-Only Transport Spec, v1.0.
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c b/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c index ad5f066..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,
@@ -847,7 +855,7 @@ OnMouseInterruptComplete ( UsbMouseAbsolutePointerDevice->State.CurrentZ =
MIN (
MAX (
- (INT64)UsbMouseAbsolutePointerDevice->State.CurrentZ + *((INT8 *)Data + 1),
+ (INT64)UsbMouseAbsolutePointerDevice->State.CurrentZ + *((INT8 *)Data + 3),
(INT64)UsbMouseAbsolutePointerDevice->Mode.AbsoluteMinZ
),
(INT64)UsbMouseAbsolutePointerDevice->Mode.AbsoluteMaxZ
diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h index cd3940d..6f08554 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -45,6 +45,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Protocol/HiiPackageList.h>
#include <Protocol/SmmBase2.h>
#include <Protocol/PeCoffImageEmulator.h>
+#include <Protocol/MemoryAttribute.h>
#include <Guid/MemoryTypeInformation.h>
#include <Guid/FirmwareFileSystem2.h>
#include <Guid/FirmwareFileSystem3.h>
@@ -250,6 +251,7 @@ extern EFI_SECURITY_ARCH_PROTOCOL *gSecurity; extern EFI_SECURITY2_ARCH_PROTOCOL *gSecurity2;
extern EFI_BDS_ARCH_PROTOCOL *gBds;
extern EFI_SMM_BASE2_PROTOCOL *gSmmBase2;
+extern EFI_MEMORY_ATTRIBUTE_PROTOCOL *gMemoryAttributeProtocol;
extern EFI_TPL gEfiCurrentTpl;
diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeMain.inf index cc315ac..40e7dc8 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -156,6 +156,7 @@ gEfiHiiPackageListProtocolGuid ## SOMETIMES_PRODUCES
gEfiSmmBase2ProtocolGuid ## SOMETIMES_CONSUMES
gEdkiiPeCoffImageEmulatorProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiMemoryAttributeProtocolGuid ## CONSUMES
# Arch Protocols
gEfiBdsArchProtocolGuid ## CONSUMES
diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index df0765b..f5cac18 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -153,6 +153,13 @@ CoreDumpGcdMemorySpaceMap ( EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
UINTN Index;
+ // The compiler is not smart enough to compile out the whole function if DEBUG_GCD is not enabled, so we end up
+ // looping through the GCD every time it gets updated, which wastes a lot of needless cycles if we aren't going to
+ // print it. So shortcircuit and jump out if we don't need to print it.
+ if (!DebugPrintLevelEnabled (DEBUG_GCD)) {
+ return;
+ }
+
Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
ASSERT (Status == EFI_SUCCESS && MemorySpaceMap != NULL);
@@ -199,6 +206,13 @@ CoreDumpGcdIoSpaceMap ( EFI_GCD_IO_SPACE_DESCRIPTOR *IoSpaceMap;
UINTN Index;
+ // The compiler is not smart enough to compile out the whole function if DEBUG_GCD is not enabled, so we end up
+ // looping through the GCD every time it gets updated, which wastes a lot of needless cycles if we aren't going to
+ // print it. So shortcircuit and jump out if we don't need to print it.
+ if (!DebugPrintLevelEnabled (DEBUG_GCD)) {
+ return;
+ }
+
Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap);
ASSERT (Status == EFI_SUCCESS && IoSpaceMap != NULL);
@@ -976,7 +990,7 @@ CoreConvertSpace ( // Set attributes operation
//
case GCD_SET_ATTRIBUTES_MEMORY_OPERATION:
- if (CpuArchAttributes == 0) {
+ if ((CpuArchAttributes == 0) && (Attributes != 0)) {
//
// Keep original CPU arch attributes when caller just calls
// SetMemorySpaceAttributes() with none CPU arch attributes (for example, RUNTIME).
diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 8d12f93..71d267b 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -584,6 +584,9 @@ CoreLoadPeImage ( EFI_STATUS Status;
BOOLEAN DstBufAlocated;
UINTN Size;
+ UINTN Index;
+ UINTN StartIndex;
+ CHAR8 EfiFileName[512];
ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext));
@@ -823,12 +826,6 @@ CoreLoadPeImage ( // Print the load address and the PDB file name if it is available
//
- DEBUG_CODE_BEGIN ();
-
- UINTN Index;
- UINTN StartIndex;
- CHAR8 EfiFileName[256];
-
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"Loading driver at 0x%11p EntryPoint=0x%11p ",
@@ -877,8 +874,6 @@ CoreLoadPeImage ( DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
- DEBUG_CODE_END ();
-
return EFI_SUCCESS;
Done:
diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index e4daa74..27c2788 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -1459,6 +1459,11 @@ CoreInternalAllocatePages ( // return EFI_NOT_FOUND.
//
if (Type == AllocateAddress) {
+ // Page 0 is not allowed to be allocated as it is reserved for null pointer detection
+ if (Start == 0) {
+ return EFI_NOT_FOUND;
+ }
+
if ((NumberOfPages == 0) ||
(NumberOfPages > RShiftU64 (MaxAddress, EFI_PAGE_SHIFT)))
{
@@ -1741,6 +1746,38 @@ CoreFreePages ( {
EFI_STATUS Status;
EFI_MEMORY_TYPE MemoryType;
+ UINT64 Attributes;
+
+ // check if this memory is returned to the core as RW at a minimum. If the memory attribute protocol is not installed,
+ // then we assume that the memory is RW by default and continue to free it.
+ if (gMemoryAttributeProtocol != NULL) {
+ Status = gMemoryAttributeProtocol->GetMemoryAttributes (
+ gMemoryAttributeProtocol,
+ Memory,
+ EFI_PAGES_TO_SIZE (NumberOfPages),
+ &Attributes
+ );
+
+ // if we failed to get the attributes, or if the memory is read-only or read-protected,
+ // then we leak the memory and return success. This is done because the UEFI spec does not specify whether pages
+ // should be freed with any specific permission attributes. As such, there exist bootloaders in the wild that will
+ // free memory that is marked RO, which can crash the core if DebugClearMemory is enabled or can be passed out to a
+ // driver in the next AllocatePages() call, which can cause a crash later on. It is deemed lower risk to leak the
+ // memory than to attempt to fix up the attributes as that requires syncing the GCD and the page table.
+ if (EFI_ERROR (Status) || (Attributes & EFI_MEMORY_RO) || (Attributes & EFI_MEMORY_RP)) {
+ DEBUG ((
+ DEBUG_WARN,
+ "%a: Memory %llx for %llx Pages failed to get attributes with status %r or it is read-only or read-protected. "
+ "Attributes: %llx. Leaking memory!\n",
+ __func__,
+ Memory,
+ NumberOfPages,
+ Status,
+ Attributes
+ ));
+ return EFI_SUCCESS;
+ }
+ }
Status = CoreInternalFreePages (Memory, NumberOfPages, &MemoryType);
if (!EFI_ERROR (Status)) {
diff --git a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c index eeb18f6..54061bf 100644 --- a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c +++ b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c @@ -177,20 +177,7 @@ CoreNewDebugImageInfoEntry ( Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
- if (mDebugInfoTableHeader.TableSize < mMaxTableEntries) {
- //
- // We still have empty entires in the Table, find the first empty entry.
- //
- Index = 0;
- while (Table[Index].NormalImage != NULL) {
- Index++;
- }
-
- //
- // There must be an empty entry in the in the table.
- //
- ASSERT (Index < mMaxTableEntries);
- } else {
+ if (mDebugInfoTableHeader.TableSize >= mMaxTableEntries) {
//
// Table is full, so re-allocate another page for a larger table...
//
@@ -218,10 +205,12 @@ CoreNewDebugImageInfoEntry ( // Enlarge the max table entries and set the first empty entry index to
// be the original max table entries.
//
- Index = mMaxTableEntries;
mMaxTableEntries += EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE;
}
+ // We always put the next entry at the end of the currently consumed table (i.e. first free entry)
+ Index = mDebugInfoTableHeader.TableSize;
+
//
// Allocate data for new entry
//
@@ -264,11 +253,13 @@ CoreRemoveDebugImageInfoEntry ( for (Index = 0; Index < mMaxTableEntries; Index++) {
if ((Table[Index].NormalImage != NULL) && (Table[Index].NormalImage->ImageHandle == ImageHandle)) {
//
- // Found a match. Free up the record, then NULL the pointer to indicate the slot
- // is free.
+ // Found a match. Free up the record, then move the final entry down to this slot; we don't care about the
+ // order of the array
//
CoreFreePool (Table[Index].NormalImage);
- Table[Index].NormalImage = NULL;
+ Table[Index].NormalImage = Table[mDebugInfoTableHeader.TableSize - 1].NormalImage;
+ Table[mDebugInfoTableHeader.TableSize - 1].NormalImage = NULL;
+
//
// Decrease the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
//
diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c index 2c069cc..69d26cb 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -38,6 +38,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Guid/MemoryAttributesTable.h>
#include <Protocol/FirmwareVolume2.h>
+#include <Protocol/MemoryAttribute.h>
#include <Protocol/SimpleFileSystem.h>
#include "DxeMain.h"
@@ -67,6 +68,8 @@ extern LIST_ENTRY mGcdMemorySpaceMap; STATIC LIST_ENTRY mProtectedImageRecordList;
+EFI_MEMORY_ATTRIBUTE_PROTOCOL *gMemoryAttributeProtocol;
+
/**
Get the image type.
@@ -194,16 +197,113 @@ SetUefiImageMemoryAttributes ( EFI_STATUS Status;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
UINT64 FinalAttributes;
+ UINT64 CurrentAddress;
+ UINT64 CurrentLength;
+ UINT64 ImageEnd;
+ UINT64 DescEnd;
+
+ CurrentAddress = BaseAddress;
+ ImageEnd = BaseAddress + Length;
+
+ // we loop here because we may have multiple memory space descriptors that overlap the requested range
+ // this will definitely be the case for unprotecting an image, because that calls this function for the entire image,
+ // which we split into different GCD descriptors when we protected it.
+ while (CurrentAddress < BaseAddress + Length) {
+ Status = CoreGetMemorySpaceDescriptor (CurrentAddress, &Descriptor);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a - Failed to get memory space descriptor for address %llx with status %r. Cannot protect image.\n",
+ __func__,
+ CurrentAddress,
+ Status
+ ));
+ ASSERT_EFI_ERROR (Status);
+ return;
+ }
- Status = CoreGetMemorySpaceDescriptor (BaseAddress, &Descriptor);
- ASSERT_EFI_ERROR (Status);
+ DescEnd = Descriptor.BaseAddress + Descriptor.Length;
- FinalAttributes = (Descriptor.Attributes & EFI_CACHE_ATTRIBUTE_MASK) | (Attributes & EFI_MEMORY_ATTRIBUTE_MASK);
+ // ensure that we only change the attributes for the range that we are interested in, not the entire descriptor, we
+ // may also be in the middle of a descriptor, so ensure our length is not larger than the descriptor length
+ if (ImageEnd > DescEnd) {
+ CurrentLength = DescEnd - CurrentAddress;
+ } else {
+ CurrentLength = ImageEnd - CurrentAddress;
+ }
+
+ // Preserve the existing caching and virtual attributes, but remove the hardware access bits
+ FinalAttributes = (Descriptor.Attributes & ~EFI_MEMORY_ACCESS_MASK) | (Attributes & EFI_MEMORY_ATTRIBUTE_MASK);
+
+ DEBUG ((DEBUG_VERBOSE, "SetUefiImageMemoryAttributes - 0x%016lx - 0x%016lx (0x%016lx)\n", CurrentAddress, CurrentLength, FinalAttributes));
- DEBUG ((DEBUG_INFO, "SetUefiImageMemoryAttributes - 0x%016lx - 0x%016lx (0x%016lx)\n", BaseAddress, Length, FinalAttributes));
+ // check to see if the capabilities support the attributes we want to set. If not, set the capabilities appropriately
+ if ((Descriptor.Capabilities & FinalAttributes) != FinalAttributes) {
+ Status = CoreSetMemorySpaceCapabilities (
+ CurrentAddress,
+ CurrentLength,
+ Descriptor.Capabilities | FinalAttributes
+ );
+
+ // if we failed to set the capabilities, we should try to continue, it is possible we could succeed
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a failed setting capabilities on %llx of length %llx with capabilities %llx - %r\n",
+ __func__,
+ CurrentAddress,
+ CurrentLength,
+ Descriptor.Capabilities | FinalAttributes,
+ Status
+ ));
+ ASSERT_EFI_ERROR (Status);
+ }
+ }
+
+ // Call into the GCD to update the attributes there. It will call into the CPU Arch protocol to update the
+ // page table attributes
+ Status = CoreSetMemorySpaceAttributes (
+ CurrentAddress,
+ CurrentLength,
+ FinalAttributes
+ );
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a failed on %llx of length %llx with attributes %llx - %r\n",
+ __func__,
+ CurrentAddress,
+ CurrentLength,
+ FinalAttributes,
+ Status
+ ));
+ ASSERT_EFI_ERROR (Status);
+ }
- ASSERT (gCpu != NULL);
- gCpu->SetMemoryAttributes (gCpu, BaseAddress, Length, FinalAttributes);
+ if (((FinalAttributes & (EFI_MEMORY_ATTRIBUTE_MASK | EFI_CACHE_ATTRIBUTE_MASK)) == 0) && (gCpu != NULL)) {
+ // if the passed hardware attributes are 0, CoreSetMemorySpaceAttributes() will not call into the CPU Arch protocol
+ // to set the attributes, so we need to do it manually here. This can be the case when we are unprotecting an
+ // image if no caching attributes are set. If gCpu has not been populated yet, we'll still have updated the GCD
+ // descriptor and we should sync the attributes with the CPU Arch protocol when it is available.
+ Status = gCpu->SetMemoryAttributes (gCpu, CurrentAddress, CurrentLength, 0);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a failed to update page table for %llx of length %llx with attributes 0 - %r\n",
+ __func__,
+ CurrentAddress,
+ CurrentLength,
+ Status
+ ));
+ ASSERT_EFI_ERROR (Status);
+ }
+ }
+
+ // we may have started in the middle of a descriptor, so we need to move to the beginning of the next descriptor,
+ // or the end of the image, whichever is smaller
+ CurrentAddress += CurrentLength;
+ }
}
/**
@@ -371,6 +471,19 @@ ProtectUefiImage ( if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a failed to create image properties record\n", __func__));
+
+ // if we failed to create the image properties record, this may mean that the image is not aligned properly
+ // the GCD will believe that this memory is non-executable, because the NX initialization routine doesn't know what
+ // memory is image memory or not, even though the page table has the correct attributes, so we need to set the
+ // attributes here to RWX so that future updates to the GCD do not apply the NX attributes to this memory in the
+ // page table (as can happen when applying virtual attributes). This may have the side effect of marking other
+ // memory as RWX, since this image may not be page aligned, but that is safe to do, it may just remove some
+ // page protections, but it already has to to execute this image.
+ SetUefiImageMemoryAttributes (
+ (UINT64)(UINTN)LoadedImage->ImageBase & ~EFI_PAGE_MASK,
+ (LoadedImage->ImageSize + EFI_PAGE_MASK) & ~EFI_PAGE_MASK,
+ 0
+ );
FreePool (ImageRecord);
goto Finish;
}
@@ -924,6 +1037,37 @@ DisableNullDetectionAtTheEndOfDxe ( }
/**
+ A notification for the Memory Attribute Protocol Installation.
+
+ @param[in] Event Event whose notification function is being invoked.
+ @param[in] Context Pointer to the notification function's context,
+ which is implementation-dependent.
+
+**/
+VOID
+EFIAPI
+MemoryAttributeProtocolNotify (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ EFI_STATUS Status;
+
+ Status = gBS->LocateProtocol (&gEfiMemoryAttributeProtocolGuid, NULL, (VOID **)&gMemoryAttributeProtocol);
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_INFO,
+ "%a - Unable to locate the memory attribute protocol! Status = %r\n",
+ __func__,
+ Status
+ ));
+ }
+
+ CoreCloseEvent (Event);
+}
+
+/**
Initialize Memory Protection support.
**/
VOID
@@ -974,6 +1118,35 @@ CoreInitializeMemoryProtection ( );
ASSERT_EFI_ERROR (Status);
+ // Register an event to populate the memory attribute protocol
+ Status = CoreCreateEvent (
+ EVT_NOTIFY_SIGNAL,
+ TPL_CALLBACK,
+ MemoryAttributeProtocolNotify,
+ NULL,
+ &Event
+ );
+
+ // if we fail to create the event or the protocol notify, we should still continue, we won't be able to query the
+ // memory attributes on FreePages(), so we may encounter a driver or bootloader that has not set attributes back to
+ // RW, but this matches the state of the world before this protocol was introduced, so it is not a regression.
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a - Failed to create event for the Memory Attribute Protocol notification: %r\n", __func__, Status));
+ ASSERT_EFI_ERROR (Status);
+ }
+
+ // Register for protocol notification
+ Status = CoreRegisterProtocolNotify (
+ &gEfiMemoryAttributeProtocolGuid,
+ Event,
+ &Registration
+ );
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a - Failed to register for the Memory Attribute Protocol notification: %r\n", __func__, Status));
+ ASSERT_EFI_ERROR (Status);
+ }
+
//
// Register a callback to disable NULL pointer detection at EndOfDxe
//
diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c index b9fe703..0b3a71f 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c +++ b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c @@ -59,7 +59,7 @@ CONST EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyList = { @param FileHandle Handle of the file being invoked.
@param PeiServices Describes the list of possible PEI Services.
- @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
+ @retval EFI_SUCCESS The entry point of DXE IPL PEIM executes successfully.
@retval Others Some error occurs during the execution of this function.
**/
@@ -80,7 +80,7 @@ PeimInitializeDxeIpl ( Status = PeiServicesRegisterForShadow (FileHandle);
if (Status == EFI_SUCCESS) {
//
- // EFI_SUCESS means it is the first time to call register for shadow.
+ // EFI_SUCCESS means it is the first time to call register for shadow.
//
return Status;
}
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c index 60878b4..98aae5a 100644 --- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c @@ -265,14 +265,6 @@ HandOffToDxeCore ( EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;
BOOLEAN BuildPageTablesIa32Pae;
- //
- // Clear page 0 and mark it as allocated if NULL pointer detection is enabled.
- //
- if (IsNullDetectionEnabled ()) {
- ClearFirst4KPage (HobList.Raw);
- BuildMemoryAllocationHob (0, EFI_PAGES_TO_SIZE (1), EfiBootServicesData);
- }
-
Status = PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack);
ASSERT_EFI_ERROR (Status);
diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c index fa2050c..034254b 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c @@ -37,14 +37,6 @@ HandOffToDxeCore ( UINTN GhcbSize;
//
- // Clear page 0 and mark it as allocated if NULL pointer detection is enabled.
- //
- if (IsNullDetectionEnabled ()) {
- ClearFirst4KPage (HobList.Raw);
- BuildMemoryAllocationHob (0, EFI_PAGES_TO_SIZE (1), EfiBootServicesData);
- }
-
- //
// Get Vector Hand-off Info PPI and build Guided HOB
//
Status = PeiServicesLocatePpi (
diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c index 1fb2a3b..ee85b31 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -32,72 +32,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent PAGE_TABLE_POOL *mPageTablePool = NULL;
/**
- Clear legacy memory located at the first 4K-page, if available.
-
- This function traverses the whole HOB list to check if memory from 0 to 4095
- exists and has not been allocated, and then clear it if so.
-
- @param HobStart The start of HobList passed to DxeCore.
-
-**/
-VOID
-ClearFirst4KPage (
- IN VOID *HobStart
- )
-{
- EFI_PEI_HOB_POINTERS RscHob;
- EFI_PEI_HOB_POINTERS MemHob;
- BOOLEAN DoClear;
-
- RscHob.Raw = HobStart;
- MemHob.Raw = HobStart;
- DoClear = FALSE;
-
- //
- // Check if page 0 exists and free
- //
- while ((RscHob.Raw = GetNextHob (
- EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,
- RscHob.Raw
- )) != NULL)
- {
- if ((RscHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&
- (RscHob.ResourceDescriptor->PhysicalStart == 0))
- {
- DoClear = TRUE;
- //
- // Make sure memory at 0-4095 has not been allocated.
- //
- while ((MemHob.Raw = GetNextHob (
- EFI_HOB_TYPE_MEMORY_ALLOCATION,
- MemHob.Raw
- )) != NULL)
- {
- if (MemHob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress
- < EFI_PAGE_SIZE)
- {
- DoClear = FALSE;
- break;
- }
-
- MemHob.Raw = GET_NEXT_HOB (MemHob);
- }
-
- break;
- }
-
- RscHob.Raw = GET_NEXT_HOB (RscHob);
- }
-
- if (DoClear) {
- DEBUG ((DEBUG_INFO, "Clearing first 4K-page!\r\n"));
- SetMem (NULL, EFI_PAGE_SIZE, 0);
- }
-
- return;
-}
-
-/**
Return configure status of NULL pointer detection feature.
@return TRUE NULL pointer detection feature is enabled
diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h index e035284..95e88a9 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h @@ -268,20 +268,6 @@ AsmGetVectorTemplatInfo ( );
/**
- Clear legacy memory located at the first 4K-page.
-
- This function traverses the whole HOB list to check if memory from 0 to 4095
- exists and has not been allocated, and then clear it if so.
-
- @param HobStart The start of HobList passed to DxeCore.
-
-**/
-VOID
-ClearFirst4KPage (
- IN VOID *HobStart
- );
-
-/**
Return configure status of NULL pointer detection feature.
@return TRUE NULL pointer detection feature is enabled
diff --git a/MdeModulePkg/Core/Pei/Image/Image.c b/MdeModulePkg/Core/Pei/Image/Image.c index cee9f09..f74406f 100644 --- a/MdeModulePkg/Core/Pei/Image/Image.c +++ b/MdeModulePkg/Core/Pei/Image/Image.c @@ -623,6 +623,10 @@ PeiLoadImageLoadImage ( UINT16 Machine;
EFI_SECTION_TYPE SearchType1;
EFI_SECTION_TYPE SearchType2;
+ CHAR8 *AsciiString;
+ CHAR8 EfiFileName[512];
+ UINTN Index;
+ UINTN StartIndex;
*EntryPoint = 0;
ImageSize = 0;
@@ -706,12 +710,6 @@ PeiLoadImageLoadImage ( *ImageSizeArg = ImageSize;
}
- DEBUG_CODE_BEGIN ();
- CHAR8 *AsciiString;
- CHAR8 EfiFileName[512];
- INT32 Index;
- INT32 StartIndex;
-
//
// Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi
//
@@ -764,8 +762,6 @@ PeiLoadImageLoadImage ( DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName));
}
- DEBUG_CODE_END ();
-
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
return EFI_SUCCESS;
diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c index 562092d..80b2f89 100644 --- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c +++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c @@ -613,10 +613,11 @@ PeiAllocatePages ( //
// Check to see if on correct boundary for the memory type.
- // If not aligned, make the allocation aligned.
+ // If not aligned, make the allocation aligned and that we are not trying to allocate page 0, which is used for
+ // null detection.
//
Padding = *(FreeMemoryTop) & (Granularity - 1);
- if ((UINTN)(*FreeMemoryTop - *FreeMemoryBottom) < Padding) {
+ if (((UINTN)(*FreeMemoryTop - *FreeMemoryBottom) < Padding) || (*(FreeMemoryTop) - Padding == 0)) {
DEBUG ((DEBUG_ERROR, "AllocatePages failed: Out of space after padding.\n"));
return EFI_OUT_OF_RESOURCES;
}
diff --git a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c index bb789e5..2011db1 100644 --- a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c +++ b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c @@ -325,6 +325,9 @@ SmmLoadImage ( EFI_DEVICE_PATH_PROTOCOL *HandleFilePath;
EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
+ UINTN Index;
+ UINTN StartIndex;
+ CHAR8 EfiFileName[512];
PERF_LOAD_IMAGE_BEGIN (DriverEntry->ImageHandle);
@@ -664,12 +667,6 @@ SmmLoadImage ( // Print the load address and the PDB file name if it is available
//
- DEBUG_CODE_BEGIN ();
-
- UINTN Index;
- UINTN StartIndex;
- CHAR8 EfiFileName[256];
-
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"Loading SMM driver at 0x%11p EntryPoint=0x%11p ",
@@ -718,8 +715,6 @@ SmmLoadImage ( DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
- DEBUG_CODE_END ();
-
//
// Free buffer allocated by Fv->ReadSection.
//
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c index e957cb6..100e006 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c @@ -670,13 +670,16 @@ SmmEntryPoint ( IN CONST EFI_SMM_ENTRY_CONTEXT *SmmEntryContext
)
{
- EFI_STATUS Status;
- EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader;
- BOOLEAN InLegacyBoot;
- BOOLEAN IsOverlapped;
- BOOLEAN IsOverUnderflow;
- VOID *CommunicationBuffer;
- UINTN BufferSize;
+ EFI_STATUS Status;
+ EFI_MM_COMMUNICATE_HEADER_V3 *CommunicateHeader;
+ EFI_SMM_COMMUNICATE_HEADER *LegacyCommunicateHeader;
+ BOOLEAN InLegacyBoot;
+ BOOLEAN IsOverlapped;
+ VOID *CommunicationBuffer;
+ UINTN BufferSize;
+ EFI_GUID *CommGuid;
+ VOID *CommData;
+ UINTN CommHeaderSize;
PERF_FUNCTION_BEGIN ();
@@ -730,10 +733,8 @@ SmmEntryPoint ( //
// Check for over or underflows
//
- IsOverUnderflow = EFI_ERROR (SafeUintnSub (BufferSize, OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data), &BufferSize));
-
if (!SmmIsBufferOutsideSmmValid ((UINTN)CommunicationBuffer, BufferSize) ||
- IsOverlapped || IsOverUnderflow)
+ IsOverlapped || (BufferSize < OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)))
{
//
// If CommunicationBuffer is not in valid address scope,
@@ -744,25 +745,50 @@ SmmEntryPoint ( gSmmCorePrivate->CommunicationBuffer = NULL;
gSmmCorePrivate->ReturnStatus = EFI_ACCESS_DENIED;
} else {
- CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommunicationBuffer;
- // BufferSize was updated by the SafeUintnSub() call above.
- Status = SmiManage (
- &CommunicateHeader->HeaderGuid,
- NULL,
- CommunicateHeader->Data,
- &BufferSize
- );
+ CommGuid = &((EFI_MM_COMMUNICATE_HEADER_V3 *)CommunicationBuffer)->HeaderGuid;
+ //
+ // Check if the signature matches EFI_MM_COMMUNICATE_HEADER_V3 definition
+ //
+ if (CompareGuid (CommGuid, &gEfiMmCommunicateHeaderV3Guid)) {
+ //
+ // If so, need to make sure the size is at least the size of the header
+ //
+ if (BufferSize < sizeof (EFI_MM_COMMUNICATE_HEADER_V3)) {
+ gSmmCorePrivate->CommunicationBuffer = NULL;
+ gSmmCorePrivate->ReturnStatus = EFI_ACCESS_DENIED;
+ goto AsyncSmi;
+ }
+
+ CommunicateHeader = (EFI_MM_COMMUNICATE_HEADER_V3 *)CommunicationBuffer;
+ CommGuid = &CommunicateHeader->MessageGuid;
+ CommData = CommunicateHeader->MessageData;
+ CommHeaderSize = sizeof (EFI_MM_COMMUNICATE_HEADER_V3);
+ } else {
+ LegacyCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommunicationBuffer;
+ CommGuid = &LegacyCommunicateHeader->HeaderGuid;
+ CommData = LegacyCommunicateHeader->Data;
+ CommHeaderSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
+ }
+
+ BufferSize -= CommHeaderSize;
+ Status = SmiManage (
+ CommGuid,
+ NULL,
+ CommData,
+ &BufferSize
+ );
//
// Update CommunicationBuffer, BufferSize and ReturnStatus
// Communicate service finished, reset the pointer to CommBuffer to NULL
//
- gSmmCorePrivate->BufferSize = BufferSize + OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
+ gSmmCorePrivate->BufferSize = BufferSize + CommHeaderSize;
gSmmCorePrivate->CommunicationBuffer = NULL;
gSmmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
}
}
}
+AsyncSmi:
//
// Process Asynchronous SMI sources
//
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf index 75a5934..22a1048 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf @@ -120,6 +120,7 @@ gSmiHandlerProfileGuid
gEdkiiEndOfS3ResumeGuid ## SOMETIMES_PRODUCES ## GUID # Install protocol
gEdkiiS3SmmInitDoneGuid ## SOMETIMES_PRODUCES ## GUID # Install protocol
+ gEfiMmCommunicateHeaderV3Guid ## CONSUMES ## GUID # Communicate header
[UserExtensions.TianoCore."ExtraFiles"]
PiSmmCoreExtra.uni
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c index fbba868..749295b 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c @@ -11,6 +11,7 @@ #include <Protocol/SmmBase2.h>
#include <Protocol/SmmCommunication.h>
#include <Protocol/MmCommunication2.h>
+#include <Protocol/MmCommunication3.h>
#include <Protocol/SmmAccess2.h>
#include <Protocol/SmmConfiguration.h>
#include <Protocol/SmmControl2.h>
@@ -147,6 +148,37 @@ SmmCommunicationMmCommunicate2 ( );
/**
+ Communicates with a registered handler.
+
+ This function provides a service to send and receive messages from a registered UEFI service.
+
+ @param[in] This The EFI_MM_COMMUNICATION3_PROTOCOL instance.
+ @param[in, out] CommBufferPhysical Physical address of the MM communication buffer, of which content must
+ start with EFI_MM_COMMUNICATE_HEADER_V3.
+ @param[in, out] CommBufferVirtual Virtual address of the MM communication buffer, of which content must
+ start with EFI_MM_COMMUNICATE_HEADER_V3.
+
+ @retval EFI_SUCCESS The message was successfully posted.
+ @retval EFI_INVALID_PARAMETER CommBufferPhysical was NULL or CommBufferVirtual was NULL.
+ @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM implementation.
+ If this error is returned, the MessageLength field
+ in the CommBuffer header or the integer pointed by
+ CommSize, are updated to reflect the maximum payload
+ size the implementation can accommodate.
+ @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or CommSize parameter,
+ if not omitted, are in address range that cannot be
+ accessed by the MM environment.
+
+**/
+EFI_STATUS
+EFIAPI
+MmCommunicationMmCommunicate3 (
+ IN CONST EFI_MM_COMMUNICATION3_PROTOCOL *This,
+ IN OUT VOID *CommBufferPhysical,
+ IN OUT VOID *CommBufferVirtual
+ );
+
+/**
Event notification that is fired every time a gEfiSmmConfigurationProtocol installs.
@param Event The Event that is being processed, not used.
@@ -276,6 +308,13 @@ EFI_MM_COMMUNICATION2_PROTOCOL mMmCommunication2 = { };
//
+// PI 1.9 MM Communication Protocol 3 instance
+//
+EFI_MM_COMMUNICATION3_PROTOCOL mMmCommunication3 = {
+ MmCommunicationMmCommunicate3
+};
+
+//
// SMM Core Private Data structure that contains the data shared between
// the SMM IPL and the SMM Core.
//
@@ -652,6 +691,140 @@ SmmCommunicationMmCommunicate2 ( }
/**
+ Communicates with a registered handler.
+
+ This function provides a service to send and receive messages from a registered UEFI service.
+
+ @param[in] This The EFI_MM_COMMUNICATION3_PROTOCOL instance.
+ @param[in, out] CommBufferPhysical Physical address of the MM communication buffer, of which content must
+ start with EFI_MM_COMMUNICATE_HEADER_V3.
+ @param[in, out] CommBufferVirtual Virtual address of the MM communication buffer, of which content must
+ start with EFI_MM_COMMUNICATE_HEADER_V3.
+ @param[out] CommSize The size of data being returned. Zero if the handler does not wish to
+ reply with any data. This parameter is optional and may be NULL.
+
+ @retval EFI_SUCCESS The message was successfully posted.
+ @retval EFI_INVALID_PARAMETER CommBufferPhysical was NULL or CommBufferVirtual was NULL.
+ @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM implementation.
+ If this error is returned, the MessageLength field
+ in the CommBuffer header or the integer pointed by
+ CommSize, are updated to reflect the maximum payload
+ size the implementation can accommodate.
+ @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or CommSize parameter,
+ if not omitted, are in address range that cannot be
+ accessed by the MM environment.
+
+**/
+EFI_STATUS
+EFIAPI
+MmCommunicationMmCommunicate3 (
+ IN CONST EFI_MM_COMMUNICATION3_PROTOCOL *This,
+ IN OUT VOID *CommBufferPhysical,
+ IN OUT VOID *CommBufferVirtual
+ )
+{
+ EFI_STATUS Status;
+ EFI_MM_COMMUNICATE_HEADER_V3 *CommunicateHeader;
+ BOOLEAN OldInSmm;
+ UINT64 MinCommSize;
+ UINT64 TempCommSize;
+
+ //
+ // Check parameters
+ //
+ if ((CommBufferPhysical == NULL) || (CommBufferVirtual == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ CommunicateHeader = (EFI_MM_COMMUNICATE_HEADER_V3 *)CommBufferVirtual;
+ if (!CompareGuid (
+ &CommunicateHeader->HeaderGuid,
+ &gEfiMmCommunicateHeaderV3Guid
+ ))
+ {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = SafeUint64Add (sizeof (EFI_MM_COMMUNICATE_HEADER_V3), CommunicateHeader->MessageSize, &MinCommSize);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // CommSize must hold the entire EFI_MM_COMMUNICATE_HEADER_V3
+ //
+ if (CommunicateHeader->BufferSize < MinCommSize) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // If not already in SMM, then generate a Software SMI
+ //
+ if (!gSmmCorePrivate->InSmm && gSmmCorePrivate->SmmEntryPointRegistered) {
+ //
+ // Put arguments for Software SMI in gSmmCorePrivate
+ //
+ gSmmCorePrivate->CommunicationBuffer = CommBufferPhysical;
+ gSmmCorePrivate->BufferSize = (UINTN)CommunicateHeader->BufferSize;
+
+ //
+ // Generate Software SMI
+ //
+ Status = mSmmControl2->Trigger (mSmmControl2, NULL, NULL, FALSE, 0);
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ return gSmmCorePrivate->ReturnStatus;
+ }
+
+ //
+ // If we are in SMM, then the execution mode must be physical, which means that
+ // OS established virtual addresses can not be used. If SetVirtualAddressMap()
+ // has been called, then a direct invocation of the Software SMI is not allowed,
+ // so return EFI_INVALID_PARAMETER.
+ //
+ if (EfiGoneVirtual ()) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // If we are not in SMM, don't allow call SmiManage() directly when SMRAM is closed or locked.
+ //
+ if ((!gSmmCorePrivate->InSmm) && (!mSmmAccess->OpenState || mSmmAccess->LockState)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Save current InSmm state and set InSmm state to TRUE
+ //
+ OldInSmm = gSmmCorePrivate->InSmm;
+ gSmmCorePrivate->InSmm = TRUE;
+
+ //
+ // Before SetVirtualAddressMap(), we are in SMM or SMRAM is open and unlocked, call SmiManage() directly.
+ //
+ TempCommSize = CommunicateHeader->BufferSize - sizeof (EFI_MM_COMMUNICATE_HEADER_V3);
+ Status = gSmmCorePrivate->Smst->SmiManage (
+ &CommunicateHeader->MessageGuid,
+ NULL,
+ CommunicateHeader->MessageData,
+ (UINTN *)&TempCommSize
+ );
+ TempCommSize += sizeof (EFI_MM_COMMUNICATE_HEADER_V3);
+
+ // Return the size of the buffer
+ CommunicateHeader->BufferSize = TempCommSize;
+
+ //
+ // Restore original InSmm state
+ //
+ gSmmCorePrivate->InSmm = OldInSmm;
+
+ return (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
+}
+
+/**
Event notification that is fired when GUIDed Event Group is signaled.
@param Event The Event that is being processed, not used.
@@ -1878,6 +2051,8 @@ SmmIplEntry ( &mSmmCommunication,
&gEfiMmCommunication2ProtocolGuid,
&mMmCommunication2,
+ &gEfiMmCommunication3ProtocolGuid,
+ &mMmCommunication3,
NULL
);
ASSERT_EFI_ERROR (Status);
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf index ddeb39c..e983bb2 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf @@ -52,6 +52,7 @@ gEfiSmmBase2ProtocolGuid ## PRODUCES
gEfiSmmCommunicationProtocolGuid ## PRODUCES
gEfiMmCommunication2ProtocolGuid ## PRODUCES
+ gEfiMmCommunication3ProtocolGuid ## PRODUCES
gEfiSmmAccess2ProtocolGuid ## CONSUMES
## NOTIFY
## CONSUMES
@@ -80,6 +81,7 @@ gEfiEventVirtualAddressChangeGuid ## CONSUMES ## Event
gEfiEndOfDxeEventGroupGuid ## CONSUMES ## Event
gLoadFixedAddressConfigurationTableGuid ## SOMETIMES_CONSUMES ## SystemTable
+ gEfiMmCommunicateHeaderV3Guid ## SOMETIMES_CONSUMES ## UNDEFINED # MM communication v3
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressSmmCodePageNumber ## SOMETIMES_CONSUMES
diff --git a/MdeModulePkg/Include/Guid/ArmFfaRxTxBufferInfo.h b/MdeModulePkg/Include/Guid/ArmFfaRxTxBufferInfo.h new file mode 100644 index 0000000..d38f8ce --- /dev/null +++ b/MdeModulePkg/Include/Guid/ArmFfaRxTxBufferInfo.h @@ -0,0 +1,39 @@ +/** @file
+ Arm FF-A ns common library Header file
+
+ Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+ Copyright (c), Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef ARM_FFA_RX_TX_BUFFER_INFO_H_
+#define ARM_FFA_RX_TX_BUFFER_INFO_H_
+
+#include <Uefi/UefiBaseType.h>
+
+/**
+ * Guid Hob Data for gArmFfaRxTxBufferInfoGuid Guid Hob.
+ */
+typedef struct ArmFfaRxTxBuffersInfo {
+ /// Tx Buffer Address.
+ EFI_PHYSICAL_ADDRESS TxBufferAddr;
+
+ /// Tx Buffer Size.
+ UINT64 TxBufferSize;
+
+ /// Rx Buffer Address.
+ EFI_PHYSICAL_ADDRESS RxBufferAddr;
+
+ /// Rx Buffer Size.
+ UINT64 RxBufferSize;
+
+ /// Rx/Tx buffer should be remapped to permanent memory.
+ BOOLEAN RemapRequired;
+
+ /// Rx/Tx buffer offset from its allocation base.
+ UINT64 RemapOffset;
+} ARM_FFA_RX_TX_BUFFER_INFO;
+
+extern EFI_GUID gArmFfaRxTxBufferInfoGuid;
+
+#endif
diff --git a/MdeModulePkg/Include/Guid/MmCommBuffer.h b/MdeModulePkg/Include/Guid/MmCommBuffer.h index df4ea31..e3484e0 100644 --- a/MdeModulePkg/Include/Guid/MmCommBuffer.h +++ b/MdeModulePkg/Include/Guid/MmCommBuffer.h @@ -47,6 +47,9 @@ typedef struct { ///
BOOLEAN IsCommBufferValid;
+ /// For padding purpose
+ UINT8 Reserved[7];
+
///
/// The return status when returning from MM to non-MM.
///
diff --git a/MdeModulePkg/Include/Guid/SmmVariableCommon.h b/MdeModulePkg/Include/Guid/SmmVariableCommon.h index 1a1ab4f..e88645e 100644 --- a/MdeModulePkg/Include/Guid/SmmVariableCommon.h +++ b/MdeModulePkg/Include/Guid/SmmVariableCommon.h @@ -81,7 +81,8 @@ typedef struct { ///
/// Size of SMM communicate header, without including the payload.
///
-#define SMM_COMMUNICATE_HEADER_SIZE (OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data))
+#define SMM_COMMUNICATE_HEADER_SIZE (OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data))
+#define SMM_COMMUNICATE_HEADER_SIZE_V3 (sizeof (EFI_MM_COMMUNICATE_HEADER_V3))
///
/// Size of SMM variable communicate header, without including the payload.
diff --git a/MdeModulePkg/Include/Library/BootLogoLib.h b/MdeModulePkg/Include/Library/BootLogoLib.h index 2d6209a..a2fd667 100644 --- a/MdeModulePkg/Include/Library/BootLogoLib.h +++ b/MdeModulePkg/Include/Library/BootLogoLib.h @@ -26,7 +26,7 @@ BootLogoEnableLogo ( Use SystemTable ConOut to turn on video based Simple Text Out consoles. The
Simple Text Out screens will now be synced up with all non-video output devices.
- @retval EFI_SUCCESS UGA devices are back in text mode and synced up.
+ @retval EFI_SUCCESS Devices are back in text mode and synced up.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Include/Library/CapsuleLib.h b/MdeModulePkg/Include/Library/CapsuleLib.h index 92904eb..048ac32 100644 --- a/MdeModulePkg/Include/Library/CapsuleLib.h +++ b/MdeModulePkg/Include/Library/CapsuleLib.h @@ -24,7 +24,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent @param CapsuleHeader Pointer to the UEFI capsule image to be checked.
- @retval EFI_SUCESS Input capsule is supported by firmware.
+ @retval EFI_SUCCESS Input capsule is supported by firmware.
@retval EFI_UNSUPPORTED Input capsule is not supported by the firmware.
**/
EFI_STATUS
@@ -41,7 +41,7 @@ SupportCapsuleImage ( @param CapsuleHeader Pointer to the UEFI capsule image to be processed.
- @retval EFI_SUCESS Capsule Image processed successfully.
+ @retval EFI_SUCCESS Capsule Image processed successfully.
@retval EFI_UNSUPPORTED Capsule image is not supported by the firmware.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Include/Library/FileExplorerLib.h b/MdeModulePkg/Include/Library/FileExplorerLib.h index 528a3ca..9159e7c 100644 --- a/MdeModulePkg/Include/Library/FileExplorerLib.h +++ b/MdeModulePkg/Include/Library/FileExplorerLib.h @@ -26,7 +26,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent after choose one file.
@param File Return the device path for the last time chosed file.
- @retval EFI_SUCESS Choose the file success.
+ @retval EFI_SUCCESS Choose the file success.
@retval Other errors Choose the file failed.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Include/Library/SecurityManagementLib.h b/MdeModulePkg/Include/Library/SecurityManagementLib.h index e10a4cd..5fa1f60 100644 --- a/MdeModulePkg/Include/Library/SecurityManagementLib.h +++ b/MdeModulePkg/Include/Library/SecurityManagementLib.h @@ -12,7 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define __SECURITY_MANAGEMENT_LIB_H__
//
-// Authentication Operation defintions for User Identity (UID), Measured and Secure boot.
+// Authentication Operation definitions for User Identity (UID), Measured and Secure boot.
//
#define EFI_AUTH_OPERATION_NONE 0x00
#define EFI_AUTH_OPERATION_VERIFY_IMAGE 0x01
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/DisplayProtocol.h b/MdeModulePkg/Include/Protocol/DisplayProtocol.h index be08b74..79a6c9d 100644 --- a/MdeModulePkg/Include/Protocol/DisplayProtocol.h +++ b/MdeModulePkg/Include/Protocol/DisplayProtocol.h @@ -238,7 +238,7 @@ struct _FORM_DISPLAY_ENGINE_FORM { //
LIST_ENTRY StatementListOSF;
//
- // The input screen dimenstions info.
+ // The input screen dimensions info.
//
EFI_SCREEN_DESCRIPTOR *ScreenDimensions;
//
diff --git a/MdeModulePkg/Include/Protocol/FileExplorer.h b/MdeModulePkg/Include/Protocol/FileExplorer.h index aa14d27..2662a5e 100644 --- a/MdeModulePkg/Include/Protocol/FileExplorer.h +++ b/MdeModulePkg/Include/Protocol/FileExplorer.h @@ -48,7 +48,7 @@ BOOLEAN after choose one file.
@param File Return the device path for the last time chosed file.
- @retval EFI_SUCESS Choose the file success.
+ @retval EFI_SUCCESS Choose the file success.
@retval Other errors Choose the file failed.
**/
typedef
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/ArmFfaLib/ArmFfaCommon.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c new file mode 100644 index 0000000..332628a --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c @@ -0,0 +1,900 @@ +/** @file
+ Arm Ffa library common code.
+
+ Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - FF-A - Firmware Framework for Arm A-profile
+
+ @par Reference(s):
+ - Arm Firmware Framework for Arm A-Profile [https://developer.arm.com/documentation/den0077/latest]
+
+**/
+#include <Uefi.h>
+#include <Pi/PiMultiPhase.h>
+
+#include <Library/ArmLib.h>
+#include <Library/ArmFfaLib.h>
+#include <Library/ArmSmcLib.h>
+#include <Library/ArmSvcLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/PcdLib.h>
+
+#include <IndustryStandard/ArmFfaSvc.h>
+#include <IndustryStandard/ArmFfaPartInfo.h>
+#include <IndustryStandard/ArmStdSmc.h>
+
+#include <Guid/ArmFfaRxTxBufferInfo.h>
+
+#include "ArmFfaCommon.h"
+
+BOOLEAN gFfaSupported;
+UINT16 gPartId;
+
+/**
+ Convert EFI_STATUS to FFA return code.
+
+ @param [in] Status edk2 status code.
+
+ @retval ARM_FFA_RET_* return value correspond to EFI_STATUS.
+
+**/
+UINTN
+EFIAPI
+EfiStatusToFfaStatus (
+ IN EFI_STATUS Status
+ )
+{
+ switch (Status) {
+ case EFI_SUCCESS:
+ return ARM_FFA_RET_SUCCESS;
+ case EFI_INVALID_PARAMETER:
+ return ARM_FFA_RET_INVALID_PARAMETERS;
+ case EFI_OUT_OF_RESOURCES:
+ return ARM_FFA_RET_NO_MEMORY;
+ case EFI_NO_RESPONSE:
+ return ARM_FFA_RET_BUSY;
+ case EFI_INTERRUPT_PENDING:
+ return ARM_FFA_RET_INTERRUPTED;
+ case EFI_ACCESS_DENIED:
+ return ARM_FFA_RET_DENIED;
+ case EFI_ABORTED:
+ return ARM_FFA_RET_ABORTED;
+ case EFI_NOT_FOUND:
+ return ARM_FFA_RET_NODATA;
+ case EFI_NOT_READY:
+ return ARM_FFA_RET_NOT_READY;
+ default:
+ return ARM_FFA_RET_NOT_SUPPORTED;
+ }
+}
+
+/**
+ Convert FFA return code to EFI_STATUS.
+
+ @param [in] FfaStatus Ffa return Status
+
+ @retval EFI_STATUS return value correspond EFI_STATUS to FfaStatus
+
+**/
+EFI_STATUS
+EFIAPI
+FfaStatusToEfiStatus (
+ IN UINTN FfaStatus
+ )
+{
+ switch ((UINT32)FfaStatus) {
+ case ARM_FFA_RET_SUCCESS:
+ return EFI_SUCCESS;
+ case ARM_FFA_RET_INVALID_PARAMETERS:
+ return EFI_INVALID_PARAMETER;
+ case ARM_FFA_RET_NO_MEMORY:
+ return EFI_OUT_OF_RESOURCES;
+ case ARM_FFA_RET_BUSY:
+ return EFI_NO_RESPONSE;
+ case ARM_FFA_RET_INTERRUPTED:
+ return EFI_INTERRUPT_PENDING;
+ case ARM_FFA_RET_DENIED:
+ return EFI_ACCESS_DENIED;
+ case ARM_FFA_RET_ABORTED:
+ return EFI_ABORTED;
+ case ARM_FFA_RET_NODATA:
+ return EFI_NOT_FOUND;
+ case ARM_FFA_RET_NOT_READY:
+ return EFI_NOT_READY;
+ default:
+ return EFI_UNSUPPORTED;
+ }
+}
+
+/**
+ Convert FfArgs to EFI_STATUS.
+
+ @param [in] FfaArgs Ffa arguments
+
+ @retval EFI_STATUS return value correspond EFI_STATUS to FfaStatus
+
+**/
+EFI_STATUS
+EFIAPI
+FfaArgsToEfiStatus (
+ IN ARM_FFA_ARGS *FfaArgs
+ )
+{
+ UINT32 FfaStatus;
+
+ if (FfaArgs == NULL) {
+ FfaStatus = ARM_FFA_RET_INVALID_PARAMETERS;
+ } else if (IS_FID_FFA_ERROR (FfaArgs->Arg0)) {
+ /*
+ * In case of error, the Arg0 will be set to the fid FFA_ERROR.
+ * and Error code is set in Arg2.
+ */
+ FfaStatus = FfaArgs->Arg2;
+ } else if (FfaArgs->Arg0 == ARM_FFA_RET_NOT_SUPPORTED) {
+ /*
+ * If Some FF-A ABI doesn't support, it sets ARM_FFA_RET_NOT_SUPPORTED
+ * in Arg0 and other register has no meaning.
+ * In this case, set Arg2 as ARM_FFA_RET_NOT_SUPPORTED so that
+ * FfaStatusToEfiStatus (FfaARgs.Arg2) returns proper EFI_STATUS.
+ */
+ FfaStatus = ARM_FFA_RET_NOT_SUPPORTED;
+ } else if (FfaArgs->Arg0 == ARM_FID_FFA_INTERRUPT) {
+ FfaStatus = ARM_FFA_RET_INTERRUPTED;
+ } else {
+ FfaStatus = ARM_FFA_RET_SUCCESS;
+ }
+
+ return FfaStatusToEfiStatus (FfaStatus);
+}
+
+/**
+ Trigger FF-A ABI call according to PcdFfaLibConduitSmc.
+
+ @param [in, out] FfaArgs Ffa arguments
+
+**/
+VOID
+EFIAPI
+ArmCallFfa (
+ IN OUT ARM_FFA_ARGS *FfaArgs
+ )
+{
+ if (PcdGetBool (PcdFfaLibConduitSmc)) {
+ ArmCallSmc ((ARM_SMC_ARGS *)FfaArgs);
+ } else {
+ ArmCallSvc ((ARM_SVC_ARGS *)FfaArgs);
+ }
+}
+
+/**
+ Check FF-A support or not.
+
+ @retval TRUE Supported
+ @retval FALSE Not supported
+
+**/
+BOOLEAN
+EFIAPI
+IsFfaSupported (
+ IN VOID
+ )
+{
+ return gFfaSupported;
+}
+
+/**
+ Get FF-A version.
+
+ @param [in] RequestMajorVersion Minimal request major version
+ @param [in] RequestMinorVersion Minimal request minor version
+ @param [out] CurrentMajorVersion Current major version
+ @param [out] CurrentMinorVersion Current minor version
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibGetVersion (
+ IN UINT16 RequestMajorVersion,
+ IN UINT16 RequestMinorVersion,
+ OUT UINT16 *CurrentMajorVersion,
+ OUT UINT16 *CurrentMinorVersion
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+
+ FfaArgs.Arg0 = ARM_FID_FFA_VERSION;
+ FfaArgs.Arg1 = ARM_FFA_CREATE_VERSION (
+ RequestMajorVersion,
+ RequestMinorVersion
+ );
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if (CurrentMajorVersion != NULL) {
+ *CurrentMajorVersion = ARM_FFA_MAJOR_VERSION_GET (FfaArgs.Arg0);
+ }
+
+ if (CurrentMinorVersion != NULL) {
+ *CurrentMinorVersion = ARM_FFA_MINOR_VERSION_GET (FfaArgs.Arg0);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Get FF-A features.
+
+ @param [in] Id Feature id or function id
+ @param [in] InputProperties Input properties according to Id
+ @param [out] Property1 First property.
+ @param [out] Property2 Second property.
+
+ @retval EFI_SUCCESS
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibGetFeatures (
+ IN UINT32 Id,
+ IN UINT32 InputProperties,
+ OUT UINTN *Property1,
+ OUT UINTN *Property2
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+
+ if ((Property1 == NULL) || (Property2 == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *Property1 = 0x00;
+ *Property2 = 0x00;
+
+ switch (Id) {
+ case ARM_FID_FFA_RXTX_MAP_AARCH32:
+ case ARM_FID_FFA_RXTX_MAP_AARCH64:
+ if ((InputProperties != FFA_RXTX_MAP_INPUT_PROPERTY_DEFAULT)) {
+ DEBUG ((DEBUG_ERROR, "%a: Invalid Parameter for FunctionId: 0x%x", __func__, Id));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ break;
+ }
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+ FfaArgs.Arg0 = ARM_FID_FFA_FEATURES;
+ FfaArgs.Arg1 = Id;
+ FfaArgs.Arg2 = InputProperties;
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ switch (Id) {
+ case ARM_FID_FFA_RXTX_MAP_AARCH32:
+ case ARM_FID_FFA_RXTX_MAP_AARCH64:
+ case ARM_FFA_FEATURE_ID_NOTIFICATION_PENDING_INTERRUPT:
+ case ARM_FFA_FEATURE_ID_SCHEDULE_RECEIVER_INTERRUPT:
+ case ARM_FFA_FEATURE_ID_MANAGED_EXIT_INTERRUPT:
+ *Property1 = FfaArgs.Arg2;
+ break;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Acquire ownership of the Rx buffer.
+
+ @param [in] PartId Partition Id
+
+ @retval EFI_SUCCESS
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibRxAcquire (
+ IN UINT16 PartId
+ )
+{
+ ARM_FFA_ARGS FfaArgs;
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+
+ FfaArgs.Arg0 = ARM_FID_FFA_RX_ACQUIRE;
+ FfaArgs.Arg1 = PartId;
+
+ ArmCallFfa (&FfaArgs);
+
+ return FfaArgsToEfiStatus (&FfaArgs);
+}
+
+/**
+ Release ownership of the Rx buffer.
+
+ @param [in] PartId Partition Id
+
+ @retval EFI_SUCCESS
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibRxRelease (
+ IN UINT16 PartId
+ )
+{
+ ARM_FFA_ARGS FfaArgs;
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+
+ FfaArgs.Arg0 = ARM_FID_FFA_RX_RELEASE;
+ FfaArgs.Arg1 = PartId;
+
+ ArmCallFfa (&FfaArgs);
+
+ return FfaArgsToEfiStatus (&FfaArgs);
+}
+
+/**
+ Get partition or VM id.
+
+ @param [out] PartId Partition id
+
+ @retval EFI_SUCCESS
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibPartitionIdGet (
+ OUT UINT16 *PartId
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+
+ if (PartId == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+
+ FfaArgs.Arg0 = ARM_FID_FFA_ID_GET;
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to get partition id. Status: %r\n",
+ __func__,
+ Status
+ ));
+ return Status;
+ }
+
+ *PartId = (FfaArgs.Arg2 >> ARM_FFA_DEST_EP_SHIFT) & ARM_FFA_PARTITION_ID_MASK;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Get spmc or spmd partition id.
+
+ @param [out] SpmPartId spmc/spmd partition id
+
+ @retval EFI_SUCCESS
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibSpmIdGet (
+ OUT UINT16 *SpmPartId
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+
+ if (SpmPartId == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+
+ FfaArgs.Arg0 = ARM_FID_FFA_SPM_ID_GET;
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to get partition id. Status: %r\n",
+ __func__,
+ Status
+ ));
+ return Status;
+ }
+
+ *SpmPartId = (FfaArgs.Arg2 >> ARM_FFA_DEST_EP_SHIFT) & ARM_FFA_PARTITION_ID_MASK;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Get Partition info.
+ If This function is called to get partition descriptors
+ (Flags isn't set with FFA_PART_INFO_FLAG_TYPE_COUNT),
+ It should call ArmFfaLibRxRelease() to release RX buffer.
+
+ @param [in] ServiceGuid Service guid.
+ @param [in] Flags If this function called to get partition desc
+ and get successfully,
+ Caller should release RX buffer by calling
+ ArmFfaLibRxRelease
+ @param [out] Count Number of partition or partition descriptor
+ @param [out] Size Size of Partition Info structure in Rx Buffer
+
+ @retval EFI_SUCCESS
+ @retval Others Error
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibPartitionInfoGet (
+ IN EFI_GUID *ServiceGuid,
+ IN UINT32 Flags,
+ OUT UINT32 *Count,
+ OUT UINT32 *Size OPTIONAL
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+ UINT64 Uuid[2];
+ UINT32 *SmcUuid;
+
+ if (Count == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((((Flags >> FFA_PART_INFO_FLAG_TYPE_SHIFT) & FFA_PART_INFO_FLAG_TYPE_MASK) !=
+ FFA_PART_INFO_FLAG_TYPE_COUNT) && (Size == NULL))
+ {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (ServiceGuid != NULL) {
+ ConvertGuidToUuid (ServiceGuid, (GUID *)Uuid);
+ } else {
+ ZeroMem (Uuid, sizeof (Uuid));
+ }
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+ SmcUuid = (UINT32 *)Uuid;
+
+ FfaArgs.Arg0 = ARM_FID_FFA_PARTITION_INFO_GET;
+ FfaArgs.Arg1 = SmcUuid[0];
+ FfaArgs.Arg2 = SmcUuid[1];
+ FfaArgs.Arg3 = SmcUuid[2];
+ FfaArgs.Arg4 = SmcUuid[3];
+ FfaArgs.Arg5 = Flags;
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to get partition information of %g. Status: %r\n",
+ __func__,
+ (ServiceGuid != NULL) ? ServiceGuid : (EFI_GUID *)Uuid,
+ Status
+ ));
+ goto ErrorHandler;
+ }
+
+ *Count = FfaArgs.Arg2;
+ if (Size != NULL) {
+ *Size = FfaArgs.Arg3;
+ }
+
+ return EFI_SUCCESS;
+
+ErrorHandler:
+ *Count = 0;
+ if (Size != NULL) {
+ *Size = 0;
+ }
+
+ return Status;
+}
+
+/**
+ Restore the context which was interrupted with FFA_INTERRUPT (EFI_INTERRUPT_PENDING).
+
+ @param [in] PartId Partition id
+ @param [in] CpuNumber Cpu number in partition
+
+ @retval EFI_SUCCESS
+ @retval Other Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibRun (
+ IN UINT16 PartId,
+ IN UINT16 CpuNumber
+ )
+{
+ ARM_FFA_ARGS FfaArgs;
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+
+ FfaArgs.Arg0 = ARM_FID_FFA_RUN;
+ FfaArgs.Arg1 = PACK_PARTITION_ID_INFO (PartId, CpuNumber);
+
+ ArmCallFfa (&FfaArgs);
+
+ return FfaArgsToEfiStatus (&FfaArgs);
+}
+
+/**
+ Send direct message request version 1.
+
+ @param [in] DestPartId Dest partition id
+ @param [in] Flags Message flags
+ @param [in, out] ImpDefArgs Implemented defined arguments and
+ Implemented defined return values
+
+ @retval EFI_SUCCESS Success
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibMsgSendDirectReq (
+ IN UINT16 DestPartId,
+ IN UINT32 Flags,
+ IN OUT DIRECT_MSG_ARGS *ImpDefArgs
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+
+ if ((DestPartId == gPartId) || (ImpDefArgs == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+
+ FfaArgs.Arg0 = ARM_FID_FFA_MSG_SEND_DIRECT_REQ;
+ FfaArgs.Arg1 = PACK_PARTITION_ID_INFO (gPartId, DestPartId);
+ FfaArgs.Arg2 = Flags;
+ FfaArgs.Arg3 = ImpDefArgs->Arg0;
+ FfaArgs.Arg4 = ImpDefArgs->Arg1;
+ FfaArgs.Arg5 = ImpDefArgs->Arg2;
+ FfaArgs.Arg6 = ImpDefArgs->Arg3;
+ FfaArgs.Arg7 = ImpDefArgs->Arg4;
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ ImpDefArgs->Arg0 = FfaArgs.Arg3;
+ ImpDefArgs->Arg1 = FfaArgs.Arg4;
+ ImpDefArgs->Arg2 = FfaArgs.Arg5;
+ ImpDefArgs->Arg3 = FfaArgs.Arg6;
+ ImpDefArgs->Arg4 = FfaArgs.Arg7;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Send direct message request version 2.
+
+ @param [in] DestPartId Dest partition id
+ @param [in] ServiceGuid Service guid
+ @param [in, out] ImpDefArgs Implemented defined arguments and
+ Implemented defined return values
+
+ @retval EFI_SUCCESS Success
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibMsgSendDirectReq2 (
+ IN UINT16 DestPartId,
+ IN EFI_GUID *ServiceGuid,
+ IN OUT DIRECT_MSG_ARGS *ImpDefArgs
+ )
+{
+ EFI_STATUS Status;
+ UINT64 Uuid[2];
+ ARM_FFA_ARGS FfaArgs;
+
+ /*
+ * Direct message request 2 is only supported on AArch64.
+ */
+ if (sizeof (UINTN) != sizeof (UINT64)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ if ((DestPartId == gPartId) || (ImpDefArgs == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (ServiceGuid != NULL) {
+ ConvertGuidToUuid (ServiceGuid, (GUID *)Uuid);
+ } else {
+ ZeroMem (Uuid, sizeof (Uuid));
+ }
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+
+ FfaArgs.Arg0 = ARM_FID_FFA_MSG_SEND_DIRECT_REQ2;
+ FfaArgs.Arg1 = PACK_PARTITION_ID_INFO (gPartId, DestPartId);
+ FfaArgs.Arg2 = Uuid[0];
+ FfaArgs.Arg3 = Uuid[1];
+ FfaArgs.Arg4 = ImpDefArgs->Arg0;
+ FfaArgs.Arg5 = ImpDefArgs->Arg1;
+ FfaArgs.Arg6 = ImpDefArgs->Arg2;
+ FfaArgs.Arg7 = ImpDefArgs->Arg3;
+ FfaArgs.Arg8 = ImpDefArgs->Arg4;
+ FfaArgs.Arg9 = ImpDefArgs->Arg5;
+ FfaArgs.Arg10 = ImpDefArgs->Arg6;
+ FfaArgs.Arg11 = ImpDefArgs->Arg7;
+ FfaArgs.Arg12 = ImpDefArgs->Arg8;
+ FfaArgs.Arg13 = ImpDefArgs->Arg9;
+ FfaArgs.Arg14 = ImpDefArgs->Arg10;
+ FfaArgs.Arg15 = ImpDefArgs->Arg11;
+ FfaArgs.Arg16 = ImpDefArgs->Arg12;
+ FfaArgs.Arg17 = ImpDefArgs->Arg13;
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ ImpDefArgs->Arg0 = FfaArgs.Arg4;
+ ImpDefArgs->Arg1 = FfaArgs.Arg5;
+ ImpDefArgs->Arg2 = FfaArgs.Arg6;
+ ImpDefArgs->Arg3 = FfaArgs.Arg7;
+ ImpDefArgs->Arg4 = FfaArgs.Arg8;
+ ImpDefArgs->Arg5 = FfaArgs.Arg9;
+ ImpDefArgs->Arg6 = FfaArgs.Arg10;
+ ImpDefArgs->Arg7 = FfaArgs.Arg11;
+ ImpDefArgs->Arg8 = FfaArgs.Arg12;
+ ImpDefArgs->Arg9 = FfaArgs.Arg13;
+ ImpDefArgs->Arg10 = FfaArgs.Arg14;
+ ImpDefArgs->Arg11 = FfaArgs.Arg15;
+ ImpDefArgs->Arg12 = FfaArgs.Arg16;
+ ImpDefArgs->Arg13 = FfaArgs.Arg17;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Common ArmFfaLib init.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_UNSUPPORTED FF-A isn't supported
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibCommonInit (
+ IN VOID
+ )
+{
+ EFI_STATUS Status;
+ UINT16 CurrentMajorVersion;
+ UINT16 CurrentMinorVersion;
+
+ gFfaSupported = FALSE;
+
+ Status = ArmFfaLibGetVersion (
+ ARM_FFA_MAJOR_VERSION,
+ ARM_FFA_MINOR_VERSION,
+ &CurrentMajorVersion,
+ &CurrentMinorVersion
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ if ((ARM_FFA_MAJOR_VERSION != CurrentMajorVersion) ||
+ (ARM_FFA_MINOR_VERSION > CurrentMinorVersion))
+ {
+ DEBUG ((
+ DEBUG_INFO,
+ "Incompatible FF-A Versions.\n" \
+ "Request Version: Major=0x%x, Minor=0x%x.\n" \
+ "Current Version: Major=0x%x, Minor>=0x%x.\n",
+ ARM_FFA_MAJOR_VERSION,
+ ARM_FFA_MINOR_VERSION,
+ CurrentMajorVersion,
+ CurrentMinorVersion
+ ));
+ return EFI_UNSUPPORTED;
+ }
+
+ Status = ArmFfaLibPartitionIdGet (&gPartId);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ gFfaSupported = TRUE;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Get first Rx/Tx Buffer allocation hob.
+ If UseGuid is TRUE, BufferAddr and BufferSize parameters are ignored.
+
+ @param[in] BufferAddr Buffer address
+ @param[in] BufferSize Buffer Size
+ @param[in] UseGuid Find MemoryAllocationHob using gArmFfaRxTxBufferInfoGuid.
+
+ @retval NULL Not found
+ @retval Other MemoryAllocationHob related to Rx/Tx buffer
+
+**/
+EFI_HOB_MEMORY_ALLOCATION *
+EFIAPI
+GetRxTxBufferAllocationHob (
+ IN EFI_PHYSICAL_ADDRESS BufferAddr,
+ IN UINT64 BufferSize,
+ IN BOOLEAN UseGuid
+ )
+{
+ EFI_PEI_HOB_POINTERS Hob;
+ EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob;
+ EFI_PHYSICAL_ADDRESS MemoryBase;
+ UINT64 MemorySize;
+
+ if (!UseGuid && (BufferAddr == 0x00)) {
+ return NULL;
+ }
+
+ MemoryAllocationHob = NULL;
+ Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
+
+ while (Hob.Raw != NULL) {
+ if (Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiConventionalMemory) {
+ continue;
+ }
+
+ MemoryBase = Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress;
+ MemorySize = Hob.MemoryAllocation->AllocDescriptor.MemoryLength;
+
+ if ((!UseGuid && (BufferAddr >= MemoryBase) &&
+ ((BufferAddr + BufferSize) <= (MemoryBase + MemorySize))) ||
+ (UseGuid && CompareGuid (
+ &gArmFfaRxTxBufferInfoGuid,
+ &Hob.MemoryAllocation->AllocDescriptor.Name
+ )))
+ {
+ MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;
+ break;
+ }
+
+ Hob.Raw = GET_NEXT_HOB (Hob);
+ Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw);
+ }
+
+ return MemoryAllocationHob;
+}
+
+/**
+ Get Rx/Tx buffer MinSizeAndAign and MaxSize
+
+ @param[out] MinSizeAndAlign Minimum size of Buffer.
+
+ @retval EFI_SUCCESS
+ @retval EFI_UNSUPPORTED Wrong min size received from SPMC
+ @retval EFI_INVALID_PARAMETER Wrong buffer size
+ @retval Others Failure of ArmFfaLibGetFeatures()
+
+**/
+EFI_STATUS
+EFIAPI
+GetRxTxBufferMinSizeAndAlign (
+ OUT UINTN *MinSizeAndAlign
+ )
+{
+ EFI_STATUS Status;
+ UINTN MinAndAlign;
+ UINTN MaxSize;
+ UINTN Property1;
+ UINTN Property2;
+
+ Status = ArmFfaLibGetFeatures (
+ ARM_FID_FFA_RXTX_MAP,
+ FFA_RXTX_MAP_INPUT_PROPERTY_DEFAULT,
+ &Property1,
+ &Property2
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to get RX/TX buffer property... Status: %r\n",
+ __func__,
+ Status
+ ));
+ return Status;
+ }
+
+ MinAndAlign =
+ ((Property1 >>
+ ARM_FFA_BUFFER_MINSIZE_AND_ALIGN_SHIFT) &
+ ARM_FFA_BUFFER_MINSIZE_AND_ALIGN_MASK);
+
+ switch (MinAndAlign) {
+ case ARM_FFA_BUFFER_MINSIZE_AND_ALIGN_4K:
+ MinAndAlign = SIZE_4KB;
+ break;
+ case ARM_FFA_BUFFER_MINSIZE_AND_ALIGN_16K:
+ MinAndAlign = SIZE_16KB;
+ break;
+ case ARM_FFA_BUFFER_MINSIZE_AND_ALIGN_64K:
+ MinAndAlign = SIZE_64KB;
+ break;
+ default:
+ DEBUG ((DEBUG_ERROR, "%a: Invalid MinSizeAndAlign: 0x%x\n", __func__, MinAndAlign));
+ return EFI_UNSUPPORTED;
+ }
+
+ MaxSize =
+ (((Property1 >>
+ ARM_FFA_BUFFER_MAXSIZE_PAGE_COUNT_SHIFT) &
+ ARM_FFA_BUFFER_MAXSIZE_PAGE_COUNT_MASK));
+
+ MaxSize = ((MaxSize == 0) ? MAX_UINTN : (MaxSize * MinAndAlign));
+
+ if ((MinAndAlign > (PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE)) ||
+ (MaxSize < (PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE)))
+ {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Buffer is too small! MinSize: 0x%x, MaxSize: 0x%x, PageCount: %d\n",
+ __func__,
+ MinAndAlign,
+ MaxSize,
+ PcdGet64 (PcdFfaTxRxPageCount)
+ ));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *MinSizeAndAlign = MinAndAlign;
+
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.h b/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.h new file mode 100644 index 0000000..1994dd8 --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.h @@ -0,0 +1,89 @@ +/** @file
+ Arm FF-A ns common library Header file
+
+ Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - FF-A - Firmware Framework for Arm A-profile
+ - spmc - Secure Partition Manager Core
+ - spmd - Secure Partition Manager Dispatcher
+
+ @par Reference(s):
+ - Arm Firmware Framework for Arm A-Profile [https://developer.arm.com/documentation/den0077/latest]
+
+**/
+
+#ifndef ARM_FFA_COMMON_LIB_H_
+#define ARM_FFA_COMMON_LIB_H_
+
+#include <Library/ArmFfaLib.h>
+
+extern BOOLEAN gFfaSupported;
+extern UINT16 gPartId;
+
+/**
+ Convert FfArgs to EFI_STATUS.
+
+ @param [in] FfaArgs Ffa arguments
+
+ @retval EFI_STATUS return value correspond EFI_STATUS to FfaStatus
+
+**/
+EFI_STATUS
+EFIAPI
+FfaArgsToEfiStatus (
+ IN ARM_FFA_ARGS *FfaArgs
+ );
+
+/**
+ Common ArmFfaLib Constructor.
+
+ @retval EFI_SUCCESS
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibCommonInit (
+ IN VOID
+ );
+
+/**
+ Get first Rx/Tx Buffer allocation hob.
+ If UseGuid is TRUE, BufferAddr and BufferSize parameters are ignored.
+
+ @param[in] BufferAddr Buffer address
+ @param[in] BufferSize Buffer Size
+ @param[in] UseGuid Find MemoryAllocationHob using gArmFfaRxTxBufferInfoGuid.
+
+ @retval NULL Not found
+ @retval Other MemoryAllocationHob related to Rx/Tx buffer
+
+**/
+EFI_HOB_MEMORY_ALLOCATION *
+EFIAPI
+GetRxTxBufferAllocationHob (
+ IN EFI_PHYSICAL_ADDRESS BufferAddr,
+ IN UINT64 BufferSize,
+ IN BOOLEAN UseGuid
+ );
+
+/**
+ Get Rx/Tx buffer MinSizeAndAign and MaxSize
+
+ @param[out] MinSizeAndAlign Minimum size of Buffer.
+
+ @retval EFI_SUCCESS
+ @retval EFI_UNSUPPORTED Wrong min size received from SPMC
+ @retval EFI_INVALID_PARAMETER Wrong buffer size
+ @retval Others Failure of ArmFfaLibGetFeatures()
+
+**/
+EFI_STATUS
+EFIAPI
+GetRxTxBufferMinSizeAndAlign (
+ OUT UINTN *MinSizeAndAlign
+ );
+
+#endif
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaDxeLib.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaDxeLib.c new file mode 100644 index 0000000..ad2ed2f --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaDxeLib.c @@ -0,0 +1,177 @@ +/** @file
+ Arm Ffa library code for Dxe Driver
+
+ Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - FF-A - Firmware Framework for Arm A-profile
+
+ @par Reference(s):
+ - Arm Firmware Framework for Arm A-Profile [https://developer.arm.com/documentation/den0077/latest]
+
+**/
+
+#include <Uefi.h>
+#include <Pi/PiMultiPhase.h>
+
+#include <Library/ArmLib.h>
+#include <Library/ArmSmcLib.h>
+#include <Library/ArmFfaLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <IndustryStandard/ArmFfaSvc.h>
+
+#include <Guid/ArmFfaRxTxBufferInfo.h>
+
+#include "ArmFfaCommon.h"
+#include "ArmFfaRxTxMap.h"
+
+STATIC EFI_EVENT mFfaExitBootServiceEvent;
+
+/**
+ Unmap RX/TX buffer on Exit Boot Service.
+
+ @param [in] Event Registered exit boot service event.
+ @param [in] Context Additional data.
+
+**/
+STATIC
+VOID
+EFIAPI
+ArmFfaLibExitBootServiceEvent (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ ArmFfaLibRxTxUnmap ();
+}
+
+/**
+ ArmFfaLib Constructor.
+
+ @param [in] ImageHandle Image Handle
+ @param [in] SystemTable System Table
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER Invalid alignment of Rx/Tx buffer
+ @retval EFI_OUT_OF_RESOURCES Out of memory
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaDxeLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ EFI_HOB_GUID_TYPE *RxTxBufferHob;
+ ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo;
+
+ Status = ArmFfaLibCommonInit ();
+ if (EFI_ERROR (Status)) {
+ if (Status == EFI_UNSUPPORTED) {
+ /*
+ * EFI_UNSUPPORTED return from ArmFfaLibCommonInit() means
+ * FF-A interface doesn't support.
+ * However, It doesn't make failure of loading driver/library instance
+ * (i.e) ArmPkg's MmCommunication Dxe/PEI Driver uses as well as SpmMm.
+ * So If FF-A is not supported the the MmCommunication Dxe/PEI falls
+ * back to SpmMm.
+ * For this case, return EFI_SUCCESS.
+ */
+ return EFI_SUCCESS;
+ }
+
+ return Status;
+ }
+
+ if (PcdGetBool (PcdFfaExitBootEventRegistered)) {
+ return EFI_SUCCESS;
+ }
+
+ RxTxBufferHob = GetFirstGuidHob (&gArmFfaRxTxBufferInfoGuid);
+ if (RxTxBufferHob != NULL) {
+ BufferInfo = GET_GUID_HOB_DATA (RxTxBufferHob);
+ if (!BufferInfo->RemapRequired) {
+ /*
+ * ArmFfaPeiLib handles the Rx/Tx buffer Remap and update the
+ * BufferInfo with permanant memory. So use it as it is.
+ */
+ PcdSet64S (PcdFfaTxBuffer, (UINTN)BufferInfo->TxBufferAddr);
+ PcdSet64S (PcdFfaRxBuffer, (UINTN)BufferInfo->RxBufferAddr);
+ } else {
+ /*
+ * SEC maps Rx/Tx buffer, But no PEIM module doesn't use
+ * ArmFfaPeiLib. In this case, the BufferInfo includes
+ * temporary Rx/Tx buffer address.
+ *
+ * Therefore, remap Rx/Tx buffer with migrated address again.
+ */
+ Status = RemapFfaRxTxBuffer (BufferInfo);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to remap Rx/Tx buffer... Status: %r\n", __func__, Status));
+ return Status;
+ }
+
+ BufferInfo->RemapRequired = FALSE;
+ }
+ } else {
+ Status = ArmFfaLibRxTxMap ();
+
+ /*
+ * When first Dxe instance (library or driver) which uses ArmFfaLib loaded,
+ * It already maps Rx/Tx buffer.
+ * From Next Dxe instance which uses ArmFfaLib it doesn't need to map Rx/Tx
+ * buffer again but it uses the mapped one.
+ * ArmFfaLibRxTxMap() returns EFI_ALREADY_STARTED when the Rx/Tx buffers
+ * already maps.
+ */
+ if ((Status != EFI_SUCCESS) && (Status != EFI_ALREADY_STARTED)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to Map Rx/Tx buffer. Status: %r\n",
+ __func__,
+ Status
+ ));
+ return Status;
+ }
+ }
+
+ Status = gBS->CreateEventEx (
+ EVT_NOTIFY_SIGNAL,
+ TPL_CALLBACK,
+ ArmFfaLibExitBootServiceEvent,
+ NULL,
+ &gEfiEventExitBootServicesGuid,
+ &mFfaExitBootServiceEvent
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to register ExitBootService event. Status: %r\n",
+ __func__,
+ Status
+ ));
+ goto ErrorHandler;
+ }
+
+ PcdSetBoolS (PcdFfaExitBootEventRegistered, TRUE);
+
+ return EFI_SUCCESS;
+
+ErrorHandler:
+ if (RxTxBufferHob != NULL) {
+ ArmFfaLibRxTxUnmap ();
+ }
+
+ return Status;
+}
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaDxeLib.inf b/MdeModulePkg/Library/ArmFfaLib/ArmFfaDxeLib.inf new file mode 100644 index 0000000..361ebf6 --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaDxeLib.inf @@ -0,0 +1,46 @@ +## @file
+# Provides FF-A ABI Library used in Dxe Driver.
+#
+# Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = ArmFfaDxeLib
+ FILE_GUID = e2a8e040-5346-11ef-8454-eff3c163f615
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = ArmFfaLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER
+ CONSTRUCTOR = ArmFfaDxeLibConstructor
+
+[Sources]
+ ArmFfaCommon.h
+ ArmFfaCommon.c
+ ArmFfaRxTxMap.h
+ ArmFfaRxTxMap.c
+ ArmFfaDxeLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ ArmSmcLib
+ ArmSvcLib
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ HobLib
+
+[Pcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaLibConduitSmc
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaTxBuffer
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaRxBuffer
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaTxRxPageCount
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaExitBootEventRegistered
+
+[Guids]
+ gArmFfaRxTxBufferInfoGuid
+ gEfiEventExitBootServicesGuid
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.c new file mode 100644 index 0000000..e2dd99b --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.c @@ -0,0 +1,200 @@ +/** @file
+ Arm Ffa library code for PEI Driver
+
+ Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - FF-A - Firmware Framework for Arm A-profile
+
+ @par Reference(s):
+ - Arm Firmware Framework for Arm A-Profile [https://developer.arm.com/documentation/den0077/latest]
+
+**/
+
+#include <Uefi.h>
+#include <PiPei.h>
+#include <Pi/PiPeiCis.h>
+#include <Pi/PiMultiPhase.h>
+
+#include <Library/ArmLib.h>
+#include <Library/ArmSmcLib.h>
+#include <Library/ArmFfaLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+
+#include <IndustryStandard/ArmFfaSvc.h>
+
+#include <Guid/ArmFfaRxTxBufferInfo.h>
+
+#include "ArmFfaCommon.h"
+#include "ArmFfaRxTxMap.h"
+
+/**
+ Notification service to be called when gEfiPeiMemoryDiscoveredPpiGuid is installed.
+ This function change reamp Rx/Tx buffer with permanent memory from
+ temporary Rx/Tx buffer.
+
+ Since, the Rx/Tx buffer is chanaged after gEfiPeiMemoryDiscoveredPpiGuid is installed,
+ the Rx/Tx buffer should be gotten in each PEIM entrypoint
+ via "ArmFfaGetRxTxBuffers()" for PEIM registered as shadow and
+ call that function always then, it always gets proper Rx/Tx buffer.
+
+ @param PeiServices Indirect reference to the PEI Services Table.
+ @param NotifyDescriptor Address of the notification descriptor data structure.
+ Type EFI_PEI_NOTIFY_DESCRIPTOR is defined above.
+ @param Ppi Address of the PPI that was installed.
+
+ @retval EFI_STATUS This function will install a PPI to PPI database.
+ The status code will be the code for (*PeiServices)->InstallPpi.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+PeiServicesMemoryDiscoveredNotifyCallback (
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
+ IN VOID *Ppi
+ )
+{
+ EFI_HOB_GUID_TYPE *RxTxBufferHob;
+ ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo;
+
+ RxTxBufferHob = GetFirstGuidHob (&gArmFfaRxTxBufferInfoGuid);
+ ASSERT (RxTxBufferHob != NULL);
+ BufferInfo = GET_GUID_HOB_DATA (RxTxBufferHob);
+
+ return RemapFfaRxTxBuffer (BufferInfo);
+}
+
+STATIC EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnPeiMemoryDiscovered = {
+ (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+ &gEfiPeiMemoryDiscoveredPpiGuid,
+ PeiServicesMemoryDiscoveredNotifyCallback
+};
+
+/**
+ ArmFfaLib Constructor.
+
+ @param [in] FileHandle File Handle
+ @param [in] PeiServices Pei Service Table
+
+ @retval EFI_SUCCESS Success
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaPeiLibConstructor (
+ IN EFI_PEI_FILE_HANDLE FileHandle,
+ IN CONST EFI_PEI_SERVICES **PeiServices
+ )
+{
+ EFI_STATUS Status;
+ EFI_HOB_GUID_TYPE *RxTxBufferHob;
+ ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo;
+ VOID *Dummy;
+ EFI_HOB_MEMORY_ALLOCATION *RxTxBufferAllocationHob;
+
+ Status = ArmFfaLibCommonInit ();
+ if (EFI_ERROR (Status)) {
+ if (Status == EFI_UNSUPPORTED) {
+ /*
+ * EFI_UNSUPPORTED return from ArmFfaLibCommonInit() means
+ * FF-A interface doesn't support.
+ * However, It doesn't make failure of loading driver/library instance
+ * (i.e) ArmPkg's MmCommunication Dxe/PEI Driver uses as well as SpmMm.
+ * So If FF-A is not supported the the MmCommunication Dxe/PEI falls
+ * back to SpmMm.
+ * For this case, return EFI_SUCCESS.
+
+ */
+ return EFI_SUCCESS;
+ }
+
+ return Status;
+ }
+
+ RxTxBufferHob = GetFirstGuidHob (&gArmFfaRxTxBufferInfoGuid);
+ if (RxTxBufferHob == NULL) {
+ Status = ArmFfaLibRxTxMap ();
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ BufferInfo = BuildGuidHob (
+ &gArmFfaRxTxBufferInfoGuid,
+ sizeof (ARM_FFA_RX_TX_BUFFER_INFO)
+ );
+ if (BufferInfo == NULL) {
+ ArmFfaLibRxTxUnmap ();
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ UpdateRxTxBufferInfo (BufferInfo);
+
+ /*
+ * When permanent memory is used, gEfiPeiMemoryDiscoveredPpiGuid
+ * is installed. If gEfiPeiMemoryDiscoveredPpiGuid is found,
+ * It doesn't need to remap Rx/Tx buffer.
+ */
+ Status = (*PeiServices)->LocatePpi (
+ PeiServices,
+ &gEfiPeiMemoryDiscoveredPpiGuid,
+ 0,
+ NULL,
+ &Dummy
+ );
+ BufferInfo->RemapRequired = EFI_ERROR (Status);
+ } else {
+ BufferInfo = GET_GUID_HOB_DATA (RxTxBufferHob);
+ }
+
+ if (BufferInfo->RemapRequired) {
+ /*
+ * If RxTxBufferAllocationHob can be found with gArmFfaRxTxBufferInfoGuid,
+ * This Rx/Tx buffer is mapped by ArmFfaSecLib.
+ */
+ RxTxBufferAllocationHob = FindRxTxBufferAllocationHob (TRUE);
+
+ /*
+ * Below case Rx/Tx buffer mapped by ArmPeiLib but in temporary memory.
+ */
+ if (RxTxBufferAllocationHob == NULL) {
+ RxTxBufferAllocationHob = FindRxTxBufferAllocationHob (FALSE);
+ ASSERT (RxTxBufferAllocationHob != NULL);
+ BufferInfo->RemapOffset =
+ (UINTN)(BufferInfo->TxBufferAddr -
+ RxTxBufferAllocationHob->AllocDescriptor.MemoryBaseAddress);
+
+ CopyGuid (
+ &RxTxBufferAllocationHob->AllocDescriptor.Name,
+ &gArmFfaRxTxBufferInfoGuid
+ );
+ }
+
+ Status = (*PeiServices)->NotifyPpi (PeiServices, &mNotifyOnPeiMemoryDiscovered);
+
+ /*
+ * Failed to register NotifyPpi.
+ * In this case, return ERROR to make failure of load for PPI
+ * and postpone to remap to other PEIM.
+ */
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ /*
+ * Change RemapRequired to FALSE here to prevent other PEIM from
+ * registering notification again.
+ */
+ BufferInfo->RemapRequired = FALSE;
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.inf b/MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.inf new file mode 100644 index 0000000..53d5750 --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.inf @@ -0,0 +1,48 @@ +## @file
+# Provides FF-A ABI Library used in PEI Driver.
+#
+# Copyright (c) 2024-2025, Arm Limited. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = ArmFfaPeiLib
+ FILE_GUID = 6e21912a-5f50-11ef-a3ae-dfe665fd4fc0
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = ArmFfaLib|PEIM
+ CONSTRUCTOR = ArmFfaPeiLibConstructor
+
+[Sources]
+ ArmFfaCommon.h
+ ArmFfaCommon.c
+ ArmFfaRxTxMap.h
+ ArmFfaRxTxMap.c
+ ArmFfaPeiLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ ArmSmcLib
+ ArmSvcLib
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ HobLib
+
+[Pcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaLibConduitSmc
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaTxBuffer
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaRxBuffer
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaTxRxPageCount
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaExitBootEventRegistered
+
+[Guids]
+ gArmFfaRxTxBufferInfoGuid
+
+[Ppis]
+ gEfiPeiMemoryDiscoveredPpiGuid
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.c new file mode 100644 index 0000000..4f0e1a4 --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.c @@ -0,0 +1,343 @@ +/** @file
+ Arm Ffa library common code.
+
+ Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - FF-A - Firmware Framework for Arm A-profile
+
+ @par Reference(s):
+ - Arm Firmware Framework for Arm A-Profile [https://developer.arm.com/documentation/den0077/latest]
+
+**/
+#include <Uefi.h>
+#include <Pi/PiMultiPhase.h>
+
+#include <Library/ArmLib.h>
+#include <Library/ArmFfaLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <IndustryStandard/ArmFfaSvc.h>
+
+#include <Guid/ArmFfaRxTxBufferInfo.h>
+
+#include "ArmFfaCommon.h"
+#include "ArmFfaRxTxMap.h"
+
+/**
+ Get mapped Rx/Tx buffers.
+
+ @param [out] TxBuffer Address of TxBuffer
+ @param [out] TxBufferSize Size of TxBuffer
+ @param [out] RxBuffer Address of RxBuffer
+ @param [out] RxBufferSize Size of RxBuffer
+
+ @retval EFI_SUCCESS
+ @retval Others Error.
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibGetRxTxBuffers (
+ OUT VOID **TxBuffer OPTIONAL,
+ OUT UINT64 *TxBufferSize OPTIONAL,
+ OUT VOID **RxBuffer OPTIONAL,
+ OUT UINT64 *RxBufferSize OPTIONAL
+ )
+{
+ UINTN TxBufferAddr;
+ UINTN RxBufferAddr;
+
+ TxBufferAddr = (UINTN)PcdGet64 (PcdFfaTxBuffer);
+ RxBufferAddr = (UINTN)PcdGet64 (PcdFfaRxBuffer);
+
+ if ((TxBufferAddr == 0x00) || (RxBufferAddr == 0x00)) {
+ return EFI_NOT_READY;
+ }
+
+ if (TxBuffer != NULL) {
+ *TxBuffer = (VOID *)TxBufferAddr;
+ }
+
+ if (TxBufferSize != NULL) {
+ *TxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE;
+ }
+
+ if (RxBuffer != NULL) {
+ *RxBuffer = (VOID *)RxBufferAddr;
+ }
+
+ if (RxBufferSize != NULL) {
+ *RxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Mapping Rx/Tx buffers.
+ This function is only called in ArmFfaLibConstructor because
+ Rx/Tx buffer is registered only once per partition.
+
+ @retval EFI_SUCCESS
+ @retval EFI_ALREADY_STARTED Rx/Tx buffer already mapped.
+ @retval EFI_OUT_OF_RESOURCE Out of memory
+ @retval EFI_INVALID_PARAMETER Invalid alignment of Rx/Tx buffer
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibRxTxMap (
+ IN VOID
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+ UINTN MinSizeAndAlign;
+ VOID *Buffers;
+ VOID *TxBuffer;
+ VOID *RxBuffer;
+ UINT64 BufferSize;
+
+ TxBuffer = (VOID *)(UINTN)PcdGet64 (PcdFfaTxBuffer);
+ RxBuffer = (VOID *)(UINTN)PcdGet64 (PcdFfaRxBuffer);
+ BufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE;
+
+ /*
+ * If someone already mapped Rx/Tx Buffers, return EFI_ALREADY_STARTED.
+ * return EFI_ALREADY_STARTED.
+ */
+ if ((TxBuffer != NULL) && (RxBuffer != NULL)) {
+ return EFI_ALREADY_STARTED;
+ }
+
+ Status = GetRxTxBufferMinSizeAndAlign (&MinSizeAndAlign);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Buffers = AllocateAlignedPages ((PcdGet64 (PcdFfaTxRxPageCount) * 2), MinSizeAndAlign);
+ if (Buffers == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ TxBuffer = Buffers;
+ RxBuffer = Buffers + BufferSize;
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+ FfaArgs.Arg0 = ARM_FID_FFA_RXTX_MAP;
+ FfaArgs.Arg1 = (UINTN)TxBuffer;
+ FfaArgs.Arg2 = (UINTN)RxBuffer;
+
+ /*
+ * PcdFfaTxRxPageCount sets with count of EFI_PAGE_SIZE granularity
+ * But, PageCounts for Tx/Rx buffer should set with
+ * count of Tx/Rx Buffer's MinSizeAndAlign. granularity.
+ */
+ FfaArgs.Arg3 = PcdGet64 (PcdFfaTxRxPageCount) / EFI_SIZE_TO_PAGES (MinSizeAndAlign);
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to map Rx/Tx buffer. Status: %r\n",
+ __func__,
+ Status
+ ));
+ goto ErrorHandler;
+ }
+
+ PcdSet64S (PcdFfaTxBuffer, (UINTN)TxBuffer);
+ PcdSet64S (PcdFfaRxBuffer, (UINTN)RxBuffer);
+
+ return EFI_SUCCESS;
+
+ErrorHandler:
+ FreeAlignedPages (Buffers, (PcdGet64 (PcdFfaTxRxPageCount) * 2));
+ TxBuffer = NULL;
+ RxBuffer = NULL;
+
+ return Status;
+}
+
+/**
+ Unmap Rx/Tx buffer.
+ This function is only called in Exit boot service because
+ Rx/Tx buffer is registered only once per partition.
+
+ @retval EFI_SUCCESS
+ @retval EFI_INVALID_PARAMETERS Already unregistered
+ @retval EFI_UNSUPPORTED Not supported
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibRxTxUnmap (
+ IN VOID
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+ VOID *Buffers;
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+
+ FfaArgs.Arg0 = ARM_FID_FFA_RXTX_UNMAP;
+ FfaArgs.Arg1 = (gPartId << ARM_FFA_SOURCE_EP_SHIFT);
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ /*
+ * Rx/Tx Buffer are allocated with continuous pages.
+ * and start address of these pages is set on PcdFfaTxBuffer.
+ * See ArmFfaLibRxTxMap().
+ */
+ Buffers = (VOID *)(UINTN)PcdGet64 (PcdFfaTxBuffer);
+ if (Buffers != NULL) {
+ FreeAlignedPages (Buffers, (PcdGet64 (PcdFfaTxRxPageCount) * 2));
+ }
+
+ PcdSet64S (PcdFfaTxBuffer, 0x00);
+ PcdSet64S (PcdFfaRxBuffer, 0x00);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Update Rx/TX buffer information.
+
+ @param BufferInfo Rx/Tx buffer information.
+
+**/
+VOID
+EFIAPI
+UpdateRxTxBufferInfo (
+ OUT ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo
+ )
+{
+ BufferInfo->TxBufferAddr = PcdGet64 (PcdFfaTxBuffer);
+ BufferInfo->TxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE;
+ BufferInfo->RxBufferAddr = PcdGet64 (PcdFfaRxBuffer);
+ BufferInfo->RxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE;
+}
+
+/**
+ Find Rx/TX buffer memory allocation hob.
+
+ @param UseGuid Find MemoryAllocationHob using gArmFfaRxTxBufferInfoGuid.
+
+ @retval MemoryAllocationHob
+ @retval NULL No memory allocation hob related to Rx/Tx buffer
+
+**/
+EFI_HOB_MEMORY_ALLOCATION *
+EFIAPI
+FindRxTxBufferAllocationHob (
+ IN BOOLEAN UseGuid
+ )
+{
+ EFI_PHYSICAL_ADDRESS BufferBase;
+ UINT64 BufferSize;
+
+ BufferBase = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFfaTxBuffer);
+ BufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE * 2;
+
+ return GetRxTxBufferAllocationHob (BufferBase, BufferSize, UseGuid);
+}
+
+/**
+ Remap Rx/TX buffer with converted Rx/Tx Buffer address after
+ using permanent memory.
+
+ @param[out] BufferInfo BufferInfo
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_NOT_FOUND No memory allocation hob related to Rx/Tx buffer
+
+**/
+EFI_STATUS
+EFIAPI
+RemapFfaRxTxBuffer (
+ OUT ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+ UINTN NewBufferBase;
+ UINTN NewTxBuffer;
+ UINTN NewRxBuffer;
+ UINTN MinSizeAndAlign;
+ EFI_HOB_MEMORY_ALLOCATION *RxTxBufferAllocationHob;
+
+ RxTxBufferAllocationHob = FindRxTxBufferAllocationHob (TRUE);
+ if (RxTxBufferAllocationHob == NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ Status = GetRxTxBufferMinSizeAndAlign (&MinSizeAndAlign);
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+ FfaArgs.Arg0 = ARM_FID_FFA_RXTX_UNMAP;
+ FfaArgs.Arg1 = (gPartId << ARM_FFA_SOURCE_EP_SHIFT);
+
+ ArmCallFfa (&FfaArgs);
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to unmap Rx/Tx buffer. Status: %r\n", __func__, Status));
+ return Status;
+ }
+
+ PcdSet64S (PcdFfaTxBuffer, 0x00);
+ PcdSet64S (PcdFfaRxBuffer, 0x00);
+
+ NewBufferBase = (UINTN)RxTxBufferAllocationHob->AllocDescriptor.MemoryBaseAddress + BufferInfo->RemapOffset;
+ NewTxBuffer = NewBufferBase;
+ NewRxBuffer = NewTxBuffer + (PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE);
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+ FfaArgs.Arg0 = ARM_FID_FFA_RXTX_MAP;
+ FfaArgs.Arg1 = NewTxBuffer;
+ FfaArgs.Arg2 = NewRxBuffer;
+
+ /*
+ * PcdFfaTxRxPageCount sets with count of EFI_PAGE_SIZE granularity
+ * But, PageCounts for Tx/Rx buffer should set with
+ * count of Tx/Rx Buffer's MinSizeAndAlign. granularity.
+ */
+ FfaArgs.Arg3 = PcdGet64 (PcdFfaTxRxPageCount) / EFI_SIZE_TO_PAGES (MinSizeAndAlign);
+
+ ArmCallFfa (&FfaArgs);
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to map with new Rx/Tx buffer. Status: %r\n", __func__, Status));
+ return Status;
+ }
+
+ PcdSet64S (PcdFfaTxBuffer, NewTxBuffer);
+ PcdSet64S (PcdFfaRxBuffer, NewRxBuffer);
+
+ UpdateRxTxBufferInfo (BufferInfo);
+
+ /*
+ * Remap is done. clear to AllocDesciptor.Name
+ * so that unnecessary remap happen again.
+ */
+ ZeroMem (&RxTxBufferAllocationHob->AllocDescriptor.Name, sizeof (EFI_GUID));
+
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.h b/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.h new file mode 100644 index 0000000..5140865 --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.h @@ -0,0 +1,99 @@ +/** @file
+ Arm FF-A ns common library Header file
+
+ Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - FF-A - Firmware Framework for Arm A-profile
+ - spmc - Secure Partition Manager Core
+ - spmd - Secure Partition Manager Dispatcher
+
+ @par Reference(s):
+ - Arm Firmware Framework for Arm A-Profile [https://developer.arm.com/documentation/den0077/latest]
+
+**/
+
+#ifndef ARM_FFA_RX_TX_MAP_LIB_H_
+#define ARM_FFA_RX_TX_MAP_LIB_H_
+
+#include <Guid/ArmFfaRxTxBufferInfo.h>
+
+/**
+ Mapping Rx/Tx buffers.
+ This function is only called in ArmFfaLibConstructor because
+ Rx/Tx buffer is registered only once per partition.
+
+ @retval EFI_SUCCESS
+ @retval EFI_ALREADY_STARTED Rx/Tx buffer already mapped in PEI phase
+ @retval EFI_OUT_OF_RESOURCE Out of memory
+ @retval EFI_INVALID_PARAMETER Invalid alignment of Rx/Tx buffer
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibRxTxMap (
+ IN VOID
+ );
+
+/**
+ Unmap Rx/Tx buffer.
+ This function is only called in Exit boot service because
+ Rx/Tx buffer is registered only once per partition.
+
+ @retval EFI_SUCCESS
+ @retval EFI_INVALID_PARAMETERS Already unregistered
+ @retval EFI_UNSUPPORTED Not supported
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibRxTxUnmap (
+ IN VOID
+ );
+
+/**
+ Update Rx/TX buffer information.
+
+ @param BufferInfo Rx/Tx buffer information.
+
+**/
+VOID
+EFIAPI
+UpdateRxTxBufferInfo (
+ OUT ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo
+ );
+
+/**
+ Find Rx/TX buffer memory allocation hob.
+
+ @param UseGuid Find MemoryAllocationHob using Guid.
+
+ @retval MemoryAllocationHob
+ @retval NULL No memory allocation hob related to Rx/Tx buffer
+
+**/
+EFI_HOB_MEMORY_ALLOCATION *
+EFIAPI
+FindRxTxBufferAllocationHob (
+ IN BOOLEAN UseGuid
+ );
+
+/**
+ Remap Rx/TX buffer with converted Rx/Tx Buffer address after
+ using permanent memory.
+
+ @param[out] BufferInfo BufferInfo
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_NOT_FOUND No memory allocation hob related to Rx/Tx buffer
+
+**/
+EFI_STATUS
+EFIAPI
+RemapFfaRxTxBuffer (
+ IN OUT ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo
+ );
+
+#endif
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecLib.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecLib.c new file mode 100644 index 0000000..7c3d39d --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecLib.c @@ -0,0 +1,107 @@ +/** @file
+ Arm Ffa library code for PeilessSec
+
+ Copyright (c) 2025, Arm Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - FF-A - Firmware Framework for Arm A-profile
+
+ @par Reference(s):
+ - Arm Firmware Framework for Arm A-Profile [https://developer.arm.com/documentation/den0077/latest]
+
+**/
+
+#include <Uefi.h>
+#include <Pi/PiMultiPhase.h>
+
+#include <Library/ArmLib.h>
+#include <Library/ArmSmcLib.h>
+#include <Library/ArmFfaLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+
+#include <IndustryStandard/ArmFfaSvc.h>
+
+#include <Guid/ArmFfaRxTxBufferInfo.h>
+
+#include "ArmFfaCommon.h"
+#include "ArmFfaRxTxMap.h"
+
+/**
+ ArmFfaLib Constructor.
+
+ @param [in] FileHandle File Handle
+ @param [in] PeiServices Pei Service Table
+
+ @retval EFI_SUCCESS Success
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaSecLibConstructor (
+ IN VOID
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo;
+ EFI_HOB_MEMORY_ALLOCATION *RxTxBufferAllocationHob;
+
+ Status = ArmFfaLibCommonInit ();
+ if (EFI_ERROR (Status)) {
+ if (Status == EFI_UNSUPPORTED) {
+ /*
+ * EFI_UNSUPPORTED return from ArmFfaLibCommonInit() means
+ * FF-A interface doesn't support.
+ * However, It doesn't make failure of loading driver/library instance
+ * (i.e) ArmPkg's MmCommunication Dxe/PEI Driver uses as well as SpmMm.
+ * So If FF-A is not supported the the MmCommunication Dxe/PEI falls
+ * back to SpmMm.
+ * For this case, return EFI_SUCCESS.
+ */
+ return EFI_SUCCESS;
+ }
+
+ return Status;
+ }
+
+ Status = ArmFfaLibRxTxMap ();
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ BufferInfo = BuildGuidHob (
+ &gArmFfaRxTxBufferInfoGuid,
+ sizeof (ARM_FFA_RX_TX_BUFFER_INFO)
+ );
+ if (BufferInfo == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to create Rx/Tx Buffer Info Hob\n", __func__));
+ ArmFfaLibRxTxUnmap ();
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ RxTxBufferAllocationHob = FindRxTxBufferAllocationHob (FALSE);
+ ASSERT (RxTxBufferAllocationHob != NULL);
+
+ /*
+ * Set then Name with gArmFfaRxTxBufferInfoGuid, so that ArmFfaPeiLib or
+ * ArmFfaDxeLib can find the Rx/Tx buffer allocation area.
+ */
+ CopyGuid (
+ &RxTxBufferAllocationHob->AllocDescriptor.Name,
+ &gArmFfaRxTxBufferInfoGuid
+ );
+
+ UpdateRxTxBufferInfo (BufferInfo);
+ BufferInfo->RemapOffset =
+ (UINTN)(BufferInfo->TxBufferAddr -
+ RxTxBufferAllocationHob->AllocDescriptor.MemoryBaseAddress);
+ BufferInfo->RemapRequired = TRUE;
+
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecLib.inf b/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecLib.inf new file mode 100644 index 0000000..611de85 --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecLib.inf @@ -0,0 +1,42 @@ +## @file
+# Provides FF-A ABI Library used in PeilessSec
+#
+# Copyright (c) 2025, Arm Limited. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = ArmFfaSecLib
+ FILE_GUID = 7b2c2aa6-3e20-11f0-a8b6-db774bafa249
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = ArmFfaLib|SEC
+ CONSTRUCTOR = ArmFfaSecLibConstructor
+
+[Sources]
+ ArmFfaCommon.h
+ ArmFfaCommon.c
+ ArmFfaRxTxMap.h
+ ArmFfaSecRxTxMap.c
+ ArmFfaSecLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ ArmSmcLib
+ ArmSvcLib
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ HobLib
+
+[Pcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaLibConduitSmc
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaTxRxPageCount
+
+[Guids]
+ gArmFfaRxTxBufferInfoGuid
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecRxTxMap.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecRxTxMap.c new file mode 100644 index 0000000..7c44e80 --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecRxTxMap.c @@ -0,0 +1,329 @@ +/** @file
+ Arm Ffa library common code.
+
+ Copyright (c) 2025, Arm Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - FF-A - Firmware Framework for Arm A-profile
+
+ @par Reference(s):
+ - Arm Firmware Framework for Arm A-Profile [https://developer.arm.com/documentation/den0077/latest]
+
+**/
+#include <Uefi.h>
+#include <Pi/PiMultiPhase.h>
+
+#include <Library/ArmLib.h>
+#include <Library/ArmFfaLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <IndustryStandard/ArmFfaSvc.h>
+
+#include <Guid/ArmFfaRxTxBufferInfo.h>
+
+#include "ArmFfaCommon.h"
+#include "ArmFfaRxTxMap.h"
+
+STATIC VOID *mTxBuffer;
+STATIC VOID *mRxBuffer;
+
+/**
+ Get mapped Rx/Tx buffers.
+
+ @param [out] TxBuffer Address of TxBuffer
+ @param [out] TxBufferSize Size of TxBuffer
+ @param [out] RxBuffer Address of RxBuffer
+ @param [out] RxBufferSize Size of RxBuffer
+
+ @retval EFI_SUCCESS
+ @retval Others Error.
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibGetRxTxBuffers (
+ OUT VOID **TxBuffer OPTIONAL,
+ OUT UINT64 *TxBufferSize OPTIONAL,
+ OUT VOID **RxBuffer OPTIONAL,
+ OUT UINT64 *RxBufferSize OPTIONAL
+ )
+{
+ if ((mTxBuffer == NULL) || (mRxBuffer == NULL)) {
+ return EFI_NOT_READY;
+ }
+
+ if (TxBuffer != NULL) {
+ *TxBuffer = mTxBuffer;
+ }
+
+ if (TxBufferSize != NULL) {
+ *TxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE;
+ }
+
+ if (RxBuffer != NULL) {
+ *RxBuffer = mRxBuffer;
+ }
+
+ if (RxBufferSize != NULL) {
+ *RxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Mapping Rx/Tx buffers.
+ This function is only called in ArmFfaLibConstructor because
+ Rx/Tx buffer is registered only once per partition.
+
+ @retval EFI_SUCCESS
+ @retval EFI_ALREADY_STARTED Rx/Tx buffer already mapped.
+ @retval EFI_OUT_OF_RESOURCE Out of memory
+ @retval EFI_INVALID_PARAMETER Invalid alignment of Rx/Tx buffer
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibRxTxMap (
+ IN VOID
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+ UINTN Property1;
+ UINTN Property2;
+ UINTN MinSizeAndAlign;
+ UINTN MaxSize;
+ VOID *Buffers;
+ VOID *TxBuffer;
+ VOID *RxBuffer;
+
+ /*
+ * If someone already mapped Rx/Tx Buffers, return EFI_ALREADY_STARTED.
+ * return EFI_ALREADY_STARTED.
+ */
+ if ((mTxBuffer != NULL) && (mRxBuffer != NULL)) {
+ return EFI_ALREADY_STARTED;
+ }
+
+ Status = ArmFfaLibGetFeatures (
+ ARM_FID_FFA_RXTX_MAP,
+ FFA_RXTX_MAP_INPUT_PROPERTY_DEFAULT,
+ &Property1,
+ &Property2
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to get RX/TX buffer property... Status: %r\n",
+ __func__,
+ Status
+ ));
+ return Status;
+ }
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+
+ MinSizeAndAlign =
+ ((Property1 >>
+ ARM_FFA_BUFFER_MINSIZE_AND_ALIGN_SHIFT) &
+ ARM_FFA_BUFFER_MINSIZE_AND_ALIGN_MASK);
+
+ switch (MinSizeAndAlign) {
+ case ARM_FFA_BUFFER_MINSIZE_AND_ALIGN_4K:
+ MinSizeAndAlign = SIZE_4KB;
+ break;
+ case ARM_FFA_BUFFER_MINSIZE_AND_ALIGN_16K:
+ MinSizeAndAlign = SIZE_16KB;
+ break;
+ case ARM_FFA_BUFFER_MINSIZE_AND_ALIGN_64K:
+ MinSizeAndAlign = SIZE_64KB;
+ break;
+ default:
+ DEBUG ((DEBUG_ERROR, "%a: Invalid MinSizeAndAlign: 0x%x\n", __func__, MinSizeAndAlign));
+ return EFI_UNSUPPORTED;
+ }
+
+ MaxSize =
+ (((Property1 >>
+ ARM_FFA_BUFFER_MAXSIZE_PAGE_COUNT_SHIFT) &
+ ARM_FFA_BUFFER_MAXSIZE_PAGE_COUNT_MASK));
+
+ MaxSize = ((MaxSize == 0) ? MAX_UINTN : (MaxSize * MinSizeAndAlign));
+
+ if ((MinSizeAndAlign > (PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE)) ||
+ (MaxSize < (PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE)))
+ {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Buffer is too small! MinSize: 0x%x, MaxSize: 0x%x, PageCount: %d\n",
+ __func__,
+ MinSizeAndAlign,
+ MaxSize,
+ PcdGet64 (PcdFfaTxRxPageCount)
+ ));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Buffers = AllocateAlignedPages ((PcdGet64 (PcdFfaTxRxPageCount) * 2), MinSizeAndAlign);
+ if (Buffers == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ TxBuffer = Buffers;
+ RxBuffer = Buffers + (PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE);
+
+ FfaArgs.Arg0 = ARM_FID_FFA_RXTX_MAP;
+ FfaArgs.Arg1 = (UINTN)TxBuffer;
+ FfaArgs.Arg2 = (UINTN)RxBuffer;
+
+ /*
+ * PcdFfaTxRxPageCount sets with count of EFI_PAGE_SIZE granularity
+ * But, PageCounts for Tx/Rx buffer should set with
+ * count of Tx/Rx Buffer's MinSizeAndAlign. granularity.
+ */
+ FfaArgs.Arg3 = PcdGet64 (PcdFfaTxRxPageCount) / EFI_SIZE_TO_PAGES (MinSizeAndAlign);
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to map Rx/Tx buffer. Status: %r\n",
+ __func__,
+ Status
+ ));
+ goto ErrorHandler;
+ }
+
+ mTxBuffer = TxBuffer;
+ mRxBuffer = RxBuffer;
+
+ return EFI_SUCCESS;
+
+ErrorHandler:
+ FreePages (Buffers, (PcdGet64 (PcdFfaTxRxPageCount) * 2));
+
+ return Status;
+}
+
+/**
+ Unmap Rx/Tx buffer.
+ This function is only called in Exit boot service because
+ Rx/Tx buffer is registered only once per partition.
+
+ @retval EFI_SUCCESS
+ @retval EFI_INVALID_PARAMETERS Already unregistered
+ @retval EFI_UNSUPPORTED Not supported
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibRxTxUnmap (
+ IN VOID
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+ VOID *Buffers;
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+
+ FfaArgs.Arg0 = ARM_FID_FFA_RXTX_UNMAP;
+ FfaArgs.Arg1 = (gPartId << ARM_FFA_SOURCE_EP_SHIFT);
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ /*
+ * Rx/Tx Buffer are allocated with continuous pages.
+ * and start address of these pages is set on PcdFfaTxBuffer.
+ * See ArmFfaLibRxTxMap().
+ */
+ Buffers = mTxBuffer;
+ if (Buffers != NULL) {
+ FreePages (Buffers, (PcdGet64 (PcdFfaTxRxPageCount) * 2));
+ }
+
+ mTxBuffer = NULL;
+ mRxBuffer = NULL;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Update Rx/TX buffer information.
+
+ @param BufferInfo Rx/Tx buffer information.
+
+**/
+VOID
+EFIAPI
+UpdateRxTxBufferInfo (
+ OUT ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo
+ )
+{
+ BufferInfo->TxBufferAddr = (UINTN)mTxBuffer;
+ BufferInfo->TxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE;
+ BufferInfo->RxBufferAddr = (UINTN)mRxBuffer;
+ BufferInfo->RxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE;
+}
+
+/**
+ Find Rx/TX buffer memory allocation hob.
+
+ @param UseGuid Find MemoryAllocationHob using Guid.
+
+ @retval MemoryAllocationHob
+ @retval NULL No memory allocation hob related to Rx/Tx buffer
+
+**/
+EFI_HOB_MEMORY_ALLOCATION *
+EFIAPI
+FindRxTxBufferAllocationHob (
+ IN BOOLEAN UseGuid
+ )
+{
+ EFI_PHYSICAL_ADDRESS BufferBase;
+ UINT64 BufferSize;
+
+ BufferBase = (EFI_PHYSICAL_ADDRESS)((UINTN)mTxBuffer);
+ BufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE * 2;
+
+ return GetRxTxBufferAllocationHob (BufferBase, BufferSize, UseGuid);
+}
+
+/**
+ Remap Rx/TX buffer with converted Rx/Tx Buffer address after
+ using permanent memory.
+
+ @param[out] BufferInfo BufferInfo
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_NOT_FOUND No memory allocation hob related to Rx/Tx buffer
+
+**/
+EFI_STATUS
+EFIAPI
+RemapFfaRxTxBuffer (
+ OUT ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo
+ )
+{
+ /*
+ * SEC binary shouldn't remap the Rx/Tx Buffer.
+ */
+ return EFI_UNSUPPORTED;
+}
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmCoreLib.inf b/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmCoreLib.inf new file mode 100644 index 0000000..67b7b5c --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmCoreLib.inf @@ -0,0 +1,43 @@ +## @file
+# Provides FF-A ABI Library used in StandaloneMmCore.
+#
+# Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x0001001B
+ BASE_NAME = ArmFfaStandaloneMmCoreLib
+ FILE_GUID = 80d2c4dc-5f0b-11ef-bc86-43b3fb486d6d
+ MODULE_TYPE = MM_CORE_STANDALONE
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x00010032
+ LIBRARY_CLASS = ArmFfaLib
+ CONSTRUCTOR = ArmFfaStandaloneMmLibConstructor
+
+[Sources]
+ ArmFfaCommon.h
+ ArmFfaCommon.c
+ ArmFfaRxTxMap.h
+ ArmFfaStandaloneMmRxTxMap.c
+ ArmFfaStandaloneMmLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ ArmSmcLib
+ ArmSvcLib
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ MmServicesTableLib
+
+[Pcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaLibConduitSmc
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaTxRxPageCount
+
+[Guids]
+ gArmFfaRxTxBufferInfoGuid
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmLib.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmLib.c new file mode 100644 index 0000000..72f9a80 --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmLib.c @@ -0,0 +1,75 @@ +/** @file
+ Arm Ffa library code for StandaloneMmCore.
+
+ Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - FF-A - Firmware Framework for Arm A-profile
+
+ @par Reference(s):
+ - Arm Firmware Framework for Arm A-Profile [https://developer.arm.com/documentation/den0077/latest]
+
+**/
+
+#include <PiMm.h>
+
+#include <Library/ArmLib.h>
+#include <Library/ArmSmcLib.h>
+#include <Library/ArmFfaLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+
+#include "ArmFfaCommon.h"
+#include "ArmFfaRxTxMap.h"
+
+/**
+ ArmFfaLib Constructor.
+
+ @param [in] ImageHandle The firmware allocated handle for the EFI image
+ @param [in] MmSystemTable A pointer to the Management mode System Table
+
+ @retval EFI_SUCCESS Success
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaStandaloneMmLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *MmSystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = ArmFfaLibCommonInit ();
+ if (Status == EFI_UNSUPPORTED) {
+ /*
+ * EFI_UNSUPPORTED means FF-A interface isn't available.
+ * However, for Standalone MM modules, FF-A availability is not required.
+ * i.e. Standalone MM could use SpmMm as a legitimate protocol.
+ * Thus, returning EFI_SUCCESS here to avoid the entrypoint to assert.
+ */
+ return EFI_SUCCESS;
+ }
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a failed. Status = %r\n", __func__, Status));
+ }
+
+ Status = ArmFfaLibRxTxMap ();
+ if (Status == EFI_ALREADY_STARTED) {
+ /*
+ * When first Stmm instance (most likely core) which uses ArmFfaLib loaded,
+ * It already maps Rx/Tx buffer.
+ * From Next Stmm instance which uses ArmFfaLib it doesn't need to map Rx/Tx
+ * buffer again but it uses the mapped one.
+ */
+ Status = EFI_SUCCESS;
+ } else if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a failed. Status = %r\n", __func__, Status));
+ }
+
+ return Status;
+}
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmLib.inf b/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmLib.inf new file mode 100644 index 0000000..532dc19 --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmLib.inf @@ -0,0 +1,44 @@ +## @file
+# Provides FF-A ABI Library used in StandaloneMmCore.
+#
+# Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x0001001B
+ BASE_NAME = ArmFfaStandaloneMmLib
+ FILE_GUID = e07db74e-6a95-11ef-97ea-c7a6149e81c9
+ MODULE_TYPE = MM_STANDALONE
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x00010032
+ LIBRARY_CLASS = ArmFfaLib
+ CONSTRUCTOR = ArmFfaStandaloneMmLibConstructor
+
+[Sources]
+ ArmFfaCommon.h
+ ArmFfaCommon.c
+ ArmFfaRxTxMap.h
+ ArmFfaStandaloneMmRxTxMap.c
+ ArmFfaStandaloneMmLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ ArmSmcLib
+ ArmSvcLib
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ MmServicesTableLib
+
+[Pcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaLibConduitSmc
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaTxRxPageCount
+
+[Guids]
+ gArmFfaRxTxBufferInfoGuid
+
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmRxTxMap.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmRxTxMap.c new file mode 100644 index 0000000..d368c32 --- /dev/null +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmRxTxMap.c @@ -0,0 +1,328 @@ +/** @file
+ Arm Ffa library common code.
+
+ Copyright (c) 2024-2025, Arm Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - FF-A - Firmware Framework for Arm A-profile
+
+ @par Reference(s):
+ - Arm Firmware Framework for Arm A-Profile v1.3 ALP1: [https://developer.arm.com/documentation/den0077/l]
+
+**/
+#include <PiMm.h>
+
+#include <Library/ArmLib.h>
+#include <Library/ArmFfaLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+#include <Library/MmServicesTableLib.h>
+
+#include <IndustryStandard/ArmFfaSvc.h>
+#include <Guid/ArmFfaRxTxBufferInfo.h>
+
+#include "ArmFfaCommon.h"
+#include "ArmFfaRxTxMap.h"
+
+EFI_HANDLE mArmFfaRxTxBufferStmmInfoHandle = NULL;
+ARM_FFA_RX_TX_BUFFER_INFO *mArmFfaRxTxBufferStmmInfo = NULL;
+
+/**
+ Get mapped Rx/Tx buffers.
+
+ @param [out] TxBuffer Address of TxBuffer
+ @param [out] TxBufferSize Size of TxBuffer
+ @param [out] RxBuffer Address of RxBuffer
+ @param [out] RxBufferSize Size of RxBuffer
+
+ @retval EFI_SUCCESS
+ @retval Others Error.
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibGetRxTxBuffers (
+ OUT VOID **TxBuffer OPTIONAL,
+ OUT UINT64 *TxBufferSize OPTIONAL,
+ OUT VOID **RxBuffer OPTIONAL,
+ OUT UINT64 *RxBufferSize OPTIONAL
+ )
+{
+ UINTN TxBufferAddr;
+ UINTN RxBufferAddr;
+
+ EFI_STATUS Status = gMmst->MmLocateProtocol (
+ &gArmFfaRxTxBufferInfoGuid,
+ NULL,
+ (VOID **)&mArmFfaRxTxBufferStmmInfo
+ );
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to locate Rx/Tx buffer protocol... Status: %r\n", __func__, Status));
+ return Status;
+ }
+
+ TxBufferAddr = (UINTN)mArmFfaRxTxBufferStmmInfo->TxBufferAddr;
+ RxBufferAddr = (UINTN)mArmFfaRxTxBufferStmmInfo->RxBufferAddr;
+
+ if ((TxBufferAddr == 0x00) || (RxBufferAddr == 0x00)) {
+ return EFI_NOT_READY;
+ }
+
+ if (TxBuffer != NULL) {
+ *TxBuffer = (VOID *)TxBufferAddr;
+ }
+
+ if (TxBufferSize != NULL) {
+ *TxBufferSize = mArmFfaRxTxBufferStmmInfo->TxBufferSize;
+ }
+
+ if (RxBuffer != NULL) {
+ *RxBuffer = (VOID *)RxBufferAddr;
+ }
+
+ if (RxBufferSize != NULL) {
+ *RxBufferSize = mArmFfaRxTxBufferStmmInfo->RxBufferSize;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Mapping Rx/Tx buffers.
+ This function is only called in ArmFfaLibConstructor because
+ Rx/Tx buffer is registered only once per partition.
+
+ @retval EFI_SUCCESS
+ @retval EFI_ALREADY_STARTED Rx/Tx buffer already mapped.
+ @retval EFI_OUT_OF_RESOURCE Out of memory
+ @retval EFI_INVALID_PARAMETER Invalid alignment of Rx/Tx buffer
+ @retval Others Error
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibRxTxMap (
+ IN VOID
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+ UINTN MinSizeAndAlign;
+ VOID *Buffers;
+ VOID *TxBuffer;
+ VOID *RxBuffer;
+ UINT64 BufferSize;
+
+ Status = gMmst->MmLocateProtocol (
+ &gArmFfaRxTxBufferInfoGuid,
+ NULL,
+ (VOID **)&mArmFfaRxTxBufferStmmInfo
+ );
+ if (!EFI_ERROR (Status)) {
+ // Great, we got what we need.
+ return EFI_ALREADY_STARTED;
+ }
+
+ Status = GetRxTxBufferMinSizeAndAlign (&MinSizeAndAlign);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Buffers = AllocateAlignedPages ((PcdGet64 (PcdFfaTxRxPageCount) * 2), MinSizeAndAlign);
+ if (Buffers == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ BufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE;
+ TxBuffer = Buffers;
+ RxBuffer = Buffers + BufferSize;
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+ FfaArgs.Arg0 = ARM_FID_FFA_RXTX_MAP;
+ FfaArgs.Arg1 = (UINTN)TxBuffer;
+ FfaArgs.Arg2 = (UINTN)RxBuffer;
+
+ /*
+ * PcdFfaTxRxPageCount sets with count of EFI_PAGE_SIZE granularity
+ * But, PageCounts for Tx/Rx buffer should set with
+ * count of Tx/Rx Buffer's MinSizeAndAlign. granularity.
+ */
+ FfaArgs.Arg3 = PcdGet64 (PcdFfaTxRxPageCount) / EFI_SIZE_TO_PAGES (MinSizeAndAlign);
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to map Rx/Tx buffer. Status: %r\n",
+ __func__,
+ Status
+ ));
+ goto ErrorHandler;
+ }
+
+ mArmFfaRxTxBufferStmmInfo = AllocateZeroPool (sizeof (ARM_FFA_RX_TX_BUFFER_INFO));
+ if (mArmFfaRxTxBufferStmmInfo == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto ErrorHandler;
+ }
+
+ mArmFfaRxTxBufferStmmInfo->TxBufferAddr = (UINTN)TxBuffer;
+ mArmFfaRxTxBufferStmmInfo->RxBufferAddr = (UINTN)RxBuffer;
+ mArmFfaRxTxBufferStmmInfo->TxBufferSize = BufferSize;
+ mArmFfaRxTxBufferStmmInfo->RxBufferSize = BufferSize;
+
+ Status = gMmst->MmInstallProtocolInterface (
+ &mArmFfaRxTxBufferStmmInfoHandle,
+ &gArmFfaRxTxBufferInfoGuid,
+ EFI_NATIVE_INTERFACE,
+ mArmFfaRxTxBufferStmmInfo
+ );
+
+ return Status;
+
+ErrorHandler:
+ FreeAlignedPages (Buffers, (PcdGet64 (PcdFfaTxRxPageCount) * 2));
+ TxBuffer = NULL;
+ RxBuffer = NULL;
+
+ return Status;
+}
+
+/**
+ Unmap Rx/Tx buffer.
+ This function is only called in Exit boot service because
+ Rx/Tx buffer is registered only once per partition.
+
+ @retval EFI_SUCCESS
+ @retval EFI_INVALID_PARAMETERS Already unregistered
+ @retval EFI_UNSUPPORTED Not supported
+
+**/
+EFI_STATUS
+EFIAPI
+ArmFfaLibRxTxUnmap (
+ IN VOID
+ )
+{
+ EFI_STATUS Status;
+ ARM_FFA_ARGS FfaArgs;
+ VOID *Buffers;
+
+ if (mArmFfaRxTxBufferStmmInfoHandle == NULL) {
+ // This means that the agent tried to unmap the buffers before even know them.
+ // Let's be a nice player...
+ return EFI_UNSUPPORTED;
+ }
+
+ ZeroMem (&FfaArgs, sizeof (ARM_FFA_ARGS));
+
+ FfaArgs.Arg0 = ARM_FID_FFA_RXTX_UNMAP;
+ FfaArgs.Arg1 = (gPartId << ARM_FFA_SOURCE_EP_SHIFT);
+
+ ArmCallFfa (&FfaArgs);
+
+ Status = FfaArgsToEfiStatus (&FfaArgs);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ /*
+ * Rx/Tx Buffer are allocated with continuous pages.
+ * and start address of these pages is set on PcdFfaTxBuffer.
+ * See ArmFfaLibRxTxMap().
+ */
+ Buffers = (VOID *)(UINTN)mArmFfaRxTxBufferStmmInfo->TxBufferAddr;
+ if (Buffers != NULL) {
+ FreeAlignedPages (Buffers, (EFI_SIZE_TO_PAGES (mArmFfaRxTxBufferStmmInfo->TxBufferSize) * 2));
+ }
+
+ Status = gMmst->MmUninstallProtocolInterface (
+ mArmFfaRxTxBufferStmmInfoHandle,
+ &gArmFfaRxTxBufferInfoGuid,
+ mArmFfaRxTxBufferStmmInfo
+ );
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to uninstall Rx/Tx buffer protocol... Status: %r\n",
+ __func__,
+ Status
+ ));
+ return Status;
+ }
+
+ FreePool (mArmFfaRxTxBufferStmmInfo);
+ mArmFfaRxTxBufferStmmInfo = NULL;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Update Rx/TX buffer information.
+
+ @param BufferInfo Rx/Tx buffer information.
+
+**/
+VOID
+EFIAPI
+UpdateRxTxBufferInfo (
+ OUT ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo
+ )
+{
+ /*
+ * StandaloneMm doesn't use Rx/Tx buffer.
+ */
+ return;
+}
+
+/**
+ Find Rx/TX buffer memory allocation hob.
+
+ @param UseGuid Find MemoryAllocationHob using Guid.
+
+ @retval MemoryAllocationHob
+ @retval NULL No memory allocation hob related to Rx/Tx buffer
+
+**/
+EFI_HOB_MEMORY_ALLOCATION *
+EFIAPI
+FindRxTxBufferAllocationHob (
+ IN BOOLEAN UseGuid
+ )
+{
+ /*
+ * StandaloneMm doesn't use Rx/Tx buffer.
+ */
+ return NULL;
+}
+
+/**
+ Remap Rx/TX buffer with converted Rx/Tx Buffer address after
+ using permanent memory.
+
+ @param[out] BufferInfo BufferInfo
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_NOT_FOUND No memory allocation hob related to Rx/Tx buffer
+
+**/
+EFI_STATUS
+EFIAPI
+RemapFfaRxTxBuffer (
+ OUT ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo
+ )
+{
+ /*
+ * StandaloneMm doesn't use Rx/Tx buffer.
+ * So, return EFI_UNSUPPORTED.
+ */
+ return EFI_UNSUPPORTED;
+}
diff --git a/MdeModulePkg/Library/BaseHobLibNull/BaseHobLibNull.c b/MdeModulePkg/Library/BaseHobLibNull/BaseHobLibNull.c index 4dc73fa..0cddccd 100644 --- a/MdeModulePkg/Library/BaseHobLibNull/BaseHobLibNull.c +++ b/MdeModulePkg/Library/BaseHobLibNull/BaseHobLibNull.c @@ -534,3 +534,58 @@ BuildMemoryAllocationHob ( {
ASSERT (FALSE);
}
+
+/**
+ Returns the next instance of the memory allocation HOB with the matched GUID from
+ the starting HOB.
+
+ This function searches the first instance of a HOB from the starting HOB pointer.
+ Such HOB should satisfy two conditions:
+ Its HOB type is EFI_HOB_TYPE_MEMORY_ALLOCATION and its GUID Name equals to input Guid.
+ If there does not exist such HOB from the starting HOB pointer, it will return NULL.
+
+ If Guid is NULL, then ASSERT().
+ If HobStart is NULL, then ASSERT().
+
+ @param Guid The GUID to match with in the HOB list.
+ @param HobStart The starting HOB pointer to search from.
+
+ @retval !NULL The next instance of the Memory Allocation HOB with matched GUID from the starting HOB.
+ @retval NULL NULL is returned if the matching Memory Allocation HOB is not found.
+
+**/
+VOID *
+EFIAPI
+GetNextMemoryAllocationGuidHob (
+ IN CONST EFI_GUID *Guid,
+ IN CONST VOID *HobStart
+ )
+{
+ ASSERT (FALSE);
+ return NULL;
+}
+
+/**
+ Search the HOB list for the Memory Allocation HOB with a matching base address
+ and set the Name GUID. If there does not exist such Memory Allocation HOB in the
+ HOB list, it will return NULL.
+
+ If Guid is NULL, then ASSERT().
+
+ @param BaseAddress BaseAddress of Memory Allocation HOB to set Name to Guid.
+ @param Guid Pointer to the GUID to set in the matching Memory Allocation GUID.
+
+ @retval !NULL The instance of the tagged Memory Allocation HOB with matched base address.
+ @return NULL NULL is returned if the matching Memory Allocation HOB is not found.
+
+**/
+VOID *
+EFIAPI
+TagMemoryAllocationHobWithGuid (
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN CONST EFI_GUID *Guid
+ )
+{
+ ASSERT (FALSE);
+ return NULL;
+}
diff --git a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c index e413cea..3739980 100644 --- a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c +++ b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c @@ -20,7 +20,7 @@ #include <Library/BaseLib.h>
//
-// PCI Defintions.
+// PCI Definitions.
//
#define PCI_BRIDGE_32_BIT_IO_SPACE 0x01
diff --git a/MdeModulePkg/Library/BootLogoLib/BootLogoLib.c b/MdeModulePkg/Library/BootLogoLib/BootLogoLib.c index 478ec2d..5beb0e0 100644 --- a/MdeModulePkg/Library/BootLogoLib/BootLogoLib.c +++ b/MdeModulePkg/Library/BootLogoLib/BootLogoLib.c @@ -12,7 +12,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Protocol/GraphicsOutput.h>
#include <Protocol/SimpleTextOut.h>
#include <Protocol/PlatformLogo.h>
-#include <Protocol/UgaDraw.h>
#include <Protocol/BootLogo.h>
#include <Protocol/BootLogo2.h>
#include <Library/BaseLib.h>
@@ -47,9 +46,6 @@ BootLogoEnableLogo ( UINT32 Instance;
EFI_IMAGE_INPUT Image;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
- UINT32 ColorDepth;
- UINT32 RefreshRate;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
EFI_BOOT_LOGO_PROTOCOL *BootLogo;
EDKII_BOOT_LOGO2_PROTOCOL *BootLogo2;
@@ -68,22 +64,10 @@ BootLogoEnableLogo ( return EFI_UNSUPPORTED;
}
- UgaDraw = NULL;
//
// Try to open GOP first
//
Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);
- if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
- GraphicsOutput = NULL;
- //
- // Open GOP failed, try to open UGA
- //
- Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **)&UgaDraw);
- if (EFI_ERROR (Status)) {
- UgaDraw = NULL;
- }
- }
-
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
@@ -109,16 +93,8 @@ BootLogoEnableLogo ( //
gST->ConOut->EnableCursor (gST->ConOut, FALSE);
- if (GraphicsOutput != NULL) {
- SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
- SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
- } else {
- ASSERT (UgaDraw != NULL);
- Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);
- if (EFI_ERROR (Status)) {
- return EFI_UNSUPPORTED;
- }
- }
+ SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
+ SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
Blt = NULL;
NumberOfLogos = 0;
@@ -206,34 +182,18 @@ BootLogoEnableLogo ( DestY += OffsetY;
if ((DestX >= 0) && (DestY >= 0)) {
- if (GraphicsOutput != NULL) {
- Status = GraphicsOutput->Blt (
- GraphicsOutput,
- Blt,
- EfiBltBufferToVideo,
- 0,
- 0,
- (UINTN)DestX,
- (UINTN)DestY,
- Image.Width,
- Image.Height,
- Image.Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
- );
- } else {
- ASSERT (UgaDraw != NULL);
- Status = UgaDraw->Blt (
- UgaDraw,
- (EFI_UGA_PIXEL *)Blt,
- EfiUgaBltBufferToVideo,
- 0,
- 0,
- (UINTN)DestX,
- (UINTN)DestY,
- Image.Width,
- Image.Height,
- Image.Width * sizeof (EFI_UGA_PIXEL)
- );
- }
+ Status = GraphicsOutput->Blt (
+ GraphicsOutput,
+ Blt,
+ EfiBltBufferToVideo,
+ 0,
+ 0,
+ (UINTN)DestX,
+ (UINTN)DestY,
+ Image.Width,
+ Image.Height,
+ Image.Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
+ );
//
// Report displayed Logo information.
@@ -307,33 +267,18 @@ BootLogoEnableLogo ( return EFI_OUT_OF_RESOURCES;
}
- if (GraphicsOutput != NULL) {
- Status = GraphicsOutput->Blt (
- GraphicsOutput,
- LogoBlt,
- EfiBltVideoToBltBuffer,
- LogoDestX,
- LogoDestY,
- 0,
- 0,
- LogoWidth,
- LogoHeight,
- LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
- );
- } else {
- Status = UgaDraw->Blt (
- UgaDraw,
- (EFI_UGA_PIXEL *)LogoBlt,
- EfiUgaVideoToBltBuffer,
- LogoDestX,
- LogoDestY,
- 0,
- 0,
- LogoWidth,
- LogoHeight,
- LogoWidth * sizeof (EFI_UGA_PIXEL)
- );
- }
+ Status = GraphicsOutput->Blt (
+ GraphicsOutput,
+ LogoBlt,
+ EfiBltVideoToBltBuffer,
+ LogoDestX,
+ LogoDestY,
+ 0,
+ 0,
+ LogoWidth,
+ LogoHeight,
+ LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
+ );
}
if (!EFI_ERROR (Status)) {
@@ -368,7 +313,7 @@ BootLogoEnableLogo ( Use SystemTable Conout to turn on video based Simple Text Out consoles. The
Simple Text Out screens will now be synced up with all non video output devices
- @retval EFI_SUCCESS UGA devices are back in text mode and synced up.
+ @retval EFI_SUCCESS GOP devices are back in text mode and synced up.
**/
EFI_STATUS
@@ -411,11 +356,8 @@ BootLogoUpdateProgress ( {
EFI_STATUS Status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
UINT32 SizeOfX;
UINT32 SizeOfY;
- UINT32 ColorDepth;
- UINT32 RefreshRate;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;
UINTN BlockHeight;
UINTN BlockWidth;
@@ -428,40 +370,13 @@ BootLogoUpdateProgress ( return EFI_INVALID_PARAMETER;
}
- UgaDraw = NULL;
- Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);
- if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
- GraphicsOutput = NULL;
-
- Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **)&UgaDraw);
- if (EFI_ERROR (Status)) {
- UgaDraw = NULL;
- }
- }
-
+ Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
- SizeOfX = 0;
- SizeOfY = 0;
- if (GraphicsOutput != NULL) {
- SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
- SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
- } else if (UgaDraw != NULL) {
- Status = UgaDraw->GetMode (
- UgaDraw,
- &SizeOfX,
- &SizeOfY,
- &ColorDepth,
- &RefreshRate
- );
- if (EFI_ERROR (Status)) {
- return EFI_UNSUPPORTED;
- }
- } else {
- return EFI_UNSUPPORTED;
- }
+ SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
+ SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
BlockWidth = SizeOfX / 100;
BlockHeight = SizeOfY / 50;
@@ -477,71 +392,37 @@ BootLogoUpdateProgress ( //
SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);
- if (GraphicsOutput != NULL) {
- Status = GraphicsOutput->Blt (
- GraphicsOutput,
- &Color,
- EfiBltVideoFill,
- 0,
- 0,
- 0,
- PosY - EFI_GLYPH_HEIGHT - 1,
- SizeOfX,
- SizeOfY - (PosY - EFI_GLYPH_HEIGHT - 1),
- SizeOfX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
- );
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- Status = UgaDraw->Blt (
- UgaDraw,
- (EFI_UGA_PIXEL *)&Color,
- EfiUgaVideoFill,
- 0,
- 0,
- 0,
- PosY - EFI_GLYPH_HEIGHT - 1,
- SizeOfX,
- SizeOfY - (PosY - EFI_GLYPH_HEIGHT - 1),
- SizeOfX * sizeof (EFI_UGA_PIXEL)
- );
- } else {
- return EFI_UNSUPPORTED;
- }
+ Status = GraphicsOutput->Blt (
+ GraphicsOutput,
+ &Color,
+ EfiBltVideoFill,
+ 0,
+ 0,
+ 0,
+ PosY - EFI_GLYPH_HEIGHT - 1,
+ SizeOfX,
+ SizeOfY - (PosY - EFI_GLYPH_HEIGHT - 1),
+ SizeOfX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
+ );
}
//
// Show progress by drawing blocks
//
for (Index = PreviousValue; Index < BlockNum; Index++) {
- PosX = Index * BlockWidth;
- if (GraphicsOutput != NULL) {
- Status = GraphicsOutput->Blt (
- GraphicsOutput,
- &ProgressColor,
- EfiBltVideoFill,
- 0,
- 0,
- PosX,
- PosY,
- BlockWidth - 1,
- BlockHeight,
- (BlockWidth) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
- );
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- Status = UgaDraw->Blt (
- UgaDraw,
- (EFI_UGA_PIXEL *)&ProgressColor,
- EfiUgaVideoFill,
- 0,
- 0,
- PosX,
- PosY,
- BlockWidth - 1,
- BlockHeight,
- (BlockWidth) * sizeof (EFI_UGA_PIXEL)
- );
- } else {
- return EFI_UNSUPPORTED;
- }
+ PosX = Index * BlockWidth;
+ Status = GraphicsOutput->Blt (
+ GraphicsOutput,
+ &ProgressColor,
+ EfiBltVideoFill,
+ 0,
+ 0,
+ PosX,
+ PosY,
+ BlockWidth - 1,
+ BlockHeight,
+ (BlockWidth) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
+ );
}
PrintXY (
diff --git a/MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf b/MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf index 7d50f2d..03fd704 100644 --- a/MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf +++ b/MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf @@ -42,11 +42,7 @@ [Protocols]
gEfiGraphicsOutputProtocolGuid ## SOMETIMES_CONSUMES
- gEfiUgaDrawProtocolGuid |PcdUgaConsumeSupport ## SOMETIMES_CONSUMES
gEfiBootLogoProtocolGuid ## SOMETIMES_CONSUMES
gEdkiiBootLogo2ProtocolGuid ## SOMETIMES_CONSUMES
gEfiUserManagerProtocolGuid ## CONSUMES
gEdkiiPlatformLogoProtocolGuid ## CONSUMES
-
-[FeaturePcd]
- gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport ## CONSUMES
diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h index 2e9a70d..e9fc4c1 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h @@ -396,7 +396,7 @@ BOpt_GetBootOptions ( @param CallbackData The BMM context data.
- @return EFI_SUCESS The functin completes successfully.
+ @return EFI_SUCCESS The function completes successfully.
@retval EFI_OUT_OF_RESOURCES Not enough memory to compete the operation.
diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c index e22aaf3..a47106d 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c @@ -281,7 +281,7 @@ BOpt_FreeMenu ( @param CallbackData The BMM context data.
@return EFI_NOT_FOUND Fail to find "BootOrder" variable.
- @return EFI_SUCESS Success build boot option menu.
+ @return EFI_SUCCESS Success build boot option menu.
**/
EFI_STATUS
@@ -669,7 +669,7 @@ BOpt_GetDriverOptionNumber ( @param CallbackData The BMM context data.
- @retval EFI_SUCESS The functin completes successfully.
+ @retval EFI_SUCCESS The function completes successfully.
@retval EFI_OUT_OF_RESOURCES Not enough memory to compete the operation.
@retval EFI_NOT_FOUND Fail to get "DriverOrder" variable.
diff --git a/MdeModulePkg/Library/BootManagerUiLib/BootManager.c b/MdeModulePkg/Library/BootManagerUiLib/BootManager.c index b752679..c2232e5 100644 --- a/MdeModulePkg/Library/BootManagerUiLib/BootManager.c +++ b/MdeModulePkg/Library/BootManagerUiLib/BootManager.c @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
#include "BootManager.h"
+#include <Protocol/LoadedImage.h>
UINT16 mKeyInput;
EFI_GUID mBootManagerGuid = BOOT_MANAGER_FORMSET_GUID;
@@ -493,6 +494,9 @@ UpdateBootManager ( BOOLEAN IsLegacyOption;
BOOLEAN NeedEndOp;
UINTN MaxLen;
+ EFI_STATUS Status;
+ EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
DeviceType = (UINT16)-1;
@@ -537,6 +541,25 @@ UpdateBootManager ( EndLabel->Number = LABEL_BOOT_OPTION_END;
mKeyInput = 0;
NeedEndOp = FALSE;
+
+ //
+ // Get UiApp FilePath
+ //
+ Status = gBS->HandleProtocol (
+ gImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ (VOID **)&LoadedImage
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ DevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle);
+ ASSERT (DevicePath != NULL);
+
+ DevicePath = AppendDevicePathNode (
+ DevicePath,
+ LoadedImage->FilePath
+ );
+
for (Index = 0; Index < BootOptionCount; Index++) {
//
// At this stage we are creating a menu entry, thus the Keys are reproduceable
@@ -551,6 +574,13 @@ UpdateBootManager ( }
//
+ // Don't display UiApp within the boot options
+ //
+ if (CompareMem (DevicePath, BootOption[Index].FilePath, GetDevicePathSize (DevicePath)) == 0) {
+ continue;
+ }
+
+ //
// Group the legacy boot option in the sub title created dynamically
//
IsLegacyOption = (BOOLEAN)(
diff --git a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.c b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.c index b3da13d..1099b64 100644 --- a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.c +++ b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.c @@ -64,7 +64,7 @@ DisplayPageFrame ( return EFI_INVALID_PARAMETER;
}
- Status = ScreenDiemensionInfoValidate (FormData);
+ Status = ScreenDimensionInfoValidate (FormData);
if (EFI_ERROR (Status)) {
return Status;
}
diff --git a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c index 42dd8f8..2d807bf 100644 --- a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c +++ b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c @@ -378,7 +378,7 @@ ProcessExternedOpcode ( }
/**
- Validate the input screen diemenstion info.
+ Validate the input screen dimension info.
@param FormData The input form data info.
@@ -387,7 +387,7 @@ ProcessExternedOpcode ( **/
EFI_STATUS
-ScreenDiemensionInfoValidate (
+ScreenDimensionInfoValidate (
IN FORM_DISPLAY_ENGINE_FORM *FormData
)
{
diff --git a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.h b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.h index 01213cb..a9ac17c 100644 --- a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.h +++ b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.h @@ -129,7 +129,7 @@ PrintFramework ( );
/**
- Validate the input screen diemenstion info.
+ Validate the input screen dimension info.
@param FormData The input form data info.
@@ -138,7 +138,7 @@ PrintFramework ( **/
EFI_STATUS
-ScreenDiemensionInfoValidate (
+ScreenDimensionInfoValidate (
IN FORM_DISPLAY_ENGINE_FORM *FormData
);
diff --git a/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c b/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c index c8ca25e..3950bbb 100644 --- a/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c +++ b/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c @@ -848,7 +848,17 @@ DeviceManagerCallback ( {
UINTN CurIndex;
- if (Action != EFI_BROWSER_ACTION_CHANGING) {
+ if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
+ //
+ // Means enter the device manager form.
+ // Update device manager page when form opens, because options may add or remove.
+ //
+ if (QuestionId == 0x1212) {
+ CreateDeviceManagerForm (DEVICE_MANAGER_FORM_ID);
+ }
+
+ return EFI_SUCCESS;
+ } else if (Action != EFI_BROWSER_ACTION_CHANGING) {
//
// Do nothing for other UEFI Action. Only do call back when data is changed.
//
@@ -926,11 +936,6 @@ DeviceManagerUiLibConstructor ( //
EfiBootManagerConnectAll ();
- //
- // Update boot manager page
- //
- CreateDeviceManagerForm (DEVICE_MANAGER_FORM_ID);
-
return EFI_SUCCESS;
}
diff --git a/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerVfr.Vfr b/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerVfr.Vfr index d81c580..911ea03 100644 --- a/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerVfr.Vfr +++ b/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerVfr.Vfr @@ -28,6 +28,17 @@ formset title = STRING_TOKEN(STR_EDKII_MENU_TITLE);
subtitle text = STRING_TOKEN(STR_DEVICES_LIST);
+ //
+ // Add this invisable text in order to indicate enter Device Manager form.
+ //
+ suppressif TRUE;
+ text
+ help = STRING_TOKEN(STR_EMPTY_STRING),
+ text = STRING_TOKEN(STR_EMPTY_STRING),
+ flags = INTERACTIVE,
+ key = 0x1212;
+ endif;
+
label LABEL_DEVICES_LIST;
label LABEL_END;
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c index f072fb4..9281322 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c @@ -104,7 +104,7 @@ RecordFmpCapsuleStatusVariable ( @param[in] Completion A value between 1 and 100 indicating the current
completion progress of the firmware update
- @retval EFI_SUCESS The capsule update progress was updated.
+ @retval EFI_SUCCESS The capsule update progress was updated.
@retval EFI_INVALID_PARAMETER Completion is greater than 100%.
**/
EFI_STATUS
@@ -201,7 +201,7 @@ IsValidCapsuleHeader ( @param[in] CapsuleHeader Points to a capsule header.
@param[out] EmbeddedDriverCount The EmbeddedDriverCount in the FMP capsule.
- @retval EFI_SUCESS Input capsule is a correct FMP capsule.
+ @retval EFI_SUCCESS Input capsule is a correct FMP capsule.
@retval EFI_INVALID_PARAMETER Input capsule is not a correct FMP capsule.
**/
EFI_STATUS
@@ -345,7 +345,7 @@ ValidateFmpCapsule ( @param[in] CapsuleHeader Points to a capsule header.
- @retval EFI_SUCESS Input capsule is supported by firmware.
+ @retval EFI_SUCCESS Input capsule is supported by firmware.
@retval EFI_UNSUPPORTED Input capsule is not supported by the firmware.
**/
EFI_STATUS
@@ -1198,7 +1198,7 @@ RecordFmpCapsuleStatus ( @param[in] CapFileName Capsule file name.
@param[out] ResetRequired Indicates whether reset is required or not.
- @retval EFI_SUCESS Process Capsule Image successfully.
+ @retval EFI_SUCCESS Process Capsule Image successfully.
@retval EFI_UNSUPPORTED Capsule image is not supported by the firmware.
@retval EFI_VOLUME_CORRUPTED FV volume in the capsule is corrupted.
@retval EFI_OUT_OF_RESOURCES Not enough memory.
@@ -1496,7 +1496,7 @@ IsFmpCapsule ( @param[in] CapsuleHeader Points to a capsule header.
- @retval EFI_SUCESS Input capsule is supported by firmware.
+ @retval EFI_SUCCESS Input capsule is supported by firmware.
@retval EFI_UNSUPPORTED Input capsule is not supported by the firmware.
@retval EFI_INVALID_PARAMETER Input capsule layout is not correct
**/
@@ -1547,7 +1547,7 @@ SupportCapsuleImage ( @param[in] CapFileName Capsule file name.
@param[out] ResetRequired Indicates whether reset is required or not.
- @retval EFI_SUCESS Process Capsule Image successfully.
+ @retval EFI_SUCCESS Process Capsule Image successfully.
@retval EFI_UNSUPPORTED Capsule image is not supported by the firmware.
@retval EFI_VOLUME_CORRUPTED FV volume in the capsule is corrupted.
@retval EFI_OUT_OF_RESOURCES Not enough memory.
@@ -1610,7 +1610,7 @@ ProcessThisCapsuleImage ( @param[in] CapsuleHeader Points to a capsule header.
- @retval EFI_SUCESS Process Capsule Image successfully.
+ @retval EFI_SUCCESS Process Capsule Image successfully.
@retval EFI_UNSUPPORTED Capsule image is not supported by the firmware.
@retval EFI_VOLUME_CORRUPTED FV volume in the capsule is corrupted.
@retval EFI_OUT_OF_RESOURCES Not enough memory.
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c index 2a38a3d..8c0023d 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c @@ -65,7 +65,7 @@ IsFmpCapsule ( @param[in] CapsuleHeader Points to a capsule header.
@param[out] EmbeddedDriverCount The EmbeddedDriverCount in the FMP capsule.
- @retval EFI_SUCESS Input capsule is a correct FMP capsule.
+ @retval EFI_SUCCESS Input capsule is a correct FMP capsule.
@retval EFI_INVALID_PARAMETER Input capsule is not a correct FMP capsule.
**/
EFI_STATUS
@@ -139,7 +139,7 @@ UINT32 mCapsuleTotalNumber; @param[in] CapFileName Capsule file name.
@param[out] ResetRequired Indicates whether reset is required or not.
- @retval EFI_SUCESS Process Capsule Image successfully.
+ @retval EFI_SUCCESS Process Capsule Image successfully.
@retval EFI_UNSUPPORTED Capsule image is not supported by the firmware.
@retval EFI_VOLUME_CORRUPTED FV volume in the capsule is corrupted.
@retval EFI_OUT_OF_RESOURCES Not enough memory.
@@ -159,7 +159,7 @@ ProcessThisCapsuleImage ( @param[in] Completion A value between 1 and 100 indicating the current
completion progress of the firmware update
- @retval EFI_SUCESS The capsule update progress was updated.
+ @retval EFI_SUCCESS The capsule update progress was updated.
@retval EFI_INVALID_PARAMETER Completion is greater than 100%.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLibNull.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLibNull.c index 9054ae4..9f45f27 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLibNull.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLibNull.c @@ -18,7 +18,7 @@ @param[in] Completion A value between 1 and 100 indicating the current
completion progress of the firmware update
- @retval EFI_SUCESS The capsule update progress was updated.
+ @retval EFI_SUCCESS The capsule update progress was updated.
@retval EFI_INVALID_PARAMETER Completion is greater than 100%.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Library/DxeFileExplorerProtocol/DxeFileExplorerProtocol.c b/MdeModulePkg/Library/DxeFileExplorerProtocol/DxeFileExplorerProtocol.c index a8f07c8..28ef4df 100644 --- a/MdeModulePkg/Library/DxeFileExplorerProtocol/DxeFileExplorerProtocol.c +++ b/MdeModulePkg/Library/DxeFileExplorerProtocol/DxeFileExplorerProtocol.c @@ -68,7 +68,7 @@ FileExplorerConstructor ( after choose one file.
@param File Return the device path for the last time chosed file.
- @retval EFI_SUCESS Choose file success.
+ @retval EFI_SUCCESS Choose file success.
@retval EFI_INVALID_PARAMETER Both ChooseHandler and return device path are NULL
One of them must not NULL.
@retval Other errors Choose file failed.
diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c index 804a03d..42ad80c 100644 --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c @@ -870,7 +870,7 @@ LibFindFileSystem ( @param MenuEntry Input Menu info.
@param RetFileHandle Return the file handle for the input device path.
- @retval EFI_SUCESS Find the file handle success.
+ @retval EFI_SUCCESS Find the file handle success.
@retval Other Find the file handle failure.
**/
EFI_STATUS
@@ -918,7 +918,7 @@ LibGetFileHandleFromMenu ( @param ParentFileName Parent file name.
@param DeviceHandle Driver handle for this partition.
- @retval EFI_SUCESS Find the file handle success.
+ @retval EFI_SUCCESS Find the file handle success.
@retval Other Find the file handle failure.
**/
EFI_STATUS
@@ -1478,7 +1478,7 @@ LibGetDevicePath ( after choose one file.
@param File Return the device path for the last time chosed file.
- @retval EFI_SUCESS Choose file success.
+ @retval EFI_SUCCESS Choose file success.
@retval EFI_INVALID_PARAMETER Both ChooseHandler and return device path are NULL
One of them must not NULL.
@retval Other errors Choose file failed.
diff --git a/MdeModulePkg/Library/SmmCorePerformanceLib/MmCorePerformanceLib.c b/MdeModulePkg/Library/SmmCorePerformanceLib/MmCorePerformanceLib.c index d335c7c..8982df0 100644 --- a/MdeModulePkg/Library/SmmCorePerformanceLib/MmCorePerformanceLib.c +++ b/MdeModulePkg/Library/SmmCorePerformanceLib/MmCorePerformanceLib.c @@ -42,13 +42,6 @@ UINT32 mCachedLength = 0; UINT32 mBootRecordSize = 0;
BOOLEAN mPerformanceMeasurementEnabled;
-//
-// Interfaces for SMM PerformanceMeasurement Protocol.
-//
-EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface = {
- CreatePerformanceMeasurement,
-};
-
/**
Return the module name and optionally module GUID for a given handle.
@@ -915,62 +908,6 @@ SmmCorePerformanceLibExitBootServicesCallback ( }
/**
- Common initialization code for the MM Core Performance Library.
-
- @param[in] ExitBootServicesProtocolGuid The GUID of the ExitBootServices protocol.
-
- @retval EFI_SUCCESS The MM Core Performance Library was initialized successfully.
- @retval Others The MM Core Performance Library was not initialized successfully.
- **/
-EFI_STATUS
-InitializeMmCorePerformanceLibCommon (
- IN CONST EFI_GUID *ExitBootServicesProtocolGuid
- )
-{
- EFI_STATUS Status;
- EFI_HANDLE Handle;
- EFI_HANDLE MmiHandle;
- VOID *Registration;
-
- //
- // Initialize spin lock
- //
- InitializeSpinLock (&mSmmFpdtLock);
-
- //
- // Install the protocol interfaces for MM performance library instance.
- //
- Handle = NULL;
- Status = gMmst->MmInstallProtocolInterface (
- &Handle,
- &gEdkiiSmmPerformanceMeasurementProtocolGuid,
- EFI_NATIVE_INTERFACE,
- &mPerformanceMeasurementInterface
- );
- ASSERT_EFI_ERROR (Status);
-
- //
- // Register MMI handler.
- //
- MmiHandle = NULL;
- Status = gMmst->MmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerformanceGuid, &MmiHandle);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Register callback function for ExitBootServices event.
- //
- Status = gMmst->MmRegisterProtocolNotify (
- ExitBootServicesProtocolGuid,
- SmmCorePerformanceLibExitBootServicesCallback,
- &Registration
- );
-
- return Status;
-}
-
-/**
Create performance record with event description and a timestamp.
@param CallerIdentifier - Image handle or pointer to caller ID GUID.
diff --git a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c index 20aa250..96bff30 100644 --- a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c +++ b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c @@ -26,6 +26,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/DxeServicesLib.h>
#include <Library/SmmMemLib.h>
+#include <Library/SmmServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Protocol/SmmBase2.h>
@@ -33,6 +34,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent PERFORMANCE_PROPERTY mPerformanceProperty;
+extern SPIN_LOCK mSmmFpdtLock;
+
+EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface = {
+ CreatePerformanceMeasurement,
+};
+
/**
A library internal MM-instance specific implementation to check if a buffer outside MM is valid.
@@ -192,10 +199,43 @@ InitializeSmmCorePerformanceLib ( {
EFI_STATUS Status;
PERFORMANCE_PROPERTY *PerformanceProperty;
+ EFI_HANDLE Handle;
+ EFI_HANDLE MmiHandle;
+ VOID *Registration;
+
+ //
+ // Initialize spin lock
+ //
+ InitializeSpinLock (&mSmmFpdtLock);
+
+ //
+ // Install the protocol interfaces for MM performance library instance.
+ //
+ Handle = NULL;
+ Status = gSmst->SmmInstallProtocolInterface (
+ &Handle,
+ &gEdkiiSmmPerformanceMeasurementProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mPerformanceMeasurementInterface
+ );
+ ASSERT_EFI_ERROR (Status);
- Status = InitializeMmCorePerformanceLibCommon (&gEdkiiSmmExitBootServicesProtocolGuid);
+ //
+ // Register MMI handler.
+ //
+ MmiHandle = NULL;
+ Status = gSmst->SmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerformanceGuid, &MmiHandle);
ASSERT_EFI_ERROR (Status);
+ //
+ // Register callback function for ExitBootServices event.
+ //
+ Status = gSmst->SmmRegisterProtocolNotify (
+ &gEdkiiSmmExitBootServicesProtocolGuid,
+ SmmCorePerformanceLibExitBootServicesCallback,
+ &Registration
+ );
+
Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **)&PerformanceProperty);
if (EFI_ERROR (Status)) {
//
diff --git a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.inf b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.inf index d5e6284..b922463 100644 --- a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.inf +++ b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.inf @@ -47,10 +47,10 @@ DebugLib
DxeServicesLib
MemoryAllocationLib
- MmServicesTableLib
PcdLib
PeCoffGetEntryPointLib
SmmMemLib
+ SmmServicesTableLib
SynchronizationLib
TimerLib
UefiBootServicesTableLib
diff --git a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLibInternal.h b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLibInternal.h index 7ff2105..bc1757c 100644 --- a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLibInternal.h +++ b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLibInternal.h @@ -24,7 +24,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
-#include <Library/MmServicesTableLib.h>
#include <Library/PcdLib.h>
#include <Library/PeCoffGetEntryPointLib.h>
#include <Library/PerformanceLib.h>
@@ -46,6 +45,57 @@ extern BOOLEAN mPerformanceMeasurementEnabled; //
/**
+ Communication service SMI Handler entry.
+
+ This SMI handler provides services for report MM boot records.
+
+ Caution: This function may receive untrusted input.
+ Communicate buffer and buffer size are external input, so this function will do basic validation.
+
+ @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
+ @param[in] RegisterContext Points to an optional handler context which was specified when the
+ handler was registered.
+ @param[in, out] CommBuffer A pointer to a collection of data in memory that will
+ be conveyed from a non-MM environment into an MM environment.
+ @param[in, out] CommBufferSize The size of the CommBuffer.
+
+ @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
+ should still be called.
+ @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should
+ still be called.
+ @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still
+ be called.
+ @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.
+
+**/
+EFI_STATUS
+EFIAPI
+FpdtSmiHandler (
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *RegisterContext,
+ IN OUT VOID *CommBuffer,
+ IN OUT UINTN *CommBufferSize
+ );
+
+/**
+ This is the Event call back function is triggered in SMM to notify the Library
+ the system is entering runtime phase.
+
+ @param[in] Protocol Points to the protocol's unique identifier
+ @param[in] Interface Points to the interface instance
+ @param[in] Handle The handle on which the interface was installed
+
+ @retval EFI_SUCCESS SmmAtRuntimeCallBack runs successfully
+ **/
+EFI_STATUS
+EFIAPI
+SmmCorePerformanceLibExitBootServicesCallback (
+ IN CONST EFI_GUID *Protocol,
+ IN VOID *Interface,
+ IN EFI_HANDLE Handle
+ );
+
+/**
Return a pointer to the loaded image protocol for the given handle.
@param[in] Handle A handle to query for the loaded image protocol.
diff --git a/MdeModulePkg/Library/SmmCorePerformanceLib/StandaloneMmCorePerformanceLib.c b/MdeModulePkg/Library/SmmCorePerformanceLib/StandaloneMmCorePerformanceLib.c index d6fae6b..55ec507 100644 --- a/MdeModulePkg/Library/SmmCorePerformanceLib/StandaloneMmCorePerformanceLib.c +++ b/MdeModulePkg/Library/SmmCorePerformanceLib/StandaloneMmCorePerformanceLib.c @@ -17,8 +17,15 @@ #include "SmmCorePerformanceLibInternal.h"
#include <Guid/EventGroup.h>
+#include <Library/MmServicesTableLib.h>
#include <Library/StandaloneMmMemLib.h>
+extern SPIN_LOCK mSmmFpdtLock;
+
+EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface = {
+ CreatePerformanceMeasurement,
+};
+
/**
A library internal MM-instance specific implementation to check if a buffer outside MM is valid.
@@ -110,6 +117,60 @@ GetNameFromUiSection ( }
/**
+ Initializes the MM Core Performance library.
+
+ @retval EFI_SUCCESS The performance library was initialized successfully.
+ @retval Other An error occurred during initialization.
+**/
+EFI_STATUS
+EFIAPI
+InitializeStandaloneMmCorePerformanceLib (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
+ EFI_HANDLE MmiHandle;
+ VOID *Registration;
+
+ //
+ // Initialize spin lock
+ //
+ InitializeSpinLock (&mSmmFpdtLock);
+ //
+ // Install the protocol interfaces for MM performance library instance.
+ //
+ Handle = NULL;
+ Status = gMmst->MmInstallProtocolInterface (
+ &Handle,
+ &gEdkiiSmmPerformanceMeasurementProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mPerformanceMeasurementInterface
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Register MMI handler.
+ //
+ MmiHandle = NULL;
+ Status = gMmst->MmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerformanceGuid, &MmiHandle);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Register callback function for ExitBootServices event.
+ //
+ Status = gMmst->MmRegisterProtocolNotify (
+ &gEfiEventExitBootServicesGuid,
+ SmmCorePerformanceLibExitBootServicesCallback,
+ &Registration
+ );
+
+ return Status;
+}
+
+/**
The constructor function initializes the Standalone MM Core performance library.
It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.
@@ -140,7 +201,7 @@ StandaloneMmCorePerformanceLibConstructor ( return EFI_SUCCESS;
}
- Status = InitializeMmCorePerformanceLibCommon (&gEfiEventExitBootServicesGuid);
+ Status = InitializeStandaloneMmCorePerformanceLib ();
ASSERT_EFI_ERROR (Status);
return EFI_SUCCESS;
diff --git a/MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.c b/MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.c index 880b428..d6853a1 100644 --- a/MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.c +++ b/MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.c @@ -6,6 +6,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
+#include <Uefi/UefiBaseType.h>
+#include <Library/TpmMeasurementLib.h>
+
/**
Tpm measure and log data, and extend the measurement result into a specific PCR.
diff --git a/MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf b/MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf index c3be447..96d816b 100644 --- a/MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf +++ b/MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf @@ -10,9 +10,9 @@ INF_VERSION = 0x00010005
BASE_NAME = TpmMeasurementLibNull
FILE_GUID = 6DFD6E9F-9278-48D8-8F45-B6CFF2C2B69C
- MODULE_TYPE = UEFI_DRIVER
+ MODULE_TYPE = BASE
VERSION_STRING = 1.0
- LIBRARY_CLASS = TpmMeasurementLib|SEC PEIM DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
+ LIBRARY_CLASS = TpmMeasurementLib
MODULE_UNI_FILE = TpmMeasurementLibNull.uni
#
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c index 3343e60..22ab4d7 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c @@ -1404,7 +1404,7 @@ BmDestroyRamDisk ( Status = mRamDisk->Unregister (RamDiskDevicePath);
ASSERT_EFI_ERROR (Status);
- FreePages (RamDiskBuffer, RamDiskSizeInPages);
+ FreeAlignedPages (RamDiskBuffer, RamDiskSizeInPages);
}
/**
@@ -1454,8 +1454,12 @@ BmExpandLoadFile ( //
// The load option resides in a RAM disk.
+ // Use a reasonable default of 2MB for alignment as the ramdisk device is
+ // implemented as an NVDIMM persistent memory and operating systems may
+ // wish to map this with huge page support.
//
- FileBuffer = AllocateReservedPages (EFI_SIZE_TO_PAGES (BufferSize));
+
+ FileBuffer = AllocateAlignedReservedPages (EFI_SIZE_TO_PAGES (BufferSize), SIZE_2MB);
if (FileBuffer == NULL) {
DEBUG_CODE_BEGIN ();
EFI_DEVICE_PATH *LoadFilePath;
@@ -1496,7 +1500,7 @@ BmExpandLoadFile ( Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer);
if (EFI_ERROR (Status)) {
- FreePages (FileBuffer, EFI_SIZE_TO_PAGES (BufferSize));
+ FreeAlignedPages (FileBuffer, EFI_SIZE_TO_PAGES (BufferSize));
return NULL;
}
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c b/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c index 46a8b78..1f6786f 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c @@ -105,6 +105,79 @@ BmGetControllerName ( }
/**
+ Return the driver name.
+
+ @param DriverHealthHandle The handle on which the Driver Health protocol instance is retrieved.
+
+ @return A pointer to the Unicode string to return. This Unicode string is the name of the controller
+ specified by DriverHealthHandle.
+**/
+CHAR16 *
+BmGetDriverName (
+ IN EFI_HANDLE DriverHealthHandle
+ )
+{
+ EFI_STATUS Status;
+ CHAR16 *DriverName;
+ CHAR8 *LanguageVariable;
+ CHAR8 *BestLanguage;
+ BOOLEAN Iso639Language;
+ EFI_COMPONENT_NAME_PROTOCOL *ComponentName;
+
+ DriverName = NULL;
+
+ //
+ // Locate Component Name (2) protocol on the driver binging handle.
+ //
+ Iso639Language = FALSE;
+ Status = gBS->HandleProtocol (
+ DriverHealthHandle,
+ &gEfiComponentName2ProtocolGuid,
+ (VOID **)&ComponentName
+ );
+ if (EFI_ERROR (Status)) {
+ Status = gBS->HandleProtocol (
+ DriverHealthHandle,
+ &gEfiComponentNameProtocolGuid,
+ (VOID **)&ComponentName
+ );
+ if (!EFI_ERROR (Status)) {
+ Iso639Language = TRUE;
+ }
+ }
+
+ if (!EFI_ERROR (Status)) {
+ GetEfiGlobalVariable2 (Iso639Language ? L"Lang" : L"PlatformLang", (VOID **)&LanguageVariable, NULL);
+ BestLanguage = GetBestLanguage (
+ ComponentName->SupportedLanguages,
+ Iso639Language,
+ (LanguageVariable != NULL) ? LanguageVariable : "",
+ Iso639Language ? "eng" : "en-US",
+ NULL
+ );
+ if (LanguageVariable != NULL) {
+ FreePool (LanguageVariable);
+ }
+
+ Status = ComponentName->GetDriverName (
+ ComponentName,
+ BestLanguage,
+ &DriverName
+ );
+ }
+
+ if (!EFI_ERROR (Status)) {
+ return AllocateCopyPool (StrSize (DriverName), DriverName);
+ } else {
+ return ConvertDevicePathToText (
+ DevicePathFromHandle (DriverHealthHandle),
+ FALSE,
+ FALSE
+ );
+ }
+}
+
+/**
Display a set of messages returned by the GetHealthStatus () service of the EFI Driver Health Protocol
@param DriverHealthInfo Pointer to the Driver Health information entry.
@@ -116,7 +189,8 @@ BmDisplayMessages ( {
UINTN Index;
EFI_STRING String;
- CHAR16 *ControllerName;
+ CHAR16 *ControllerName = NULL;
+ CHAR16 *DriverName = NULL;
if ((DriverHealthInfo->MessageList == NULL) ||
(DriverHealthInfo->MessageList[0].HiiHandle == NULL))
@@ -124,14 +198,30 @@ BmDisplayMessages ( return;
}
- ControllerName = BmGetControllerName (
- DriverHealthInfo->DriverHealthHandle,
- DriverHealthInfo->ControllerHandle,
- DriverHealthInfo->ChildHandle
- );
+ if (DriverHealthInfo->DriverHealthHandle != NULL) {
+ DriverName = BmGetDriverName (DriverHealthInfo->DriverHealthHandle);
+ if (DriverName != NULL) {
+ DEBUG ((DEBUG_INFO, "Driver: %s\n", DriverName));
+ Print (L"Driver: %s\n", DriverName);
+ }
+ }
+
+ if (DriverHealthInfo->ControllerHandle != NULL) {
+ ControllerName = BmGetControllerName (
+ DriverHealthInfo->DriverHealthHandle,
+ DriverHealthInfo->ControllerHandle,
+ DriverHealthInfo->ChildHandle
+ );
+ if (ControllerName != NULL) {
+ DEBUG ((DEBUG_INFO, "Controller: %s\n", ControllerName));
+ Print (L"Controller: %s\n", ControllerName);
+ }
+ }
+
+ if ((DriverName == NULL) && (ControllerName == NULL)) {
+ return;
+ }
- DEBUG ((DEBUG_INFO, "Controller: %s\n", ControllerName));
- Print (L"Controller: %s\n", ControllerName);
for (Index = 0; DriverHealthInfo->MessageList[Index].HiiHandle != NULL; Index++) {
String = HiiGetString (
DriverHealthInfo->MessageList[Index].HiiHandle,
@@ -147,6 +237,12 @@ BmDisplayMessages ( if (ControllerName != NULL) {
FreePool (ControllerName);
+ ControllerName = NULL;
+ }
+
+ if (DriverName != NULL) {
+ FreePool (DriverName);
+ DriverName = NULL;
}
}
@@ -550,24 +646,58 @@ BmRepairAllControllers ( EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count);
DEBUG_CODE_BEGIN ();
- CHAR16 *ControllerName;
+ CHAR16 *ControllerName = NULL;
+ CHAR16 *DriverName = NULL;
+ CHAR16 String[512];
DriverHealthInfo = EfiBootManagerGetDriverHealthInfo (&Count);
for (Index = 0; Index < Count; Index++) {
- ControllerName = BmGetControllerName (
- DriverHealthInfo[Index].DriverHealthHandle,
- DriverHealthInfo[Index].ControllerHandle,
- DriverHealthInfo[Index].ChildHandle
- );
+ if (DriverHealthInfo == NULL) {
+ continue;
+ }
+
+ ZeroMem (String, sizeof (String));
+ if (DriverHealthInfo[Index].DriverHealthHandle != NULL) {
+ DriverName = BmGetDriverName (DriverHealthInfo[Index].DriverHealthHandle);
+ }
+
+ if (DriverHealthInfo[Index].ControllerHandle != NULL) {
+ ControllerName = BmGetControllerName (
+ DriverHealthInfo[Index].DriverHealthHandle,
+ DriverHealthInfo[Index].ControllerHandle,
+ DriverHealthInfo[Index].ChildHandle
+ );
+ }
+
+ if ((DriverName == NULL) && (ControllerName == NULL)) {
+ continue;
+ }
+
+ UnicodeSPrint (
+ String,
+ sizeof (String),
+ L"%s%s%s",
+ DriverName != NULL ? DriverName : L"",
+ (DriverName != NULL && ControllerName != NULL) ? L" " : L"",
+ ControllerName != NULL ? ControllerName : L""
+ );
+
DEBUG ((
DEBUG_INFO,
"%02d: %s - %s\n",
Index,
- ControllerName,
+ String,
mBmHealthStatusText[DriverHealthInfo[Index].HealthStatus]
));
+
if (ControllerName != NULL) {
FreePool (ControllerName);
+ ControllerName = NULL;
+ }
+
+ if (DriverName != NULL) {
+ FreePool (DriverName);
+ DriverName = NULL;
}
}
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c index 284f511..7813c87 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c @@ -437,6 +437,10 @@ EfiBootManagerSortLoadOptionVariable ( LoadOption = EfiBootManagerGetLoadOptions (&LoadOptionCount, OptionType);
+ if (LoadOptionCount == 0) {
+ return;
+ }
+
//
// Insertion sort algorithm
//
diff --git a/MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.c b/MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.c index f5b9418..7f377f1 100644 --- a/MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.c +++ b/MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.c @@ -2,6 +2,8 @@ Business logic for Variable Policy enforcement.
Copyright (c) Microsoft Corporation.
+Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
+
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -107,7 +109,7 @@ IsValidVariablePolicyStructure ( // Sanitize some quick values.
if ((NewPolicy == NULL) || (NewPolicy->Size == 0) ||
- // Structure size should be at least as long as the minumum structure and a NULL string.
+ // Structure size should be at least as long as the minimum structure and a NULL string.
(NewPolicy->Size < sizeof (VARIABLE_POLICY_ENTRY)) ||
// Check for the known revision.
(NewPolicy->Version != VARIABLE_POLICY_ENTRY_REVISION))
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index aa21365..24cc64f 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -494,6 +494,9 @@ ## Include/Guid/DelayedDispatch.h
gEfiDelayedDispatchTableGuid = { 0x4b733449, 0x8eff, 0x488c, { 0x92, 0x1a, 0x15, 0x4a, 0xda, 0x25, 0x18, 0x07 }}
+ ## Include/Guid/ArmFfaRxTxBufferInfo.h
+ gArmFfaRxTxBufferInfoGuid = { 0x96fd3d26, 0x6fb1, 0x11ef, { 0x8c, 0x11, 0xf3, 0xc9, 0xc5, 0x02, 0x31, 0xab } }
+
[Ppis]
## Include/Ppi/FirmwareVolumeShadowPpi.h
gEdkiiPeiFirmwareVolumeShadowPpiGuid = { 0x7dfe756c, 0xed8d, 0x4d77, {0x9e, 0xc4, 0x39, 0x9a, 0x8a, 0x81, 0x51, 0x16 } }
@@ -501,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 }}
@@ -821,13 +821,6 @@ # @Prompt Enable ConOut GOP support.
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE|BOOLEAN|0x00010042
- ## Indicates if UGA Draw Protocol will be installed on virtual handle created by ConsplitterDxe.
- # It could be set FALSE to save size.<BR><BR>
- # TRUE - Installs UGA Draw Protocol on virtual handle created by ConsplitterDxe.<BR>
- # FALSE - Does not install UGA Draw Protocol on virtual handle created by ConsplitterDxe.<BR>
- # @Prompt Enable ConOut UGA support.
- gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|TRUE|BOOLEAN|0x00010043
-
## Indicates PeiCore will first search TE section from the PEIM to load the image, or PE32 section, when PeiCore dispatches a PEI module.
# This PCD is used to tune PEI phase performance to reduce the search image time.
# It can be set according to the generated image section type.<BR><BR>
@@ -1215,6 +1208,10 @@ # @Prompt Defines the page allocation for the MM communication buffer; default is 128 pages (512KB).
gEfiMdeModulePkgTokenSpaceGuid.PcdMmCommBufferPages|128|UINT32|0x30001061
+ ## This PCD holds the number of pages for the FFA TX/RX buffer.
+ # @Prompt FFA TX/RX Buffer Page Count
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaTxRxPageCount|1|UINT64|0x30001062
+
[PcdsFixedAtBuild, PcdsPatchableInModule]
## Dynamic type PCD can be registered callback function for Pcd setting action.
# PcdMaxPeiPcdCallBackNumberPerPcdEntry indicates the maximum number of callback function
@@ -1352,10 +1349,6 @@ # @Prompt Enable serial port cable detetion.
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable|FALSE|BOOLEAN|0x00020006
- ## Base address of 16550 serial port registers in MMIO or I/O space. Default is 0x3F8.
- # @Prompt Base address of serial port registers.
- gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x03F8|UINT64|0x00020002
-
## Baud rate for the 16550 serial port. Default is 115200 baud.
# @Prompt Baud rate for serial port.
# @ValidList 0x80000001 | 921600, 460800, 230400, 115200, 57600, 38400, 19200, 9600, 7200, 4800, 3600, 2400, 2000, 1800, 1200, 600, 300, 150, 134, 110, 75, 50
@@ -1512,8 +1505,7 @@ # OEM Reserved 0x4000000000000000<BR>
# OS Reserved 0x8000000000000000<BR>
#
- # NOTE: User must NOT set NX protection for EfiLoaderCode / EfiBootServicesCode / EfiRuntimeServicesCode. <BR>
- # User MUST set the same NX protection for EfiBootServicesData and EfiConventionalMemory. <BR>
+ # NOTE: User MUST set the same NX protection for EfiBootServicesData and EfiConventionalMemory. <BR>
#
# e.g. 0x7FD5 can be used for all memory except Code. <BR>
# e.g. 0x7BD4 can be used for all memory except Code and ACPINVS/Reserved. <BR>
@@ -1791,6 +1783,11 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions|0x20|UINT32|0x0001004c
[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
+
+ ## Base address of 16550 serial port registers in MMIO or I/O space. Default is 0x3F8.
+ # @Prompt Base address of serial port registers.
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x03F8|UINT64|0x00020002
+
## UART clock frequency is for the baud rate configuration.
# @Prompt Serial Port Clock Rate.
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|1843200|UINT32|0x00010066
@@ -2281,6 +2278,12 @@ # @Prompt The value is use for Usb Network rate limiting supported.
gEfiMdeModulePkgTokenSpaceGuid.PcdUsbNetworkRateLimitingFactor|100|UINT32|0x10000028
+ ## Define the conduit to use in ArmFfalib.
+ # Default PcdFfaLibConduitSmc == TRUE, conduit = SMC
+ # If PcdFfaLibConduitSvc == FALSE, conduit = SVC
+ # @Prompt Conduit to use in ArmFfaLib.
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaLibConduitSmc|TRUE|BOOLEAN|0x10000029
+
[PcdsPatchableInModule]
## Specify memory size with page number for PEI code when
# Loading Module at Fixed Address feature is enabled.
@@ -2359,5 +2362,17 @@ # @Prompt 64bit VPD base address.
gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress64|0x0|UINT64|0x00030006
+ ## This dynamic PCD holds the address of the FFA TX buffer.
+ # @Prompt FFA TX Buffer Address
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaTxBuffer|0x00|UINT64|0x00030009
+
+ ## This dynamic PCD holds the address of the FFA RX buffer.
+ # @Prompt FFA RX Buffer Address
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaRxBuffer|0x00|UINT64|0x0003000A
+
+ ## This dynamic PCD holds the information if the FFA exit boot event is registered.
+ # @Prompt FFA Exit Boot Event Registered
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFfaExitBootEventRegistered|FALSE|BOOLEAN|0x0003000C
+
[UserExtensions.TianoCore."ExtraFiles"]
MdeModulePkgExtra.uni
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 4b7f3e4..62ece76 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -184,6 +184,8 @@ [LibraryClasses.ARM, LibraryClasses.AARCH64]
LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf
+ ArmSmcLib|MdePkg/Library/ArmSmcLib/ArmSmcLib.inf
+ ArmSvcLib|MdePkg/Library/ArmSvcLib/ArmSvcLib.inf
[LibraryClasses.EBC, LibraryClasses.RISCV64, LibraryClasses.LOONGARCH64]
LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf
@@ -248,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
@@ -532,5 +533,12 @@ [Components.X64]
MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf
+[Components.ARM, Components.AARCH64]
+ MdeModulePkg/Library/ArmFfaLib/ArmFfaSecLib.inf
+ MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.inf
+ MdeModulePkg/Library/ArmFfaLib/ArmFfaDxeLib.inf
+ MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmCoreLib.inf
+ MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmLib.inf
+
[BuildOptions]
diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni index 6079285..7aa8322 100644 --- a/MdeModulePkg/MdeModulePkg.uni +++ b/MdeModulePkg/MdeModulePkg.uni @@ -709,12 +709,6 @@ "TRUE - Installs Graphics Output Protocol on virtual handle created by ConsplitterDxe.<BR>\n"
"FALSE - Does not install Graphics Output Protocol on virtual handle created by ConsplitterDxe.<BR>"
-#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdConOutUgaSupport_PROMPT #language en-US "Enable ConOut UGA support"
-
-#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdConOutUgaSupport_HELP #language en-US "Indicates if UGA Draw Protocol will be installed on virtual handle created by ConsplitterDxe. It could be set FALSE to save size.<BR><BR>\n"
- "TRUE - Installs UGA Draw Protocol on virtual handle created by ConsplitterDxe.<BR>\n"
- "FALSE - Does not install UGA Draw Protocol on virtual handle created by ConsplitterDxe.<BR>"
-
#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdPeiCoreImageLoaderSearchTeSectionFirst_PROMPT #language en-US "PeiCore search TE section first"
#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdPeiCoreImageLoaderSearchTeSectionFirst_HELP #language en-US "Indicates PeiCore will first search TE section from the PEIM to load the image, or PE32 section, when PeiCore dispatches a PEI module. This PCD is used to tune PEI phase performance to reduce the search image time. It can be set according to the generated image section type.<BR><BR>\n"
diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc index d8b220c..2361374 100644 --- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc +++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc @@ -68,5 +68,7 @@ #
# Build HOST_APPLICATION Libraries
#
+ MdeModulePkg/Test/Mock/Library/GoogleTest/MockHiiLib/MockHiiLib.inf
MdeModulePkg/Test/Mock/Library/GoogleTest/MockPciHostBridgeLib/MockPciHostBridgeLib.inf
MdeModulePkg/Test/Mock/Library/GoogleTest/MockVariablePolicyHelperLib/MockVariablePolicyHelperLib.inf
+ MdeModulePkg/Test/Mock/Library/GoogleTest/MockSecurityManagementLib/MockSecurityManagementLib.inf
diff --git a/MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockHiiLib.h b/MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockHiiLib.h new file mode 100644 index 0000000..fdc88cb --- /dev/null +++ b/MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockHiiLib.h @@ -0,0 +1,356 @@ +/** @file MockHiiLib.h
+ Google Test mocks for HiiLib
+
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_HII_LIB_H_
+#define MOCK_HII_LIB_H_
+
+#include <Library/GoogleTestLib.h>
+#include <Library/FunctionMockLib.h>
+extern "C" {
+ #include <Uefi.h>
+ #include <Library/HiiLib.h>
+}
+
+struct MockHiiLib {
+ MOCK_INTERFACE_DECLARATION (MockHiiLib);
+
+ MOCK_FUNCTION_DECLARATION (
+ VOID,
+ HiiRemovePackages,
+ (IN EFI_HII_HANDLE HiiHandle)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STRING_ID,
+ HiiSetString,
+ (IN EFI_HII_HANDLE HiiHandle,
+ IN EFI_STRING_ID StringId OPTIONAL,
+ IN CONST EFI_STRING String,
+ IN CONST CHAR8 *SupportedLanguages OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STRING,
+ HiiGetString,
+ (IN EFI_HII_HANDLE HiiHandle,
+ IN EFI_STRING_ID StringId,
+ IN CONST CHAR8 *Language OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STRING,
+ HiiGetStringEx,
+ (IN EFI_HII_HANDLE HiiHandle,
+ IN EFI_STRING_ID StringId,
+ IN CONST CHAR8 *Language OPTIONAL,
+ IN BOOLEAN TryBestLanguage)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STRING,
+ HiiGetPackageString,
+ (IN CONST EFI_GUID *PackageListGuid,
+ IN EFI_STRING_ID StringId,
+ IN CONST CHAR8 *Language OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_HII_HANDLE *,
+ HiiGetHiiHandles,
+ (IN CONST EFI_GUID *PackageListGuid OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ HiiGetFormSetFromHiiHandle,
+ (IN EFI_HII_HANDLE Handle,
+ OUT EFI_IFR_FORM_SET **Buffer,
+ OUT UINTN *BufferSize)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ CHAR8 *,
+ HiiGetSupportedLanguages,
+ (IN EFI_HII_HANDLE HiiHandle)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STRING,
+ HiiConstructConfigHdr,
+ (IN CONST EFI_GUID *Guid OPTIONAL,
+ IN CONST CHAR16 *Name OPTIONAL,
+ IN EFI_HANDLE DriverHandle)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ BOOLEAN,
+ HiiSetToDefaults,
+ (IN CONST EFI_STRING Request OPTIONAL,
+ IN UINT16 DefaultId)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ BOOLEAN,
+ HiiValidateSettings,
+ (IN CONST EFI_STRING Request OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ BOOLEAN,
+ HiiIsConfigHdrMatch,
+ (IN CONST EFI_STRING ConfigHdr,
+ IN CONST EFI_GUID *Guid OPTIONAL,
+ IN CONST CHAR16 *Name OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ BOOLEAN,
+ HiiGetBrowserData,
+ (IN CONST EFI_GUID *VariableGuid OPTIONAL,
+ IN CONST CHAR16 *VariableName OPTIONAL,
+ IN UINTN BufferSize,
+ OUT UINT8 *Buffer)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ BOOLEAN,
+ HiiSetBrowserData,
+ (IN CONST EFI_GUID *VariableGuid OPTIONAL,
+ IN CONST CHAR16 *VariableName OPTIONAL,
+ IN UINTN BufferSize,
+ IN CONST UINT8 *Buffer,
+ IN CONST CHAR16 *RequestElement OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ VOID *,
+ HiiAllocateOpCodeHandle,
+ ()
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ VOID,
+ HiiFreeOpCodeHandle,
+ (VOID *OpCodeHandle)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateRawOpCodes,
+ (IN VOID *OpCodeHandle,
+ IN UINT8 *RawBuffer,
+ IN UINTN RawBufferSize)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateEndOpCode,
+ (IN VOID *OpCodeHandle)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateOneOfOptionOpCode,
+ (IN VOID *OpCodeHandle,
+ IN UINT16 StringId,
+ IN UINT8 Flags,
+ IN UINT8 Type,
+ IN UINT64 Value)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateDefaultOpCode,
+ (IN VOID *OpCodeHandle,
+ IN UINT16 DefaultId,
+ IN UINT8 Type,
+ IN UINT64 Value)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateGuidOpCode,
+ (IN VOID *OpCodeHandle,
+ IN CONST EFI_GUID *Guid,
+ IN CONST VOID *GuidOpCode OPTIONAL,
+ IN UINTN OpCodeSize)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateActionOpCode,
+ (IN VOID *OpCodeHandle,
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN EFI_STRING_ID QuestionConfig)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateSubTitleOpCode,
+ (IN VOID *OpCodeHandle,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 Flags,
+ IN UINT8 Scope)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateGotoOpCode,
+ (IN VOID *OpCodeHandle,
+ IN EFI_FORM_ID FormId,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN EFI_QUESTION_ID QuestionId)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateGotoExOpCode,
+ (IN VOID *OpCodeHandle,
+ IN EFI_FORM_ID RefFormId,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_QUESTION_ID RefQuestionId,
+ IN EFI_GUID *RefFormSetId OPTIONAL,
+ IN EFI_STRING_ID RefDevicePath)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateCheckBoxOpCode,
+ (IN VOID *OpCodeHandle,
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_VARSTORE_ID VarStoreId,
+ IN UINT16 VarOffset,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN UINT8 CheckBoxFlags,
+ IN VOID *DefaultsOpCodeHandle OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateNumericOpCode,
+ (IN VOID *OpCodeHandle,
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_VARSTORE_ID VarStoreId,
+ IN UINT16 VarOffset,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN UINT8 NumericFlags,
+ IN UINT64 Minimum,
+ IN UINT64 Maximum,
+ IN UINT64 Step,
+ IN VOID *DefaultsOpCodeHandle OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateStringOpCode,
+ (IN VOID *OpCodeHandle,
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_VARSTORE_ID VarStoreId,
+ IN UINT16 VarOffset,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN UINT8 StringFlags,
+ IN UINT8 MinSize,
+ IN UINT8 MaxSize,
+ IN VOID *DefaultsOpCodeHandle OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateOneOfOpCode,
+ (IN VOID *OpCodeHandle,
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_VARSTORE_ID VarStoreId,
+ IN UINT16 VarOffset,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN UINT8 OneOfFlags,
+ IN VOID *OptionsOpCodeHandle,
+ IN VOID *DefaultsOpCodeHandle OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateOrderedListOpCode,
+ (IN VOID *OpCodeHandle,
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_VARSTORE_ID VarStoreId,
+ IN UINT16 VarOffset,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN UINT8 OrderedListFlags,
+ IN UINT8 DataType,
+ IN UINT8 MaxContainers,
+ IN VOID *OptionsOpCodeHandle,
+ IN VOID *DefaultsOpCodeHandle OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateTextOpCode,
+ (IN VOID *OpCodeHandle,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN EFI_STRING_ID TextTwo)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateDateOpCode,
+ (IN VOID *OpCodeHandle,
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_VARSTORE_ID VarStoreId OPTIONAL,
+ IN UINT16 VarOffset OPTIONAL,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN UINT8 DateFlags,
+ IN VOID *DefaultsOpCodeHandle OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8 *,
+ HiiCreateTimeOpCode,
+ (IN VOID *OpCodeHandle,
+ IN EFI_QUESTION_ID QuestionId,
+ IN EFI_VARSTORE_ID VarStoreId OPTIONAL,
+ IN UINT16 VarOffset OPTIONAL,
+ IN EFI_STRING_ID Prompt,
+ IN EFI_STRING_ID Help,
+ IN UINT8 QuestionFlags,
+ IN UINT8 TimeFlags,
+ IN VOID *DefaultsOpCodeHandle OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ HiiUpdateForm,
+ (IN EFI_HII_HANDLE HiiHandle,
+ IN EFI_GUID *FormSetGuid OPTIONAL,
+ IN EFI_FORM_ID FormId,
+ IN VOID *StartOpCodeHandle,
+ IN VOID *EndOpCodeHandle OPTIONAL)
+ );
+};
+
+#endif
diff --git a/MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockSecurityManagementLib.h b/MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockSecurityManagementLib.h new file mode 100644 index 0000000..59ec205 --- /dev/null +++ b/MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockSecurityManagementLib.h @@ -0,0 +1,54 @@ +/** @file
+ Google Test mocks for DevicePathLib
+
+ Copyright (c) 2025, Yandex. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_SECURITY_MANAGEMENT_LIB_H_
+#define MOCK_SECURITY_MANAGEMENT_LIB_LIB_H_
+
+#include <Library/GoogleTestLib.h>
+#include <Library/FunctionMockLib.h>
+extern "C" {
+ #include <Uefi.h>
+ #include <Library/SecurityManagementLib.h>
+}
+
+struct MockSecurityManagementLib {
+ MOCK_INTERFACE_DECLARATION (MockSecurityManagementLib);
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ RegisterSecurityHandler,
+ (IN SECURITY_FILE_AUTHENTICATION_STATE_HANDLER SecurityHandler,
+ IN UINT32 AuthenticationOperation)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ ExecuteSecurityHandlers,
+ (IN UINT32 AuthenticationStatus,
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *FilePath)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ RegisterSecurity2Handler,
+ (IN SECURITY2_FILE_AUTHENTICATION_HANDLER Security2Handler,
+ IN UINT32 AuthenticationOperation)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ ExecuteSecurity2Handlers,
+ (IN UINT32 AuthenticationOperation,
+ IN UINT32 AuthenticationStatus,
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *File OPTIONAL,
+ IN VOID *FileBuffer,
+ IN UINTN FileSize,
+ IN BOOLEAN BootPolicy)
+ );
+};
+
+#endif // MOCK_SECURITY_MANAGEMENT_LIB_H_
diff --git a/MdeModulePkg/Test/Mock/Library/GoogleTest/MockHiiLib/MockHiiLib.cpp b/MdeModulePkg/Test/Mock/Library/GoogleTest/MockHiiLib/MockHiiLib.cpp new file mode 100644 index 0000000..37c8f99 --- /dev/null +++ b/MdeModulePkg/Test/Mock/Library/GoogleTest/MockHiiLib/MockHiiLib.cpp @@ -0,0 +1,49 @@ +/** @file MockHiiLib.cpp
+ Google Test mocks for HiiLib
+
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <GoogleTest/Library/MockHiiLib.h>
+
+//
+// Global Variables that are not const
+//
+
+MOCK_INTERFACE_DEFINITION (MockHiiLib);
+
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiRemovePackages, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiSetString, 4, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiGetString, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiGetStringEx, 4, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiGetPackageString, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiGetHiiHandles, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiGetFormSetFromHiiHandle, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiGetSupportedLanguages, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiConstructConfigHdr, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiSetToDefaults, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiValidateSettings, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiIsConfigHdrMatch, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiGetBrowserData, 4, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiSetBrowserData, 5, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiAllocateOpCodeHandle, 0, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiFreeOpCodeHandle, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateRawOpCodes, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateEndOpCode, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateOneOfOptionOpCode, 5, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateDefaultOpCode, 4, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateGuidOpCode, 4, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateActionOpCode, 6, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateSubTitleOpCode, 5, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateGotoOpCode, 6, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateGotoExOpCode, 9, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateCheckBoxOpCode, 9, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateNumericOpCode, 12, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateStringOpCode, 11, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateOneOfOpCode, 10, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateOrderedListOpCode, 12, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateTextOpCode, 4, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateDateOpCode, 9, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiCreateTimeOpCode, 9, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHiiLib, HiiUpdateForm, 5, EFIAPI);
diff --git a/MdeModulePkg/Test/Mock/Library/GoogleTest/MockHiiLib/MockHiiLib.inf b/MdeModulePkg/Test/Mock/Library/GoogleTest/MockHiiLib/MockHiiLib.inf new file mode 100644 index 0000000..a6baa48 --- /dev/null +++ b/MdeModulePkg/Test/Mock/Library/GoogleTest/MockHiiLib/MockHiiLib.inf @@ -0,0 +1,34 @@ +## @file MockHiiLib.inf
+# Google Test mocks for HiiLib
+#
+# Copyright (c) Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = MockHiiLib
+ FILE_GUID = d29d29fa-e62f-543a-8d6d-793858ac7f35
+ MODULE_TYPE = HOST_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = HiiLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ MockHiiLib.cpp
+
+[Packages]
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+ GoogleTestLib
+
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = /EHs /bigobj
diff --git a/MdeModulePkg/Test/Mock/Library/GoogleTest/MockSecurityManagementLib/MockSecurityManagementLib.cpp b/MdeModulePkg/Test/Mock/Library/GoogleTest/MockSecurityManagementLib/MockSecurityManagementLib.cpp new file mode 100644 index 0000000..fa3b24b --- /dev/null +++ b/MdeModulePkg/Test/Mock/Library/GoogleTest/MockSecurityManagementLib/MockSecurityManagementLib.cpp @@ -0,0 +1,15 @@ +/** @file
+ Google Test mocks for SecurityManagementLib
+
+ Copyright (c) 2025, Yandex. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <GoogleTest/Library/MockSecurityManagementLib.h>
+
+MOCK_INTERFACE_DEFINITION (MockSecurityManagementLib);
+
+MOCK_FUNCTION_DEFINITION (MockSecurityManagementLib, RegisterSecurityHandler, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockSecurityManagementLib, ExecuteSecurityHandlers, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockSecurityManagementLib, RegisterSecurity2Handler, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockSecurityManagementLib, ExecuteSecurity2Handlers, 6, EFIAPI);
diff --git a/MdeModulePkg/Test/Mock/Library/GoogleTest/MockSecurityManagementLib/MockSecurityManagementLib.inf b/MdeModulePkg/Test/Mock/Library/GoogleTest/MockSecurityManagementLib/MockSecurityManagementLib.inf new file mode 100644 index 0000000..d64e28c --- /dev/null +++ b/MdeModulePkg/Test/Mock/Library/GoogleTest/MockSecurityManagementLib/MockSecurityManagementLib.inf @@ -0,0 +1,34 @@ +## @file
+# Google Test mocks for SecurityManagementLib
+#
+# Copyright (c) 2025, Yandex. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = MockSecurityManagementLib
+ FILE_GUID = 22FF8498-3FE9-495B-81B7-6595145F5832
+ MODULE_TYPE = HOST_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = SecurityManagementLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ MockSecurityManagementLib.cpp
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+ GoogleTestLib
+
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = /EHsc
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c index f2a7be5..56f3c8b 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c @@ -1968,10 +1968,18 @@ InstallAcpiTableFromAcpiSiliconHob ( EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *SiAcpiHobRsdp;
EFI_ACPI_DESCRIPTION_HEADER *SiCommonAcpiTable;
EFI_STATUS Status;
- UINT8 *TempBuffer;
UINTN NumOfTblEntries;
+ EFI_ACPI_TABLE_VERSION Version;
+ UINT64 SocTablePtr;
+ EFI_ACPI_DESCRIPTION_HEADER *SocEntryTable;
+ UINTN Index;
+ UINTN TableKey;
+ VOID *NeedToInstallTable;
+ UINT8 *Buffer;
+ EFI_PHYSICAL_ADDRESS PageAddress;
+ UINTN TotalSocTablesize;
- DEBUG ((DEBUG_INFO, "InstallAcpiTableFromAcpiSiliconHob\n"));
+ DEBUG ((DEBUG_INFO, "InstallAcpiTableFromAcpiSiliconHob - Start\n"));
//
// Initial variable.
//
@@ -1979,6 +1987,8 @@ InstallAcpiTableFromAcpiSiliconHob ( SiCommonAcpiTable = NULL;
AcpiSiliconHob = GET_GUID_HOB_DATA (GuidHob);
Status = EFI_SUCCESS;
+ Version = PcdGet32 (PcdAcpiExposedTableVersions);
+ TableKey = 0;
//
// Got RSDP table from ACPI Silicon Hob.
//
@@ -1988,63 +1998,173 @@ InstallAcpiTableFromAcpiSiliconHob ( return EFI_NOT_FOUND;
}
- DEBUG ((DEBUG_INFO, "Silicon ACPI RSDP address : 0x%lx\n", SiAcpiHobRsdp));
+ DEBUG ((DEBUG_INFO, "Silicon ACPI RSDP address : 0x%016lx\n", SiAcpiHobRsdp));
AcpiTableInstance->Rsdp3 = SiAcpiHobRsdp;
- if (SiAcpiHobRsdp->RsdtAddress != 0x00000000) {
- //
- // Initial RSDT.
- //
- TempBuffer = (UINT8 *)(UINTN)(SiAcpiHobRsdp->RsdtAddress);
- SiCommonAcpiTable = (EFI_ACPI_DESCRIPTION_HEADER *)TempBuffer;
- AcpiTableInstance->Rsdt3 = SiCommonAcpiTable;
+ //
+ // Got XSDT address from RSDP table.
+ //
+ Buffer = (UINT8 *)(UINTN)(SiAcpiHobRsdp->XsdtAddress);
+ SiCommonAcpiTable = (EFI_ACPI_DESCRIPTION_HEADER *)Buffer;
- if (SiCommonAcpiTable->Length <= sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
- DEBUG ((DEBUG_ERROR, "RSDT length is incorrect\n"));
- return EFI_ABORTED;
- }
+ DEBUG ((DEBUG_INFO, "Silicon ACPI XSDT address : 0x%016lx\n", SiCommonAcpiTable));
+ if (SiCommonAcpiTable->Length <= sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
+ DEBUG ((DEBUG_ERROR, "XSDT length is incorrect\n"));
+ return EFI_ABORTED;
+ }
+
+ //
+ // Calcaue 64bit Acpi table number.
+ //
+ NumOfTblEntries = (SiCommonAcpiTable->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof (UINT64);
+ DEBUG ((DEBUG_ERROR, "64bit NumOfTblEntries : 0x%x\n", NumOfTblEntries));
+ //
+ // Reserved the ACPI reclaim memory for XSDT.
+ //
+ //
+ TotalSocTablesize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + sizeof (UINT64);
+ PageAddress = 0xFFFFFFFF;
+ Status = gBS->AllocatePages (
+ mAcpiTableAllocType,
+ EfiACPIReclaimMemory,
+ EFI_SIZE_TO_PAGES (TotalSocTablesize),
+ &PageAddress
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Fail to allocate EfiACPIReclaimMemory for XSDT. Status : %r\n", Status));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ ZeroMem (&PageAddress, TotalSocTablesize);
+ AcpiTableInstance->Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)PageAddress;
+
+ //
+ // Initial XSDT table content.
+ //
+ AcpiTableInstance->Xsdt->Signature = SiCommonAcpiTable->Signature;
+ //
+ // Always reserve first one for FADT table.
+ //
+ AcpiTableInstance->Xsdt->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + sizeof (UINT64);
+ AcpiTableInstance->Xsdt->Revision = SiCommonAcpiTable->Revision;
+ CopyMem (
+ &AcpiTableInstance->Xsdt->OemId,
+ SiCommonAcpiTable->OemId,
+ sizeof (AcpiTableInstance->Xsdt->OemId)
+ );
+ CopyMem (
+ &AcpiTableInstance->Xsdt->OemTableId,
+ &SiCommonAcpiTable->OemTableId,
+ sizeof (UINT64)
+ );
+ AcpiTableInstance->Xsdt->OemRevision = SiCommonAcpiTable->OemRevision;
+ AcpiTableInstance->Xsdt->CreatorId = SiCommonAcpiTable->CreatorId;
+ AcpiTableInstance->Xsdt->CreatorRevision = SiCommonAcpiTable->CreatorRevision;
+ AcpiTableInstance->NumberOfTableEntries3 = 1;
+ //
+ // Extract ACPI table from AcpiSiliconHob XSDT.
+ //
+ for (Index = 0; Index < NumOfTblEntries; Index++) {
+ CopyMem (&SocTablePtr, (((UINT8 *)(SiCommonAcpiTable + 1)) + ((sizeof (UINT64)) * Index)), sizeof (UINT64));
+ SocEntryTable = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)SocTablePtr;
//
- // Calcaue 32bit Acpi table number.
+ // Display table information.
//
- NumOfTblEntries = (SiCommonAcpiTable->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof (UINT32);
- AcpiTableInstance->NumberOfTableEntries1 = NumOfTblEntries;
- DEBUG ((DEBUG_INFO, "32bit NumOfTblEntries : 0x%x\n", NumOfTblEntries));
+ DEBUG ((DEBUG_INFO, "[%x] Table address : 0x%016lx\n", Index, SocTablePtr));
+
+ Buffer = (UINT8 *)&SocEntryTable->Signature;
+ DEBUG ((DEBUG_INFO, "Table signature = %c%c%c%c\n", Buffer[0], Buffer[1], Buffer[2], Buffer[3]));
+
+ DEBUG ((DEBUG_INFO, "Table Length : 0x%x\n", SocEntryTable->Length));
+
+ Buffer = (UINT8 *)&SocEntryTable->OemId;
+ DEBUG (
+ (DEBUG_INFO, "Table OemId = %c%c%c%c%c%c\n",
+ Buffer[0],
+ Buffer[1],
+ Buffer[2],
+ Buffer[3],
+ Buffer[4],
+ Buffer[5]
+ )
+ );
+
+ Buffer = (UINT8 *)&SocEntryTable->OemTableId;
+ DEBUG (
+ (DEBUG_INFO, "Table OemTableId = %c%c%c%c%c%c%c%c\n",
+ Buffer[0],
+ Buffer[1],
+ Buffer[2],
+ Buffer[3],
+ Buffer[4],
+ Buffer[5],
+ Buffer[6],
+ Buffer[7]
+ )
+ );
+ DEBUG ((DEBUG_INFO, "\n"));
//
- // Enlarge the max table number from mEfiAcpiMaxNumTables to current ACPI tables + EFI_ACPI_MAX_NUM_TABLES
+ // Add ACPI table in the DXE AcpiTableInstance.
//
- if (AcpiTableInstance->NumberOfTableEntries1 >= EFI_ACPI_MAX_NUM_TABLES) {
- mEfiAcpiMaxNumTables = AcpiTableInstance->NumberOfTableEntries1 + EFI_ACPI_MAX_NUM_TABLES;
- DEBUG ((DEBUG_ERROR, "mEfiAcpiMaxNumTables : 0x%x\n", mEfiAcpiMaxNumTables));
+ Status = AddTableToList (AcpiTableInstance, SocEntryTable, TRUE, Version, TRUE, &TableKey);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromAcpiSiliconHob: Fail to add ACPI table at 0x%p\n", SocEntryTable));
+ ASSERT_EFI_ERROR (Status);
+ break;
}
- } else {
- //
- // Initial XSDT.
- //
- TempBuffer = (UINT8 *)(UINTN)(SiAcpiHobRsdp->XsdtAddress);
- SiCommonAcpiTable = (EFI_ACPI_DESCRIPTION_HEADER *)TempBuffer;
- AcpiTableInstance->Xsdt = SiCommonAcpiTable;
- if (SiCommonAcpiTable->Length <= sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
- DEBUG ((DEBUG_ERROR, "XSDT length is incorrect\n"));
- return EFI_ABORTED;
- }
+ if (SocEntryTable->Signature == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
+ //
+ // According ACPI spec, if XDsdt field contains a nonzero value which can be used by the OSPM, then the Dsdt field must be ignored by the OSPM.
+ //
+ if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->XDsdt != 0) {
+ NeedToInstallTable = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->XDsdt;
+ } else if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->Dsdt != 0) {
+ NeedToInstallTable = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->Dsdt;
+ }
- //
- // Calcaue 64bit Acpi table number.
- //
- NumOfTblEntries = (SiCommonAcpiTable->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof (UINT64);
- AcpiTableInstance->NumberOfTableEntries3 = NumOfTblEntries;
- DEBUG ((DEBUG_ERROR, "64bit NumOfTblEntries : 0x%x\n", NumOfTblEntries));
- //
- // Enlarge the max table number from mEfiAcpiMaxNumTables to current ACPI tables + EFI_ACPI_MAX_NUM_TABLES
- //
- if (AcpiTableInstance->NumberOfTableEntries3 >= EFI_ACPI_MAX_NUM_TABLES) {
- mEfiAcpiMaxNumTables = AcpiTableInstance->NumberOfTableEntries3 + EFI_ACPI_MAX_NUM_TABLES;
- DEBUG ((DEBUG_ERROR, "mEfiAcpiMaxNumTables : 0x%x\n", mEfiAcpiMaxNumTables));
+ //
+ // if signature can not be found from the XDsdt / Dsdt field then skip it.
+ //
+ if (((EFI_ACPI_DESCRIPTION_HEADER *)NeedToInstallTable)->Signature == EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) {
+ Status = AddTableToList (AcpiTableInstance, NeedToInstallTable, TRUE, Version, TRUE, &TableKey);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Fail to add DSDT in the DXE Table list!\n"));
+ ASSERT_EFI_ERROR (Status);
+ break;
+ } else {
+ DEBUG ((DEBUG_ERROR, "Installed DSDT in the DXE Table list!\n"));
+ }
+ } else {
+ DEBUG ((DEBUG_ERROR, "The DSDT content is not correct, then skip it!\n"));
+ }
+
+ //
+ // According ACPI spec, if XFirmwareCtrl field contains a nonzero value which can be used by the OSPM, then the FirmwareCtrl field must be ignored by the OSPM.
+ //
+ if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->XFirmwareCtrl != 0) {
+ NeedToInstallTable = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->XFirmwareCtrl;
+ } else if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->FirmwareCtrl != 0) {
+ NeedToInstallTable = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->FirmwareCtrl;
+ }
+
+ if (((EFI_ACPI_DESCRIPTION_HEADER *)NeedToInstallTable)->Signature == EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) {
+ Status = AddTableToList (AcpiTableInstance, NeedToInstallTable, TRUE, Version, TRUE, &TableKey);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Fail to add FACS in the DXE Table list!\n"));
+ ASSERT_EFI_ERROR (Status);
+ break;
+ } else {
+ DEBUG ((DEBUG_ERROR, "Installed FACS in the DXE Table list!\n"));
+ }
+ } else {
+ DEBUG ((DEBUG_ERROR, "The FACS content is not correct, then skip it!\n"));
+ }
}
}
+ DEBUG ((DEBUG_INFO, "InstallAcpiTableFromAcpiSiliconHob - End\n"));
return Status;
}
diff --git a/MdeModulePkg/Universal/CapsuleOnDiskLoadPei/CapsuleOnDiskLoadPei.c b/MdeModulePkg/Universal/CapsuleOnDiskLoadPei/CapsuleOnDiskLoadPei.c index 0ea4fb3..c7be6c5 100644 --- a/MdeModulePkg/Universal/CapsuleOnDiskLoadPei/CapsuleOnDiskLoadPei.c +++ b/MdeModulePkg/Universal/CapsuleOnDiskLoadPei/CapsuleOnDiskLoadPei.c @@ -20,7 +20,7 @@ #include <PiPei.h>
//
-// The protocols, PPI and GUID defintions for this module
+// The protocols, PPI and GUID definitions for this module
//
#include <Ppi/MasterBootMode.h>
#include <Ppi/FirmwareVolumeInfo.h>
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c index a7f0225..7d32d9a 100644 --- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c +++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c @@ -1096,10 +1096,8 @@ ConPlatformMatchDevicePaths ( //
// If performing Delete operation, the NewDevicePath must not be NULL.
//
- if (Delete) {
- if (NewDevicePath == NULL) {
- return EFI_INVALID_PARAMETER;
- }
+ if (Delete && (NewDevicePath == NULL)) {
+ return EFI_INVALID_PARAMETER;
}
TempDevicePath1 = NULL;
@@ -1178,6 +1176,8 @@ ConPlatformUpdateDeviceVariable ( EFI_DEVICE_PATH_PROTOCOL *VariableDevicePath;
EFI_DEVICE_PATH_PROTOCOL *NewVariableDevicePath;
+ Status = EFI_SUCCESS;
+
VariableDevicePath = NULL;
NewVariableDevicePath = NULL;
@@ -1187,7 +1187,7 @@ ConPlatformUpdateDeviceVariable ( // it is the caller's responsibility to free the memory before return.
//
VariableDevicePath = ConPlatformGetVariable (VariableName);
-
+ // At this point, VariableDevicePath may be null. This is expected.
if (Operation != Delete) {
//
// Match specified DevicePath in Console Variable.
diff --git a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c index 0a776f3..2dbb7ea 100644 --- a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c +++ b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c @@ -108,15 +108,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_IN_SPLITTER_PRIVATE_DATA mConIn = { };
//
-// Uga Draw Protocol Private Data template
-//
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_UGA_DRAW_PROTOCOL mUgaDrawProtocolTemplate = {
- ConSplitterUgaDrawGetMode,
- ConSplitterUgaDrawSetMode,
- ConSplitterUgaDrawBlt
-};
-
-//
// Graphics Output Protocol Private Data template
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_PROTOCOL mGraphicsOutputProtocolTemplate = {
@@ -156,22 +147,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = { {
NULL,
NULL,
- NULL
- },
- 0,
- 0,
- 0,
- 0,
-
- {
- NULL,
- NULL,
NULL,
NULL
},
(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *)NULL,
0,
- 0,
0,
(TEXT_OUT_AND_GOP_DATA *)NULL,
@@ -212,22 +192,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = { {
NULL,
NULL,
- NULL
- },
- 0,
- 0,
- 0,
- 0,
-
- {
- NULL,
- NULL,
NULL,
NULL
},
(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *)NULL,
0,
- 0,
0,
(TEXT_OUT_AND_GOP_DATA *)NULL,
@@ -422,7 +391,7 @@ ToggleStateSyncReInitialization ( Installs driver module protocols and. Creates virtual device handles for ConIn,
ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,
Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.
- Installs Graphics Output protocol and/or UGA Draw protocol if needed.
+ Installs Graphics Output protocol.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@@ -494,12 +463,9 @@ ConSplitterDriverEntry ( ASSERT_EFI_ERROR (Status);
//
- // Either Graphics Output protocol or UGA Draw protocol must be supported.
+ // Graphics Output protocol must be supported.
//
- ASSERT (
- FeaturePcdGet (PcdConOutGopSupport) ||
- FeaturePcdGet (PcdConOutUgaSupport)
- );
+ ASSERT (FeaturePcdGet (PcdConOutGopSupport));
//
// The driver creates virtual handles for ConIn, ConOut, StdErr.
@@ -757,10 +723,6 @@ ConSplitterTextOutConstructor ( //
// Copy protocols template
//
- if (FeaturePcdGet (PcdConOutUgaSupport)) {
- CopyMem (&ConOutPrivate->UgaDraw, &mUgaDrawProtocolTemplate, sizeof (EFI_UGA_DRAW_PROTOCOL));
- }
-
if (FeaturePcdGet (PcdConOutGopSupport)) {
CopyMem (&ConOutPrivate->GraphicsOutput, &mGraphicsOutputProtocolTemplate, sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL));
}
@@ -806,13 +768,6 @@ ConSplitterTextOutConstructor ( ConOutPrivate->TextOutQueryData[0].Rows = 25;
TextOutSetMode (ConOutPrivate, 0);
- if (FeaturePcdGet (PcdConOutUgaSupport)) {
- //
- // Setup the UgaDraw to 800 x 600 x 32 bits per pixel, 60Hz.
- //
- ConSplitterUgaDrawSetMode (&ConOutPrivate->UgaDraw, 800, 600, 32, 60);
- }
-
if (FeaturePcdGet (PcdConOutGopSupport)) {
//
// Setup resource for mode information in Graphics Output Protocol interface
@@ -1335,7 +1290,6 @@ ConSplitterConOutDriverBindingStart ( EFI_STATUS Status;
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
UINTN SizeOfInfo;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
@@ -1356,7 +1310,6 @@ ConSplitterConOutDriverBindingStart ( }
GraphicsOutput = NULL;
- UgaDraw = NULL;
//
// Try to Open Graphics Output protocol
//
@@ -1369,20 +1322,6 @@ ConSplitterConOutDriverBindingStart ( EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
- if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
- //
- // Open UGA DRAW protocol
- //
- gBS->OpenProtocol (
- ControllerHandle,
- &gEfiUgaDrawProtocolGuid,
- (VOID **)&UgaDraw,
- This->DriverBindingHandle,
- mConOut.VirtualHandle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL
- );
- }
-
//
// When new console device is added, the new mode will be set later,
// so put current mode back to init state.
@@ -1393,36 +1332,18 @@ ConSplitterConOutDriverBindingStart ( // If both ConOut and StdErr incorporate the same Text Out device,
// their MaxMode and QueryData should be the intersection of both.
//
- Status = ConSplitterTextOutAddDevice (&mConOut, TextOut, GraphicsOutput, UgaDraw);
+ Status = ConSplitterTextOutAddDevice (&mConOut, TextOut, GraphicsOutput);
ConSplitterTextOutSetAttribute (&mConOut.TextOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
- if (FeaturePcdGet (PcdConOutUgaSupport)) {
- //
- // Get the UGA mode data of ConOut from the current mode
- //
- if (GraphicsOutput != NULL) {
- Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- ASSERT (SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
-
- mConOut.UgaHorizontalResolution = Info->HorizontalResolution;
- mConOut.UgaVerticalResolution = Info->VerticalResolution;
- mConOut.UgaColorDepth = 32;
- mConOut.UgaRefreshRate = 60;
-
- FreePool (Info);
- } else if (UgaDraw != NULL) {
- Status = UgaDraw->GetMode (
- UgaDraw,
- &mConOut.UgaHorizontalResolution,
- &mConOut.UgaVerticalResolution,
- &mConOut.UgaColorDepth,
- &mConOut.UgaRefreshRate
- );
+ if (GraphicsOutput != NULL) {
+ Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);
+ if (EFI_ERROR (Status)) {
+ return Status;
}
+
+ ASSERT (SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
+
+ FreePool (Info);
}
return Status;
@@ -1477,7 +1398,7 @@ ConSplitterStdErrDriverBindingStart ( // If both ConOut and StdErr incorporate the same Text Out device,
// their MaxMode and QueryData should be the intersection of both.
//
- Status = ConSplitterTextOutAddDevice (&mStdErr, TextOut, NULL, NULL);
+ Status = ConSplitterTextOutAddDevice (&mStdErr, TextOut, NULL);
ConSplitterTextOutSetAttribute (&mStdErr.TextOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
return Status;
@@ -2737,7 +2658,6 @@ ConSplitterGetIntersectionBetweenConOutAndStrErr ( @param Private Text Out Splitter pointer.
@param GraphicsOutput Graphics Output protocol pointer.
- @param UgaDraw UGA Draw protocol pointer.
@retval EFI_SUCCESS Output mode added successfully.
@retval other Failed to add output mode.
@@ -2746,8 +2666,7 @@ ConSplitterGetIntersectionBetweenConOutAndStrErr ( EFI_STATUS
ConSplitterAddGraphicsOutputMode (
IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
- IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
- IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
+ IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput
)
{
EFI_STATUS Status;
@@ -2762,12 +2681,8 @@ ConSplitterAddGraphicsOutputMode ( UINTN NumberIndex;
BOOLEAN Match;
BOOLEAN AlreadyExist;
- UINT32 UgaHorizontalResolution;
- UINT32 UgaVerticalResolution;
- UINT32 UgaColorDepth;
- UINT32 UgaRefreshRate;
- ASSERT (GraphicsOutput != NULL || UgaDraw != NULL);
+ ASSERT (GraphicsOutput != NULL);
CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;
@@ -2775,15 +2690,6 @@ ConSplitterAddGraphicsOutputMode ( CurrentIndex = 0;
Status = EFI_SUCCESS;
- if (Private->CurrentNumberOfUgaDraw != 0) {
- //
- // If any UGA device has already been added, then there is no need to
- // calculate intersection of display mode of different GOP/UGA device,
- // since only one display mode will be exported (i.e. user-defined mode)
- //
- goto Done;
- }
-
if (GraphicsOutput != NULL) {
if (Private->CurrentNumberOfGraphicsOutput == 0) {
//
@@ -2937,51 +2843,12 @@ ConSplitterAddGraphicsOutputMode ( }
}
}
- } else if (UgaDraw != NULL) {
- //
- // Graphics console driver can ensure the same mode for all GOP devices
- // so we can get the current mode from this video device
- //
- UgaDraw->GetMode (
- UgaDraw,
- &UgaHorizontalResolution,
- &UgaVerticalResolution,
- &UgaColorDepth,
- &UgaRefreshRate
- );
-
- CurrentGraphicsOutputMode->MaxMode = 1;
- Info = CurrentGraphicsOutputMode->Info;
- Info->Version = 0;
- Info->HorizontalResolution = UgaHorizontalResolution;
- Info->VerticalResolution = UgaVerticalResolution;
- Info->PixelFormat = PixelBltOnly;
- Info->PixelsPerScanLine = UgaHorizontalResolution;
- CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
- CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS)(UINTN)NULL;
- CurrentGraphicsOutputMode->FrameBufferSize = 0;
-
- //
- // Update the private mode buffer
- //
- CopyMem (&Private->GraphicsOutputModeBuffer[0], Info, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
-
- //
- // Only mode 0 is available to be set
- //
- CurrentIndex = 0;
}
-Done:
-
if (GraphicsOutput != NULL) {
Private->CurrentNumberOfGraphicsOutput++;
}
- if (UgaDraw != NULL) {
- Private->CurrentNumberOfUgaDraw++;
- }
-
//
// Force GraphicsOutput mode to be set,
//
@@ -3130,7 +2997,6 @@ ConsplitterSetConsoleOutMode ( @param Private Text Out Splitter pointer.
@param TextOut Simple Text Output protocol pointer.
@param GraphicsOutput Graphics Output protocol pointer.
- @param UgaDraw UGA Draw protocol pointer.
@retval EFI_SUCCESS Text Output Device added successfully.
@retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
@@ -3140,17 +3006,12 @@ EFI_STATUS ConSplitterTextOutAddDevice (
IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut,
- IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
- IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
+ IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput
)
{
EFI_STATUS Status;
UINTN CurrentNumOfConsoles;
INT32 MaxMode;
- UINT32 UgaHorizontalResolution;
- UINT32 UgaVerticalResolution;
- UINT32 UgaColorDepth;
- UINT32 UgaRefreshRate;
TEXT_OUT_AND_GOP_DATA *TextAndGop;
UINTN SizeOfInfo;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
@@ -3186,7 +3047,6 @@ ConSplitterTextOutAddDevice ( TextAndGop->TextOut = TextOut;
TextAndGop->GraphicsOutput = GraphicsOutput;
- TextAndGop->UgaDraw = UgaDraw;
if (CurrentNumOfConsoles == 0) {
//
@@ -3215,101 +3075,33 @@ ConSplitterTextOutAddDevice ( //
// This device display mode will be added into Graphics Ouput modes.
//
- if ((GraphicsOutput != NULL) || (UgaDraw != NULL)) {
- DeviceStatus = ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput, UgaDraw);
+ if (GraphicsOutput != NULL) {
+ DeviceStatus = ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput);
}
- if (FeaturePcdGet (PcdConOutUgaSupport)) {
- //
- // If UGA is produced by Consplitter
- //
- if (GraphicsOutput != NULL) {
- Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- ASSERT (SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
-
- UgaHorizontalResolution = Info->HorizontalResolution;
- UgaVerticalResolution = Info->VerticalResolution;
-
- FreePool (Info);
- } else if (UgaDraw != NULL) {
- Status = UgaDraw->GetMode (
- UgaDraw,
- &UgaHorizontalResolution,
- &UgaVerticalResolution,
- &UgaColorDepth,
- &UgaRefreshRate
- );
- if (!EFI_ERROR (Status) && EFI_ERROR (DeviceStatus)) {
- //
- // if GetMode is successfully and UGA device hasn't been set, set it
- //
- Status = ConSplitterUgaDrawSetMode (
- &Private->UgaDraw,
- UgaHorizontalResolution,
- UgaVerticalResolution,
- UgaColorDepth,
- UgaRefreshRate
- );
- }
-
- //
- // If GetMode/SetMode is failed, set to 800x600 mode
- //
- if (EFI_ERROR (Status)) {
- Status = ConSplitterUgaDrawSetMode (
- &Private->UgaDraw,
- 800,
- 600,
- 32,
- 60
- );
- }
+ if (GraphicsOutput != NULL) {
+ Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);
+ if (EFI_ERROR (Status)) {
+ return Status;
}
+
+ ASSERT (SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
+ FreePool (Info);
}
if (((!EFI_ERROR (DeviceStatus)) || (!EFI_ERROR (Status))) &&
- ((Private->CurrentNumberOfGraphicsOutput + Private->CurrentNumberOfUgaDraw) == 1))
+ ((Private->CurrentNumberOfGraphicsOutput) == 1))
{
- if (!FeaturePcdGet (PcdConOutGopSupport)) {
- //
- // If Graphics Outpurt protocol not supported, UGA Draw protocol is installed
- // on the virtual handle.
- //
- Status = gBS->InstallMultipleProtocolInterfaces (
- &mConOut.VirtualHandle,
- &gEfiUgaDrawProtocolGuid,
- &mConOut.UgaDraw,
- NULL
- );
- } else if (!FeaturePcdGet (PcdConOutUgaSupport)) {
- //
- // If UGA Draw protocol not supported, Graphics Output Protocol is installed
- // on virtual handle.
- //
- Status = gBS->InstallMultipleProtocolInterfaces (
- &mConOut.VirtualHandle,
- &gEfiGraphicsOutputProtocolGuid,
- &mConOut.GraphicsOutput,
- NULL
- );
- } else {
- //
- // Boot Graphics Output protocol and UGA Draw protocol are supported,
- // both they will be installed on virtual handle.
- //
- Status = gBS->InstallMultipleProtocolInterfaces (
- &mConOut.VirtualHandle,
- &gEfiGraphicsOutputProtocolGuid,
- &mConOut.GraphicsOutput,
- &gEfiUgaDrawProtocolGuid,
- &mConOut.UgaDraw,
- NULL
- );
- }
+ //
+ // Graphics Output Protocol is installed
+ // on virtual handle.
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &mConOut.VirtualHandle,
+ &gEfiGraphicsOutputProtocolGuid,
+ &mConOut.GraphicsOutput,
+ NULL
+ );
}
//
@@ -3353,10 +3145,6 @@ ConSplitterTextOutDeleteDevice ( TextOutList = Private->TextOutList;
while (Index >= 0) {
if (TextOutList->TextOut == TextOut) {
- if (TextOutList->UgaDraw != NULL) {
- Private->CurrentNumberOfUgaDraw--;
- }
-
if (TextOutList->GraphicsOutput != NULL) {
Private->CurrentNumberOfGraphicsOutput--;
}
@@ -3377,33 +3165,16 @@ ConSplitterTextOutDeleteDevice ( return EFI_NOT_FOUND;
}
- if ((Private->CurrentNumberOfGraphicsOutput == 0) && (Private->CurrentNumberOfUgaDraw == 0)) {
+ if ((Private->CurrentNumberOfGraphicsOutput == 0)) {
//
- // If there is not any physical GOP and UGA device in system,
- // Consplitter GOP or UGA protocol will be uninstalled
+ // If there is not any physical GOP in system,
+ // Consplitter GOP protocol will be uninstalled
//
- if (!FeaturePcdGet (PcdConOutGopSupport)) {
- Status = gBS->UninstallProtocolInterface (
- Private->VirtualHandle,
- &gEfiUgaDrawProtocolGuid,
- &Private->UgaDraw
- );
- } else if (!FeaturePcdGet (PcdConOutUgaSupport)) {
- Status = gBS->UninstallProtocolInterface (
- Private->VirtualHandle,
- &gEfiGraphicsOutputProtocolGuid,
- &Private->GraphicsOutput
- );
- } else {
- Status = gBS->UninstallMultipleProtocolInterfaces (
- Private->VirtualHandle,
- &gEfiUgaDrawProtocolGuid,
- &Private->UgaDraw,
- &gEfiGraphicsOutputProtocolGuid,
- &Private->GraphicsOutput,
- NULL
- );
- }
+ Status = gBS->UninstallProtocolInterface (
+ Private->VirtualHandle,
+ &gEfiGraphicsOutputProtocolGuid,
+ &Private->GraphicsOutput
+ );
}
if (CurrentNumOfConsoles == 0) {
diff --git a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.h b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.h index 354107c..f6d90d5 100644 --- a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.h +++ b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.h @@ -21,7 +21,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Protocol/SimpleTextIn.h>
#include <Protocol/SimpleTextInEx.h>
#include <Protocol/GraphicsOutput.h>
-#include <Protocol/UgaDraw.h>
#include <Guid/ConsoleInDevice.h>
#include <Guid/StandardErrorDevice.h>
@@ -182,7 +181,6 @@ typedef struct { typedef struct {
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
} TEXT_OUT_AND_GOP_DATA;
@@ -195,16 +193,9 @@ typedef struct { EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL TextOut;
EFI_SIMPLE_TEXT_OUTPUT_MODE TextOutMode;
- EFI_UGA_DRAW_PROTOCOL UgaDraw;
- UINT32 UgaHorizontalResolution;
- UINT32 UgaVerticalResolution;
- UINT32 UgaColorDepth;
- UINT32 UgaRefreshRate;
-
EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *GraphicsOutputModeBuffer;
UINTN CurrentNumberOfGraphicsOutput;
- UINTN CurrentNumberOfUgaDraw;
UINTN CurrentNumberOfConsoles;
TEXT_OUT_AND_GOP_DATA *TextOutList;
@@ -230,13 +221,6 @@ typedef struct { TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE \
)
-#define UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS(a) \
- CR ((a), \
- TEXT_OUT_SPLITTER_PRIVATE_DATA, \
- UgaDraw, \
- TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE \
- )
-
#define CONSOLE_CONTROL_SPLITTER_PRIVATE_DATA_FROM_THIS(a) \
CR ((a), \
TEXT_OUT_SPLITTER_PRIVATE_DATA, \
@@ -254,7 +238,7 @@ typedef struct { Installs driver module protocols and. Creates virtual device handles for ConIn,
ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,
Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.
- Installs Graphics Output protocol and/or UGA Draw protocol if needed.
+ Installs Graphics Output protocol if needed.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@@ -1202,7 +1186,6 @@ ConSplitterSimplePointerDeleteDevice ( @param Private Text Out Splitter pointer.
@param TextOut Simple Text Output protocol pointer.
@param GraphicsOutput Graphics Output protocol pointer.
- @param UgaDraw UGA Draw protocol pointer.
@retval EFI_SUCCESS Text Output Device added successfully.
@retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
@@ -1212,8 +1195,7 @@ EFI_STATUS ConSplitterTextOutAddDevice (
IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut,
- IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
- IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
+ IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput
);
/**
@@ -1858,118 +1840,6 @@ ConSplitterGraphicsOutputBlt ( );
/**
- Return the current video mode information.
-
- @param This The EFI_UGA_DRAW_PROTOCOL instance.
- @param HorizontalResolution The size of video screen in pixels in the X dimension.
- @param VerticalResolution The size of video screen in pixels in the Y dimension.
- @param ColorDepth Number of bits per pixel, currently defined to be 32.
- @param RefreshRate The refresh rate of the monitor in Hertz.
-
- @retval EFI_SUCCESS Mode information returned.
- @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
- @retval EFI_INVALID_PARAMETER One of the input args was NULL.
-
-**/
-EFI_STATUS
-EFIAPI
-ConSplitterUgaDrawGetMode (
- IN EFI_UGA_DRAW_PROTOCOL *This,
- OUT UINT32 *HorizontalResolution,
- OUT UINT32 *VerticalResolution,
- OUT UINT32 *ColorDepth,
- OUT UINT32 *RefreshRate
- );
-
-/**
- Set the current video mode information.
-
- @param This The EFI_UGA_DRAW_PROTOCOL instance.
- @param HorizontalResolution The size of video screen in pixels in the X dimension.
- @param VerticalResolution The size of video screen in pixels in the Y dimension.
- @param ColorDepth Number of bits per pixel, currently defined to be 32.
- @param RefreshRate The refresh rate of the monitor in Hertz.
-
- @retval EFI_SUCCESS Mode information returned.
- @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
- @retval EFI_OUT_OF_RESOURCES Out of resources.
-
-**/
-EFI_STATUS
-EFIAPI
-ConSplitterUgaDrawSetMode (
- IN EFI_UGA_DRAW_PROTOCOL *This,
- IN UINT32 HorizontalResolution,
- IN UINT32 VerticalResolution,
- IN UINT32 ColorDepth,
- IN UINT32 RefreshRate
- );
-
-/**
- Blt a rectangle of pixels on the graphics screen.
-
- The following table defines actions for BltOperations.
-
- EfiUgaVideoFill:
- Write data from the BltBuffer pixel (SourceX, SourceY)
- directly to every pixel of the video display rectangle
- (DestinationX, DestinationY)
- (DestinationX + Width, DestinationY + Height).
- Only one pixel will be used from the BltBuffer. Delta is NOT used.
- EfiUgaVideoToBltBuffer:
- Read data from the video display rectangle
- (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
- the BltBuffer rectangle (DestinationX, DestinationY )
- (DestinationX + Width, DestinationY + Height). If DestinationX or
- DestinationY is not zero then Delta must be set to the length in bytes
- of a row in the BltBuffer.
- EfiUgaBltBufferToVideo:
- Write data from the BltBuffer rectangle
- (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
- video display rectangle (DestinationX, DestinationY)
- (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
- not zero then Delta must be set to the length in bytes of a row in the
- BltBuffer.
- EfiUgaVideoToVideo:
- Copy from the video display rectangle
- (SourceX, SourceY) (SourceX + Width, SourceY + Height) .
- to the video display rectangle (DestinationX, DestinationY)
- (DestinationX + Width, DestinationY + Height).
- The BltBuffer and Delta are not used in this mode.
-
- @param This Protocol instance pointer.
- @param BltBuffer Buffer containing data to blit into video buffer. This
- buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL)
- @param BltOperation Operation to perform on BlitBuffer and video memory
- @param SourceX X coordinate of source for the BltBuffer.
- @param SourceY Y coordinate of source for the BltBuffer.
- @param DestinationX X coordinate of destination for the BltBuffer.
- @param DestinationY Y coordinate of destination for the BltBuffer.
- @param Width Width of rectangle in BltBuffer in pixels.
- @param Height Hight of rectangle in BltBuffer in pixels.
- @param Delta OPTIONAL
-
- @retval EFI_SUCCESS The Blt operation completed.
- @retval EFI_INVALID_PARAMETER BltOperation is not valid.
- @retval EFI_DEVICE_ERROR A hardware error occurred writting to the video buffer.
-
-**/
-EFI_STATUS
-EFIAPI
-ConSplitterUgaDrawBlt (
- IN EFI_UGA_DRAW_PROTOCOL *This,
- IN EFI_UGA_PIXEL *BltBuffer OPTIONAL,
- IN EFI_UGA_BLT_OPERATION BltOperation,
- IN UINTN SourceX,
- IN UINTN SourceY,
- IN UINTN DestinationX,
- IN UINTN DestinationY,
- IN UINTN Width,
- IN UINTN Height,
- IN UINTN Delta OPTIONAL
- );
-
-/**
Sets the output device(s) to a specified mode.
@param Private Text Out Splitter pointer.
diff --git a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf index 9aa1dad..156757a 100644 --- a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf +++ b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf @@ -3,12 +3,9 @@ #
# This driver acts as a virtual console, takes over the console I/O control from selected
# standard console devices, and transmits console I/O to related console device drivers.
-# Consplitter could install Graphics Output protocol and/or UGA Draw protocol in system
-# table according PCD settings(PcdConOutGopSupport, and PcdConOutUgaSupport). It always
-# consumes Graphics Output protocol which is produced by display device, and consumes UGA Draw
-# protocol which is produced by display device according to PcdUgaConsumeSupport value.
-# Note: If only UGA Draw protocol is installed in system, PcdUgaConsumeSupport should be
-# set to TRUE.
+# Consplitter could install Graphics Output protocol in system
+# table according PCD settings(PcdConOutGopSupport). It always
+# consumes Graphics Output protocol which is produced by display device
#
# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
#
@@ -92,14 +89,9 @@ ## SOMETIMES_PRODUCES
## SOMETIMES_CONSUMES
gEfiGraphicsOutputProtocolGuid
- ## SOMETIMES_PRODUCES
- ## SOMETIMES_CONSUMES
- gEfiUgaDrawProtocolGuid
[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport ## CONSUMES
- gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport ## CONSUMES
[Pcd]
## SOMETIMES_PRODUCES
diff --git a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.uni b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.uni index 13c25b2..903c505 100644 --- a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.uni +++ b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.uni @@ -3,12 +3,9 @@ //
// This driver acts as a virtual console, takes over the console I/O control from selected
// standard console devices, and transmits console I/O to related console device drivers.
-// Consplitter could install Graphics Output protocol and/or UGA Draw protocol in system
-// table according PCD settings(PcdConOutGopSupport, and PcdConOutUgaSupport). It always
-// consumes Graphics Output protocol which is produced by display device, and consumes UGA Draw
-// protocol which is produced by display device according to PcdUgaConsumeSupport value.
-// Note: If only UGA Draw protocol is installed in system, PcdUgaConsumeSupport should be
-// set to TRUE.
+// Consplitter could install Graphics Output protocol in system
+// table according PCD settings(PcdConOutGopSupport). It always
+// consumes Graphics Output protocol which is produced by display device
//
// Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
//
@@ -19,5 +16,5 @@ #string STR_MODULE_ABSTRACT #language en-US "Provides multi console support"
-#string STR_MODULE_DESCRIPTION #language en-US "This driver acts as a virtual console, takes over the console I/O control from selected standard console devices, and transmits console I/O to related console device drivers. Consplitter could install Graphics Output protocol and/or UGA Draw protocol in system table according PCD settings(PcdConOutGopSupport, and PcdConOutUgaSupport). It always consumes Graphics Output protocol, which is produced by display device, and consumes UGA Draw protocol, which is produced by display device according to PcdUgaConsumeSupport value. Note: If only UGA Draw protocol is installed in system, PcdUgaConsumeSupport should be set to TRUE."
+#string STR_MODULE_DESCRIPTION #language en-US "This driver acts as a virtual console, takes over the console I/O control from selected standard console devices, and transmits console I/O to related console device drivers. Consplitter could install Graphics Output protocol in system table according PCD settings(PcdConOutGopSupport). It always consumes Graphics Output protocol, which is produced by display device."
diff --git a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterGraphics.c b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterGraphics.c index 64ad567..8353f0b 100644 --- a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterGraphics.c +++ b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterGraphics.c @@ -117,7 +117,6 @@ ConSplitterGraphicsOutputSetMode ( UINTN NumberIndex;
UINTN SizeOfInfo;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
if (ModeNumber >= This->Mode->MaxMode) {
return EFI_UNSUPPORTED;
@@ -157,20 +156,6 @@ ConSplitterGraphicsOutputSetMode ( if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- UgaDraw = Private->TextOutList[Index].UgaDraw;
- if (UgaDraw != NULL) {
- Status = UgaDraw->SetMode (
- UgaDraw,
- Mode->HorizontalResolution,
- Mode->VerticalResolution,
- 32,
- 60
- );
- if (EFI_ERROR (Status)) {
- ReturnStatus = Status;
- }
- }
}
}
@@ -261,7 +246,6 @@ ConSplitterGraphicsOutputBlt ( TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
if ((This == NULL) || (((UINTN)BltOperation) >= EfiGraphicsOutputBltOperationMax)) {
return EFI_INVALID_PARAMETER;
@@ -298,298 +282,6 @@ ConSplitterGraphicsOutputBlt ( return EFI_SUCCESS;
}
}
-
- UgaDraw = Private->TextOutList[Index].UgaDraw;
- if ((UgaDraw != NULL) && FeaturePcdGet (PcdUgaConsumeSupport)) {
- Status = UgaDraw->Blt (
- UgaDraw,
- (EFI_UGA_PIXEL *)BltBuffer,
- (EFI_UGA_BLT_OPERATION)BltOperation,
- SourceX,
- SourceY,
- DestinationX,
- DestinationY,
- Width,
- Height,
- Delta
- );
- if (EFI_ERROR (Status)) {
- ReturnStatus = Status;
- } else if (BltOperation == EfiBltVideoToBltBuffer) {
- //
- // Only need to read the data into buffer one time
- //
- return EFI_SUCCESS;
- }
- }
- }
-
- return ReturnStatus;
-}
-
-/**
- Return the current video mode information.
-
- @param This The EFI_UGA_DRAW_PROTOCOL instance.
- @param HorizontalResolution The size of video screen in pixels in the X dimension.
- @param VerticalResolution The size of video screen in pixels in the Y dimension.
- @param ColorDepth Number of bits per pixel, currently defined to be 32.
- @param RefreshRate The refresh rate of the monitor in Hertz.
-
- @retval EFI_SUCCESS Mode information returned.
- @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
- @retval EFI_INVALID_PARAMETER One of the input args was NULL.
-
-**/
-EFI_STATUS
-EFIAPI
-ConSplitterUgaDrawGetMode (
- IN EFI_UGA_DRAW_PROTOCOL *This,
- OUT UINT32 *HorizontalResolution,
- OUT UINT32 *VerticalResolution,
- OUT UINT32 *ColorDepth,
- OUT UINT32 *RefreshRate
- )
-{
- TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
-
- if ((HorizontalResolution == NULL) ||
- (VerticalResolution == NULL) ||
- (RefreshRate == NULL) ||
- (ColorDepth == NULL))
- {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // retrieve private data
- //
- Private = UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
-
- *HorizontalResolution = Private->UgaHorizontalResolution;
- *VerticalResolution = Private->UgaVerticalResolution;
- *ColorDepth = Private->UgaColorDepth;
- *RefreshRate = Private->UgaRefreshRate;
-
- return EFI_SUCCESS;
-}
-
-/**
- Set the current video mode information.
-
- @param This The EFI_UGA_DRAW_PROTOCOL instance.
- @param HorizontalResolution The size of video screen in pixels in the X dimension.
- @param VerticalResolution The size of video screen in pixels in the Y dimension.
- @param ColorDepth Number of bits per pixel, currently defined to be 32.
- @param RefreshRate The refresh rate of the monitor in Hertz.
-
- @retval EFI_SUCCESS Mode information returned.
- @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
- @retval EFI_OUT_OF_RESOURCES Out of resources.
-
-**/
-EFI_STATUS
-EFIAPI
-ConSplitterUgaDrawSetMode (
- IN EFI_UGA_DRAW_PROTOCOL *This,
- IN UINT32 HorizontalResolution,
- IN UINT32 VerticalResolution,
- IN UINT32 ColorDepth,
- IN UINT32 RefreshRate
- )
-{
- EFI_STATUS Status;
- TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
- UINTN Index;
- EFI_STATUS ReturnStatus;
- EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
- UINTN NumberIndex;
- UINTN SizeOfInfo;
- EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
-
- Private = UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
-
- ReturnStatus = EFI_SUCCESS;
-
- //
- // Update the Mode data
- //
- Private->UgaHorizontalResolution = HorizontalResolution;
- Private->UgaVerticalResolution = VerticalResolution;
- Private->UgaColorDepth = ColorDepth;
- Private->UgaRefreshRate = RefreshRate;
-
- //
- // return the worst status met
- //
- for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
- GraphicsOutput = Private->TextOutList[Index].GraphicsOutput;
- if (GraphicsOutput != NULL) {
- //
- // Find corresponding ModeNumber of this GraphicsOutput instance
- //
- for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex++) {
- Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32)NumberIndex, &SizeOfInfo, &Info);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- if ((Info->HorizontalResolution == HorizontalResolution) && (Info->VerticalResolution == VerticalResolution)) {
- FreePool (Info);
- break;
- }
-
- FreePool (Info);
- }
-
- Status = GraphicsOutput->SetMode (GraphicsOutput, (UINT32)NumberIndex);
- if (EFI_ERROR (Status)) {
- ReturnStatus = Status;
- }
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- UgaDraw = Private->TextOutList[Index].UgaDraw;
- if (UgaDraw != NULL) {
- Status = UgaDraw->SetMode (
- UgaDraw,
- HorizontalResolution,
- VerticalResolution,
- ColorDepth,
- RefreshRate
- );
- if (EFI_ERROR (Status)) {
- ReturnStatus = Status;
- }
- }
- }
- }
-
- return ReturnStatus;
-}
-
-/**
- Blt a rectangle of pixels on the graphics screen.
-
- The following table defines actions for BltOperations.
-
- EfiUgaVideoFill:
- Write data from the BltBuffer pixel (SourceX, SourceY)
- directly to every pixel of the video display rectangle
- (DestinationX, DestinationY)
- (DestinationX + Width, DestinationY + Height).
- Only one pixel will be used from the BltBuffer. Delta is NOT used.
- EfiUgaVideoToBltBuffer:
- Read data from the video display rectangle
- (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
- the BltBuffer rectangle (DestinationX, DestinationY )
- (DestinationX + Width, DestinationY + Height). If DestinationX or
- DestinationY is not zero then Delta must be set to the length in bytes
- of a row in the BltBuffer.
- EfiUgaBltBufferToVideo:
- Write data from the BltBuffer rectangle
- (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
- video display rectangle (DestinationX, DestinationY)
- (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
- not zero then Delta must be set to the length in bytes of a row in the
- BltBuffer.
- EfiUgaVideoToVideo:
- Copy from the video display rectangle
- (SourceX, SourceY) (SourceX + Width, SourceY + Height) .
- to the video display rectangle (DestinationX, DestinationY)
- (DestinationX + Width, DestinationY + Height).
- The BltBuffer and Delta are not used in this mode.
-
- @param This Protocol instance pointer.
- @param BltBuffer Buffer containing data to blit into video buffer. This
- buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL)
- @param BltOperation Operation to perform on BlitBuffer and video memory
- @param SourceX X coordinate of source for the BltBuffer.
- @param SourceY Y coordinate of source for the BltBuffer.
- @param DestinationX X coordinate of destination for the BltBuffer.
- @param DestinationY Y coordinate of destination for the BltBuffer.
- @param Width Width of rectangle in BltBuffer in pixels.
- @param Height Hight of rectangle in BltBuffer in pixels.
- @param Delta OPTIONAL
-
- @retval EFI_SUCCESS The Blt operation completed.
- @retval EFI_INVALID_PARAMETER BltOperation is not valid.
- @retval EFI_DEVICE_ERROR A hardware error occurred writting to the video buffer.
-
-**/
-EFI_STATUS
-EFIAPI
-ConSplitterUgaDrawBlt (
- IN EFI_UGA_DRAW_PROTOCOL *This,
- IN EFI_UGA_PIXEL *BltBuffer OPTIONAL,
- IN EFI_UGA_BLT_OPERATION BltOperation,
- IN UINTN SourceX,
- IN UINTN SourceY,
- IN UINTN DestinationX,
- IN UINTN DestinationY,
- IN UINTN Width,
- IN UINTN Height,
- IN UINTN Delta OPTIONAL
- )
-{
- EFI_STATUS Status;
- TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
- UINTN Index;
- EFI_STATUS ReturnStatus;
- EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
-
- Private = UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
-
- ReturnStatus = EFI_SUCCESS;
- //
- // return the worst status met
- //
- for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
- GraphicsOutput = Private->TextOutList[Index].GraphicsOutput;
- if (GraphicsOutput != NULL) {
- Status = GraphicsOutput->Blt (
- GraphicsOutput,
- (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)BltBuffer,
- (EFI_GRAPHICS_OUTPUT_BLT_OPERATION)BltOperation,
- SourceX,
- SourceY,
- DestinationX,
- DestinationY,
- Width,
- Height,
- Delta
- );
- if (EFI_ERROR (Status)) {
- ReturnStatus = Status;
- } else if (BltOperation == EfiUgaVideoToBltBuffer) {
- //
- // Only need to read the data into buffer one time
- //
- return EFI_SUCCESS;
- }
- }
-
- if ((Private->TextOutList[Index].UgaDraw != NULL) && FeaturePcdGet (PcdUgaConsumeSupport)) {
- Status = Private->TextOutList[Index].UgaDraw->Blt (
- Private->TextOutList[Index].UgaDraw,
- BltBuffer,
- BltOperation,
- SourceX,
- SourceY,
- DestinationX,
- DestinationY,
- Width,
- Height,
- Delta
- );
- if (EFI_ERROR (Status)) {
- ReturnStatus = Status;
- } else if (BltOperation == EfiUgaVideoToBltBuffer) {
- //
- // Only need to read the data into buffer one time
- //
- return EFI_SUCCESS;
- }
- }
}
return ReturnStatus;
diff --git a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c index b895daf..50a88f5 100644 --- a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c +++ b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c @@ -14,7 +14,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate = {
GRAPHICS_CONSOLE_DEV_SIGNATURE,
(EFI_GRAPHICS_OUTPUT_PROTOCOL *)NULL,
- (EFI_UGA_DRAW_PROTOCOL *)NULL,
{
GraphicsConsoleConOutReset,
GraphicsConsoleConOutOutputString,
@@ -104,9 +103,8 @@ EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding = { /**
Test to see if Graphics Console could be supported on the Controller.
- Graphics Console could be supported if Graphics Output Protocol or UGA Draw
- Protocol exists on the Controller. (UGA Draw Protocol could be skipped
- if PcdUgaConsumeSupport is set to FALSE.)
+ Graphics Console could be supported if Graphics Output Protocol
+ exists on the Controller.
@param This Protocol instance pointer.
@param Controller Handle of device to test.
@@ -127,11 +125,9 @@ GraphicsConsoleControllerDriverSupported ( {
EFI_STATUS Status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
GraphicsOutput = NULL;
- UgaDraw = NULL;
//
// Open the IO Abstraction(s) needed to perform the supported test
//
@@ -143,21 +139,6 @@ GraphicsConsoleControllerDriverSupported ( Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
-
- if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
- //
- // Open Graphics Output Protocol failed, try to open UGA Draw Protocol
- //
- Status = gBS->OpenProtocol (
- Controller,
- &gEfiUgaDrawProtocolGuid,
- (VOID **)&UgaDraw,
- This->DriverBindingHandle,
- Controller,
- EFI_OPEN_PROTOCOL_BY_DRIVER
- );
- }
-
if (EFI_ERROR (Status)) {
return Status;
}
@@ -202,13 +183,6 @@ Error: This->DriverBindingHandle,
Controller
);
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- gBS->CloseProtocol (
- Controller,
- &gEfiUgaDrawProtocolGuid,
- This->DriverBindingHandle,
- Controller
- );
}
return Status;
@@ -283,7 +257,10 @@ InitializeGraphicsConsoleTextMode ( // Reserve 2 modes for 80x25, 80x50 of graphics console.
//
NewModeBuffer = AllocateZeroPool (sizeof (GRAPHICS_CONSOLE_MODE_DATA) * (Count + 2));
- ASSERT (NewModeBuffer != NULL);
+ if (NewModeBuffer == NULL) {
+ ASSERT (NewModeBuffer != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
//
// Mode 0 and mode 1 is for 80x25, 80x50 according to UEFI spec.
@@ -369,9 +346,8 @@ InitializeGraphicsConsoleTextMode ( }
/**
- Start this driver on Controller by opening Graphics Output protocol or
- UGA Draw protocol, and installing Simple Text Out protocol on Controller.
- (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
+ Start this driver on Controller by opening Graphics Output protocol
+ and installing Simple Text Out protocol on Controller.
@param This Protocol instance pointer.
@param Controller Handle of device to bind driver to
@@ -394,8 +370,6 @@ GraphicsConsoleControllerDriverStart ( GRAPHICS_CONSOLE_DEV *Private;
UINT32 HorizontalResolution;
UINT32 VerticalResolution;
- UINT32 ColorDepth;
- UINT32 RefreshRate;
UINT32 ModeIndex;
UINTN MaxMode;
UINT32 ModeNumber;
@@ -432,18 +406,6 @@ GraphicsConsoleControllerDriverStart ( Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
-
- if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
- Status = gBS->OpenProtocol (
- Controller,
- &gEfiUgaDrawProtocolGuid,
- (VOID **)&Private->UgaDraw,
- This->DriverBindingHandle,
- Controller,
- EFI_OPEN_PROTOCOL_BY_DRIVER
- );
- }
-
if (EFI_ERROR (Status)) {
goto Error;
}
@@ -463,7 +425,7 @@ GraphicsConsoleControllerDriverStart ( //
MaxMode = Private->GraphicsOutput->Mode->MaxMode;
- for (ModeIndex = 0; ModeIndex < MaxMode; ModeIndex++) {
+ for (ModeIndex = 0; (UINTN)ModeIndex < MaxMode; ModeIndex++) {
Status = Private->GraphicsOutput->QueryMode (
Private->GraphicsOutput,
ModeIndex,
@@ -534,43 +496,6 @@ GraphicsConsoleControllerDriverStart ( goto Error;
}
}
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- //
- // At first try to set user-defined resolution
- //
- ColorDepth = 32;
- RefreshRate = 60;
- Status = Private->UgaDraw->SetMode (
- Private->UgaDraw,
- HorizontalResolution,
- VerticalResolution,
- ColorDepth,
- RefreshRate
- );
- if (EFI_ERROR (Status)) {
- //
- // Try to set 800*600 which is required by UEFI/EFI spec
- //
- Status = Private->UgaDraw->SetMode (
- Private->UgaDraw,
- 800,
- 600,
- ColorDepth,
- RefreshRate
- );
- if (EFI_ERROR (Status)) {
- Status = Private->UgaDraw->GetMode (
- Private->UgaDraw,
- &HorizontalResolution,
- &VerticalResolution,
- &ColorDepth,
- &RefreshRate
- );
- if (EFI_ERROR (Status)) {
- goto Error;
- }
- }
- }
}
DEBUG ((DEBUG_INFO, "GraphicsConsole video resolution %d x %d\n", HorizontalResolution, VerticalResolution));
@@ -638,7 +563,7 @@ GraphicsConsoleControllerDriverStart ( Error:
if (EFI_ERROR (Status)) {
//
- // Close the GOP and UGA Draw Protocol
+ // Close the GOP
//
if (Private->GraphicsOutput != NULL) {
gBS->CloseProtocol (
@@ -647,13 +572,6 @@ Error: This->DriverBindingHandle,
Controller
);
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- gBS->CloseProtocol (
- Controller,
- &gEfiUgaDrawProtocolGuid,
- This->DriverBindingHandle,
- Controller
- );
}
if (Private->LineBuffer != NULL) {
@@ -675,9 +593,7 @@ Error: /**
Stop this driver on Controller by removing Simple Text Out protocol
- and closing the Graphics Output Protocol or UGA Draw protocol on Controller.
- (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
-
+ and closing the Graphics Output Protocol on Controller.
@param This Protocol instance pointer.
@param Controller Handle of device to stop driver on
@@ -726,7 +642,7 @@ GraphicsConsoleControllerDriverStop ( if (!EFI_ERROR (Status)) {
//
- // Close the GOP or UGA IO Protocol
+ // Close the GOP Protocol
//
if (Private->GraphicsOutput != NULL) {
gBS->CloseProtocol (
@@ -735,13 +651,6 @@ GraphicsConsoleControllerDriverStop ( This->DriverBindingHandle,
Controller
);
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- gBS->CloseProtocol (
- Controller,
- &gEfiUgaDrawProtocolGuid,
- This->DriverBindingHandle,
- Controller
- );
}
if (Private->LineBuffer != NULL) {
@@ -933,7 +842,6 @@ GraphicsConsoleConOutOutputString ( {
GRAPHICS_CONSOLE_DEV *Private;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
INTN Mode;
UINTN MaxColumn;
UINTN MaxRow;
@@ -967,7 +875,6 @@ GraphicsConsoleConOutOutputString ( Mode = This->Mode->Mode;
Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
GraphicsOutput = Private->GraphicsOutput;
- UgaDraw = Private->UgaDraw;
MaxColumn = Private->ModeData[Mode].Columns;
MaxRow = Private->ModeData[Mode].Rows;
@@ -1055,38 +962,6 @@ GraphicsConsoleConOutOutputString ( EFI_GLYPH_HEIGHT,
Delta
);
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- //
- // Scroll Screen Up One Row
- //
- UgaDraw->Blt (
- UgaDraw,
- NULL,
- EfiUgaVideoToVideo,
- DeltaX,
- DeltaY + EFI_GLYPH_HEIGHT,
- DeltaX,
- DeltaY,
- Width,
- Height,
- Delta
- );
-
- //
- // Print Blank Line at last line
- //
- UgaDraw->Blt (
- UgaDraw,
- (EFI_UGA_PIXEL *)(UINTN)&Background,
- EfiUgaVideoFill,
- 0,
- 0,
- DeltaX,
- DeltaY + Height,
- Width,
- EFI_GLYPH_HEIGHT,
- Delta
- );
}
} else {
This->Mode->CursorRow++;
@@ -1320,19 +1195,13 @@ GraphicsConsoleConOutSetMode ( GRAPHICS_CONSOLE_DEV *Private;
GRAPHICS_CONSOLE_MODE_DATA *ModeData;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *NewLineBuffer;
- UINT32 HorizontalResolution;
- UINT32 VerticalResolution;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
- UINT32 ColorDepth;
- UINT32 RefreshRate;
EFI_TPL OldTpl;
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
GraphicsOutput = Private->GraphicsOutput;
- UgaDraw = Private->UgaDraw;
//
// Make sure the requested mode number is supported
@@ -1366,7 +1235,7 @@ GraphicsConsoleConOutSetMode ( }
//
- // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,
+ // Otherwise, the size of the text console and/or the GOP mode will be changed,
// so erase the cursor, and free the LineBuffer for the current mode
//
FlushCursor (This);
@@ -1422,51 +1291,6 @@ GraphicsConsoleConOutSetMode ( 0
);
}
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- //
- // Get the current UGA Draw mode information
- //
- Status = UgaDraw->GetMode (
- UgaDraw,
- &HorizontalResolution,
- &VerticalResolution,
- &ColorDepth,
- &RefreshRate
- );
- if (EFI_ERROR (Status) || (HorizontalResolution != ModeData->GopWidth) || (VerticalResolution != ModeData->GopHeight)) {
- //
- // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
- //
- Status = UgaDraw->SetMode (
- UgaDraw,
- ModeData->GopWidth,
- ModeData->GopHeight,
- 32,
- 60
- );
- if (EFI_ERROR (Status)) {
- //
- // The mode set operation failed
- //
- goto Done;
- }
- } else {
- //
- // The current graphics mode is correct, so simply clear the entire display
- //
- Status = UgaDraw->Blt (
- UgaDraw,
- (EFI_UGA_PIXEL *)(UINTN)&mGraphicsEfiColors[0],
- EfiUgaVideoFill,
- 0,
- 0,
- 0,
- 0,
- ModeData->GopWidth,
- ModeData->GopHeight,
- 0
- );
- }
}
//
@@ -1558,7 +1382,6 @@ GraphicsConsoleConOutClearScreen ( GRAPHICS_CONSOLE_DEV *Private;
GRAPHICS_CONSOLE_MODE_DATA *ModeData;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
EFI_TPL OldTpl;
@@ -1574,7 +1397,6 @@ GraphicsConsoleConOutClearScreen ( Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
GraphicsOutput = Private->GraphicsOutput;
- UgaDraw = Private->UgaDraw;
ModeData = &(Private->ModeData[This->Mode->Mode]);
GetTextColors (This, &Foreground, &Background);
@@ -1591,19 +1413,6 @@ GraphicsConsoleConOutClearScreen ( ModeData->GopHeight,
0
);
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- Status = UgaDraw->Blt (
- UgaDraw,
- (EFI_UGA_PIXEL *)(UINTN)&Background,
- EfiUgaVideoFill,
- 0,
- 0,
- 0,
- 0,
- ModeData->GopWidth,
- ModeData->GopHeight,
- 0
- );
} else {
Status = EFI_UNSUPPORTED;
}
@@ -1764,7 +1573,7 @@ GetTextColors ( @param Count The count of Unicode string.
@retval EFI_OUT_OF_RESOURCES If no memory resource to use.
- @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
+ @retval EFI_UNSUPPORTED If no Graphics Output protocol
protocol exist.
@retval EFI_SUCCESS Drawing Unicode string implemented successfully.
@@ -1781,9 +1590,6 @@ DrawUnicodeWeightAtCursorN ( EFI_IMAGE_OUTPUT *Blt;
EFI_STRING String;
EFI_FONT_DISPLAY_INFO *FontInfo;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
- EFI_HII_ROW_INFO *RowInfoArray;
- UINTN RowInfoArraySize;
Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
Blt = (EFI_IMAGE_OUTPUT *)AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
@@ -1835,63 +1641,6 @@ DrawUnicodeWeightAtCursorN ( NULL,
NULL
);
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- //
- // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,
- // using UGA Draw protocol to draw.
- //
- ASSERT (Private->UgaDraw != NULL);
-
- UgaDraw = Private->UgaDraw;
-
- Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
- if (Blt->Image.Bitmap == NULL) {
- FreePool (Blt);
- FreePool (String);
- return EFI_OUT_OF_RESOURCES;
- }
-
- RowInfoArray = NULL;
- //
- // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
- // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
- //
- Status = mHiiFont->StringToImage (
- mHiiFont,
- EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_IGNORE_LINE_BREAK,
- String,
- FontInfo,
- &Blt,
- This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,
- This->Mode->CursorRow * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,
- &RowInfoArray,
- &RowInfoArraySize,
- NULL
- );
-
- if (!EFI_ERROR (Status)) {
- //
- // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
- // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
- //
- ASSERT (RowInfoArraySize <= 1);
-
- Status = UgaDraw->Blt (
- UgaDraw,
- (EFI_UGA_PIXEL *)Blt->Image.Bitmap,
- EfiUgaBltBufferToVideo,
- This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,
- (This->Mode->CursorRow) * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,
- This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,
- (This->Mode->CursorRow) * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,
- RowInfoArray[0].LineWidth,
- RowInfoArray[0].LineHeight,
- Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
- );
- }
-
- FreePool (RowInfoArray);
- FreePool (Blt->Image.Bitmap);
} else {
Status = EFI_UNSUPPORTED;
}
@@ -1934,7 +1683,6 @@ FlushCursor ( INTN GlyphX;
INTN GlyphY;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar[EFI_GLYPH_HEIGHT][EFI_GLYPH_WIDTH];
@@ -1949,7 +1697,6 @@ FlushCursor ( Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
GraphicsOutput = Private->GraphicsOutput;
- UgaDraw = Private->UgaDraw;
//
// In this driver, only narrow character was supported.
@@ -1972,19 +1719,6 @@ FlushCursor ( EFI_GLYPH_HEIGHT,
EFI_GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
);
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- UgaDraw->Blt (
- UgaDraw,
- (EFI_UGA_PIXEL *)(UINTN)BltChar,
- EfiUgaVideoToBltBuffer,
- GlyphX,
- GlyphY,
- 0,
- 0,
- EFI_GLYPH_WIDTH,
- EFI_GLYPH_HEIGHT,
- EFI_GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)
- );
}
GetTextColors (This, &Foreground.Pixel, &Background.Pixel);
@@ -2013,19 +1747,6 @@ FlushCursor ( EFI_GLYPH_HEIGHT,
EFI_GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
);
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
- UgaDraw->Blt (
- UgaDraw,
- (EFI_UGA_PIXEL *)(UINTN)BltChar,
- EfiUgaBltBufferToVideo,
- 0,
- 0,
- GlyphX,
- GlyphY,
- EFI_GLYPH_WIDTH,
- EFI_GLYPH_HEIGHT,
- EFI_GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)
- );
}
return EFI_SUCCESS;
@@ -2084,7 +1805,10 @@ RegisterFontPackage ( PackageLength = sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR) + mNarrowFontSize + 4;
Package = AllocateZeroPool (PackageLength);
- ASSERT (Package != NULL);
+ if (Package == NULL) {
+ ASSERT (Package != NULL);
+ return;
+ }
WriteUnaligned32 ((UINT32 *)Package, PackageLength);
SimplifiedFont = (EFI_HII_SIMPLE_FONT_PACKAGE_HDR *)(Package + 4);
diff --git a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.h b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.h index e4abad4..e1a6b37 100644 --- a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.h +++ b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.h @@ -12,7 +12,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Uefi.h>
#include <Protocol/SimpleTextOut.h>
#include <Protocol/GraphicsOutput.h>
-#include <Protocol/UgaDraw.h>
#include <Protocol/DevicePath.h>
#include <Library/DebugLib.h>
#include <Library/UefiDriverEntryPoint.h>
@@ -59,7 +58,6 @@ typedef struct { typedef struct {
UINTN Signature;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
- EFI_UGA_DRAW_PROTOCOL *UgaDraw;
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput;
EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode;
GRAPHICS_CONSOLE_MODE_DATA *ModeData;
@@ -417,9 +415,8 @@ GraphicsConsoleConOutEnableCursor ( /**
Test to see if Graphics Console could be supported on the Controller.
- Graphics Console could be supported if Graphics Output Protocol or UGADraw
- Protocol exists on the Controller. (UGA Draw Protocol could be skipped
- if PcdUgaConsumeSupport is set to FALSE.)
+ Graphics Console could be supported if Graphics Output Protocol
+ exists on the Controller.
@param This Protocol instance pointer.
@param Controller Handle of device to test.
@@ -439,9 +436,8 @@ GraphicsConsoleControllerDriverSupported ( );
/**
- Start this driver on Controller by opening Graphics Output protocol or
- UGA Draw protocol, and installing Simple Text Out protocol on Controller.
- (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
+ Start this driver on Controller by opening Graphics Output protocol
+ and installing Simple Text Out protocol on Controller.
@param This Protocol instance pointer.
@param Controller Handle of device to bind driver to
@@ -462,9 +458,7 @@ GraphicsConsoleControllerDriverStart ( /**
Stop this driver on Controller by removing Simple Text Out protocol
- and closing the Graphics Output Protocol or UGA Draw protocol on Controller.
- (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
-
+ and closing the Graphics Output Protocol on Controller.
@param This Protocol instance pointer.
@param Controller Handle of device to stop driver on
@@ -526,8 +520,7 @@ GetTextColors ( @param Count The count of Unicode string.
@retval EFI_OUT_OF_RESOURCES If no memory resource to use.
- @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
- protocol exist.
+ @retval EFI_UNSUPPORTED If no Graphics Output protocol exist.
@retval EFI_SUCCESS Drawing Unicode string implemented successfully.
**/
diff --git a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf index bcfd306..975871b 100644 --- a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf +++ b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf @@ -2,7 +2,7 @@ # Console support on graphic devices.
#
# This driver will install Simple Text Output protocol by consuming Graphices Output
-# protocol or UGA Draw protocol on graphic devices.
+# protocol on graphic devices.
#
# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -53,15 +53,11 @@ gEfiDevicePathProtocolGuid ## TO_START
gEfiSimpleTextOutProtocolGuid ## BY_START
gEfiGraphicsOutputProtocolGuid ## TO_START
- gEfiUgaDrawProtocolGuid ## TO_START
gEfiHiiFontProtocolGuid ## TO_START
## TO_START
## NOTIFY
gEfiHiiDatabaseProtocolGuid
-[FeaturePcd]
- gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport ## CONSUMES
-
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution ## SOMETIMES_CONSUMES
diff --git a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.uni b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.uni index aec5d57..45dbb24 100644 --- a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.uni +++ b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.uni @@ -2,7 +2,7 @@ // Console support on graphic devices.
//
// This driver will install Simple Text Output protocol by consuming Graphices Output
-// protocol or UGA Draw protocol on graphic devices.
+// protocol on graphic devices.
//
// Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
//
@@ -14,5 +14,5 @@ #string STR_MODULE_ABSTRACT #language en-US "Console support on graphic devices"
#string STR_MODULE_DESCRIPTION #language en-US "This driver will install SimpleTextOutputProtocol by consuming GraphicesOutput\n"
- "Protocol or UgaDrawProtocol on graphics devices."
+ "Protocol on graphics devices."
diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c index 50f79f5..2f45571 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c +++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c @@ -1265,19 +1265,21 @@ TerminalRemoveConsoleDevVariable ( FreePool (OriginalVariable);
if (FoundOne) {
- VariableSize = GetDevicePathSize (NewVariable);
-
- Status = gRT->SetVariable (
- VariableName,
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- VariableSize,
- NewVariable
- );
- //
- // Shrinking variable with existing variable driver implementation shouldn't fail.
- //
- ASSERT_EFI_ERROR (Status);
+ if (NewVariable != NULL) {
+ VariableSize = GetDevicePathSize (NewVariable);
+
+ Status = gRT->SetVariable (
+ VariableName,
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ VariableSize,
+ NewVariable
+ );
+ //
+ // Shrinking variable with existing variable driver implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
+ }
}
if (NewVariable != NULL) {
diff --git a/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.c b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.c index b340727..cc3257e 100644 --- a/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.c +++ b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.c @@ -78,7 +78,7 @@ PeiDebugAssert ( @param FileHandle Handle of the file being invoked.
@param PeiServices Describes the list of possible PEI Services.
- @retval EFI_SUCESS The entry point of Debug Service PEIM executes successfully.
+ @retval EFI_SUCCESS The entry point of Debug Service PEIM executes successfully.
@retval Others Some error occurs during the execution of this function.
**/
diff --git a/MdeModulePkg/Universal/DebugSupportDxe/Ia32/PlDebugSupport.c b/MdeModulePkg/Universal/DebugSupportDxe/Ia32/PlDebugSupport.c index 40fe74d..2291985 100644 --- a/MdeModulePkg/Universal/DebugSupportDxe/Ia32/PlDebugSupport.c +++ b/MdeModulePkg/Universal/DebugSupportDxe/Ia32/PlDebugSupport.c @@ -262,17 +262,24 @@ InvalidateInstructionCache ( **/
VOID
InterruptDistrubutionHub (
- EFI_EXCEPTION_TYPE ExceptionType,
- EFI_SYSTEM_CONTEXT_IA32 *ContextRecord
+ IN EFI_EXCEPTION_TYPE ExceptionType,
+ IN EFI_SYSTEM_CONTEXT ContextRecord
)
{
- if (IdtEntryTable[ExceptionType].RegisteredCallback != NULL) {
- if (ExceptionType != SYSTEM_TIMER_VECTOR) {
- IdtEntryTable[ExceptionType].RegisteredCallback (ExceptionType, ContextRecord);
- } else {
- OrigVector = IdtEntryTable[ExceptionType].OrigVector;
- IdtEntryTable[ExceptionType].RegisteredCallback (ContextRecord);
- }
+ EFI_EXCEPTION_CALLBACK ExceptionCallback;
+ EFI_PERIODIC_CALLBACK PeriodicCallback;
+
+ if (IdtEntryTable[ExceptionType].RegisteredCallback == NULL) {
+ return;
+ }
+
+ if (ExceptionType == SYSTEM_TIMER_VECTOR) {
+ OrigVector = IdtEntryTable[ExceptionType].OrigVector;
+ PeriodicCallback = (EFI_PERIODIC_CALLBACK)IdtEntryTable[ExceptionType].RegisteredCallback;
+ PeriodicCallback (ContextRecord);
+ } else {
+ ExceptionCallback = (EFI_EXCEPTION_CALLBACK)IdtEntryTable[ExceptionType].RegisteredCallback;
+ ExceptionCallback (ExceptionType, ContextRecord);
}
}
diff --git a/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c b/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c index a7b7dc7..81020b2 100644 --- a/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c +++ b/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c @@ -2014,8 +2014,8 @@ FindTopMenu ( /**
Record the highlight menu and top of screen menu info.
- @param Highlight The menu opton which is highlight.
- @param TopOfScreen The menu opton which is at the top of the form.
+ @param Highlight The menu option which is highlight.
+ @param TopOfScreen The menu option which is at the top of the form.
@param SkipValue The skip line info for the top of screen menu.
**/
@@ -2095,9 +2095,9 @@ UpdateHighlightMenuInfo ( }
/**
- Update attribut for this menu.
+ Update attribute for this menu.
- @param MenuOption The menu opton which this attribut used to.
+ @param MenuOption The menu option which this attribute used to.
@param Highlight Whether this menu will be highlight.
**/
@@ -2130,7 +2130,7 @@ SetDisplayAttribute ( /**
Print string for this menu option.
- @param MenuOption The menu opton which this attribut used to.
+ @param MenuOption The menu option which this attribute used to.
@param Col The column that this string will be print at.
@param Row The row that this string will be print at.
@param String The string which need to print.
@@ -2164,19 +2164,20 @@ DisplayMenuString ( // First print the highlight string.
//
SetDisplayAttribute (MenuOption, TRUE);
- Length = PrintStringAt (Col, Row, String);
+ PrintStringAt (Col, Row, String);
//
// Second, clean the empty after the string.
//
SetDisplayAttribute (MenuOption, FALSE);
+ Length = GetStringWidth (String) / 2 - 1;
PrintStringAtWithWidth (Col + Length, Row, L"", Width - Length);
}
/**
Check whether this menu can has option string.
- @param MenuOption The menu opton which this attribut used to.
+ @param MenuOption The menu option which this attribute used to.
@retval TRUE This menu option can have option string.
@retval FALSE This menu option can't have option string.
@@ -2371,7 +2372,7 @@ FxConfirmPopup ( /**
Print string for this menu option.
- @param MenuOption The menu opton which this attribut used to.
+ @param MenuOption The menu option which this attribute used to.
@param SkipWidth The skip width between the left to the start of the prompt.
@param BeginCol The begin column for one menu.
@param SkipLine The skip line for this menu.
@@ -2379,7 +2380,7 @@ FxConfirmPopup ( @param Highlight Whether this menu will be highlight.
@param UpdateCol Whether need to update the column info for Date/Time.
- @retval EFI_SUCESSS Process the user selection success.
+ @retval EFI_SUCCESS Process the user selection success.
**/
EFI_STATUS
@@ -2626,7 +2627,7 @@ DisplayOneMenu ( @param FormData The current form data info.
- @retval EFI_SUCESSS Process the user selection success.
+ @retval EFI_SUCCESS Process the user selection success.
@retval EFI_NOT_FOUND Process option string for orderedlist/Oneof fail.
**/
@@ -2904,9 +2905,9 @@ UiDisplayMenu ( case CfRefreshHighLight:
//
- // MenuOption: Last menu option that need to remove hilight
+ // MenuOption: Last menu option that need to remove highlight
// MenuOption is set to NULL in Repaint
- // NewPos: Current menu option that need to hilight
+ // NewPos: Current menu option that need to highlight
//
ControlFlag = CfUpdateHelpString;
@@ -2986,13 +2987,13 @@ UiDisplayMenu ( }
//
- // NewLine means only update highlight menu (remove old highlight and highlith
- // the new one), not need to full repain the form.
+ // NewLine means only update highlight menu (remove old highlight and highlight
+ // the new one), not need to full repaint the form.
//
if (Repaint || NewLine) {
if (IsListEmpty (&gMenuOption)) {
//
- // Don't print anything if no mwnu option.
+ // Don't print anything if no menu option.
//
StringPtr = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
} else {
diff --git a/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.h b/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.h index 6e26704..a7b15a8 100644 --- a/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.h +++ b/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.h @@ -696,8 +696,8 @@ RefreshTimeOutProcess ( /**
Record the highlight menu and top of screen menu info.
- @param Highlight The menu opton which is highlight.
- @param TopOfScreen The menu opton which is at the top of the form.
+ @param Highlight The menu option which is highlight.
+ @param TopOfScreen The menu option which is at the top of the form.
@param SkipValue The skip line info for the top of screen menu.
**/
diff --git a/MdeModulePkg/Universal/DisplayEngineDxe/InputHandler.c b/MdeModulePkg/Universal/DisplayEngineDxe/InputHandler.c index b6dc234..b2a3ef6 100644 --- a/MdeModulePkg/Universal/DisplayEngineDxe/InputHandler.c +++ b/MdeModulePkg/Universal/DisplayEngineDxe/InputHandler.c @@ -229,8 +229,8 @@ ReadString ( case CHAR_BACKSPACE:
if ((StringPtr[0] != CHAR_NULL) && (CurrentCursor != 0)) {
- for (Index = 0; Index < CurrentCursor - 1; Index++) {
- TempString[Index] = StringPtr[Index];
+ if (CurrentCursor > 1) {
+ CopyMem (TempString, StringPtr, (CurrentCursor - 1) * sizeof (CHAR16));
}
Count = GetStringWidth (StringPtr) / 2 - 1;
@@ -261,9 +261,7 @@ ReadString ( KeyPad[1] = CHAR_NULL;
Count = GetStringWidth (StringPtr) / 2 - 1;
if (CurrentCursor < Count) {
- for (Index = 0; Index < CurrentCursor; Index++) {
- TempString[Index] = StringPtr[Index];
- }
+ CopyMem (TempString, StringPtr, CurrentCursor * sizeof (CHAR16));
TempString[Index] = CHAR_NULL;
StrCatS (TempString, MaxLen, KeyPad);
diff --git a/MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.c b/MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.c index de33f1b..d629684 100644 --- a/MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.c +++ b/MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.c @@ -874,7 +874,7 @@ DriverHealthManagerUpdateForm ( }
/**
- Called when the form is closing to remove the dynamicly added string from the HII package list.
+ Called when the form is closing to remove the dynamically added string from the HII package list.
**/
VOID
DriverHealthManagerCleanDynamicString (
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c index 003cb49..b8c903b 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c @@ -1746,7 +1746,7 @@ DriverCallback ( @param ImageHandle Image handle this driver.
@param SystemTable Pointer to SystemTable.
- @retval EFI_SUCESS This function always complete successfully.
+ @retval EFI_SUCCESS This function always complete successfully.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.c index 834c90e..cc3b3e3 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.c +++ b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.c @@ -1773,7 +1773,7 @@ FindSymbolStr ( Get line number and offset from this line in code file.
@param Line - Line buffer in code file
- @param Offset - Offset to functin entry
+ @param Offset - Offset to function entry
@return Line number
@@ -1867,7 +1867,7 @@ typedef enum { Get line number from this code file.
@param Entry - Symbol entry
- @param FuncOffset - Offset to functin entry
+ @param FuncOffset - Offset to function entry
@param SearchType - Search type for the code
@return Line number
@@ -2045,7 +2045,7 @@ EdbGetSourceStrFromCodeByLine ( Get source string from this code file.
@param Entry - Symbol entry
- @param FuncOffset - Offset to functin entry
+ @param FuncOffset - Offset to function entry
@param FuncEnd - Function end
@retval Funtion start
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c index d442ccb..5c168c8 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c @@ -1300,7 +1300,10 @@ InitFtwProtocol ( // Refresh the working space data from working block
//
Status = WorkSpaceRefresh (FtwDevice);
- ASSERT_EFI_ERROR (Status);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Ftw: Init.. WorkSpaceRefresh failed: Status = %r\n", Status));
+ }
+
//
// If the working block workspace is not valid, try the spare block
//
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c index fd56364..caa87e9 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c @@ -286,6 +286,10 @@ WorkSpaceRefresh ( return EFI_ABORTED;
}
+ if (!IsValidWorkSpace (FtwDevice->FtwWorkSpaceHeader)) {
+ return EFI_ABORTED;
+ }
+
//
// Refresh the FtwLastWriteHeader
//
diff --git a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c index 0252db1..42ab3f1 100644 --- a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c +++ b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c @@ -562,6 +562,10 @@ FvSimpleFileSystemOpen ( // NewFileNameLength = FileNameLength + 1 + 4 = (Number of non-null character) + (file extension) + (a null character)
NewFileNameLength = FileNameLength + 1 + 4;
FileNameWithExtension = AllocatePool (NewFileNameLength * 2);
+ if (FileNameWithExtension == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
StrCpyS (FileNameWithExtension, NewFileNameLength, FileName);
StrCatS (FileNameWithExtension, NewFileNameLength, L".EFI");
diff --git a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c index 3f96407..5d7fdaa 100644 --- a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c +++ b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c @@ -450,7 +450,10 @@ FvSimpleFileSystemDriverStart ( // Create an instance
//
Instance = AllocateZeroPool (sizeof (FV_FILESYSTEM_INSTANCE));
- ASSERT (Instance != NULL);
+ if (Instance == NULL) {
+ ASSERT (Instance != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
Instance->Root = NULL;
Instance->FvProtocol = FvProtocol;
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c index 09aefc6..314e408 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c @@ -687,6 +687,11 @@ FindQuestionDefaultSetting ( PCD_DATA_DELTA *DeltaData;
BOOLEAN VarCheck;
+ if (EfiVarStore == NULL) {
+ DEBUG ((DEBUG_ERROR, "EfiVarStore is null\n"));
+ return EFI_NOT_FOUND;
+ }
+
if (gSkuId == 0xFFFFFFFFFFFFFFFF) {
gSkuId = LibPcdGetSku ();
}
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c index b35360e..ae5eff7 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c @@ -1407,7 +1407,7 @@ HiiDrawImage ( //
if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {
//
- // Caller should make sure the current UGA console is grarphic mode.
+ // Caller should make sure the current console is grarphic mode.
//
//
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/String.c b/MdeModulePkg/Universal/HiiDatabaseDxe/String.c index e3fceed..c70f308 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/String.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/String.c @@ -1000,7 +1000,7 @@ SetStringWorker ( case EFI_HII_SIBT_STRING_SCSU_FONT:
case EFI_HII_SIBT_STRINGS_SCSU:
case EFI_HII_SIBT_STRINGS_SCSU_FONT:
- BlockSize = OldBlockSize + StrLen (String);
+ BlockSize = OldBlockSize + StrSize (String);
BlockSize -= AsciiStrSize ((CHAR8 *)StringTextPtr);
Block = AllocateZeroPool (BlockSize);
if (Block == NULL) {
diff --git a/MdeModulePkg/Universal/HiiResourcesSampleDxe/HiiResourcesSample.c b/MdeModulePkg/Universal/HiiResourcesSampleDxe/HiiResourcesSample.c index dd0ae50..cbcb7b2 100644 --- a/MdeModulePkg/Universal/HiiResourcesSampleDxe/HiiResourcesSample.c +++ b/MdeModulePkg/Universal/HiiResourcesSampleDxe/HiiResourcesSample.c @@ -57,7 +57,7 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath = { @param[in] ImageHandle Image handle this driver.
@param[in] SystemTable Pointer to SystemTable.
- @retval EFI_SUCESS This function always complete successfully.
+ @retval EFI_SUCCESS This function always complete successfully.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c index 24da4a4..e30a55f 100644 --- a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c +++ b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c @@ -6,9 +6,9 @@ drivers to controllers.
The main flow:
- 1. It dynamicly locate all controller device path.
- 2. It dynamicly locate all drivers which support binding protocol.
- 3. It export and dynamicly update two menu to let user select the
+ 1. It dynamically locate all controller device path.
+ 2. It dynamically locate all drivers which support binding protocol.
+ 3. It export and dynamically update two menu to let user select the
mapping between drivers to controllers.
4. It save all the mapping info in NV variables which will be consumed
by platform override protocol driver to publish the platform override protocol.
diff --git a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.uni b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.uni index 9905a28..8f81593 100644 --- a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.uni +++ b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.uni @@ -10,9 +10,9 @@ // drivers to controllers.
//
// The main flow:
-// 1. It dynamicly locate all controller device path.
-// 2. It dynamicly locate all drivers which support binding protocol.
-// 3. It export and dynamicly update two menu to let user select the
+// 1. It dynamically locate all controller device path.
+// 2. It dynamically locate all drivers which support binding protocol.
+// 3. It export and dynamically update two menu to let user select the
// mapping between drivers to controllers.
// 4. It save all the mapping info in NV variables for the following boot,
// which will be consumed by GetDriver API of the produced the platform override protocol.
@@ -32,6 +32,6 @@ "The main flow:<BR>\n"
"1. It dynamically locates all controller device path.<BR>\n"
"2. It dynamically locates all drivers which support binding protocol.<BR>\n"
- "3. It exports and dynamicly updates two menu to let user select the mapping between drivers to controllers.<BR>\n"
+ "3. It exports and dynamically updates two menu to let user select the mapping between drivers to controllers.<BR>\n"
"4. It saves all the mapping info in NV variables for the following boot, which will be consumed by GetDriver API of the produced the platform override protocol.<BR>"
diff --git a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatOverMngr.h b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatOverMngr.h index 0e200c0..fbc9c8f 100644 --- a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatOverMngr.h +++ b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatOverMngr.h @@ -1,6 +1,6 @@ /** @file
- The defintions are required both by Source code and Vfr file.
+ The definitions are required both by Source code and Vfr file.
The PLAT_OVER_MNGR_DATA structure, form guid and Ifr question ID are defined.
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
diff --git a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatformDriOverrideDxe.inf b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatformDriOverrideDxe.inf index 97c8e3c..e12d784 100644 --- a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatformDriOverrideDxe.inf +++ b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatformDriOverrideDxe.inf @@ -9,9 +9,9 @@ # drivers to controllers.
#
# The main flow:
-# 1. It dynamicly locate all controller device path.
-# 2. It dynamicly locate all drivers which support binding protocol.
-# 3. It export and dynamicly update two menu to let user select the
+# 1. It dynamically locate all controller device path.
+# 2. It dynamically locate all drivers which support binding protocol.
+# 3. It export and dynamically update two menu to let user select the
# mapping between drivers to controllers.
# 4. It save all the mapping info in NV variables for the following boot,
# which will be consumed by GetDriver API of the produced the platform override protocol.
diff --git a/MdeModulePkg/Universal/RegularExpressionDxe/OnigurumaUefiPort.h b/MdeModulePkg/Universal/RegularExpressionDxe/OnigurumaUefiPort.h index 8931f8e..ee173d5 100644 --- a/MdeModulePkg/Universal/RegularExpressionDxe/OnigurumaUefiPort.h +++ b/MdeModulePkg/Universal/RegularExpressionDxe/OnigurumaUefiPort.h @@ -32,6 +32,7 @@ typedef UINTN size_t;
typedef UINT32 uint32_t;
typedef INTN intptr_t;
+typedef INT64 ptrdiff_t;
#ifndef offsetof
#define offsetof OFFSET_OF
diff --git a/MdeModulePkg/Universal/RegularExpressionDxe/oniguruma b/MdeModulePkg/Universal/RegularExpressionDxe/oniguruma -Subproject abfc8ff81df4067f309032467785e06975678f0 +Subproject 4ef89209a239c1aea328cf13c05a2807e5c146d diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.c b/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.c index b123983..e1b1021 100644 --- a/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.c +++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.c @@ -275,7 +275,7 @@ ReportDispatcher ( @param FileHandle Handle of the file being invoked.
@param PeiServices Describes the list of possible PEI Services.
- @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
+ @retval EFI_SUCCESS The entry point of DXE IPL PEIM executes successfully.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPei.c b/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPei.c index 8a11643..5229fd8 100644 --- a/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPei.c +++ b/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPei.c @@ -251,12 +251,15 @@ SectionExtractionPeiEntry ( if (ExtractHandlerNumber > 0) {
GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *)AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));
ASSERT (GuidPpi != NULL);
- while (ExtractHandlerNumber-- > 0) {
- GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
- GuidPpi->Ppi = (VOID *)&mCustomGuidedSectionExtractionPpi;
- GuidPpi->Guid = &ExtractHandlerGuidTable[ExtractHandlerNumber];
- Status = PeiServicesInstallPpi (GuidPpi++);
- ASSERT_EFI_ERROR (Status);
+
+ if (GuidPpi != NULL) {
+ while (ExtractHandlerNumber-- > 0) {
+ GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
+ GuidPpi->Ppi = (VOID *)&mCustomGuidedSectionExtractionPpi;
+ GuidPpi->Guid = &ExtractHandlerGuidTable[ExtractHandlerNumber];
+ Status = PeiServicesInstallPpi (GuidPpi++);
+ ASSERT_EFI_ERROR (Status);
+ }
}
}
diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c b/MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c index de7e79e..e44a70c 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c @@ -1004,7 +1004,7 @@ UpdateStatementStatus ( @param Action The user input action request info.
@param DefaultId The user input default Id info.
- @retval EFI_SUCESSS This function always return successfully for now.
+ @retval EFI_SUCCESS This function always return successfully for now.
**/
EFI_STATUS
@@ -1557,7 +1557,7 @@ ProcessQuestionConfig ( @param UserInput The user input data.
- @retval EFI_SUCESSS This function always return successfully for now.
+ @retval EFI_SUCCESS This function always return successfully for now.
**/
EFI_STATUS
@@ -1687,7 +1687,7 @@ ProcessUserInput ( Display form and wait for user to select one menu option, then return it.
- @retval EFI_SUCESSS This function always return successfully for now.
+ @retval EFI_SUCCESS This function always return successfully for now.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferDxe.c b/MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferDxe.c index a47311c..8121e0c 100644 --- a/MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferDxe.c +++ b/MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferDxe.c @@ -63,6 +63,10 @@ SmmCommunicationBufferEntryPoint ( //
PiSmmCommunicationRegionTable = AllocateReservedPool (sizeof (EDKII_PI_SMM_COMMUNICATION_REGION_TABLE) + DescriptorSize);
ASSERT (PiSmmCommunicationRegionTable != NULL);
+ if (PiSmmCommunicationRegionTable == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
ZeroMem (PiSmmCommunicationRegionTable, sizeof (EDKII_PI_SMM_COMMUNICATION_REGION_TABLE) + DescriptorSize);
PiSmmCommunicationRegionTable->Version = EDKII_PI_SMM_COMMUNICATION_REGION_TABLE_VERSION;
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.c b/MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.c index d740a62..b29b78b 100644 --- a/MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.c +++ b/MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.c @@ -19,7 +19,7 @@ @param FileHandle Handle of the file being invoked.
@param PeiServices Describes the list of possible PEI Services.
- @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
+ @retval EFI_SUCCESS The entry point of DXE IPL PEIM executes successfully.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c index 4f937e2..eac1da5 100644 --- a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c +++ b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c @@ -66,7 +66,9 @@ PopulateHeaderAndCommunicate ( {
EFI_STATUS Status;
EFI_PEI_MM_COMMUNICATION_PPI *MmCommunicationPpi;
+ EFI_PEI_MM_COMMUNICATION3_PPI *MmCommunicationPpiV3;
EFI_MM_COMMUNICATE_HEADER *MmCommunicateHeader;
+ EFI_MM_COMMUNICATE_HEADER_V3 *MmCommunicateHeaderV3;
SMM_VARIABLE_COMMUNICATE_HEADER *MmVarCommsHeader;
// Minimal sanity check
@@ -86,30 +88,67 @@ PopulateHeaderAndCommunicate ( goto Exit;
}
- Status = PeiServicesLocatePpi (&gEfiPeiMmCommunicationPpiGuid, 0, NULL, (VOID **)&MmCommunicationPpi);
+ MmCommunicationPpiV3 = NULL;
+ MmCommunicationPpi = NULL;
+
+ Status = PeiServicesLocatePpi (&gEfiPeiMmCommunication3PpiGuid, 0, NULL, (VOID **)&MmCommunicationPpiV3);
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a: Failed to locate PEI MM Communication PPI: %r\n", __func__, Status));
- goto Exit;
+ DEBUG ((DEBUG_WARN, "%a: Unable to locate PEI MM Communication3 PPI: %r\n", __func__, Status));
+ // Try to locate the older version of the PPI
+ Status = PeiServicesLocatePpi (&gEfiPeiMmCommunicationPpiGuid, 0, NULL, (VOID **)&MmCommunicationPpi);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to locate PEI MM Communication PPI: %r\n", __func__, Status));
+ goto Exit;
+ }
}
- // Zero the entire Communication Buffer Header
- MmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)CommunicateBuffer;
+ if (MmCommunicationPpiV3 != NULL) {
+ // Zero the entire Communication Buffer Header
+ MmCommunicateHeaderV3 = (EFI_MM_COMMUNICATE_HEADER_V3 *)CommunicateBuffer;
- ZeroMem (MmCommunicateHeader, SMM_COMMUNICATE_HEADER_SIZE);
+ ZeroMem (MmCommunicateHeaderV3, SMM_COMMUNICATE_HEADER_SIZE_V3);
- // Use gEfiSmmVariableProtocolGuid to request the MM variable service in Standalone MM
- CopyMem ((VOID *)&MmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid, sizeof (GUID));
+ // Use gEfiSmmVariableProtocolGuid to request the MM variable service in Standalone MM
+ CopyMem ((VOID *)&MmCommunicateHeaderV3->HeaderGuid, &gEfiMmCommunicateHeaderV3Guid, sizeof (GUID));
+ MmCommunicateHeaderV3->BufferSize = CommunicateBufferSize;
- // Program the MM header size
- MmCommunicateHeader->MessageLength = CommunicateBufferSize - SMM_COMMUNICATE_HEADER_SIZE;
+ CopyMem ((VOID *)&MmCommunicateHeaderV3->MessageGuid, &gEfiSmmVariableProtocolGuid, sizeof (GUID));
- MmVarCommsHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)(CommunicateBuffer + SMM_COMMUNICATE_HEADER_SIZE);
+ // Program the MM header size
+ MmCommunicateHeaderV3->MessageSize = CommunicateBufferSize - SMM_COMMUNICATE_HEADER_SIZE_V3;
- // We are only supporting GetVariable and GetNextVariableName
- MmVarCommsHeader->Function = Function;
+ MmVarCommsHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)(MmCommunicateHeaderV3->MessageData);
+
+ // We are only supporting GetVariable and GetNextVariableName
+ MmVarCommsHeader->Function = Function;
+
+ // Send the MM request using MmCommunicationPei
+ Status = MmCommunicationPpiV3->Communicate (MmCommunicationPpiV3, CommunicateBuffer);
+ } else if (MmCommunicationPpi != NULL) {
+ // Zero the entire Communication Buffer Header
+ MmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)CommunicateBuffer;
+
+ ZeroMem (MmCommunicateHeader, SMM_COMMUNICATE_HEADER_SIZE);
+
+ // Use gEfiSmmVariableProtocolGuid to request the MM variable service in Standalone MM
+ CopyMem ((VOID *)&MmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid, sizeof (GUID));
+
+ // Program the MM header size
+ MmCommunicateHeader->MessageLength = CommunicateBufferSize - SMM_COMMUNICATE_HEADER_SIZE;
+
+ MmVarCommsHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)(CommunicateBuffer + SMM_COMMUNICATE_HEADER_SIZE);
+
+ // We are only supporting GetVariable and GetNextVariableName
+ MmVarCommsHeader->Function = Function;
+
+ // Send the MM request using MmCommunicationPei
+ Status = MmCommunicationPpi->Communicate (MmCommunicationPpi, CommunicateBuffer, &CommunicateBufferSize);
+ } else {
+ // We should never reach here, but just in case
+ Status = EFI_UNSUPPORTED;
+ DEBUG ((DEBUG_ERROR, "%a: No MM Communication PPI found!\n", __func__));
+ }
- // Send the MM request using MmCommunicationPei
- Status = MmCommunicationPpi->Communicate (MmCommunicationPpi, CommunicateBuffer, &CommunicateBufferSize);
if (EFI_ERROR (Status)) {
// Received an error from MM interface.
DEBUG ((DEBUG_ERROR, "%a - MM Interface Error: %r\n", __func__, Status));
diff --git a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h index 0feed8c..0b38329 100644 --- a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h +++ b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h @@ -23,6 +23,7 @@ #include <Ppi/ReadOnlyVariable2.h>
#include <Ppi/MmCommunication.h>
+#include <Ppi/MmCommunication3.h>
#include <Protocol/SmmVariable.h>
#include <Protocol/MmCommunication.h>
diff --git a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf index 13e8052..1f972db 100644 --- a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf +++ b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf @@ -34,7 +34,11 @@ [Ppis]
gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES
- gEfiPeiMmCommunicationPpiGuid ## CONSUMES
+ gEfiPeiMmCommunication3PpiGuid ## CONSUMES
+ gEfiPeiMmCommunicationPpiGuid ## SOMETIMES_CONSUMES
+
+[Guids]
+ gEfiMmCommunicateHeaderV3Guid
[Depex]
- gEfiPeiMmCommunicationPpiGuid
+ gEfiPeiMmCommunicationPpiGuid OR gEfiPeiMmCommunication3PpiGuid
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/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c index 28dedad..47f14c5 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c @@ -22,6 +22,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Protocol/VariableWrite.h>
#include <Protocol/Variable.h>
#include <Protocol/MmCommunication2.h>
+#include <Protocol/MmCommunication3.h>
#include <Protocol/SmmVariable.h>
#include <Protocol/VariableLock.h>
#include <Protocol/VarCheck.h>
@@ -48,6 +49,7 @@ EFI_HANDLE mHandle = NULL; EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable = NULL;
EFI_EVENT mVirtualAddressChangeEvent = NULL;
EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2 = NULL;
+EFI_MM_COMMUNICATION3_PROTOCOL *mMmCommunication3 = NULL;
UINT8 *mVariableBuffer = NULL;
UINT8 *mVariableBufferPhysical = NULL;
VARIABLE_INFO_ENTRY *mVariableInfo = NULL;
@@ -163,17 +165,33 @@ InitCommunicateBuffer ( )
{
EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
+ EFI_MM_COMMUNICATE_HEADER_V3 *SmmCommunicateHeaderV3;
SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;
- if (DataSize + SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE > mVariableBufferSize) {
- return EFI_INVALID_PARAMETER;
- }
+ ZeroMem (mVariableBuffer, mVariableBufferSize);
+ if (mMmCommunication3 != NULL) {
+ if (DataSize + SMM_COMMUNICATE_HEADER_SIZE_V3 + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE > mVariableBufferSize) {
+ return EFI_INVALID_PARAMETER;
+ }
- SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)mVariableBuffer;
- CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
- SmmCommunicateHeader->MessageLength = DataSize + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
+ SmmCommunicateHeaderV3 = (EFI_MM_COMMUNICATE_HEADER_V3 *)mVariableBuffer;
+ CopyGuid (&SmmCommunicateHeaderV3->HeaderGuid, &gEfiMmCommunicateHeaderV3Guid);
+ SmmCommunicateHeaderV3->BufferSize = mVariableBufferSize;
+ CopyGuid (&SmmCommunicateHeaderV3->MessageGuid, &gEfiSmmVariableProtocolGuid);
+ SmmCommunicateHeaderV3->MessageSize = DataSize + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
+ SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeaderV3->MessageData;
+ } else {
+ // Use v1 communication header, if v3 protocol is not available.
+ if (DataSize + SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE > mVariableBufferSize) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)mVariableBuffer;
+ CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
+ SmmCommunicateHeader->MessageLength = DataSize + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
+ SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data;
+ }
- SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data;
SmmVariableFunctionHeader->Function = Function;
if (DataPtr != NULL) {
*DataPtr = SmmVariableFunctionHeader->Data;
@@ -187,7 +205,7 @@ InitCommunicateBuffer ( @param[in] DataSize This size of the function header and the data.
- @retval EFI_SUCCESS Success is returned from the functin in SMM.
+ @retval EFI_SUCCESS Success is returned from the function in SMM.
@retval Others Failure is returned from the function in SMM.
**/
@@ -199,20 +217,38 @@ SendCommunicateBuffer ( EFI_STATUS Status;
UINTN CommSize;
EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
+ EFI_MM_COMMUNICATE_HEADER_V3 *SmmCommunicateHeaderV3;
SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;
- CommSize = DataSize + SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
- Status = mMmCommunication2->Communicate (
- mMmCommunication2,
+ if (mMmCommunication3 != NULL) {
+ Status = mMmCommunication3->Communicate (
+ mMmCommunication3,
mVariableBufferPhysical,
- mVariableBuffer,
- &CommSize
+ mVariableBuffer
);
- ASSERT_EFI_ERROR (Status);
+ ASSERT_EFI_ERROR (Status);
- SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)mVariableBuffer;
- SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data;
- return SmmVariableFunctionHeader->ReturnStatus;
+ SmmCommunicateHeaderV3 = (EFI_MM_COMMUNICATE_HEADER_V3 *)mVariableBuffer;
+ SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeaderV3->MessageData;
+
+ Status = SmmVariableFunctionHeader->ReturnStatus;
+ } else {
+ CommSize = DataSize + SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
+ Status = mMmCommunication2->Communicate (
+ mMmCommunication2,
+ mVariableBufferPhysical,
+ mVariableBuffer,
+ &CommSize
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)mVariableBuffer;
+ SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data;
+
+ Status = SmmVariableFunctionHeader->ReturnStatus;
+ }
+
+ return Status;
}
/**
@@ -1342,7 +1378,12 @@ VariableAddressChangeEvent ( )
{
EfiConvertPointer (0x0, (VOID **)&mVariableBuffer);
- EfiConvertPointer (0x0, (VOID **)&mMmCommunication2);
+ if (mMmCommunication3 != NULL) {
+ EfiConvertPointer (0x0, (VOID **)&mMmCommunication3);
+ } else {
+ EfiConvertPointer (0x0, (VOID **)&mMmCommunication2);
+ }
+
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRtCacheInfo.CacheInfoFlagBuffer);
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRtCacheInfo.RuntimeHobCacheBuffer);
EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mVariableRtCacheInfo.RuntimeNvCacheBuffer);
@@ -1367,6 +1408,7 @@ GetVariablePayloadSize ( EFI_STATUS Status;
SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *SmmGetPayloadSize;
EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
+ EFI_MM_COMMUNICATE_HEADER_V3 *SmmCommunicateHeaderV3;
SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;
UINTN CommSize;
UINT8 *CommBuffer;
@@ -1384,26 +1426,52 @@ GetVariablePayloadSize ( // Init the communicate buffer. The buffer data size is:
// SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE);
//
- CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE);
- CommBuffer = AllocateZeroPool (CommSize);
- if (CommBuffer == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
- goto Done;
- }
- SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)CommBuffer;
- CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
- SmmCommunicateHeader->MessageLength = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE);
+ if (mMmCommunication3 != NULL) {
+ CommSize = SMM_COMMUNICATE_HEADER_SIZE_V3 + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE);
+ CommBuffer = AllocateZeroPool (CommSize);
+ if (CommBuffer == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Done;
+ }
- SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data;
- SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE;
- SmmGetPayloadSize = (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *)SmmVariableFunctionHeader->Data;
+ SmmCommunicateHeaderV3 = (EFI_MM_COMMUNICATE_HEADER_V3 *)CommBuffer;
+ CopyGuid (&SmmCommunicateHeaderV3->HeaderGuid, &gEfiMmCommunicateHeaderV3Guid);
+ SmmCommunicateHeaderV3->BufferSize = CommSize;
+ CopyGuid (&SmmCommunicateHeaderV3->MessageGuid, &gEfiSmmVariableProtocolGuid);
+ SmmCommunicateHeaderV3->MessageSize = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE);
+ SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeaderV3->MessageData;
- //
- // Send data to SMM.
- //
- Status = mMmCommunication2->Communicate (mMmCommunication2, CommBuffer, CommBuffer, &CommSize);
- ASSERT_EFI_ERROR (Status);
+ SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE;
+ SmmGetPayloadSize = (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *)SmmVariableFunctionHeader->Data;
+
+ //
+ // Send data to SMM.
+ //
+ Status = mMmCommunication3->Communicate (mMmCommunication3, CommBuffer, CommBuffer);
+ ASSERT_EFI_ERROR (Status);
+ } else {
+ CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE);
+ CommBuffer = AllocateZeroPool (CommSize);
+ if (CommBuffer == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Done;
+ }
+
+ SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)CommBuffer;
+ CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
+ SmmCommunicateHeader->MessageLength = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE);
+ SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data;
+
+ SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE;
+ SmmGetPayloadSize = (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *)SmmVariableFunctionHeader->Data;
+
+ //
+ // Send data to SMM.
+ //
+ Status = mMmCommunication2->Communicate (mMmCommunication2, CommBuffer, CommBuffer, &CommSize);
+ ASSERT_EFI_ERROR (Status);
+ }
Status = SmmVariableFunctionHeader->ReturnStatus;
if (EFI_ERROR (Status)) {
@@ -1449,6 +1517,7 @@ GetRuntimeCacheInfo ( EFI_STATUS Status;
SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO *SmmGetRuntimeCacheInfo;
EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
+ EFI_MM_COMMUNICATE_HEADER_V3 *SmmCommunicateHeaderV3;
SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;
UINTN CommSize;
UINT8 *CommBuffer;
@@ -1466,22 +1535,44 @@ GetRuntimeCacheInfo ( AcquireLockOnlyAtBootTime (&mVariableServicesLock);
- CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO);
- ZeroMem (CommBuffer, CommSize);
+ if (mMmCommunication3 != NULL) {
+ CommSize = SMM_COMMUNICATE_HEADER_SIZE_V3 + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO);
+ ZeroMem (CommBuffer, CommSize);
- SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)CommBuffer;
- CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
- SmmCommunicateHeader->MessageLength = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO);
+ SmmCommunicateHeaderV3 = (EFI_MM_COMMUNICATE_HEADER_V3 *)CommBuffer;
+ CopyGuid (&SmmCommunicateHeaderV3->HeaderGuid, &gEfiMmCommunicateHeaderV3Guid);
+ SmmCommunicateHeaderV3->BufferSize = mVariableBufferSize;
+ CopyGuid (&SmmCommunicateHeaderV3->MessageGuid, &gEfiSmmVariableProtocolGuid);
+ SmmCommunicateHeaderV3->MessageSize = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO);
- SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data;
- SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_RUNTIME_CACHE_INFO;
- SmmGetRuntimeCacheInfo = (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO *)SmmVariableFunctionHeader->Data;
+ SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeaderV3->MessageData;
+ SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_RUNTIME_CACHE_INFO;
+ SmmGetRuntimeCacheInfo = (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO *)SmmVariableFunctionHeader->Data;
+
+ //
+ // Send data to SMM.
+ //
+ Status = mMmCommunication3->Communicate (mMmCommunication3, CommBuffer, CommBuffer);
+ ASSERT_EFI_ERROR (Status);
+ } else {
+ CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO);
+ ZeroMem (CommBuffer, CommSize);
+
+ SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)CommBuffer;
+ CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
+ SmmCommunicateHeader->MessageLength = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO);
+
+ SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data;
+ SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_RUNTIME_CACHE_INFO;
+ SmmGetRuntimeCacheInfo = (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO *)SmmVariableFunctionHeader->Data;
+
+ //
+ // Send data to SMM.
+ //
+ Status = mMmCommunication2->Communicate (mMmCommunication2, CommBuffer, CommBuffer, &CommSize);
+ ASSERT_EFI_ERROR (Status);
+ }
- //
- // Send data to SMM.
- //
- Status = mMmCommunication2->Communicate (mMmCommunication2, CommBuffer, CommBuffer, &CommSize);
- ASSERT_EFI_ERROR (Status);
if (CommSize <= SMM_VARIABLE_COMMUNICATE_HEADER_SIZE) {
Status = EFI_BAD_BUFFER_SIZE;
goto Done;
@@ -1599,6 +1690,7 @@ SendRuntimeVariableCacheContextToSmm ( EFI_STATUS Status;
SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *SmmRuntimeVarCacheContext;
EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
+ EFI_MM_COMMUNICATE_HEADER_V3 *SmmCommunicateHeaderV3;
SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;
UINTN CommSize;
UINT8 *CommBuffer;
@@ -1612,33 +1704,66 @@ SendRuntimeVariableCacheContextToSmm ( AcquireLockOnlyAtBootTime (&mVariableServicesLock);
- //
- // Init the communicate buffer. The buffer data size is:
- // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT);
- //
- CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT);
- ZeroMem (CommBuffer, CommSize);
+ if (mMmCommunication3 != NULL) {
+ //
+ // Init the communicate buffer. The buffer data size is:
+ // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT);
+ //
+ CommSize = SMM_COMMUNICATE_HEADER_SIZE_V3 + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT);
+ ZeroMem (CommBuffer, CommSize);
+
+ SmmCommunicateHeaderV3 = (EFI_MM_COMMUNICATE_HEADER_V3 *)CommBuffer;
+ CopyGuid (&SmmCommunicateHeaderV3->HeaderGuid, &gEfiMmCommunicateHeaderV3Guid);
+ SmmCommunicateHeaderV3->BufferSize = mVariableBufferSize;
+ CopyGuid (&SmmCommunicateHeaderV3->MessageGuid, &gEfiSmmVariableProtocolGuid);
+ SmmCommunicateHeaderV3->MessageSize = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT);
+
+ SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeaderV3->MessageData;
+ SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_INIT_RUNTIME_VARIABLE_CACHE_CONTEXT;
+ SmmRuntimeVarCacheContext = (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *)SmmVariableFunctionHeader->Data;
+
+ SmmRuntimeVarCacheContext->RuntimeHobCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeHobCacheBuffer;
+ SmmRuntimeVarCacheContext->RuntimeVolatileCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeVolatileCacheBuffer;
+ SmmRuntimeVarCacheContext->RuntimeNvCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeNvCacheBuffer;
+ SmmRuntimeVarCacheContext->PendingUpdate = &((CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer)->PendingUpdate;
+ SmmRuntimeVarCacheContext->ReadLock = &((CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer)->ReadLock;
+ SmmRuntimeVarCacheContext->HobFlushComplete = &((CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer)->HobFlushComplete;
- SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)CommBuffer;
- CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
- SmmCommunicateHeader->MessageLength = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT);
+ //
+ // Send data to SMM.
+ //
+ Status = mMmCommunication3->Communicate (mMmCommunication3, CommBuffer, CommBuffer);
+ ASSERT_EFI_ERROR (Status);
+ } else {
+ //
+ // Init the communicate buffer. The buffer data size is:
+ // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT);
+ //
+ CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT);
+ ZeroMem (CommBuffer, CommSize);
- SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data;
- SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_INIT_RUNTIME_VARIABLE_CACHE_CONTEXT;
- SmmRuntimeVarCacheContext = (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *)SmmVariableFunctionHeader->Data;
+ SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)CommBuffer;
+ CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
+ SmmCommunicateHeader->MessageLength = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT);
- SmmRuntimeVarCacheContext->RuntimeHobCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeHobCacheBuffer;
- SmmRuntimeVarCacheContext->RuntimeVolatileCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeVolatileCacheBuffer;
- SmmRuntimeVarCacheContext->RuntimeNvCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeNvCacheBuffer;
- SmmRuntimeVarCacheContext->PendingUpdate = &((CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer)->PendingUpdate;
- SmmRuntimeVarCacheContext->ReadLock = &((CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer)->ReadLock;
- SmmRuntimeVarCacheContext->HobFlushComplete = &((CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer)->HobFlushComplete;
+ SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data;
+ SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_INIT_RUNTIME_VARIABLE_CACHE_CONTEXT;
+ SmmRuntimeVarCacheContext = (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *)SmmVariableFunctionHeader->Data;
+
+ SmmRuntimeVarCacheContext->RuntimeHobCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeHobCacheBuffer;
+ SmmRuntimeVarCacheContext->RuntimeVolatileCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeVolatileCacheBuffer;
+ SmmRuntimeVarCacheContext->RuntimeNvCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableRtCacheInfo.RuntimeNvCacheBuffer;
+ SmmRuntimeVarCacheContext->PendingUpdate = &((CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer)->PendingUpdate;
+ SmmRuntimeVarCacheContext->ReadLock = &((CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer)->ReadLock;
+ SmmRuntimeVarCacheContext->HobFlushComplete = &((CACHE_INFO_FLAG *)(UINTN)mVariableRtCacheInfo.CacheInfoFlagBuffer)->HobFlushComplete;
+
+ //
+ // Send data to SMM.
+ //
+ Status = mMmCommunication2->Communicate (mMmCommunication2, CommBuffer, CommBuffer, &CommSize);
+ ASSERT_EFI_ERROR (Status);
+ }
- //
- // Send data to SMM.
- //
- Status = mMmCommunication2->Communicate (mMmCommunication2, CommBuffer, CommBuffer, &CommSize);
- ASSERT_EFI_ERROR (Status);
if (CommSize <= SMM_VARIABLE_COMMUNICATE_HEADER_SIZE) {
Status = EFI_BAD_BUFFER_SIZE;
goto Done;
@@ -1677,7 +1802,12 @@ SmmVariableReady ( return;
}
- Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **)&mMmCommunication2);
+ Status = gBS->LocateProtocol (&gEfiMmCommunication3ProtocolGuid, NULL, (VOID **)&mMmCommunication3);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_WARN, "Unable to locate MM communication v3 (%r). Falling back to v2\n", Status));
+ Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **)&mMmCommunication2);
+ }
+
ASSERT_EFI_ERROR (Status);
//
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf index d984a36..af8a32a 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf @@ -66,6 +66,7 @@ gEfiVariableWriteArchProtocolGuid ## PRODUCES
gEfiVariableArchProtocolGuid ## PRODUCES
gEfiMmCommunication2ProtocolGuid ## CONSUMES
+ gEfiMmCommunication3ProtocolGuid ## CONSUMES
## CONSUMES
## NOTIFY
## UNDEFINED # Used to do smm communication
@@ -113,9 +114,10 @@ gEfiEndOfDxeEventGroupGuid
gEfiDeviceSignatureDatabaseGuid
gEdkiiVariableRuntimeCacheInfoHobGuid
+ gEfiMmCommunicateHeaderV3Guid
[Depex]
- gEfiMmCommunication2ProtocolGuid
+ gEfiMmCommunication2ProtocolGuid OR gEfiMmCommunication3ProtocolGuid
[UserExtensions.TianoCore."ExtraFiles"]
VariableSmmRuntimeDxeExtra.uni
|