From 5175a329de08b2f83867aa523177d887cd316c70 Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Sat, 17 Sep 2022 14:00:46 +0200 Subject: [PATCH 01/11] .gitmodules: fix cmocka URL Signed-off-by: Krystian Hebel --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index b30f5bf136bc..e517c704e54a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,4 +6,4 @@ url = https://github.com/ucb-bar/berkeley-softfloat-3.git [submodule "UnitTestFrameworkPkg/Library/CmockaLib/cmocka"] path = UnitTestFrameworkPkg/Library/CmockaLib/cmocka - url = https://git.cryptomilk.org/projects/cmocka.git + url = https://github.com/tianocore/edk2-cmocka.git From c829579ac9a182c8733aecc0c97321e562eec69f Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Sat, 17 Sep 2022 14:13:50 +0200 Subject: [PATCH 02/11] rename UefiPayloadPkgIa32X64.dsc -> UefiPayloadPkg.dsc Signed-off-by: Krystian Hebel --- ...yloadPkgIa32X64.dsc => UefiPayloadPkg.dsc} | 1494 ++++++++--------- 1 file changed, 747 insertions(+), 747 deletions(-) rename UefiPayloadPkg/{UefiPayloadPkgIa32X64.dsc => UefiPayloadPkg.dsc} (97%) diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc similarity index 97% rename from UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc rename to UefiPayloadPkg/UefiPayloadPkg.dsc index 4c5bf2613e49..3173456ce640 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -1,747 +1,747 @@ -## @file -# Bootloader Payload Package -# -# Provides drivers and definitions to create uefi payload for bootloaders. -# -# Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: BSD-2-Clause-Patent -# -## - -################################################################################ -# -# Defines Section - statements that will be processed to create a Makefile. -# -################################################################################ -[Defines] - PLATFORM_NAME = UefiPayloadPkg - PLATFORM_GUID = F71608AB-D63D-4491-B744-A99998C8CD96 - PLATFORM_VERSION = 0.1 - DSC_SPECIFICATION = 0x00010005 - SUPPORTED_ARCHITECTURES = IA32|X64 - BUILD_TARGETS = DEBUG|RELEASE|NOOPT - SKUID_IDENTIFIER = DEFAULT - OUTPUT_DIRECTORY = Build/UefiPayloadPkgX64 - FLASH_DEFINITION = UefiPayloadPkg/UefiPayloadPkg.fdf - - DEFINE SOURCE_DEBUG_ENABLE = FALSE - DEFINE PS2_KEYBOARD_ENABLE = TRUE - - # - # SBL: UEFI payload for Slim Bootloader - # COREBOOT: UEFI payload for coreboot - # - DEFINE BOOTLOADER = SBL - - # - # CPU options - # - DEFINE MAX_LOGICAL_PROCESSORS = 64 - - # - # Serial port set up - # - DEFINE BAUD_RATE = 115200 - DEFINE SERIAL_CLOCK_RATE = 1843200 - DEFINE SERIAL_LINE_CONTROL = 3 # 8-bits, no parity - DEFINE SERIAL_HARDWARE_FLOW_CONTROL = FALSE - DEFINE SERIAL_DETECT_CABLE = FALSE - DEFINE SERIAL_FIFO_CONTROL = 7 # Enable FIFO - DEFINE SERIAL_EXTENDED_TX_FIFO_SIZE = 16 - DEFINE UART_DEFAULT_BAUD_RATE = $(BAUD_RATE) - DEFINE UART_DEFAULT_DATA_BITS = 8 - DEFINE UART_DEFAULT_PARITY = 1 - DEFINE UART_DEFAULT_STOP_BITS = 1 - DEFINE DEFAULT_TERMINAL_TYPE = 0 - - # Enabling the serial terminal will slow down the boot menu redering! - DEFINE SERIAL_TERMINAL = FALSE - - # - # typedef struct { - # UINT16 VendorId; ///< Vendor ID to match the PCI device. The value 0xFFFF terminates the list of entries. - # UINT16 DeviceId; ///< Device ID to match the PCI device - # UINT32 ClockRate; ///< UART clock rate. Set to 0 for default clock rate of 1843200 Hz - # UINT64 Offset; ///< The byte offset into to the BAR - # UINT8 BarIndex; ///< Which BAR to get the UART base address - # UINT8 RegisterStride; ///< UART register stride in bytes. Set to 0 for default register stride of 1 byte. - # UINT16 ReceiveFifoDepth; ///< UART receive FIFO depth in bytes. Set to 0 for a default FIFO depth of 16 bytes. - # UINT16 TransmitFifoDepth; ///< UART transmit FIFO depth in bytes. Set to 0 for a default FIFO depth of 16 bytes. - # UINT8 Reserved[2]; - # } PCI_SERIAL_PARAMETER; - # - # Vendor FFFF Device 0000 Prog Interface 1, BAR #0, Offset 0, Stride = 1, Clock 1843200 (0x1c2000) - # - # [Vendor] [Device] [----ClockRate---] [------------Offset-----------] [Bar] [Stride] [RxFifo] [TxFifo] [Rsvd] [Vendor] - DEFINE PCI_SERIAL_PARAMETERS = {0xff,0xff, 0x00,0x00, 0x0,0x20,0x1c,0x00, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x00, 0x01, 0x0,0x0, 0x0,0x0, 0x0,0x0, 0xff,0xff} - - # - # Shell options: [BUILD_SHELL, MIN_BIN, NONE, UEFI_BIN] - # - DEFINE SHELL_TYPE = BUILD_SHELL - - # - # Security options: - # - DEFINE SECURE_BOOT_ENABLE = FALSE - DEFINE TPM_ENABLE = TRUE - - # - # Network definition - # - DEFINE NETWORK_PXE_BOOT = FALSE - DEFINE NETWORK_ENABLE = FALSE - DEFINE NETWORK_TLS_ENABLE = FALSE - DEFINE NETWORK_IP6_ENABLE = FALSE - DEFINE NETWORK_IP4_ENABLE = TRUE - DEFINE NETWORK_INTEL_10GBE = FALSE - DEFINE NETWORK_INTEL_PRO1000 = FALSE - DEFINE NETWORK_INTEL_40GBE = FALSE - DEFINE NETWORK_INTEL_GBE = FALSE - -!if $(NETWORK_PXE_BOOT) == TRUE - DEFINE NETWORK_SNP_ENABLE = TRUE - DEFINE NETWORK_HTTP_BOOT_ENABLE = FALSE - DEFINE NETWORK_ISCSI_ENABLE = FALSE -!else - DEFINE NETWORK_SNP_ENABLE = FALSE - DEFINE NETWORK_HTTP_BOOT_ENABLE = TRUE - DEFINE NETWORK_ALLOW_HTTP_CONNECTIONS = TRUE - DEFINE NETWORK_ISCSI_ENABLE = TRUE -!endif - - -!include NetworkPkg/NetworkDefines.dsc.inc - # - # IPXE support - # - DEFINE NETWORK_IPXE = FALSE - -[BuildOptions] - *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES - GCC:*_UNIXGCC_*_CC_FLAGS = -DMDEPKG_NDEBUG - GCC:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG - INTEL:RELEASE_*_*_CC_FLAGS = /D MDEPKG_NDEBUG - MSFT:RELEASE_*_*_CC_FLAGS = /D MDEPKG_NDEBUG - - -################################################################################ -# -# SKU Identification section - list of all SKU IDs supported by this Platform. -# -################################################################################ -[SkuIds] - 0|DEFAULT - -################################################################################ -# -# Library Class section - list of all Library Classes needed by this Platform. -# -################################################################################ -[LibraryClasses] - # - # Entry point - # - PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf - PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf - DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf - UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf - UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf - - # - # Basic - # - BaseLib|MdePkg/Library/BaseLib/BaseLib.inf - BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf - SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf - PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf - CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf - IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf - PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf - PciLib|UefiPayloadPkg/Library/BasePciLibPciExpress/BasePciLibPciExpress.inf - PciExpressLib|UefiPayloadPkg/Library/BasePciExpressLib/BasePciExpressLib.inf - PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf - PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf - PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf - CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf - - # - # UEFI & PI - # - UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf - UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf - UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf - UefiLib|MdePkg/Library/UefiLib/UefiLib.inf - UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf - HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf - DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf - UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf - PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf - PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf - DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf - DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf - UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf - SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf - - # - # Generic Modules - # - UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf - UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf - OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf - CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf - SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf - UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf - BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf - CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf - FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf - - # - # CPU - # - MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf - LocalApicLib|UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf - - # - # Platform - # - TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf - ResetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf - SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf - PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf - PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf - IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf - - # - # Misc - # - DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf - PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf -!if $(SOURCE_DEBUG_ENABLE) == TRUE - PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf - DebugCommunicationLib|SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf -!else - PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf - DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf -!endif - PlatformSupportLib|UefiPayloadPkg/Library/PlatformSupportLibNull/PlatformSupportLibNull.inf -!if $(BOOTLOADER) == "COREBOOT" - BlParseLib|UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf -!else - BlParseLib|UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf -!endif - - DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf - LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf - FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf - TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf - VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf - - IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf - ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf - -# -# Network -# -!include NetworkPkg/NetworkLibs.dsc.inc -!if $(NETWORK_TLS_ENABLE) == TRUE - OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf - TlsLib|CryptoPkg/Library/TlsLib/TlsLib.inf -!else - OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf -!endif - -!if $(SECURE_BOOT_ENABLE) == TRUE - PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf - AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf -!else - AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf -!endif -!if $(BOOTLOADER) == "COREBOOT" - SmmStoreLib|UefiPayloadPkg/Library/CbSMMStoreLib/CbSMMStoreLib.inf -!else - SmmStoreLib|UefiPayloadPkg/Library/SblSMMStoreLib/SblSMMStoreLib.inf -!endif - -!if $(TPM_ENABLE) == TRUE - Tpm12CommandLib|SecurityPkg/Library/Tpm12CommandLib/Tpm12CommandLib.inf - Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf - Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf - Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf - TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf -!endif - -[LibraryClasses.IA32.SEC] - DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf - PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf - HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf - MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf - DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf - ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf - -[LibraryClasses.IA32.PEI_CORE, LibraryClasses.IA32.PEIM] - PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf - HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf - PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf - MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf - ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf - ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf -!if $(SOURCE_DEBUG_ENABLE) - DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf -!endif - -[LibraryClasses.common.PEIM] -!if $(TPM_ENABLE) == TRUE - BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf - Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12DeviceLibDTpm.inf - Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf -!endif - -[LibraryClasses.common.DXE_CORE] - PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf - HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf - MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf - ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf - ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf -!if $(SOURCE_DEBUG_ENABLE) - DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf -!endif - CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf - BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf - -[LibraryClasses.common.DXE_DRIVER] - PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf - MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf - ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf - ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf -!if $(SOURCE_DEBUG_ENABLE) - DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf -!endif - CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf - MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf - BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf - SmbusLib|MdePkg/Library/DxeSmbusLib/DxeSmbusLib.inf - -[LibraryClasses.common.DXE_RUNTIME_DRIVER] - PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf - MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf - ReportStatusCodeLib|MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeReportStatusCodeLib.inf - BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf - SmbusLib|MdePkg/Library/DxeSmbusLib/DxeSmbusLib.inf - -[LibraryClasses.common.UEFI_DRIVER,LibraryClasses.common.UEFI_APPLICATION] - PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf - ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf - HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf -!if $(NETWORK_ENABLE) == TRUE - BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf -!endif -################################################################################ -# -# Pcd Section - list of all EDK II PCD Entries defined by this Platform. -# -################################################################################ -[PcdsFeatureFlag] -!if $(TARGET) == DEBUG - gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|TRUE -!else - gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|FALSE -!endif - gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory|FALSE - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|TRUE - gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE - gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|FALSE - -[PcdsFixedAtBuild] - # UEFI spec: Minimal value is 0x8000! - gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8000 - gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x8800 - gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize|0x8000 - gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x10000 - gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0 - gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable|TRUE - gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 } - -!if $(SOURCE_DEBUG_ENABLE) - gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod|0x2 -!endif - -[PcdsPatchableInModule.common] - gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x7 - gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F -!if $(SOURCE_DEBUG_ENABLE) - gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17 -!else - gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F -!endif - - # - # Network Pcds - # -!include NetworkPkg/NetworkPcds.dsc.inc - - # - # The following parameters are set by Library/PlatformHookLib - # - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|FALSE - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x3f8 - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate|$(BAUD_RATE) - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride|1 - - # - # Enable these parameters to be set on the command line - # - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|$(SERIAL_CLOCK_RATE) - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl|$(SERIAL_LINE_CONTROL) - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl|$(SERIAL_HARDWARE_FLOW_CONTROL) - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable|$(SERIAL_DETECT_CABLE) - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl|$(SERIAL_FIFO_CONTROL) - gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize|$(SERIAL_EXTENDED_TX_FIFO_SIZE) - - gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|TRUE - gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|$(UART_DEFAULT_BAUD_RATE) - gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits|$(UART_DEFAULT_DATA_BITS) - gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity|$(UART_DEFAULT_PARITY) - gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits|$(UART_DEFAULT_STOP_BITS) - gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|$(DEFAULT_TERMINAL_TYPE) - gEfiMdeModulePkgTokenSpaceGuid.PcdPciSerialParameters|$(PCI_SERIAL_PARAMETERS) - - gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|$(MAX_LOGICAL_PROCESSORS) - - -################################################################################ -# -# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform -# -################################################################################ - -[PcdsDynamicDefault] - gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0 - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0 - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0 - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0 - gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|2 - gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable|FALSE - - ## This PCD defines the video horizontal resolution. - # This PCD could be set to 0 then video resolution could be at highest resolution. - gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|0 - ## This PCD defines the video vertical resolution. - # This PCD could be set to 0 then video resolution could be at highest resolution. - gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|0 - - ## The PCD is used to specify the video horizontal resolution of text setup. - gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution|0 - ## The PCD is used to specify the video vertical resolution of text setup. - gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution|0 - - gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow|31 - gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn|100 - - gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid|{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} - -################################################################################ -# -# Components Section - list of all EDK II Modules needed by this Platform. -# -################################################################################ -[Components.IA32] - # - # SEC Core - # - UefiPayloadPkg/SecCore/SecCore.inf - - # - # PEI Core - # - MdeModulePkg/Core/Pei/PeiMain.inf - - # - # PEIM - # - MdeModulePkg/Universal/PCD/Pei/Pcd.inf { - - PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf - } - MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf - MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf - - UefiPayloadPkg/BlSupportPei/BlSupportPei.inf - MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf - -!if $(TPM_ENABLE) == TRUE - UefiPayloadPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf - SecurityPkg/Tcg/TcgPei/TcgPei.inf - SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { - - HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf - NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf - NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf - NULL|SecurityPkg/Library/HashInstanceLibSha384/HashInstanceLibSha384.inf - NULL|SecurityPkg/Library/HashInstanceLibSha512/HashInstanceLibSha512.inf - NULL|SecurityPkg/Library/HashInstanceLibSm3/HashInstanceLibSm3.inf - } -!endif - -[Components.X64] - # - # DXE Core - # - MdeModulePkg/Core/Dxe/DxeMain.inf { - - NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf - } - - # - # Components that produce the architectural protocols - # - MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf { - -!if $(SECURE_BOOT_ENABLE) == TRUE - NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf -!endif -!if $(TPM_ENABLE) == TRUE - NULL|SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.inf - NULL|SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf -!endif - } - -!if $(SECURE_BOOT_ENABLE) == TRUE - SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf - OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.inf - UefiPayloadPkg/SecureBootEnrollDefaultKeys/SecureBootSetup.inf -!endif - - UefiCpuPkg/CpuDxe/CpuDxe.inf - MdeModulePkg/Universal/BdsDxe/BdsDxe.inf - MdeModulePkg/Logo/LogoDxe.inf - MdeModulePkg/Application/UiApp/UiApp.inf { - - NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf - NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf - NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf - } - - PcAtChipsetPkg/HpetTimerDxe/HpetTimerDxe.inf - MdeModulePkg/Universal/Metronome/Metronome.inf - MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf - MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf - MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf - MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf - MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf - PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf - MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { - - NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf - } - - # - # Following are the DXE drivers - # - MdeModulePkg/Universal/PCD/Dxe/Pcd.inf { - - PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf - } - - MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf - MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf - UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf - MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf - MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf - MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf - MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf - MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf - - UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf - - # - # SMBIOS Support - # - MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf - - # - # ACPI Support - # - MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf - - # - # PCI Support - # - MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf - MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf { - - PciHostBridgeLib|UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf - } - - # - # SCSI/ATA/IDE/DISK Support - # - MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf - MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf - MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf - FatPkg/EnhancedFatDxe/Fat.inf - MdeModulePkg/Bus/Pci/SataControllerDxe/SataControllerDxe.inf - MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf - MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf - MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf - MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf - MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf - - # - # SD/eMMC Support - # - MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf - MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.inf - MdeModulePkg/Bus/Sd/SdDxe/SdDxe.inf - - # - # Usb Support - # - MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf - MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf - MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf - MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf - MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf - - # - # ISA Support - # - MdeModulePkg/Universal/SerialDxe/SerialDxe.inf -!if $(PS2_KEYBOARD_ENABLE) == TRUE - OvmfPkg/SioBusDxe/SioBusDxe.inf - MdeModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KeyboardDxe.inf -!endif - - # - # Console Support - # - MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf - MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf -!if $(SERIAL_TERMINAL) == TRUE - MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf -!endif - UefiPayloadPkg/GraphicsOutputDxe/GraphicsOutputDxe.inf - UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf - - # - # SMMSTORE - # -!if $(BOOTLOADER) == "COREBOOT" - UefiPayloadPkg/BlSMMStoreDxe/BlSMMStoreDxe.inf -!endif - - # - # Network Support - # -!include NetworkPkg/NetworkComponents.dsc.inc - -!if $(NETWORK_TLS_ENABLE) == TRUE - NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf { - - NULL|OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.inf - } -!endif - - # - # Random Number Generator - # - SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf { - - RngLib|UefiPayloadPkg/Library/BaseRngLib/BaseRngLib.inf - } - -!if $(TPM_ENABLE) == TRUE - SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf { - - Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf - NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf - HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf - NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf - NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf - NULL|SecurityPkg/Library/HashInstanceLibSha384/HashInstanceLibSha384.inf - NULL|SecurityPkg/Library/HashInstanceLibSha512/HashInstanceLibSha512.inf - NULL|SecurityPkg/Library/HashInstanceLibSm3/HashInstanceLibSm3.inf - } - SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDxe.inf { - - Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf - } - SecurityPkg/Tcg/TcgDxe/TcgDxe.inf { - - Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12DeviceLibDTpm.inf - } -!endif - - #------------------------------ - # Build the shell - #------------------------------ - -!if $(SHELL_TYPE) == BUILD_SHELL - - # - # Shell Lib - # -[LibraryClasses] - BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf - DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf - FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf - ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf - -[Components.X64] - ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf { - - ## This flag is used to control initialization of the shell library - # This should be FALSE for compiling the dynamic command. - gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE - } - ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.inf { - - ## This flag is used to control initialization of the shell library - # This should be FALSE for compiling the dynamic command. - gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE - } - ShellPkg/Application/Shell/Shell.inf { - - ## This flag is used to control initialization of the shell library - # This should be FALSE for compiling the shell application itself only. - gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE - - #------------------------------ - # Basic commands - #------------------------------ - - - NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf - NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf - NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf - NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf - NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf - NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf - - #------------------------------ - # Networking commands - #------------------------------ - - - NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf - - #------------------------------ - # Support libraries - #------------------------------ - - - DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf - DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf - HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf - PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf - ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf - SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf - } -!endif +## @file +# Bootloader Payload Package +# +# Provides drivers and definitions to create uefi payload for bootloaders. +# +# Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +################################################################################ +# +# Defines Section - statements that will be processed to create a Makefile. +# +################################################################################ +[Defines] + PLATFORM_NAME = UefiPayloadPkg + PLATFORM_GUID = F71608AB-D63D-4491-B744-A99998C8CD96 + PLATFORM_VERSION = 0.1 + DSC_SPECIFICATION = 0x00010005 + SUPPORTED_ARCHITECTURES = IA32|X64 + BUILD_TARGETS = DEBUG|RELEASE|NOOPT + SKUID_IDENTIFIER = DEFAULT + OUTPUT_DIRECTORY = Build/UefiPayloadPkgX64 + FLASH_DEFINITION = UefiPayloadPkg/UefiPayloadPkg.fdf + + DEFINE SOURCE_DEBUG_ENABLE = FALSE + DEFINE PS2_KEYBOARD_ENABLE = TRUE + + # + # SBL: UEFI payload for Slim Bootloader + # COREBOOT: UEFI payload for coreboot + # + DEFINE BOOTLOADER = SBL + + # + # CPU options + # + DEFINE MAX_LOGICAL_PROCESSORS = 64 + + # + # Serial port set up + # + DEFINE BAUD_RATE = 115200 + DEFINE SERIAL_CLOCK_RATE = 1843200 + DEFINE SERIAL_LINE_CONTROL = 3 # 8-bits, no parity + DEFINE SERIAL_HARDWARE_FLOW_CONTROL = FALSE + DEFINE SERIAL_DETECT_CABLE = FALSE + DEFINE SERIAL_FIFO_CONTROL = 7 # Enable FIFO + DEFINE SERIAL_EXTENDED_TX_FIFO_SIZE = 16 + DEFINE UART_DEFAULT_BAUD_RATE = $(BAUD_RATE) + DEFINE UART_DEFAULT_DATA_BITS = 8 + DEFINE UART_DEFAULT_PARITY = 1 + DEFINE UART_DEFAULT_STOP_BITS = 1 + DEFINE DEFAULT_TERMINAL_TYPE = 0 + + # Enabling the serial terminal will slow down the boot menu redering! + DEFINE SERIAL_TERMINAL = FALSE + + # + # typedef struct { + # UINT16 VendorId; ///< Vendor ID to match the PCI device. The value 0xFFFF terminates the list of entries. + # UINT16 DeviceId; ///< Device ID to match the PCI device + # UINT32 ClockRate; ///< UART clock rate. Set to 0 for default clock rate of 1843200 Hz + # UINT64 Offset; ///< The byte offset into to the BAR + # UINT8 BarIndex; ///< Which BAR to get the UART base address + # UINT8 RegisterStride; ///< UART register stride in bytes. Set to 0 for default register stride of 1 byte. + # UINT16 ReceiveFifoDepth; ///< UART receive FIFO depth in bytes. Set to 0 for a default FIFO depth of 16 bytes. + # UINT16 TransmitFifoDepth; ///< UART transmit FIFO depth in bytes. Set to 0 for a default FIFO depth of 16 bytes. + # UINT8 Reserved[2]; + # } PCI_SERIAL_PARAMETER; + # + # Vendor FFFF Device 0000 Prog Interface 1, BAR #0, Offset 0, Stride = 1, Clock 1843200 (0x1c2000) + # + # [Vendor] [Device] [----ClockRate---] [------------Offset-----------] [Bar] [Stride] [RxFifo] [TxFifo] [Rsvd] [Vendor] + DEFINE PCI_SERIAL_PARAMETERS = {0xff,0xff, 0x00,0x00, 0x0,0x20,0x1c,0x00, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x00, 0x01, 0x0,0x0, 0x0,0x0, 0x0,0x0, 0xff,0xff} + + # + # Shell options: [BUILD_SHELL, MIN_BIN, NONE, UEFI_BIN] + # + DEFINE SHELL_TYPE = BUILD_SHELL + + # + # Security options: + # + DEFINE SECURE_BOOT_ENABLE = FALSE + DEFINE TPM_ENABLE = TRUE + + # + # Network definition + # + DEFINE NETWORK_PXE_BOOT = FALSE + DEFINE NETWORK_ENABLE = FALSE + DEFINE NETWORK_TLS_ENABLE = FALSE + DEFINE NETWORK_IP6_ENABLE = FALSE + DEFINE NETWORK_IP4_ENABLE = TRUE + DEFINE NETWORK_INTEL_10GBE = FALSE + DEFINE NETWORK_INTEL_PRO1000 = FALSE + DEFINE NETWORK_INTEL_40GBE = FALSE + DEFINE NETWORK_INTEL_GBE = FALSE + +!if $(NETWORK_PXE_BOOT) == TRUE + DEFINE NETWORK_SNP_ENABLE = TRUE + DEFINE NETWORK_HTTP_BOOT_ENABLE = FALSE + DEFINE NETWORK_ISCSI_ENABLE = FALSE +!else + DEFINE NETWORK_SNP_ENABLE = FALSE + DEFINE NETWORK_HTTP_BOOT_ENABLE = TRUE + DEFINE NETWORK_ALLOW_HTTP_CONNECTIONS = TRUE + DEFINE NETWORK_ISCSI_ENABLE = TRUE +!endif + + +!include NetworkPkg/NetworkDefines.dsc.inc + # + # IPXE support + # + DEFINE NETWORK_IPXE = FALSE + +[BuildOptions] + *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES + GCC:*_UNIXGCC_*_CC_FLAGS = -DMDEPKG_NDEBUG + GCC:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG + INTEL:RELEASE_*_*_CC_FLAGS = /D MDEPKG_NDEBUG + MSFT:RELEASE_*_*_CC_FLAGS = /D MDEPKG_NDEBUG + + +################################################################################ +# +# SKU Identification section - list of all SKU IDs supported by this Platform. +# +################################################################################ +[SkuIds] + 0|DEFAULT + +################################################################################ +# +# Library Class section - list of all Library Classes needed by this Platform. +# +################################################################################ +[LibraryClasses] + # + # Entry point + # + PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf + PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf + DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf + UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf + UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf + + # + # Basic + # + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf + SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf + IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf + PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf + PciLib|UefiPayloadPkg/Library/BasePciLibPciExpress/BasePciLibPciExpress.inf + PciExpressLib|UefiPayloadPkg/Library/BasePciExpressLib/BasePciExpressLib.inf + PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf + PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf + PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf + CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf + + # + # UEFI & PI + # + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf + UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf + HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf + PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf + PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf + DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf + UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + + # + # Generic Modules + # + UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf + UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf + OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf + CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf + SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf + BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf + CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf + FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf + + # + # CPU + # + MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf + LocalApicLib|UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf + + # + # Platform + # + TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf + ResetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf + SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf + PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf + PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf + IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf + + # + # Misc + # + DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf + PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf +!if $(SOURCE_DEBUG_ENABLE) == TRUE + PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf + DebugCommunicationLib|SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf +!else + PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf + DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf +!endif + PlatformSupportLib|UefiPayloadPkg/Library/PlatformSupportLibNull/PlatformSupportLibNull.inf +!if $(BOOTLOADER) == "COREBOOT" + BlParseLib|UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf +!else + BlParseLib|UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf +!endif + + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf + LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf + TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf + VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf + + IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf + ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf + +# +# Network +# +!include NetworkPkg/NetworkLibs.dsc.inc +!if $(NETWORK_TLS_ENABLE) == TRUE + OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf + TlsLib|CryptoPkg/Library/TlsLib/TlsLib.inf +!else + OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf +!endif + +!if $(SECURE_BOOT_ENABLE) == TRUE + PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf + AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf +!else + AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf +!endif +!if $(BOOTLOADER) == "COREBOOT" + SmmStoreLib|UefiPayloadPkg/Library/CbSMMStoreLib/CbSMMStoreLib.inf +!else + SmmStoreLib|UefiPayloadPkg/Library/SblSMMStoreLib/SblSMMStoreLib.inf +!endif + +!if $(TPM_ENABLE) == TRUE + Tpm12CommandLib|SecurityPkg/Library/Tpm12CommandLib/Tpm12CommandLib.inf + Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf + Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf + TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf +!endif + +[LibraryClasses.IA32.SEC] + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf + MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf + DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf + ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf + +[LibraryClasses.IA32.PEI_CORE, LibraryClasses.IA32.PEIM] + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf + ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf +!if $(SOURCE_DEBUG_ENABLE) + DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf +!endif + +[LibraryClasses.common.PEIM] +!if $(TPM_ENABLE) == TRUE + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf + Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12DeviceLibDTpm.inf + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf +!endif + +[LibraryClasses.common.DXE_CORE] + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf + MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf + ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf +!if $(SOURCE_DEBUG_ENABLE) + DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf +!endif + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + +[LibraryClasses.common.DXE_DRIVER] + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf +!if $(SOURCE_DEBUG_ENABLE) + DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf +!endif + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + SmbusLib|MdePkg/Library/DxeSmbusLib/DxeSmbusLib.inf + +[LibraryClasses.common.DXE_RUNTIME_DRIVER] + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeReportStatusCodeLib.inf + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf + SmbusLib|MdePkg/Library/DxeSmbusLib/DxeSmbusLib.inf + +[LibraryClasses.common.UEFI_DRIVER,LibraryClasses.common.UEFI_APPLICATION] + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf +!if $(NETWORK_ENABLE) == TRUE + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf +!endif +################################################################################ +# +# Pcd Section - list of all EDK II PCD Entries defined by this Platform. +# +################################################################################ +[PcdsFeatureFlag] +!if $(TARGET) == DEBUG + gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|TRUE +!else + gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|FALSE +!endif + gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory|FALSE + gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|FALSE + +[PcdsFixedAtBuild] + # UEFI spec: Minimal value is 0x8000! + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8000 + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x8800 + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize|0x8000 + gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x10000 + gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0 + gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable|TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 } + +!if $(SOURCE_DEBUG_ENABLE) + gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod|0x2 +!endif + +[PcdsPatchableInModule.common] + gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x7 + gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F +!if $(SOURCE_DEBUG_ENABLE) + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17 +!else + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F +!endif + + # + # Network Pcds + # +!include NetworkPkg/NetworkPcds.dsc.inc + + # + # The following parameters are set by Library/PlatformHookLib + # + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|FALSE + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x3f8 + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate|$(BAUD_RATE) + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride|1 + + # + # Enable these parameters to be set on the command line + # + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|$(SERIAL_CLOCK_RATE) + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl|$(SERIAL_LINE_CONTROL) + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl|$(SERIAL_HARDWARE_FLOW_CONTROL) + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable|$(SERIAL_DETECT_CABLE) + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl|$(SERIAL_FIFO_CONTROL) + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize|$(SERIAL_EXTENDED_TX_FIFO_SIZE) + + gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|TRUE + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|$(UART_DEFAULT_BAUD_RATE) + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits|$(UART_DEFAULT_DATA_BITS) + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity|$(UART_DEFAULT_PARITY) + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits|$(UART_DEFAULT_STOP_BITS) + gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|$(DEFAULT_TERMINAL_TYPE) + gEfiMdeModulePkgTokenSpaceGuid.PcdPciSerialParameters|$(PCI_SERIAL_PARAMETERS) + + gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|$(MAX_LOGICAL_PROCESSORS) + + +################################################################################ +# +# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform +# +################################################################################ + +[PcdsDynamicDefault] + gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0 + gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|2 + gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable|FALSE + + ## This PCD defines the video horizontal resolution. + # This PCD could be set to 0 then video resolution could be at highest resolution. + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|0 + ## This PCD defines the video vertical resolution. + # This PCD could be set to 0 then video resolution could be at highest resolution. + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|0 + + ## The PCD is used to specify the video horizontal resolution of text setup. + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution|0 + ## The PCD is used to specify the video vertical resolution of text setup. + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution|0 + + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow|31 + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn|100 + + gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid|{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} + +################################################################################ +# +# Components Section - list of all EDK II Modules needed by this Platform. +# +################################################################################ +[Components.IA32] + # + # SEC Core + # + UefiPayloadPkg/SecCore/SecCore.inf + + # + # PEI Core + # + MdeModulePkg/Core/Pei/PeiMain.inf + + # + # PEIM + # + MdeModulePkg/Universal/PCD/Pei/Pcd.inf { + + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + } + MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf + MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf + + UefiPayloadPkg/BlSupportPei/BlSupportPei.inf + MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf + +!if $(TPM_ENABLE) == TRUE + UefiPayloadPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf + SecurityPkg/Tcg/TcgPei/TcgPei.inf + SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { + + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + NULL|SecurityPkg/Library/HashInstanceLibSha384/HashInstanceLibSha384.inf + NULL|SecurityPkg/Library/HashInstanceLibSha512/HashInstanceLibSha512.inf + NULL|SecurityPkg/Library/HashInstanceLibSm3/HashInstanceLibSm3.inf + } +!endif + +[Components.X64] + # + # DXE Core + # + MdeModulePkg/Core/Dxe/DxeMain.inf { + + NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf + } + + # + # Components that produce the architectural protocols + # + MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf { + +!if $(SECURE_BOOT_ENABLE) == TRUE + NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf +!endif +!if $(TPM_ENABLE) == TRUE + NULL|SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.inf + NULL|SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf +!endif + } + +!if $(SECURE_BOOT_ENABLE) == TRUE + SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf + OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.inf + UefiPayloadPkg/SecureBootEnrollDefaultKeys/SecureBootSetup.inf +!endif + + UefiCpuPkg/CpuDxe/CpuDxe.inf + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf + MdeModulePkg/Logo/LogoDxe.inf + MdeModulePkg/Application/UiApp/UiApp.inf { + + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf + } + + PcAtChipsetPkg/HpetTimerDxe/HpetTimerDxe.inf + MdeModulePkg/Universal/Metronome/Metronome.inf + MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf + MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf + MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf + MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf + MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf + PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf + MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { + + NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf + } + + # + # Following are the DXE drivers + # + MdeModulePkg/Universal/PCD/Dxe/Pcd.inf { + + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + } + + MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf + MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf + UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf + MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf + MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf + MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf + MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf + MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf + + UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf + + # + # SMBIOS Support + # + MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf + + # + # ACPI Support + # + MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf + + # + # PCI Support + # + MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf + MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf { + + PciHostBridgeLib|UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf + } + + # + # SCSI/ATA/IDE/DISK Support + # + MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf + MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf + MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf + FatPkg/EnhancedFatDxe/Fat.inf + MdeModulePkg/Bus/Pci/SataControllerDxe/SataControllerDxe.inf + MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf + MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf + MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf + MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf + MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf + + # + # SD/eMMC Support + # + MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf + MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.inf + MdeModulePkg/Bus/Sd/SdDxe/SdDxe.inf + + # + # Usb Support + # + MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf + MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf + MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf + MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf + MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf + MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf + + # + # ISA Support + # + MdeModulePkg/Universal/SerialDxe/SerialDxe.inf +!if $(PS2_KEYBOARD_ENABLE) == TRUE + OvmfPkg/SioBusDxe/SioBusDxe.inf + MdeModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KeyboardDxe.inf +!endif + + # + # Console Support + # + MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf + MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf + MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf +!if $(SERIAL_TERMINAL) == TRUE + MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf +!endif + UefiPayloadPkg/GraphicsOutputDxe/GraphicsOutputDxe.inf + UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf + + # + # SMMSTORE + # +!if $(BOOTLOADER) == "COREBOOT" + UefiPayloadPkg/BlSMMStoreDxe/BlSMMStoreDxe.inf +!endif + + # + # Network Support + # +!include NetworkPkg/NetworkComponents.dsc.inc + +!if $(NETWORK_TLS_ENABLE) == TRUE + NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf { + + NULL|OvmfPkg/Library/TlsAuthConfigLib/TlsAuthConfigLib.inf + } +!endif + + # + # Random Number Generator + # + SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf { + + RngLib|UefiPayloadPkg/Library/BaseRngLib/BaseRngLib.inf + } + +!if $(TPM_ENABLE) == TRUE + SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf { + + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf + NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + NULL|SecurityPkg/Library/HashInstanceLibSha384/HashInstanceLibSha384.inf + NULL|SecurityPkg/Library/HashInstanceLibSha512/HashInstanceLibSha512.inf + NULL|SecurityPkg/Library/HashInstanceLibSm3/HashInstanceLibSm3.inf + } + SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDxe.inf { + + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + } + SecurityPkg/Tcg/TcgDxe/TcgDxe.inf { + + Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12DeviceLibDTpm.inf + } +!endif + + #------------------------------ + # Build the shell + #------------------------------ + +!if $(SHELL_TYPE) == BUILD_SHELL + + # + # Shell Lib + # +[LibraryClasses] + BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + +[Components.X64] + ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf { + + ## This flag is used to control initialization of the shell library + # This should be FALSE for compiling the dynamic command. + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } + ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.inf { + + ## This flag is used to control initialization of the shell library + # This should be FALSE for compiling the dynamic command. + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } + ShellPkg/Application/Shell/Shell.inf { + + ## This flag is used to control initialization of the shell library + # This should be FALSE for compiling the shell application itself only. + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + + #------------------------------ + # Basic commands + #------------------------------ + + + NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf + NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf + NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf + NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf + NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf + NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf + + #------------------------------ + # Networking commands + #------------------------------ + + + NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf + + #------------------------------ + # Support libraries + #------------------------------ + + + DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf + ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + } +!endif From 0569d9b3c05bc4a500a30908cb3173a05d5d89ac Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Sat, 17 Sep 2022 17:19:15 +0200 Subject: [PATCH 03/11] UefiPayloadPkg/SkinitDxe: driver for detecting and reacting to SKINIT Signed-off-by: Krystian Hebel --- UefiPayloadPkg/SkinitDxe/SkinitDxe.c | 39 ++++++++++++++++++++++++++ UefiPayloadPkg/SkinitDxe/SkinitDxe.inf | 37 ++++++++++++++++++++++++ UefiPayloadPkg/UefiPayloadPkg.dsc | 2 ++ UefiPayloadPkg/UefiPayloadPkg.fdf | 2 ++ 4 files changed, 80 insertions(+) create mode 100644 UefiPayloadPkg/SkinitDxe/SkinitDxe.c create mode 100644 UefiPayloadPkg/SkinitDxe/SkinitDxe.inf diff --git a/UefiPayloadPkg/SkinitDxe/SkinitDxe.c b/UefiPayloadPkg/SkinitDxe/SkinitDxe.c new file mode 100644 index 000000000000..054b8d711ca2 --- /dev/null +++ b/UefiPayloadPkg/SkinitDxe/SkinitDxe.c @@ -0,0 +1,39 @@ +/** @file + + Copyright (c) 2022, 3mdeb Sp. z o.o.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +/* TODO: move this to external function, compilable by tools other than GCC */ +static void SetGIF(void) +{ + asm volatile ("stgi"); +} + +EFI_STATUS +EFIAPI +Entry ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + DEBUG ((DEBUG_INFO, "SKINIT Driver entry\n")); + + /* TODO: check if AMD and SKINIT available before reading MSR */ + UINT64 VmCr = AsmReadMsr64(0xc0010114); + + if (VmCr & (1 << 1)) { + DEBUG ((DEBUG_INFO, "SKINIT detected\n")); + SetGIF(); + /* TODO: install protocol/set PCD for later */ + return EFI_SUCCESS; + } + + DEBUG ((DEBUG_INFO, "SKINIT not detected\n")); + return EFI_UNSUPPORTED; +} diff --git a/UefiPayloadPkg/SkinitDxe/SkinitDxe.inf b/UefiPayloadPkg/SkinitDxe/SkinitDxe.inf new file mode 100644 index 000000000000..80f030054099 --- /dev/null +++ b/UefiPayloadPkg/SkinitDxe/SkinitDxe.inf @@ -0,0 +1,37 @@ +## @file +# Copyright (c) 2022, 3mdeb Sp. z o.o.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SkinitDxe + MODULE_UNI_FILE = SkinitDxe.uni + FILE_GUID = 0220091c-1ab7-47a2-ae63-d33be1811753 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = Entry + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 EBC +# +# + +[Sources] + SkinitDxe.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + PcdLib + IoLib + DebugLib + UefiDriverEntryPoint + BaseLib + +[Depex] + TRUE diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index 3173456ce640..46a4e8cf5eea 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -558,6 +558,8 @@ UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf + UefiPayloadPkg/SkinitDxe/SkinitDxe.inf + # # SMBIOS Support # diff --git a/UefiPayloadPkg/UefiPayloadPkg.fdf b/UefiPayloadPkg/UefiPayloadPkg.fdf index 52e72faedce6..7acb8cd65fa6 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.fdf +++ b/UefiPayloadPkg/UefiPayloadPkg.fdf @@ -84,6 +84,7 @@ APRIORI DXE { INF MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf INF MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf !if $(BOOTLOADER) == "COREBOOT" + INF UefiPayloadPkg/SkinitDxe/SkinitDxe.inf # Initialize VariableStore and update PCDs before VariableRuntimeDxe INF UefiPayloadPkg/BlSMMStoreDxe/BlSMMStoreDxe.inf !endif @@ -127,6 +128,7 @@ INF UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf INF MdeModulePkg/Logo/LogoDxe.inf !if $(BOOTLOADER) == "COREBOOT" +INF UefiPayloadPkg/SkinitDxe/SkinitDxe.inf INF UefiPayloadPkg/BlSMMStoreDxe/BlSMMStoreDxe.inf !endif From 528886ed51eff45842278840afd5d1fd5680e37a Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Sun, 18 Sep 2022 13:40:22 +0200 Subject: [PATCH 04/11] UefiPayloadPkg/IoMmuDxe: skeleton for IOMMU driver Signed-off-by: Krystian Hebel --- UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c | 630 ++++++++++++++++++++++++ UefiPayloadPkg/IoMmuDxe/AmdIoMmuDxe.inf | 40 ++ UefiPayloadPkg/UefiPayloadPkg.dsc | 1 + UefiPayloadPkg/UefiPayloadPkg.fdf | 2 + 4 files changed, 673 insertions(+) create mode 100644 UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c create mode 100644 UefiPayloadPkg/IoMmuDxe/AmdIoMmuDxe.inf diff --git a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c new file mode 100644 index 000000000000..6a1dce03991e --- /dev/null +++ b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c @@ -0,0 +1,630 @@ +/** @file + + The protocol provides support to allocate, free, map and umap a DMA buffer + for bus master (e.g PciHostBridge). + + Copyright (c) 2017, AMD Inc. All rights reserved.
+ Copyright (c) 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2022, 3mdeb Sp. z o.o.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include + +#define MAP_INFO_SIG SIGNATURE_64 ('M', 'A', 'P', '_', 'I', 'N', 'F', 'O') + +typedef struct { + UINT64 Signature; + LIST_ENTRY Link; + EDKII_IOMMU_OPERATION Operation; + UINTN NumberOfBytes; + UINTN NumberOfPages; + EFI_PHYSICAL_ADDRESS Address; +} MAP_INFO; + +// +// List of the MAP_INFO structures that have been set up by IoMmuMap() and not +// yet torn down by IoMmuUnmap(). The list represents the full set of mappings +// currently in effect. +// +STATIC LIST_ENTRY mMapInfos = INITIALIZE_LIST_HEAD_VARIABLE (mMapInfos); + +// +// ASCII names for EDKII_IOMMU_OPERATION constants, for debug logging. +// +STATIC CONST CHAR8 * CONST +mBusMasterOperationName[EdkiiIoMmuOperationMaximum] = { + "Read", + "Write", + "CommonBuffer", + "Read64", + "Write64", + "CommonBuffer64" +}; + +// +// The following structure enables Map() and Unmap() to perform in-place +// decryption and encryption, respectively, for BusMasterCommonBuffer[64] +// operations, without dynamic memory allocation or release. +// +// Both COMMON_BUFFER_HEADER and COMMON_BUFFER_HEADER.StashBuffer are allocated +// by AllocateBuffer() and released by FreeBuffer(). +// +#pragma pack (1) +typedef struct { + UINT64 Signature; + + // + // Always allocated from EfiBootServicesData type memory, and always + // encrypted. + // + VOID *StashBuffer; + + // + // Followed by the actual common buffer, starting at the next page. + // +} COMMON_BUFFER_HEADER; +#pragma pack () + +/** + Provides the controller-specific addresses required to access system memory + from a DMA bus master. + + @param This The protocol instance pointer. + @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 +EFIAPI +IoMmuMap ( + IN EDKII_IOMMU_PROTOCOL *This, + IN EDKII_IOMMU_OPERATION Operation, + IN VOID *HostAddress, + IN OUT UINTN *NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, + OUT VOID **Mapping + ) +{ + EFI_STATUS Status; + MAP_INFO *MapInfo; + + DEBUG (( + DEBUG_VERBOSE, + "%a: Operation=%a Host=0x%p Bytes=0x%Lx\n", + __FUNCTION__, + ((Operation >= 0 && + Operation < ARRAY_SIZE (mBusMasterOperationName)) ? + mBusMasterOperationName[Operation] : + "Invalid"), + HostAddress, + (UINT64)((NumberOfBytes == NULL) ? 0 : *NumberOfBytes) + )); + + if (HostAddress == NULL || NumberOfBytes == NULL || DeviceAddress == NULL || + Mapping == NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Allocate a MAP_INFO structure to remember the mapping when Unmap() is + // called later. + // + MapInfo = AllocatePool (sizeof (MAP_INFO)); + if (MapInfo == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Failed; + } + + // + // Initialize the MAP_INFO structure, except the PlainTextAddress field + // + ZeroMem (&MapInfo->Link, sizeof MapInfo->Link); + MapInfo->Signature = MAP_INFO_SIG; + MapInfo->Operation = Operation; + MapInfo->NumberOfBytes = *NumberOfBytes; + MapInfo->NumberOfPages = EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes); + MapInfo->Address = (UINTN)HostAddress; + + // + // Allocate the buffer. + // + Status = gBS->AllocatePages ( + AllocateAnyPages, + EfiBootServicesData, + MapInfo->NumberOfPages, + &MapInfo->Address + ); + if (EFI_ERROR (Status)) { + goto FreeMapInfo; + } + + // + // Track all MAP_INFO structures. + // + InsertHeadList (&mMapInfos, &MapInfo->Link); + // + // Populate output parameters. + // + *DeviceAddress = MapInfo->Address; + *Mapping = MapInfo; + + DEBUG (( + DEBUG_VERBOSE, + "%a: Mapping=0x%p Address=0x%Lx Pages=0x%Lx\n", + __FUNCTION__, + MapInfo, + MapInfo->Address, + (UINT64)MapInfo->NumberOfPages + )); + + return EFI_SUCCESS; + +FreeMapInfo: + FreePool (MapInfo); + +Failed: + *NumberOfBytes = 0; + return Status; +} + +/** + Completes the Map() operation and releases any corresponding resources. + + This is an internal worker function that only extends the Map() API with + the MemoryMapLocked parameter. + + @param This The protocol instance pointer. + @param Mapping The mapping value returned from Map(). + @param MemoryMapLocked The function is executing on the stack of + gBS->ExitBootServices(); changes to the UEFI + memory map are forbidden. + + @retval EFI_SUCCESS The range was unmapped. + @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by + Map(). + @retval EFI_DEVICE_ERROR The data was not committed to the target system + memory. +**/ +STATIC +EFI_STATUS +EFIAPI +IoMmuUnmapWorker ( + IN EDKII_IOMMU_PROTOCOL *This, + IN VOID *Mapping, + IN BOOLEAN MemoryMapLocked + ) +{ + MAP_INFO *MapInfo; + + DEBUG (( + DEBUG_VERBOSE, + "%a: Mapping=0x%p MemoryMapLocked=%d\n", + __FUNCTION__, + Mapping, + MemoryMapLocked + )); + + if (Mapping == NULL) { + return EFI_INVALID_PARAMETER; + } + + MapInfo = (MAP_INFO *)Mapping; + + // + // Forget the MAP_INFO structure, then free it (unless the UEFI memory map is + // locked). + // + RemoveEntryList (&MapInfo->Link); + if (!MemoryMapLocked) { + FreePool (MapInfo); + } + + return EFI_SUCCESS; +} + +/** + Completes the Map() operation and releases any corresponding resources. + + @param This The protocol instance pointer. + @param Mapping The mapping value returned from Map(). + + @retval EFI_SUCCESS The range was unmapped. + @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by + Map(). + @retval EFI_DEVICE_ERROR The data was not committed to the target system + memory. +**/ +EFI_STATUS +EFIAPI +IoMmuUnmap ( + IN EDKII_IOMMU_PROTOCOL *This, + IN VOID *Mapping + ) +{ + return IoMmuUnmapWorker ( + This, + Mapping, + FALSE // MemoryMapLocked + ); +} + +/** + Allocates pages that are suitable for an OperationBusMasterCommonBuffer or + OperationBusMasterCommonBuffer64 mapping. + + @param This The protocol instance pointer. + @param Type This parameter is not used and must be ignored. + @param MemoryType The type of memory to allocate, + EfiBootServicesData or EfiRuntimeServicesData. + @param Pages The number of pages to allocate. + @param HostAddress A pointer to store the base system memory + address of the allocated range. + @param Attributes The requested bit mask of attributes for the + allocated range. + + @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 +EFIAPI +IoMmuAllocateBuffer ( + IN EDKII_IOMMU_PROTOCOL *This, + IN EFI_ALLOCATE_TYPE Type, + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages, + IN OUT VOID **HostAddress, + IN UINT64 Attributes + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS PhysicalAddress; + + DEBUG (( + DEBUG_VERBOSE, + "%a: MemoryType=%u Pages=0x%Lx Attributes=0x%Lx\n", + __FUNCTION__, + (UINT32)MemoryType, + (UINT64)Pages, + Attributes + )); + + // + // Validate Attributes + // + if ((Attributes & EDKII_IOMMU_ATTRIBUTE_INVALID_FOR_ALLOCATE_BUFFER) != 0) { + return EFI_UNSUPPORTED; + } + + // + // Check for invalid inputs + // + if (HostAddress == NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // The only valid memory types are EfiBootServicesData and + // EfiRuntimeServicesData + // + if (MemoryType != EfiBootServicesData && + MemoryType != EfiRuntimeServicesData) { + return EFI_INVALID_PARAMETER; + } + + PhysicalAddress = (UINTN)-1; + if ((Attributes & EDKII_IOMMU_ATTRIBUTE_DUAL_ADDRESS_CYCLE) == 0) { + // + // Limit allocations to memory below 4GB + // + PhysicalAddress = SIZE_4GB - 1; + } + Status = gBS->AllocatePages ( + AllocateMaxAddress, + MemoryType, + Pages, + &PhysicalAddress + ); + if (EFI_ERROR (Status)) { + return Status; + } + + *HostAddress = (VOID *)(UINTN)PhysicalAddress; + + return EFI_SUCCESS; +} + +/** + Frees memory that was allocated with AllocateBuffer(). + + @param This The protocol instance pointer. + @param Pages The number of pages to free. + @param HostAddress The base system memory address of the allocated + range. + + @retval EFI_SUCCESS The requested memory pages were freed. + @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and + Pages was not allocated with AllocateBuffer(). + +**/ +EFI_STATUS +EFIAPI +IoMmuFreeBuffer ( + IN EDKII_IOMMU_PROTOCOL *This, + IN UINTN Pages, + IN VOID *HostAddress + ) +{ + + DEBUG (( + DEBUG_VERBOSE, + "%a: Host=0x%p Pages=0x%Lx\n", + __FUNCTION__, + HostAddress, + (UINT64)Pages + )); + + return gBS->FreePages ((UINTN)HostAddress, Pages); +} + + +/** + Set IOMMU attribute for a system memory. + + If the IOMMU protocol exists, the system memory cannot be used + for DMA by default. + + When a device requests a DMA access for a system memory, + the device driver need use SetAttribute() to update the IOMMU + attribute to request DMA access (read and/or write). + + The DeviceHandle is used to identify which device submits the request. + The IOMMU implementation need translate the device path to an IOMMU device + ID, and set IOMMU hardware register accordingly. + 1) DeviceHandle can be a standard PCI device. + The memory for BusMasterRead need set EDKII_IOMMU_ACCESS_READ. + The memory for BusMasterWrite need set EDKII_IOMMU_ACCESS_WRITE. + The memory for BusMasterCommonBuffer need set + EDKII_IOMMU_ACCESS_READ|EDKII_IOMMU_ACCESS_WRITE. + After the memory is used, the memory need set 0 to keep it being + protected. + 2) DeviceHandle can be an ACPI device (ISA, I2C, SPI, etc). + The memory for DMA access need set EDKII_IOMMU_ACCESS_READ and/or + EDKII_IOMMU_ACCESS_WRITE. + + @param[in] This The protocol instance pointer. + @param[in] DeviceHandle The device who initiates the DMA access + request. + @param[in] Mapping The mapping value returned from Map(). + @param[in] IoMmuAccess The IOMMU access. + + @retval EFI_SUCCESS The IoMmuAccess is set for the memory range + specified by DeviceAddress and Length. + @retval EFI_INVALID_PARAMETER DeviceHandle is an invalid handle. + @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by + Map(). + @retval EFI_INVALID_PARAMETER IoMmuAccess specified an illegal combination + of access. + @retval EFI_UNSUPPORTED DeviceHandle is unknown by the IOMMU. + @retval EFI_UNSUPPORTED The bit mask of IoMmuAccess is not supported + by the IOMMU. + @retval EFI_UNSUPPORTED The IOMMU does not support the memory range + specified by Mapping. + @retval EFI_OUT_OF_RESOURCES There are not enough resources available to + modify the IOMMU access. + @retval EFI_DEVICE_ERROR The IOMMU device reported an error while + attempting the operation. + +**/ +EFI_STATUS +EFIAPI +IoMmuSetAttribute ( + IN EDKII_IOMMU_PROTOCOL *This, + IN EFI_HANDLE DeviceHandle, + IN VOID *Mapping, + IN UINT64 IoMmuAccess + ) +{ + // + // TODO: this should be the function doing all the heavy lifting: + // - create page tables for mapping + // - convert DeviceHandle (UEFI) to DeviceID (IOMMU) + // - set IW/IR based on IoMmuAccess + // - flush IOMMU TLB + // + return EFI_UNSUPPORTED; +} + +EDKII_IOMMU_PROTOCOL mAmdIoMmu = { + EDKII_IOMMU_PROTOCOL_REVISION, + IoMmuSetAttribute, + IoMmuMap, + IoMmuUnmap, + IoMmuAllocateBuffer, + IoMmuFreeBuffer, +}; + +/** + Notification function that is queued when gBS->ExitBootServices() signals the + EFI_EVENT_GROUP_EXIT_BOOT_SERVICES event group. This function signals another + event, received as Context, and returns. + + Signaling an event in this context is safe. The UEFI spec allows + gBS->SignalEvent() to return EFI_SUCCESS only; EFI_OUT_OF_RESOURCES is not + listed, hence memory is not allocated. The edk2 implementation also does not + release memory (and we only have to care about the edk2 implementation + because EDKII_IOMMU_PROTOCOL is edk2-specific anyway). + + @param[in] Event Event whose notification function is being invoked. + Event is permitted to request the queueing of this + function at TPL_CALLBACK or TPL_NOTIFY task + priority level. + + @param[in] EventToSignal Identifies the EFI_EVENT to signal. EventToSignal + is permitted to request the queueing of its + notification function only at TPL_CALLBACK level. +**/ +STATIC +VOID +EFIAPI +AmdIoMmuExitBoot ( + IN EFI_EVENT Event, + IN VOID *EventToSignal + ) +{ + DEBUG ((DEBUG_VERBOSE, "%a\n", __FUNCTION__)); + // + // TODO: dump IOMMU log + // + gBS->SignalEvent (EventToSignal); +} + +/** + Notification function that is queued after the notification functions of all + events in the EFI_EVENT_GROUP_EXIT_BOOT_SERVICES event group. The same memory + map restrictions apply. + + This function unmaps all currently existing IOMMU mappings. + + @param[in] Event Event whose notification function is being invoked. Event + is permitted to request the queueing of this function + only at TPL_CALLBACK task priority level. + + @param[in] Context Ignored. +**/ +STATIC +VOID +EFIAPI +AmdIoMmuUnmapAllMappings ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + LIST_ENTRY *Node; + LIST_ENTRY *NextNode; + MAP_INFO *MapInfo; + + DEBUG ((DEBUG_VERBOSE, "%a\n", __FUNCTION__)); + + // + // All drivers that had set up IOMMU mappings have halted their respective + // controllers by now; tear down the mappings. + // + for (Node = GetFirstNode (&mMapInfos); Node != &mMapInfos; Node = NextNode) { + NextNode = GetNextNode (&mMapInfos, Node); + MapInfo = CR (Node, MAP_INFO, Link, MAP_INFO_SIG); + IoMmuUnmapWorker ( + &mAmdIoMmu, // This + MapInfo, // Mapping + TRUE // MemoryMapLocked + ); + } +} + +/** + Initialize Iommu Protocol. + +**/ +EFI_STATUS +EFIAPI +AmdInstallIoMmuProtocol ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT UnmapAllMappingsEvent; + EFI_EVENT ExitBootEvent; + EFI_HANDLE Handle; + + // + // TODO: allocate and initialize IOMMU data structures: + // - device table + // - command buffer + // - I/O page tables (or leave it to IoMmuSetAttribute() maybe?) + // - event log + // - interrupt remapping tables (probably can be skipped?) + // - peripheral page request log (probably can be skipped?) + // + + // + // Create the "late" event whose notification function will tear down all + // left-over IOMMU mappings. + // + Status = gBS->CreateEvent ( + EVT_NOTIFY_SIGNAL, // Type + TPL_CALLBACK, // NotifyTpl + AmdIoMmuUnmapAllMappings, // NotifyFunction + NULL, // NotifyContext + &UnmapAllMappingsEvent // Event + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Create the event whose notification function will be queued by + // gBS->ExitBootServices() and will signal the event created above. + // + Status = gBS->CreateEvent ( + EVT_SIGNAL_EXIT_BOOT_SERVICES, // Type + TPL_CALLBACK, // NotifyTpl + AmdIoMmuExitBoot, // NotifyFunction + UnmapAllMappingsEvent, // NotifyContext + &ExitBootEvent // Event + ); + if (EFI_ERROR (Status)) { + goto CloseUnmapAllMappingsEvent; + } + + Handle = NULL; + Status = gBS->InstallMultipleProtocolInterfaces ( + &Handle, + &gEdkiiIoMmuProtocolGuid, &mAmdIoMmu, + NULL + ); + if (EFI_ERROR (Status)) { + goto CloseExitBootEvent; + } + + return EFI_SUCCESS; + +CloseExitBootEvent: + gBS->CloseEvent (ExitBootEvent); + +CloseUnmapAllMappingsEvent: + gBS->CloseEvent (UnmapAllMappingsEvent); + + return Status; +} diff --git a/UefiPayloadPkg/IoMmuDxe/AmdIoMmuDxe.inf b/UefiPayloadPkg/IoMmuDxe/AmdIoMmuDxe.inf new file mode 100644 index 000000000000..e60a80d28cd3 --- /dev/null +++ b/UefiPayloadPkg/IoMmuDxe/AmdIoMmuDxe.inf @@ -0,0 +1,40 @@ +#/** @file +# +# Driver provides the IOMMU protcol support for PciHostBridgeIo and others +# drivers. +# +# Copyright (c) 2017, AMD Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION = 1.25 + BASE_NAME = IoMmuDxe + FILE_GUID = 0e9830e7-c781-4c8b-83cd-ef984ca3817b + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = AmdInstallIoMmuProtocol + +[Sources] + AmdIoMmu.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gEdkiiIoMmuProtocolGuid ## SOMETIME_PRODUCES +# gIoMmuAbsentProtocolGuid ## SOMETIME_PRODUCES + +[Depex] + TRUE diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index 46a4e8cf5eea..4df6c5b1e994 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -559,6 +559,7 @@ UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf UefiPayloadPkg/SkinitDxe/SkinitDxe.inf + UefiPayloadPkg/IoMmuDxe/AmdIoMmuDxe.inf # # SMBIOS Support diff --git a/UefiPayloadPkg/UefiPayloadPkg.fdf b/UefiPayloadPkg/UefiPayloadPkg.fdf index 7acb8cd65fa6..2720e0932395 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.fdf +++ b/UefiPayloadPkg/UefiPayloadPkg.fdf @@ -85,6 +85,7 @@ APRIORI DXE { INF MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf !if $(BOOTLOADER) == "COREBOOT" INF UefiPayloadPkg/SkinitDxe/SkinitDxe.inf + INF UefiPayloadPkg/IoMmuDxe/AmdIoMmuDxe.inf # Initialize VariableStore and update PCDs before VariableRuntimeDxe INF UefiPayloadPkg/BlSMMStoreDxe/BlSMMStoreDxe.inf !endif @@ -129,6 +130,7 @@ INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf INF MdeModulePkg/Logo/LogoDxe.inf !if $(BOOTLOADER) == "COREBOOT" INF UefiPayloadPkg/SkinitDxe/SkinitDxe.inf +INF UefiPayloadPkg/IoMmuDxe/AmdIoMmuDxe.inf INF UefiPayloadPkg/BlSMMStoreDxe/BlSMMStoreDxe.inf !endif From 0e27d77f2ad685dad4383b99511eaede41467645 Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Mon, 26 Sep 2022 19:26:59 +0200 Subject: [PATCH 05/11] UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c: allocate device addresses Signed-off-by: Krystian Hebel --- UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c | 395 ++++++++++++++++++++++++++--- 1 file changed, 364 insertions(+), 31 deletions(-) diff --git a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c index 6a1dce03991e..7903d53c8253 100644 --- a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c +++ b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -28,6 +29,7 @@ typedef struct { UINTN NumberOfBytes; UINTN NumberOfPages; EFI_PHYSICAL_ADDRESS Address; + EFI_PHYSICAL_ADDRESS DevAddress; } MAP_INFO; // @@ -37,6 +39,190 @@ typedef struct { // STATIC LIST_ENTRY mMapInfos = INITIALIZE_LIST_HEAD_VARIABLE (mMapInfos); +typedef struct { + // First UINT64 + UINT64 V:1; + UINT64 TV:1; + UINT64 res0:6; + UINT64 HAD:2; + UINT64 Mode:3; + UINT64 HPTRP:40; + UINT64 PPR:1; + UINT64 GPRP:1; + UINT64 GloV:1; + UINT64 GV:1; + UINT64 GLX:1; + UINT64 GCR3TRP1:3; + UINT64 IR:1; + UINT64 IW:1; + UINT64 res1:1; + // Second UINT64 + UINT64 DomainID:16; + UINT64 GCR3TRP2:16; + UINT64 I:1; + UINT64 SE:1; + UINT64 SA:1; + UINT64 IoCtl:2; + UINT64 Cache:1; + UINT64 SD:1; + UINT64 EX:1; + UINT64 SysMgt:2; + UINT64 res2:1; + UINT64 GCR3TRP3:21; + // Third UINT64 + UINT64 IV:1; + UINT64 IntTabLen:4; + UINT64 IG:1; + UINT64 ITRP:46; + UINT64 res3:4; + UINT64 InitPass:1; + UINT64 EIntPass:1; + UINT64 NMIPass:1; + UINT64 res4:1; + UINT64 IntCtl:2; + UINT64 Lint0Pass:1; + UINT64 Lint1Pass:1; + // Fourth UINT64 + UINT64 res5:54; + UINT64 AttrV:1; + UINT64 Mode0FC:1; + UINT64 SnoopAttribute:8; +} DT_ENTRY; + +typedef struct { + UINT64 PR:1; + UINT64 res0:4; + UINT64 A:1; + UINT64 D:1; + UINT64 res1:2; + UINT64 NextLevel:3; + UINT64 PageAddress:40; + UINT64 res2:7; + UINT64 U:1; + UINT64 FC:1; + UINT64 IR:1; + UINT64 IW:1; + UINT64 res3:1; +} IO_PTE; + +typedef union { + UINT64 Val[2]; + struct { + UINT64 res0:60; + UINT64 Opcode:4; + UINT64 res1; + } Generic; + struct { + UINT64 s:1; + UINT64 i:1; + UINT64 f:1; + UINT64 StoreAddress:49; + UINT64 res0:8; + UINT64 Opcode:4; + UINT64 StoreData; + } CompletionWait; +} IOMMU_CMD; + +#define COMPLETION_WAIT(addr, data) ((IOMMU_CMD) \ +{ \ + .CompletionWait.f = 1, \ + .CompletionWait.s = 1, \ + .CompletionWait.StoreAddress = ((EFI_PHYSICAL_ADDRESS)(addr)) >> 3, \ + .CompletionWait.StoreData = (data), \ + .CompletionWait.Opcode = 1, \ +}) + +#define INVALIDATE_IOMMU_ALL ((IOMMU_CMD) { .Generic.Opcode = 8}) + +#define IOMMU_DONE SIGNATURE_64 ('C', 'O', 'M', 'P', 'L', 'E', 'T', 'E') + +STATIC IO_PTE *mDenyAll; + +// +// Due to the way EDK2 IOMMU protocol is defined, we don't know the device at +// the time the mapping is produced, so we're using one global DPA space shared +// across all devices. +// +// Addresses are limited to 21 bits, so we can use 1-level paging. +// +// WARNING: there are no mechanisms to protect against concurrent accesses to +// this protocol. Something WILL break if APs are to call Map()/Unmap(). +// +typedef struct { + LIST_ENTRY Link; + UINTN BasePFN; + UINTN Pages; +} FREE_PAGES_LIST; + +STATIC LIST_ENTRY mFP = INITIALIZE_LIST_HEAD_VARIABLE (mFP); + +STATIC DT_ENTRY *mDT; +STATIC IOMMU_CMD *mCmdBuf; +STATIC void *mEvtLog; + +STATIC UINT64 *mMmioBase; +#define IOMMU_MMIO_DEVICE_TABLE_BA (0x0000 / sizeof(UINT64)) +#define IOMMU_MMIO_COMMAND_BUF_BA (0x0008 / sizeof(UINT64)) +#define IOMMU_MMIO_EVENT_LOG_BA (0x0010 / sizeof(UINT64)) +#define IOMMU_MMIO_CONTROL_REGISTER (0x0018 / sizeof(UINT64)) +#define IOMMU_MMIO_EXTENDED_FEATURE (0x0030 / sizeof(UINT64)) +#define IOMMU_MMIO_COMMAND_BUF_HEAD (0x2000 / sizeof(UINT64)) +#define IOMMU_MMIO_COMMAND_BUF_TAIL (0x2008 / sizeof(UINT64)) +#define IOMMU_MMIO_EVENT_LOG_HEAD (0x2010 / sizeof(UINT64)) +#define IOMMU_MMIO_EVENT_LOG_TAIL (0x2018 / sizeof(UINT64)) +#define IOMMU_MMIO_STATUS_REGISTER (0x2020 / sizeof(UINT64)) + +#define IOMMU_CR_IommuEn (1ULL << 0) +#define IOMMU_CR_HtTunEn (1ULL << 1) +#define IOMMU_CR_EventLogEn (1ULL << 2) +#define IOMMU_CR_EventIntEn (1ULL << 3) +#define IOMMU_CR_ComWaitIntEn (1ULL << 4) +#define IOMMU_CR_CmdBufEn (1ULL << 12) +#define IOMMU_CR_PPRLogEn (1ULL << 13) +#define IOMMU_CR_PprIntEn (1ULL << 14) +#define IOMMU_CR_PPREn (1ULL << 15) +#define IOMMU_CR_GTEn (1ULL << 16) +#define IOMMU_CR_GAEn (1ULL << 17) +#define IOMMU_CR_SmiFEn (1ULL << 22) +#define IOMMU_CR_SmiFLogEn (1ULL << 24) +#define IOMMU_CR_GALogEn (1ULL << 28) +#define IOMMU_CR_GAIntEn (1ULL << 29) +#define IOMMU_CR_DualPprLogEn (3ULL << 30) +#define IOMMU_CR_DualEventLogEn (3ULL << 32) +#define IOMMU_CR_DevTblSegEn (7ULL << 34) +#define IOMMU_CR_PrivAbrtEn (3ULL << 37) +#define IOMMU_CR_PprAutoRspEn (1ULL << 39) +#define IOMMU_CR_MarcEn (1ULL << 40) +#define IOMMU_CR_BlkStopMrkEn (1ULL << 41) +#define IOMMU_CR_PprAutoRspAon (1ULL << 42) + + +#define IOMMU_EF_IASup (1ULL << 6) + +#define IOMMU_CR_ENABLE_ALL_MASK (IOMMU_CR_IommuEn | \ + IOMMU_CR_HtTunEn | \ + IOMMU_CR_EventLogEn | \ + IOMMU_CR_EventIntEn | \ + IOMMU_CR_ComWaitIntEn | \ + IOMMU_CR_CmdBufEn | \ + IOMMU_CR_PPRLogEn | \ + IOMMU_CR_PprIntEn | \ + IOMMU_CR_PPREn | \ + IOMMU_CR_GTEn | \ + IOMMU_CR_GAEn | \ + IOMMU_CR_SmiFEn | \ + IOMMU_CR_SmiFLogEn | \ + IOMMU_CR_GALogEn | \ + IOMMU_CR_GAIntEn | \ + IOMMU_CR_DualPprLogEn | \ + IOMMU_CR_DualEventLogEn | \ + IOMMU_CR_DevTblSegEn | \ + IOMMU_CR_PrivAbrtEn | \ + IOMMU_CR_PprAutoRspEn | \ + IOMMU_CR_MarcEn | \ + IOMMU_CR_BlkStopMrkEn | \ + IOMMU_CR_PprAutoRspAon) + // // ASCII names for EDKII_IOMMU_OPERATION constants, for debug logging. // @@ -50,29 +236,47 @@ mBusMasterOperationName[EdkiiIoMmuOperationMaximum] = { "CommonBuffer64" }; -// -// The following structure enables Map() and Unmap() to perform in-place -// decryption and encryption, respectively, for BusMasterCommonBuffer[64] -// operations, without dynamic memory allocation or release. -// -// Both COMMON_BUFFER_HEADER and COMMON_BUFFER_HEADER.StashBuffer are allocated -// by AllocateBuffer() and released by FreeBuffer(). -// -#pragma pack (1) -typedef struct { - UINT64 Signature; +STATIC void SendCommand(IOMMU_CMD cmd) +{ + STATIC int idx = 0; + mCmdBuf[idx++] = cmd; + if (idx == EFI_PAGE_SIZE / sizeof(IOMMU_CMD)) + idx = 0; + MemoryFence(); + mMmioBase[IOMMU_MMIO_COMMAND_BUF_TAIL] = + (EFI_PHYSICAL_ADDRESS)(&mCmdBuf[idx]) & ~(EFI_PAGE_SIZE - 1); +} - // - // Always allocated from EfiBootServicesData type memory, and always - // encrypted. - // - VOID *StashBuffer; +// This is defined in Library/BaseLib.h for newer versions of edk2 +#define BASE_LIST_FOR_EACH(Entry, ListHead) \ + for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink) - // - // Followed by the actual common buffer, starting at the next page. - // -} COMMON_BUFFER_HEADER; -#pragma pack () +STATIC EFI_PHYSICAL_ADDRESS AllocDevPages (UINTN Pages) +{ + LIST_ENTRY *Entry; + EFI_PHYSICAL_ADDRESS Ret = 0; + + BASE_LIST_FOR_EACH(Entry, &mFP) { + FREE_PAGES_LIST *E = BASE_CR (Entry, FREE_PAGES_LIST, Link); + + if (E->Pages < Pages) + continue; + + Ret = EFI_PAGE_SIZE * E->BasePFN; + + if (E->Pages == Pages) { + Entry = RemoveEntryList (Entry); + FreePool (E); + } else { + E->BasePFN += Pages; + E->Pages -= Pages; + } + + break; + } + + return Ret; +} /** Provides the controller-specific addresses required to access system memory @@ -143,7 +347,7 @@ IoMmuMap ( } // - // Initialize the MAP_INFO structure, except the PlainTextAddress field + // Initialize the MAP_INFO structure. // ZeroMem (&MapInfo->Link, sizeof MapInfo->Link); MapInfo->Signature = MAP_INFO_SIG; @@ -165,6 +369,11 @@ IoMmuMap ( goto FreeMapInfo; } + MapInfo->DevAddress = AllocDevPages(MapInfo->NumberOfPages); + if (MapInfo->DevAddress == 0) { + goto FreeMapInfo; + } + // // Track all MAP_INFO structures. // @@ -172,7 +381,7 @@ IoMmuMap ( // // Populate output parameters. // - *DeviceAddress = MapInfo->Address; + *DeviceAddress = MapInfo->DevAddress; *Mapping = MapInfo; DEBUG (( @@ -237,12 +446,15 @@ IoMmuUnmapWorker ( MapInfo = (MAP_INFO *)Mapping; + // TODO: free pages in device space and return them to mFP + // // Forget the MAP_INFO structure, then free it (unless the UEFI memory map is // locked). // RemoveEntryList (&MapInfo->Link); if (!MemoryMapLocked) { + // TODO: free buffer from UEFI FreePool (MapInfo); } @@ -461,7 +673,7 @@ IoMmuSetAttribute ( // - create page tables for mapping // - convert DeviceHandle (UEFI) to DeviceID (IOMMU) // - set IW/IR based on IoMmuAccess - // - flush IOMMU TLB + // - flush IOMMU cache // return EFI_UNSUPPORTED; } @@ -567,16 +779,137 @@ AmdInstallIoMmuProtocol ( EFI_EVENT UnmapAllMappingsEvent; EFI_EVENT ExitBootEvent; EFI_HANDLE Handle; + UINT32 lo, hi; + volatile UINT64 done = 0; + FREE_PAGES_LIST *FP; + + // + // Allocate 2MB for IOMMU Device Table, enough for all 2^16 DeviceIDs. + // + Status = gBS->AllocatePages ( + AllocateAnyPages, // Type + EfiBootServicesData, // MemoryType + 1, // Pages + (EFI_PHYSICAL_ADDRESS *)&mDenyAll // Memory + ); + if (EFI_ERROR (Status)) { + return Status; + } + gBS->SetMem (mDenyAll, EFI_PAGE_SIZE, 0); + + DT_ENTRY DefaultEntry = + { + .V = 1, // valid + .TV = 1, // translation valid + //.Mode = 1, // 21-bit GPA space + //.HPTRP = ((EFI_PHYSICAL_ADDRESS)mDenyAll) >> 12, + }; + + // + // Allocate 2MB for IOMMU Device Table, enough for all 2^16 DeviceIDs. + // + Status = gBS->AllocatePages ( + AllocateAnyPages, // Type + EfiBootServicesData, // MemoryType + 512, // Pages + (EFI_PHYSICAL_ADDRESS *)&mDT // Memory + ); + if (EFI_ERROR (Status)) { + return Status; + } + for (int i = 0; i < 0x10000; i++) + mDT[i] = DefaultEntry; // - // TODO: allocate and initialize IOMMU data structures: - // - device table - // - command buffer - // - I/O page tables (or leave it to IoMmuSetAttribute() maybe?) - // - event log - // - interrupt remapping tables (probably can be skipped?) - // - peripheral page request log (probably can be skipped?) + // Allocate one page for Command Buffer. + // + Status = gBS->AllocatePages ( + AllocateAnyPages, // Type + EfiBootServicesData, // MemoryType + 1, // Pages + (EFI_PHYSICAL_ADDRESS *)&mCmdBuf // Memory + ); + if (EFI_ERROR (Status)) { + return Status; + } + gBS->SetMem (mCmdBuf, EFI_PAGE_SIZE, 0); + // + // Allocate one page for Event Log. + // + Status = gBS->AllocatePages ( + AllocateAnyPages, // Type + EfiBootServicesData, // MemoryType + 1, // Pages + (EFI_PHYSICAL_ADDRESS *)&mEvtLog // Memory + ); + if (EFI_ERROR (Status)) { + return Status; + } + gBS->SetMem (mEvtLog, EFI_PAGE_SIZE, 0); + + // + // Add initial element to free pages list. + // + FP = AllocatePool (sizeof (FREE_PAGES_LIST)); + if (FP == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } + FP->BasePFN = 1; // Allocate first page due to omnipresent NULL checks + FP->Pages = 0x1ff; // 2^21 / 2^12 - 1 + InsertHeadList (&mFP, &FP->Link); + + // + // TODO: unhardcode, find IOMMU capability + // + lo = PciRead32 (PCI_LIB_ADDRESS (0, 0, 2, 0x44)); + hi = PciRead32 (PCI_LIB_ADDRESS (0, 0, 2, 0x48)); + + // + // TODO: define bit + // + ASSERT (lo & 1); + + if (lo & 1) + return EFI_UNSUPPORTED; + + mMmioBase = (UINT64 *)(EFI_PHYSICAL_ADDRESS) + ((UINT64)hi << 32 | (lo & 0xffffc000)); + + mMmioBase[IOMMU_MMIO_CONTROL_REGISTER] &= ~IOMMU_CR_ENABLE_ALL_MASK; + MemoryFence (); + + mMmioBase[IOMMU_MMIO_DEVICE_TABLE_BA] = (EFI_PHYSICAL_ADDRESS)mDT | 0x1ff; + + mMmioBase[IOMMU_MMIO_COMMAND_BUF_BA] = (EFI_PHYSICAL_ADDRESS)mCmdBuf | (8ULL << 56); + mMmioBase[IOMMU_MMIO_COMMAND_BUF_HEAD] = 0; + mMmioBase[IOMMU_MMIO_COMMAND_BUF_TAIL] = 0; + + mMmioBase[IOMMU_MMIO_EVENT_LOG_BA] = (EFI_PHYSICAL_ADDRESS)mEvtLog | (8ULL << 56); + mMmioBase[IOMMU_MMIO_EVENT_LOG_HEAD] = 0; + mMmioBase[IOMMU_MMIO_EVENT_LOG_TAIL] = 0; + + // + // Clear EventLogInt set by IOMMU not being able to read command buffer + // + mMmioBase[IOMMU_MMIO_STATUS_REGISTER] &= ~2; + MemoryFence (); + mMmioBase[IOMMU_MMIO_CONTROL_REGISTER] |= IOMMU_CR_CmdBufEn | IOMMU_CR_EventLogEn; + MemoryFence (); + + mMmioBase[IOMMU_MMIO_CONTROL_REGISTER] |= IOMMU_CR_IommuEn; + + // + // TODO: check if EXTENDED_FEATURES even exist + // + if ( mMmioBase[IOMMU_MMIO_EXTENDED_FEATURE] & IOMMU_EF_IASup ) { + SendCommand (INVALIDATE_IOMMU_ALL); + } /* TODO: else? */ + + SendCommand (COMPLETION_WAIT( &done, IOMMU_DONE)); + + while (done != IOMMU_DONE) + CpuPause (); // // Create the "late" event whose notification function will tear down all From 9f4a572ac63f9d420134102c5624ca6ddc7ff39a Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Mon, 26 Sep 2022 19:44:22 +0200 Subject: [PATCH 06/11] UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c: fix IOMMU enabled check Signed-off-by: Krystian Hebel --- UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c index 7903d53c8253..f8774593b76f 100644 --- a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c +++ b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c @@ -870,7 +870,7 @@ AmdInstallIoMmuProtocol ( // ASSERT (lo & 1); - if (lo & 1) + if (!(lo & 1)) return EFI_UNSUPPORTED; mMmioBase = (UINT64 *)(EFI_PHYSICAL_ADDRESS) From b8aec73dec935b8a2cf2d022363daa2ccd51da0c Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Mon, 26 Sep 2022 21:27:29 +0200 Subject: [PATCH 07/11] UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c: basic IoMmuSetAttribute() implementation Signed-off-by: Krystian Hebel --- UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c | 112 ++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 24 deletions(-) diff --git a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c index f8774593b76f..22c15cfceed1 100644 --- a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c +++ b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -136,8 +137,6 @@ typedef union { #define IOMMU_DONE SIGNATURE_64 ('C', 'O', 'M', 'P', 'L', 'E', 'T', 'E') -STATIC IO_PTE *mDenyAll; - // // Due to the way EDK2 IOMMU protocol is defined, we don't know the device at // the time the mapping is produced, so we're using one global DPA space shared @@ -668,14 +667,93 @@ IoMmuSetAttribute ( IN UINT64 IoMmuAccess ) { - // - // TODO: this should be the function doing all the heavy lifting: - // - create page tables for mapping - // - convert DeviceHandle (UEFI) to DeviceID (IOMMU) - // - set IW/IR based on IoMmuAccess - // - flush IOMMU cache - // - return EFI_UNSUPPORTED; + MAP_INFO *MapInfo = (MAP_INFO *) Mapping; + EFI_DEVICE_PATH_PROTOCOL *Node = DevicePathFromHandle(DeviceHandle); + UINT32 DeviceID; + IO_PTE *PTE; + EFI_STATUS Status; + UINTN BasePFN; + volatile UINT64 done = 0; + + if (Node == NULL) + return EFI_UNSUPPORTED; + + DEBUG ((DEBUG_INFO, "IOMMU: remapping %s\n", + ConvertDevicePathToText( + DevicePathFromHandle(DeviceHandle), + FALSE, FALSE + ) + )); + + DEBUG ((DEBUG_INFO, " (DPA) 0x%lx -> 0x%lx (SPA), 0x%lx pages\n", + MapInfo->DevAddress, MapInfo->Address, MapInfo->NumberOfPages)); + + while (!IsDevicePathEnd(Node) && + DevicePathType(Node) != HARDWARE_DEVICE_PATH && + DevicePathSubType(Node) != HW_PCI_DP) { + DEBUG ((DEBUG_INFO, " T: 0x%lx ST: 0x%lx\n", DevicePathType(Node), DevicePathSubType(Node))); + Node = NextDevicePathNode(Node); + } + + DEBUG ((DEBUG_INFO, " Last: T: 0x%lx ST: 0x%lx\n", DevicePathType(Node), DevicePathSubType(Node))); + + if (IsDevicePathEnd(Node)) + return EFI_UNSUPPORTED; + + DeviceID = (((PCI_DEVICE_PATH *)Node)->Function << 3) | + ((PCI_DEVICE_PATH *)Node)->Device; + + // FIXME: check if device already has PTE + if (mDT[DeviceID].HPTRP == 0) { + Status = gBS->AllocatePages ( + AllocateAnyPages, // Type + EfiBootServicesData, // MemoryType + 1, // Pages + (EFI_PHYSICAL_ADDRESS *)&PTE // Memory + ); + if (EFI_ERROR (Status)) { + return Status; + } + gBS->SetMem (mCmdBuf, EFI_PAGE_SIZE, 0); + } else { + PTE = (IO_PTE *)(EFI_PHYSICAL_ADDRESS)(mDT[DeviceID].HPTRP << 12); + } + + BasePFN = MapInfo->DevAddress >> 12; + + for (UINTN i = 0; i < MapInfo->NumberOfPages; i++) { + PTE[BasePFN + i] = (IO_PTE) { + .PageAddress = BasePFN + i, + .PR = 1, + .IR = 1, // FIXME + .IW = 1, // FIXME + // others 0 + }; + } + + mDT[DeviceID].Mode = 1; // 21-bit GPA space + mDT[DeviceID].HPTRP = ((EFI_PHYSICAL_ADDRESS)PTE) >> 12; + + // FIXME: I am lazy + SendCommand(INVALIDATE_IOMMU_ALL); + SendCommand(COMPLETION_WAIT(&done, IOMMU_DONE)); + + for (int i = 0; i < 0x100; i++) { + if (i%16 == 0) DEBUG ((DEBUG_INFO, "\n")); + DEBUG ((DEBUG_INFO, "%02x ", ((UINT8 *)mEvtLog)[i])); + } + + DEBUG ((DEBUG_INFO, "\n")); + + for (int i = 0; i < 0x100; i++) { + if (i%16 == 0) DEBUG ((DEBUG_INFO, "\n")); + DEBUG ((DEBUG_INFO, "%02x ", ((UINT8 *)mCmdBuf)[i])); + } + + while (done != IOMMU_DONE) + CpuPause (); + + return EFI_SUCCESS; } EDKII_IOMMU_PROTOCOL mAmdIoMmu = { @@ -783,20 +861,6 @@ AmdInstallIoMmuProtocol ( volatile UINT64 done = 0; FREE_PAGES_LIST *FP; - // - // Allocate 2MB for IOMMU Device Table, enough for all 2^16 DeviceIDs. - // - Status = gBS->AllocatePages ( - AllocateAnyPages, // Type - EfiBootServicesData, // MemoryType - 1, // Pages - (EFI_PHYSICAL_ADDRESS *)&mDenyAll // Memory - ); - if (EFI_ERROR (Status)) { - return Status; - } - gBS->SetMem (mDenyAll, EFI_PAGE_SIZE, 0); - DT_ENTRY DefaultEntry = { .V = 1, // valid From 671e118cf7df031ab363e7a7e0ab0b57203313fa Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Mon, 26 Sep 2022 21:30:07 +0200 Subject: [PATCH 08/11] UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c: fix bug in SendCommand() Signed-off-by: Krystian Hebel --- UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c index 22c15cfceed1..1903f59500ae 100644 --- a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c +++ b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c @@ -243,7 +243,7 @@ STATIC void SendCommand(IOMMU_CMD cmd) idx = 0; MemoryFence(); mMmioBase[IOMMU_MMIO_COMMAND_BUF_TAIL] = - (EFI_PHYSICAL_ADDRESS)(&mCmdBuf[idx]) & ~(EFI_PAGE_SIZE - 1); + (EFI_PHYSICAL_ADDRESS)(&mCmdBuf[idx]) & (EFI_PAGE_SIZE - 1); } // This is defined in Library/BaseLib.h for newer versions of edk2 From 1ab6c36bb3b090fe0f752d9a82417f68bd075649 Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Wed, 28 Sep 2022 11:20:52 +0200 Subject: [PATCH 09/11] UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c: fix some bugs and add debug output Signed-off-by: Krystian Hebel --- UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c | 46 ++++++++++++++++++++++-------- UefiPayloadPkg/UefiPayloadPkg.dsc | 2 +- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c index 1903f59500ae..05ccfb876235 100644 --- a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c +++ b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c @@ -44,7 +44,7 @@ typedef struct { // First UINT64 UINT64 V:1; UINT64 TV:1; - UINT64 res0:6; + UINT64 res0:5; UINT64 HAD:2; UINT64 Mode:3; UINT64 HPTRP:40; @@ -52,7 +52,7 @@ typedef struct { UINT64 GPRP:1; UINT64 GloV:1; UINT64 GV:1; - UINT64 GLX:1; + UINT64 GLX:2; UINT64 GCR3TRP1:3; UINT64 IR:1; UINT64 IW:1; @@ -672,7 +672,8 @@ IoMmuSetAttribute ( UINT32 DeviceID; IO_PTE *PTE; EFI_STATUS Status; - UINTN BasePFN; + UINTN DevPFN; + UINTN HostPFN; volatile UINT64 done = 0; if (Node == NULL) @@ -689,8 +690,8 @@ IoMmuSetAttribute ( MapInfo->DevAddress, MapInfo->Address, MapInfo->NumberOfPages)); while (!IsDevicePathEnd(Node) && - DevicePathType(Node) != HARDWARE_DEVICE_PATH && - DevicePathSubType(Node) != HW_PCI_DP) { + (DevicePathType(Node) != HARDWARE_DEVICE_PATH || + DevicePathSubType(Node) != HW_PCI_DP)) { DEBUG ((DEBUG_INFO, " T: 0x%lx ST: 0x%lx\n", DevicePathType(Node), DevicePathSubType(Node))); Node = NextDevicePathNode(Node); } @@ -700,10 +701,11 @@ IoMmuSetAttribute ( if (IsDevicePathEnd(Node)) return EFI_UNSUPPORTED; - DeviceID = (((PCI_DEVICE_PATH *)Node)->Function << 3) | - ((PCI_DEVICE_PATH *)Node)->Device; + DEBUG ((DEBUG_INFO, " Dev: 0x%lx Fn: 0x%lx\n", ((PCI_DEVICE_PATH *)Node)->Device, ((PCI_DEVICE_PATH *)Node)->Function)); + + DeviceID = (((PCI_DEVICE_PATH *)Node)->Device << 3) | + ((PCI_DEVICE_PATH *)Node)->Function; - // FIXME: check if device already has PTE if (mDT[DeviceID].HPTRP == 0) { Status = gBS->AllocatePages ( AllocateAnyPages, // Type @@ -714,30 +716,47 @@ IoMmuSetAttribute ( if (EFI_ERROR (Status)) { return Status; } - gBS->SetMem (mCmdBuf, EFI_PAGE_SIZE, 0); + gBS->SetMem (PTE, EFI_PAGE_SIZE, 0); } else { PTE = (IO_PTE *)(EFI_PHYSICAL_ADDRESS)(mDT[DeviceID].HPTRP << 12); } - BasePFN = MapInfo->DevAddress >> 12; + DevPFN = MapInfo->DevAddress >> 12; + HostPFN = MapInfo->Address >> 12; for (UINTN i = 0; i < MapInfo->NumberOfPages; i++) { - PTE[BasePFN + i] = (IO_PTE) { - .PageAddress = BasePFN + i, + PTE[DevPFN + i] = (IO_PTE) { + .PageAddress = HostPFN + i, .PR = 1, .IR = 1, // FIXME .IW = 1, // FIXME // others 0 }; + DEBUG ((DEBUG_INFO, "\nPTE %lx:\n", DevPFN + i)); + for (int ii = 0; ii < sizeof(PTE[0]); ii++) { + if (ii%16 == 0) DEBUG ((DEBUG_INFO, "\n")); + DEBUG ((DEBUG_INFO, "%02x ", ((UINT8 *)&PTE[DevPFN + i])[ii])); + } } mDT[DeviceID].Mode = 1; // 21-bit GPA space mDT[DeviceID].HPTRP = ((EFI_PHYSICAL_ADDRESS)PTE) >> 12; + mDT[DeviceID].IW = 1; // FIXME + mDT[DeviceID].IR = 1; // FIXME + + DEBUG ((DEBUG_INFO, "\nmDT[%lx]:\n", DeviceID)); + for (int i = 0; i < sizeof(mDT[0]); i++) { + if (i%16 == 0) DEBUG ((DEBUG_INFO, "\n")); + DEBUG ((DEBUG_INFO, "%02x ", ((UINT8 *)&mDT[DeviceID])[i])); + } + + DEBUG ((DEBUG_INFO, "\n")); // FIXME: I am lazy SendCommand(INVALIDATE_IOMMU_ALL); SendCommand(COMPLETION_WAIT(&done, IOMMU_DONE)); + DEBUG ((DEBUG_INFO, "EvtLog:\n")); for (int i = 0; i < 0x100; i++) { if (i%16 == 0) DEBUG ((DEBUG_INFO, "\n")); DEBUG ((DEBUG_INFO, "%02x ", ((UINT8 *)mEvtLog)[i])); @@ -745,11 +764,14 @@ IoMmuSetAttribute ( DEBUG ((DEBUG_INFO, "\n")); + DEBUG ((DEBUG_INFO, "CmdBuf:\n")); for (int i = 0; i < 0x100; i++) { if (i%16 == 0) DEBUG ((DEBUG_INFO, "\n")); DEBUG ((DEBUG_INFO, "%02x ", ((UINT8 *)mCmdBuf)[i])); } + DEBUG ((DEBUG_INFO, "\n")); + while (done != IOMMU_DONE) CpuPause (); diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index 4df6c5b1e994..a45d5791396d 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -371,7 +371,7 @@ [PcdsPatchableInModule.common] gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x7 - gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F + gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8040004F !if $(SOURCE_DEBUG_ENABLE) gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17 !else From a3995367621d001be12495c8c44ae115b9a2c874 Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Thu, 29 Sep 2022 21:36:39 +0200 Subject: [PATCH 10/11] UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c: more fixes Signed-off-by: Krystian Hebel --- UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c | 94 ++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 23 deletions(-) diff --git a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c index 05ccfb876235..e92ccc81c0c4 100644 --- a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c +++ b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c @@ -277,6 +277,47 @@ STATIC EFI_PHYSICAL_ADDRESS AllocDevPages (UINTN Pages) return Ret; } +STATIC EFI_STATUS FreeDevPages (UINTN PFN, UINTN Pages) +{ + LIST_ENTRY *Entry; + + DEBUG ((DEBUG_VERBOSE, "FreeDevPages: PFN=0x%x Pages=0x%x\n", PFN, Pages)); + // Create and insert element at head of list + FREE_PAGES_LIST *FP = AllocatePool (sizeof (FREE_PAGES_LIST)); + if (FP == NULL) { + // Yes, we need resources to free resources + return EFI_OUT_OF_RESOURCES; + } + FP->BasePFN = PFN; + FP->Pages = Pages; + InsertHeadList (&mFP, &FP->Link); + + BASE_LIST_FOR_EACH (Entry, &mFP) { + FREE_PAGES_LIST *E = BASE_CR (Entry, FREE_PAGES_LIST, Link); + + if (E == FP) + continue; + + // Bubble sort it to proper place + if (FP->BasePFN > E->BasePFN + E->Pages) { + Entry = SwapListEntries (Entry, &FP->Link); + continue; + } + + // Merge if possible + if (FP->BasePFN == E->BasePFN + E->Pages) { + DEBUG ((DEBUG_VERBOSE, " Trying to merge\n")); + E->Pages += FP->Pages; + RemoveEntryList (&FP->Link); + FreePool (FP); + } + + break; + } + + return EFI_SUCCESS; +} + /** Provides the controller-specific addresses required to access system memory from a DMA bus master. @@ -317,6 +358,7 @@ IoMmuMap ( { EFI_STATUS Status; MAP_INFO *MapInfo; + UINTN PageOffset; DEBUG (( DEBUG_VERBOSE, @@ -335,12 +377,15 @@ IoMmuMap ( return EFI_INVALID_PARAMETER; } + PageOffset = ((UINTN)HostAddress) & (EFI_PAGE_SIZE - 1); + // // Allocate a MAP_INFO structure to remember the mapping when Unmap() is // called later. // MapInfo = AllocatePool (sizeof (MAP_INFO)); if (MapInfo == NULL) { + DEBUG ((DEBUG_VERBOSE, "MapInfo == NULL\n")); Status = EFI_OUT_OF_RESOURCES; goto Failed; } @@ -349,27 +394,21 @@ IoMmuMap ( // Initialize the MAP_INFO structure. // ZeroMem (&MapInfo->Link, sizeof MapInfo->Link); - MapInfo->Signature = MAP_INFO_SIG; - MapInfo->Operation = Operation; - MapInfo->NumberOfBytes = *NumberOfBytes; - MapInfo->NumberOfPages = EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes); - MapInfo->Address = (UINTN)HostAddress; - - // - // Allocate the buffer. - // - Status = gBS->AllocatePages ( - AllocateAnyPages, - EfiBootServicesData, - MapInfo->NumberOfPages, - &MapInfo->Address - ); - if (EFI_ERROR (Status)) { - goto FreeMapInfo; - } - - MapInfo->DevAddress = AllocDevPages(MapInfo->NumberOfPages); + MapInfo->Signature = MAP_INFO_SIG; + MapInfo->Operation = Operation; + MapInfo->NumberOfBytes = *NumberOfBytes; + MapInfo->NumberOfPages = EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes + PageOffset); + MapInfo->Address = (UINTN)HostAddress; + MapInfo->DevAddress = AllocDevPages(MapInfo->NumberOfPages); if (MapInfo->DevAddress == 0) { + LIST_ENTRY *Entry; + DEBUG ((DEBUG_VERBOSE, "AllocDevPages returned 0, free pages:\n")); + BASE_LIST_FOR_EACH(Entry, &mFP) { + FREE_PAGES_LIST *E = BASE_CR (Entry, FREE_PAGES_LIST, Link); + DEBUG ((DEBUG_VERBOSE, "PFN %3x: 0x%x pages\n", E->BasePFN, E->Pages)); + } + + Status = EFI_OUT_OF_RESOURCES; goto FreeMapInfo; } @@ -380,8 +419,14 @@ IoMmuMap ( // // Populate output parameters. // - *DeviceAddress = MapInfo->DevAddress; + *DeviceAddress = MapInfo->DevAddress + PageOffset; *Mapping = MapInfo; + // + // According to comment in IoMmu.h we should return number of bytes actually + // mapped, however there are drivers that check if value on output is the same + // as it was on input, and fail if they are not. + // + //*NumberOfBytes = MapInfo->NumberOfPages * EFI_PAGE_SIZE; DEBUG (( DEBUG_VERBOSE, @@ -445,7 +490,11 @@ IoMmuUnmapWorker ( MapInfo = (MAP_INFO *)Mapping; - // TODO: free pages in device space and return them to mFP + // TODO: undo IoMmuSetAttribute + + if (FreeDevPages (MapInfo->DevAddress >> 12, MapInfo->NumberOfPages) != EFI_SUCCESS) { + DEBUG ((DEBUG_INFO, "%a: couldn't free device pages from pool\n", __FUNCTION__)); + } // // Forget the MAP_INFO structure, then free it (unless the UEFI memory map is @@ -453,7 +502,6 @@ IoMmuUnmapWorker ( // RemoveEntryList (&MapInfo->Link); if (!MemoryMapLocked) { - // TODO: free buffer from UEFI FreePool (MapInfo); } From a33a6275e7429a66ba6bf0f9c7f1053e8de267c0 Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Fri, 30 Sep 2022 10:17:19 +0200 Subject: [PATCH 11/11] UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c: remove most of debug output Signed-off-by: Krystian Hebel --- UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c | 67 +++++++++--------------------- UefiPayloadPkg/UefiPayloadPkg.dsc | 2 +- 2 files changed, 21 insertions(+), 48 deletions(-) diff --git a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c index e92ccc81c0c4..c5c658a25503 100644 --- a/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c +++ b/UefiPayloadPkg/IoMmuDxe/AmdIoMmu.c @@ -281,7 +281,6 @@ STATIC EFI_STATUS FreeDevPages (UINTN PFN, UINTN Pages) { LIST_ENTRY *Entry; - DEBUG ((DEBUG_VERBOSE, "FreeDevPages: PFN=0x%x Pages=0x%x\n", PFN, Pages)); // Create and insert element at head of list FREE_PAGES_LIST *FP = AllocatePool (sizeof (FREE_PAGES_LIST)); if (FP == NULL) { @@ -306,7 +305,6 @@ STATIC EFI_STATUS FreeDevPages (UINTN PFN, UINTN Pages) // Merge if possible if (FP->BasePFN == E->BasePFN + E->Pages) { - DEBUG ((DEBUG_VERBOSE, " Trying to merge\n")); E->Pages += FP->Pages; RemoveEntryList (&FP->Link); FreePool (FP); @@ -360,6 +358,7 @@ IoMmuMap ( MAP_INFO *MapInfo; UINTN PageOffset; + (void)mBusMasterOperationName; // Unused variable when building release target DEBUG (( DEBUG_VERBOSE, "%a: Operation=%a Host=0x%p Bytes=0x%Lx\n", @@ -405,6 +404,7 @@ IoMmuMap ( DEBUG ((DEBUG_VERBOSE, "AllocDevPages returned 0, free pages:\n")); BASE_LIST_FOR_EACH(Entry, &mFP) { FREE_PAGES_LIST *E = BASE_CR (Entry, FREE_PAGES_LIST, Link); + (void)E; // Unused variable when building release target DEBUG ((DEBUG_VERBOSE, "PFN %3x: 0x%x pages\n", E->BasePFN, E->Pages)); } @@ -727,30 +727,15 @@ IoMmuSetAttribute ( if (Node == NULL) return EFI_UNSUPPORTED; - DEBUG ((DEBUG_INFO, "IOMMU: remapping %s\n", - ConvertDevicePathToText( - DevicePathFromHandle(DeviceHandle), - FALSE, FALSE - ) - )); - - DEBUG ((DEBUG_INFO, " (DPA) 0x%lx -> 0x%lx (SPA), 0x%lx pages\n", - MapInfo->DevAddress, MapInfo->Address, MapInfo->NumberOfPages)); - while (!IsDevicePathEnd(Node) && (DevicePathType(Node) != HARDWARE_DEVICE_PATH || DevicePathSubType(Node) != HW_PCI_DP)) { - DEBUG ((DEBUG_INFO, " T: 0x%lx ST: 0x%lx\n", DevicePathType(Node), DevicePathSubType(Node))); Node = NextDevicePathNode(Node); } - DEBUG ((DEBUG_INFO, " Last: T: 0x%lx ST: 0x%lx\n", DevicePathType(Node), DevicePathSubType(Node))); - if (IsDevicePathEnd(Node)) return EFI_UNSUPPORTED; - DEBUG ((DEBUG_INFO, " Dev: 0x%lx Fn: 0x%lx\n", ((PCI_DEVICE_PATH *)Node)->Device, ((PCI_DEVICE_PATH *)Node)->Function)); - DeviceID = (((PCI_DEVICE_PATH *)Node)->Device << 3) | ((PCI_DEVICE_PATH *)Node)->Function; @@ -780,11 +765,6 @@ IoMmuSetAttribute ( .IW = 1, // FIXME // others 0 }; - DEBUG ((DEBUG_INFO, "\nPTE %lx:\n", DevPFN + i)); - for (int ii = 0; ii < sizeof(PTE[0]); ii++) { - if (ii%16 == 0) DEBUG ((DEBUG_INFO, "\n")); - DEBUG ((DEBUG_INFO, "%02x ", ((UINT8 *)&PTE[DevPFN + i])[ii])); - } } mDT[DeviceID].Mode = 1; // 21-bit GPA space @@ -792,34 +772,10 @@ IoMmuSetAttribute ( mDT[DeviceID].IW = 1; // FIXME mDT[DeviceID].IR = 1; // FIXME - DEBUG ((DEBUG_INFO, "\nmDT[%lx]:\n", DeviceID)); - for (int i = 0; i < sizeof(mDT[0]); i++) { - if (i%16 == 0) DEBUG ((DEBUG_INFO, "\n")); - DEBUG ((DEBUG_INFO, "%02x ", ((UINT8 *)&mDT[DeviceID])[i])); - } - - DEBUG ((DEBUG_INFO, "\n")); - // FIXME: I am lazy SendCommand(INVALIDATE_IOMMU_ALL); SendCommand(COMPLETION_WAIT(&done, IOMMU_DONE)); - DEBUG ((DEBUG_INFO, "EvtLog:\n")); - for (int i = 0; i < 0x100; i++) { - if (i%16 == 0) DEBUG ((DEBUG_INFO, "\n")); - DEBUG ((DEBUG_INFO, "%02x ", ((UINT8 *)mEvtLog)[i])); - } - - DEBUG ((DEBUG_INFO, "\n")); - - DEBUG ((DEBUG_INFO, "CmdBuf:\n")); - for (int i = 0; i < 0x100; i++) { - if (i%16 == 0) DEBUG ((DEBUG_INFO, "\n")); - DEBUG ((DEBUG_INFO, "%02x ", ((UINT8 *)mCmdBuf)[i])); - } - - DEBUG ((DEBUG_INFO, "\n")); - while (done != IOMMU_DONE) CpuPause (); @@ -865,8 +821,25 @@ AmdIoMmuExitBoot ( { DEBUG ((DEBUG_VERBOSE, "%a\n", __FUNCTION__)); // - // TODO: dump IOMMU log + // Dump IOMMU log // + UINT8 NotAllZeros = 1; + + DEBUG ((DEBUG_VERBOSE, "EvtLog:")); + for (int i = 0; i < EFI_PAGE_SIZE; i++) { + if (i%16 == 0) { + DEBUG ((DEBUG_VERBOSE, "\n")); + if (NotAllZeros == 0) { + DEBUG ((DEBUG_VERBOSE, "...")); + break; + } + NotAllZeros = 0; + } + NotAllZeros |= ((UINT8 *)mEvtLog)[i]; + DEBUG ((DEBUG_VERBOSE, "%02x ", ((UINT8 *)mEvtLog)[i])); + } + DEBUG ((DEBUG_VERBOSE, "\n")); + gBS->SignalEvent (EventToSignal); } diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index a45d5791396d..4df6c5b1e994 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -371,7 +371,7 @@ [PcdsPatchableInModule.common] gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x7 - gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8040004F + gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F !if $(SOURCE_DEBUG_ENABLE) gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17 !else