From 6749969917f3137d8f8af06b9407aac179a108b8 Mon Sep 17 00:00:00 2001 From: Guo Mang Date: Thu, 22 Dec 2016 18:26:27 +0800 Subject: OvmfPkg: Remove unused Package Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Guo Mang --- OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c | 216 --- OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.h | 29 - OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c | 105 -- OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf | 40 - OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c | 122 -- .../Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf | 39 - OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c | 89 - OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf | 40 - .../Library/EmuVariableFvbLib/EmuVariableFvbLib.c | 103 -- .../EmuVariableFvbLib/EmuVariableFvbLib.inf | 48 - .../Library/LoadLinuxLib/Ia32/JumpToKernel.nasm | 49 - OvmfPkg/Library/LoadLinuxLib/Linux.c | 670 -------- OvmfPkg/Library/LoadLinuxLib/LinuxGdt.c | 181 -- OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.h | 59 - OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf | 48 - OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.nasm | 93 - OvmfPkg/Library/LockBoxLib/LockBoxBase.c | 42 - OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf | 44 - OvmfPkg/Library/LockBoxLib/LockBoxDxe.c | 119 -- OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf | 45 - OvmfPkg/Library/LockBoxLib/LockBoxLib.c | 376 ---- OvmfPkg/Library/LockBoxLib/LockBoxLib.h | 60 - OvmfPkg/Library/NvVarsFileLib/FsAccess.c | 517 ------ OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c | 83 - OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.h | 61 - OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.inf | 60 - OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c | 1597 ----------------- OvmfPkg/Library/PlatformBdsLib/BdsPlatform.h | 292 ---- OvmfPkg/Library/PlatformBdsLib/PlatformBdsLib.inf | 72 - OvmfPkg/Library/PlatformBdsLib/PlatformData.c | 51 - OvmfPkg/Library/PlatformBdsLib/QemuKernel.c | 170 -- OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c | 287 ---- .../PlatformDebugLibIoPort.inf | 51 - .../PlatformFvbLibNull/PlatformFvbLibNull.c | 89 - .../PlatformFvbLibNull/PlatformFvbLibNull.inf | 39 - .../Library/PlatformSecureLib/PlatformSecureLib.c | 40 - .../PlatformSecureLib/PlatformSecureLib.inf | 33 - OvmfPkg/Library/QemuBootOrderLib/ExtraRootBusMap.c | 313 ---- OvmfPkg/Library/QemuBootOrderLib/ExtraRootBusMap.h | 40 - .../Library/QemuBootOrderLib/QemuBootOrderLib.c | 1793 -------------------- .../Library/QemuBootOrderLib/QemuBootOrderLib.inf | 68 - OvmfPkg/Library/QemuFwCfgLib/Ia32/IoLibExAsm.nasm | 55 - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c | 325 ---- OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf | 54 - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiDxe.c | 92 - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c | 81 - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf | 52 - OvmfPkg/Library/QemuFwCfgLib/X64/IoLibExAsm.nasm | 52 - OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c | 108 -- OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf | 42 - .../SerializeVariablesLib/SerializeVariablesLib.c | 870 ---------- .../SerializeVariablesLib/SerializeVariablesLib.h | 39 - .../SerializeVariablesLib.inf | 41 - .../SmbiosVersionLib/DetectSmbiosVersionLib.c | 107 -- .../SmbiosVersionLib/DetectSmbiosVersionLib.inf | 53 - OvmfPkg/Library/VirtioLib/VirtioLib.c | 319 ---- OvmfPkg/Library/VirtioLib/VirtioLib.inf | 36 - .../Library/VirtioMmioDeviceLib/VirtioMmioDevice.c | 224 --- .../Library/VirtioMmioDeviceLib/VirtioMmioDevice.h | 147 -- .../VirtioMmioDeviceFunctions.c | 310 ---- .../VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf | 42 - .../XenConsoleSerialPortLib.c | 302 ---- .../XenConsoleSerialPortLib.inf | 35 - .../Library/XenHypercallLib/Aarch64/Hypercall.S | 26 - OvmfPkg/Library/XenHypercallLib/Arm/Hypercall.S | 25 - OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c | 44 - .../Library/XenHypercallLib/Ia32/hypercall.nasm | 25 - OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm | 26 - OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c | 102 -- OvmfPkg/Library/XenHypercallLib/XenHypercall.c | 63 - .../Library/XenHypercallLib/XenHypercallLib.inf | 66 - OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.c | 166 -- OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf | 39 - 73 files changed, 12241 deletions(-) delete mode 100644 OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c delete mode 100644 OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.h delete mode 100644 OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c delete mode 100644 OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf delete mode 100644 OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c delete mode 100644 OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf delete mode 100644 OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c delete mode 100644 OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf delete mode 100644 OvmfPkg/Library/EmuVariableFvbLib/EmuVariableFvbLib.c delete mode 100644 OvmfPkg/Library/EmuVariableFvbLib/EmuVariableFvbLib.inf delete mode 100644 OvmfPkg/Library/LoadLinuxLib/Ia32/JumpToKernel.nasm delete mode 100644 OvmfPkg/Library/LoadLinuxLib/Linux.c delete mode 100644 OvmfPkg/Library/LoadLinuxLib/LinuxGdt.c delete mode 100644 OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.h delete mode 100644 OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf delete mode 100644 OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.nasm delete mode 100644 OvmfPkg/Library/LockBoxLib/LockBoxBase.c delete mode 100644 OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf delete mode 100644 OvmfPkg/Library/LockBoxLib/LockBoxDxe.c delete mode 100644 OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf delete mode 100644 OvmfPkg/Library/LockBoxLib/LockBoxLib.c delete mode 100644 OvmfPkg/Library/LockBoxLib/LockBoxLib.h delete mode 100644 OvmfPkg/Library/NvVarsFileLib/FsAccess.c delete mode 100644 OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c delete mode 100644 OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.h delete mode 100644 OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.inf delete mode 100644 OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c delete mode 100644 OvmfPkg/Library/PlatformBdsLib/BdsPlatform.h delete mode 100644 OvmfPkg/Library/PlatformBdsLib/PlatformBdsLib.inf delete mode 100644 OvmfPkg/Library/PlatformBdsLib/PlatformData.c delete mode 100644 OvmfPkg/Library/PlatformBdsLib/QemuKernel.c delete mode 100644 OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c delete mode 100644 OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf delete mode 100644 OvmfPkg/Library/PlatformFvbLibNull/PlatformFvbLibNull.c delete mode 100644 OvmfPkg/Library/PlatformFvbLibNull/PlatformFvbLibNull.inf delete mode 100644 OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.c delete mode 100644 OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf delete mode 100644 OvmfPkg/Library/QemuBootOrderLib/ExtraRootBusMap.c delete mode 100644 OvmfPkg/Library/QemuBootOrderLib/ExtraRootBusMap.h delete mode 100644 OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c delete mode 100644 OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf delete mode 100644 OvmfPkg/Library/QemuFwCfgLib/Ia32/IoLibExAsm.nasm delete mode 100644 OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c delete mode 100644 OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf delete mode 100644 OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiDxe.c delete mode 100644 OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c delete mode 100644 OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf delete mode 100644 OvmfPkg/Library/QemuFwCfgLib/X64/IoLibExAsm.nasm delete mode 100644 OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c delete mode 100644 OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf delete mode 100644 OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.c delete mode 100644 OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.h delete mode 100644 OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf delete mode 100644 OvmfPkg/Library/SmbiosVersionLib/DetectSmbiosVersionLib.c delete mode 100644 OvmfPkg/Library/SmbiosVersionLib/DetectSmbiosVersionLib.inf delete mode 100644 OvmfPkg/Library/VirtioLib/VirtioLib.c delete mode 100644 OvmfPkg/Library/VirtioLib/VirtioLib.inf delete mode 100644 OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c delete mode 100644 OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h delete mode 100644 OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c delete mode 100644 OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf delete mode 100644 OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c delete mode 100644 OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf delete mode 100644 OvmfPkg/Library/XenHypercallLib/Aarch64/Hypercall.S delete mode 100644 OvmfPkg/Library/XenHypercallLib/Arm/Hypercall.S delete mode 100644 OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c delete mode 100644 OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm delete mode 100644 OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm delete mode 100644 OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c delete mode 100644 OvmfPkg/Library/XenHypercallLib/XenHypercall.c delete mode 100644 OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf delete mode 100644 OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.c delete mode 100644 OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf (limited to 'OvmfPkg/Library') diff --git a/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c b/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c deleted file mode 100644 index 938b77cdc6..0000000000 --- a/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c +++ /dev/null @@ -1,216 +0,0 @@ -/** @file - ACPI Timer implements one instance of Timer Library. - - Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
- Copyright (c) 2011, Andrei Warkentin - - This program and the accompanying materials are - licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include -#include -#include - -#include "AcpiTimerLib.h" - -// -// The ACPI Time is a 24-bit counter -// -#define ACPI_TIMER_COUNT_SIZE BIT24 - -/** - Stalls the CPU for at least the given number of ticks. - - Stalls the CPU for at least the given number of ticks. It's invoked by - MicroSecondDelay() and NanoSecondDelay(). - - @param Delay A period of time to delay in ticks. - -**/ -VOID -InternalAcpiDelay ( - IN UINT32 Delay - ) -{ - UINT32 Ticks; - UINT32 Times; - - Times = Delay >> 22; - Delay &= BIT22 - 1; - do { - // - // The target timer count is calculated here - // - Ticks = InternalAcpiGetTimerTick () + Delay; - Delay = BIT22; - // - // Wait until time out - // Delay >= 2^23 could not be handled by this function - // Timer wrap-arounds are handled correctly by this function - // - while (((Ticks - InternalAcpiGetTimerTick ()) & BIT23) == 0) { - CpuPause (); - } - } while (Times-- > 0); -} - -/** - Stalls the CPU for at least the given number of microseconds. - - Stalls the CPU for the number of microseconds specified by MicroSeconds. - - @param MicroSeconds The minimum number of microseconds to delay. - - @return MicroSeconds - -**/ -UINTN -EFIAPI -MicroSecondDelay ( - IN UINTN MicroSeconds - ) -{ - InternalAcpiDelay ( - (UINT32)DivU64x32 ( - MultU64x32 ( - MicroSeconds, - ACPI_TIMER_FREQUENCY - ), - 1000000u - ) - ); - return MicroSeconds; -} - -/** - Stalls the CPU for at least the given number of nanoseconds. - - Stalls the CPU for the number of nanoseconds specified by NanoSeconds. - - @param NanoSeconds The minimum number of nanoseconds to delay. - - @return NanoSeconds - -**/ -UINTN -EFIAPI -NanoSecondDelay ( - IN UINTN NanoSeconds - ) -{ - InternalAcpiDelay ( - (UINT32)DivU64x32 ( - MultU64x32 ( - NanoSeconds, - ACPI_TIMER_FREQUENCY - ), - 1000000000u - ) - ); - return NanoSeconds; -} - -/** - Retrieves the current value of a 64-bit free running performance counter. - - Retrieves the current value of a 64-bit free running performance counter. The - counter can either count up by 1 or count down by 1. If the physical - performance counter counts by a larger increment, then the counter values - must be translated. The properties of the counter can be retrieved from - GetPerformanceCounterProperties(). - - @return The current value of the free running performance counter. - -**/ -UINT64 -EFIAPI -GetPerformanceCounter ( - VOID - ) -{ - return (UINT64)InternalAcpiGetTimerTick (); -} - -/** - Retrieves the 64-bit frequency in Hz and the range of performance counter - values. - - If StartValue is not NULL, then the value that the performance counter starts - with immediately after is it rolls over is returned in StartValue. If - EndValue is not NULL, then the value that the performance counter end with - immediately before it rolls over is returned in EndValue. The 64-bit - frequency of the performance counter in Hz is always returned. If StartValue - is less than EndValue, then the performance counter counts up. If StartValue - is greater than EndValue, then the performance counter counts down. For - example, a 64-bit free running counter that counts up would have a StartValue - of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter - that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0. - - @param StartValue The value the performance counter starts with when it - rolls over. - @param EndValue The value that the performance counter ends with before - it rolls over. - - @return The frequency in Hz. - -**/ -UINT64 -EFIAPI -GetPerformanceCounterProperties ( - OUT UINT64 *StartValue, OPTIONAL - OUT UINT64 *EndValue OPTIONAL - ) -{ - if (StartValue != NULL) { - *StartValue = 0; - } - - if (EndValue != NULL) { - *EndValue = ACPI_TIMER_COUNT_SIZE - 1; - } - - return ACPI_TIMER_FREQUENCY; -} - -/** - Converts elapsed ticks of performance counter to time in nanoseconds. - - This function converts the elapsed ticks of running performance counter to - time value in unit of nanoseconds. - - @param Ticks The number of elapsed ticks of running performance counter. - - @return The elapsed time in nanoseconds. - -**/ -UINT64 -EFIAPI -GetTimeInNanoSecond ( - IN UINT64 Ticks - ) -{ - UINT64 NanoSeconds; - UINT32 Remainder; - - // - // Ticks - // Time = --------- x 1,000,000,000 - // Frequency - // - NanoSeconds = MultU64x32 (DivU64x32Remainder (Ticks, ACPI_TIMER_FREQUENCY, &Remainder), 1000000000u); - - // - // Frequency < 0x100000000, so Remainder < 0x100000000, then (Remainder * 1,000,000,000) - // will not overflow 64-bit. - // - NanoSeconds += DivU64x32 (MultU64x32 ((UINT64) Remainder, 1000000000u), ACPI_TIMER_FREQUENCY); - - return NanoSeconds; -} diff --git a/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.h b/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.h deleted file mode 100644 index 475da70ac8..0000000000 --- a/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.h +++ /dev/null @@ -1,29 +0,0 @@ -/** @file - Internal definitions for ACPI Timer Library - - Copyright (C) 2014, Gabriel L. Somlo - - This program and the accompanying materials are licensed and made - available under the terms and conditions of the BSD License which - accompanies this distribution. The full text of the license may - be found at http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#ifndef _ACPI_TIMER_LIB_INTERNAL_H_ -#define _ACPI_TIMER_LIB_INTERNAL_H_ - -/** - Internal function to read the current tick counter of ACPI. - - @return The tick counter read. - -**/ -UINT32 -InternalAcpiGetTimerTick ( - VOID - ); - -#endif // _ACPI_TIMER_LIB_INTERNAL_H_ diff --git a/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c b/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c deleted file mode 100644 index c3c50c05d3..0000000000 --- a/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c +++ /dev/null @@ -1,105 +0,0 @@ -/** @file - Provide constructor and GetTick for Base instance of ACPI Timer Library - - Copyright (C) 2014, Gabriel L. Somlo - - This program and the accompanying materials are licensed and made - available under the terms and conditions of the BSD License which - accompanies this distribution. The full text of the license may - be found at http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#include -#include -#include -#include -#include - -// -// Cached ACPI Timer IO Address -// -STATIC UINT32 mAcpiTimerIoAddr; - -/** - The constructor function caches the ACPI tick counter address, and, - if necessary, enables ACPI IO space. - - @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. - -**/ -RETURN_STATUS -EFIAPI -AcpiTimerLibConstructor ( - VOID - ) -{ - UINT16 HostBridgeDevId; - UINTN Pmba; - UINTN AcpiCtlReg; - UINT8 AcpiEnBit; - - // - // Query Host Bridge DID to determine platform type - // - HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID); - switch (HostBridgeDevId) { - case INTEL_82441_DEVICE_ID: - Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA); - AcpiCtlReg = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC); - AcpiEnBit = PIIX4_PMREGMISC_PMIOSE; - break; - case INTEL_Q35_MCH_DEVICE_ID: - Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE); - AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL); - AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN; - break; - default: - DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n", - __FUNCTION__, HostBridgeDevId)); - ASSERT (FALSE); - return RETURN_UNSUPPORTED; - } - - mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET; - - // - // Check to see if the Power Management Base Address is already enabled - // - if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) { - // - // If the Power Management Base Address is not programmed, - // then program the Power Management Base Address from a PCD. - // - PciAndThenOr32 (Pmba, (UINT32) ~0xFFC0, PcdGet16 (PcdAcpiPmBaseAddress)); - - // - // Enable PMBA I/O port decodes - // - PciOr8 (AcpiCtlReg, AcpiEnBit); - } - - return RETURN_SUCCESS; -} - -/** - Internal function to read the current tick counter of ACPI. - - Read the current ACPI tick counter using the counter address cached - by this instance's constructor. - - @return The tick counter read. - -**/ -UINT32 -InternalAcpiGetTimerTick ( - VOID - ) -{ - // - // Return the current ACPI timer value. - // - return IoRead32 (mAcpiTimerIoAddr); -} diff --git a/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf b/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf deleted file mode 100644 index 4c0e615955..0000000000 --- a/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf +++ /dev/null @@ -1,40 +0,0 @@ -## @file -# Base ACPI Timer Library Instance. -# -# Copyright (C) 2014, Gabriel L. Somlo -# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved. -# -# This program and the accompanying materials are licensed and made -# available under the terms and conditions of the BSD License which -# accompanies this distribution. The full text of the license may -# be found at http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = BaseAcpiTimerLib - FILE_GUID = FB648CF5-91BE-4737-9023-FD807AC6D96D - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = TimerLib|PEI_CORE PEIM DXE_CORE - CONSTRUCTOR = AcpiTimerLibConstructor - -[Sources] - AcpiTimerLib.c - BaseAcpiTimerLib.c - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[Pcd] - gUefiOvmfPkgTokenSpaceGuid.PcdAcpiPmBaseAddress - -[LibraryClasses] - BaseLib - PciLib - IoLib diff --git a/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c b/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c deleted file mode 100644 index 5164769f60..0000000000 --- a/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c +++ /dev/null @@ -1,122 +0,0 @@ -/** @file - Provide constructor and GetTick for BaseRom instance of ACPI Timer Library - - Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved. - Copyright (c) 2011, Andrei Warkentin - - This program and the accompanying materials are licensed and made - available under the terms and conditions of the BSD License which - accompanies this distribution. The full text of the license may - be found at http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#include -#include -#include -#include -#include - -/** - The constructor function enables ACPI IO space. - - If ACPI I/O space not enabled, this function will enable it. - It will always return RETURN_SUCCESS. - - @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. - -**/ -RETURN_STATUS -EFIAPI -AcpiTimerLibConstructor ( - VOID - ) -{ - UINT16 HostBridgeDevId; - UINTN Pmba; - UINTN AcpiCtlReg; - UINT8 AcpiEnBit; - - // - // Query Host Bridge DID to determine platform type - // - HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID); - switch (HostBridgeDevId) { - case INTEL_82441_DEVICE_ID: - Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA); - AcpiCtlReg = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC); - AcpiEnBit = PIIX4_PMREGMISC_PMIOSE; - break; - case INTEL_Q35_MCH_DEVICE_ID: - Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE); - AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL); - AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN; - break; - default: - DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n", - __FUNCTION__, HostBridgeDevId)); - ASSERT (FALSE); - return RETURN_UNSUPPORTED; - } - - // - // Check to see if the Power Management Base Address is already enabled - // - if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) { - // - // If the Power Management Base Address is not programmed, - // then program the Power Management Base Address from a PCD. - // - PciAndThenOr32 (Pmba, (UINT32) ~0xFFC0, PcdGet16 (PcdAcpiPmBaseAddress)); - - // - // Enable PMBA I/O port decodes - // - PciOr8 (AcpiCtlReg, AcpiEnBit); - } - - return RETURN_SUCCESS; -} - -/** - Internal function to read the current tick counter of ACPI. - - Dynamically compute the address of the ACPI tick counter based on the - properties of the underlying platform, to avoid relying on global variables. - - @return The tick counter read. - -**/ -UINT32 -InternalAcpiGetTimerTick ( - VOID - ) -{ - UINT16 HostBridgeDevId; - UINTN Pmba; - - // - // Query Host Bridge DID to determine platform type - // - HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID); - switch (HostBridgeDevId) { - case INTEL_82441_DEVICE_ID: - Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA); - break; - case INTEL_Q35_MCH_DEVICE_ID: - Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE); - break; - default: - DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n", - __FUNCTION__, HostBridgeDevId)); - ASSERT (FALSE); - return 0; - } - - // - // Read PMBA to read and return the current ACPI timer value. - // - return IoRead32 ((PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET); -} diff --git a/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf b/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf deleted file mode 100644 index d5e50aef61..0000000000 --- a/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf +++ /dev/null @@ -1,39 +0,0 @@ -## @file -# BaseRom ACPI Timer Library Instance. -# -# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved. -# -# This program and the accompanying materials are licensed and made -# available under the terms and conditions of the BSD License which -# accompanies this distribution. The full text of the license may -# be found at http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = BaseRomAcpiTimerLib - FILE_GUID = CDD9D74F-213E-4c28-98F7-8B4A167DB936 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = TimerLib|SEC - CONSTRUCTOR = AcpiTimerLibConstructor - -[Sources] - AcpiTimerLib.c - BaseRomAcpiTimerLib.c - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[Pcd] - gUefiOvmfPkgTokenSpaceGuid.PcdAcpiPmBaseAddress - -[LibraryClasses] - BaseLib - PciLib - IoLib diff --git a/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c deleted file mode 100644 index e673434ae6..0000000000 --- a/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c +++ /dev/null @@ -1,89 +0,0 @@ -/** @file - Provide constructor and GetTick for Dxe instance of ACPI Timer Library - - Copyright (C) 2014, Gabriel L. Somlo - - This program and the accompanying materials are licensed and made - available under the terms and conditions of the BSD License which - accompanies this distribution. The full text of the license may - be found at http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#include -#include -#include -#include -#include - -// -// Cached ACPI Timer IO Address -// -STATIC UINT32 mAcpiTimerIoAddr; - -/** - The constructor function caches the ACPI tick counter address - - At the time this constructor runs (DXE_CORE or later), ACPI IO space - has already been enabled by either PlatformPei or by the "Base" - instance of this library. - In order to avoid querying the underlying platform type during each - tick counter read operation, we cache the counter address during - initialization of this instance of the Timer Library. - - @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. - -**/ -RETURN_STATUS -EFIAPI -AcpiTimerLibConstructor ( - VOID - ) -{ - UINT16 HostBridgeDevId; - UINTN Pmba; - - // - // Query Host Bridge DID to determine platform type - // - HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId); - switch (HostBridgeDevId) { - case INTEL_82441_DEVICE_ID: - Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA); - break; - case INTEL_Q35_MCH_DEVICE_ID: - Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE); - break; - default: - DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n", - __FUNCTION__, HostBridgeDevId)); - ASSERT (FALSE); - return RETURN_UNSUPPORTED; - } - - mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET; - - return RETURN_SUCCESS; -} - -/** - Internal function to read the current tick counter of ACPI. - - Read the current ACPI tick counter using the counter address cached - by this instance's constructor. - - @return The tick counter read. - -**/ -UINT32 -InternalAcpiGetTimerTick ( - VOID - ) -{ - // - // Return the current ACPI timer value. - // - return IoRead32 (mAcpiTimerIoAddr); -} diff --git a/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf deleted file mode 100644 index 25a9823d25..0000000000 --- a/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf +++ /dev/null @@ -1,40 +0,0 @@ -## @file -# DXE ACPI Timer Library Instance. -# -# Copyright (C) 2014, Gabriel L. Somlo -# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved. -# -# This program and the accompanying materials are licensed and made -# available under the terms and conditions of the BSD License which -# accompanies this distribution. The full text of the license may -# be found at http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = DxeAcpiTimerLib - FILE_GUID = 52DECA02-2EE8-4EAA-8EAD-1AB83F8A5955 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = TimerLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION SMM_CORE - CONSTRUCTOR = AcpiTimerLibConstructor - -[Sources] - AcpiTimerLib.c - DxeAcpiTimerLib.c - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[Pcd] - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId - -[LibraryClasses] - BaseLib - PciLib - IoLib diff --git a/OvmfPkg/Library/EmuVariableFvbLib/EmuVariableFvbLib.c b/OvmfPkg/Library/EmuVariableFvbLib/EmuVariableFvbLib.c deleted file mode 100644 index 9b449a6dec..0000000000 --- a/OvmfPkg/Library/EmuVariableFvbLib/EmuVariableFvbLib.c +++ /dev/null @@ -1,103 +0,0 @@ -/** @file - OVMF platform customization for EMU Variable FVB driver - - Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "PiDxe.h" -#include -#include -#include -#include -#include - - -/** - This function will be called following a call to the - EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL Read function. - - @param[in] This The EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance. - @param[in] Lba The starting logical block index - from which to read. - @param[in] Offset Offset into the block at which to begin reading. - @param[in] NumBytes The number of bytes read. - @param[in] Buffer Pointer to the buffer that was read, and will be - returned to the caller. - -**/ -VOID -EFIAPI -PlatformFvbDataRead ( - IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, - IN EFI_LBA Lba, - IN UINTN Offset, - IN UINTN NumBytes, - IN UINT8 *Buffer - ) -{ -} - - -/** - This function will be called following a call to the - EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL Write function. - - @param[in] This EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance. - @param[in] Lba The starting logical block index to written to. - @param[in] Offset Offset into the block at which to begin writing. - @param[in] NumBytes The number of bytes written. - @param[in] Buffer Pointer to the buffer that was written. - -**/ -VOID -EFIAPI -PlatformFvbDataWritten ( - IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, - IN EFI_LBA Lba, - IN UINTN Offset, - IN UINTN NumBytes, - IN UINT8 *Buffer - ) -{ - STATIC EFI_EVENT EventToSignal = NULL; - - if (!EfiAtRuntime ()) { - if (EventToSignal == NULL) { - EventToSignal = (EFI_EVENT)(UINTN) PcdGet64 (PcdEmuVariableEvent); - } - if (EventToSignal != NULL) { - gBS->SignalEvent (EventToSignal); - } - } -} - - -/** - This function will be called following a call to the - EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL Erase function. - - @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL - instance. - @param List The variable argument list as documented for - the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL Erase - function. - -**/ -VOID -EFIAPI -PlatformFvbBlocksErased ( - IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, - IN VA_LIST List - ) -{ -} - - diff --git a/OvmfPkg/Library/EmuVariableFvbLib/EmuVariableFvbLib.inf b/OvmfPkg/Library/EmuVariableFvbLib/EmuVariableFvbLib.inf deleted file mode 100644 index ec6764d760..0000000000 --- a/OvmfPkg/Library/EmuVariableFvbLib/EmuVariableFvbLib.inf +++ /dev/null @@ -1,48 +0,0 @@ -## @file -# OVMF platform customization for EMU Variable FVB driver -# -# This library handles hooks for the EMU Variable FVB driver. -# -# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = EmuVariableFvbLib - FILE_GUID = 8a6062ed-7140-4a74-b4ea-fe900e79e24b - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = PlatformFvbLib|DXE_RUNTIME_DRIVER - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources] - EmuVariableFvbLib.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseLib - BaseMemoryLib - DebugLib - MemoryAllocationLib - -[Pcd] - gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent - diff --git a/OvmfPkg/Library/LoadLinuxLib/Ia32/JumpToKernel.nasm b/OvmfPkg/Library/LoadLinuxLib/Ia32/JumpToKernel.nasm deleted file mode 100644 index fcb686c644..0000000000 --- a/OvmfPkg/Library/LoadLinuxLib/Ia32/JumpToKernel.nasm +++ /dev/null @@ -1,49 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
-; -; This program and the accompanying materials -; are licensed and made available under the terms and conditions of the BSD License -; which accompanies this distribution. The full text of the license may be found at -; http://opensource.org/licenses/bsd-license.php. -; -; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -; -;------------------------------------------------------------------------------ - - SECTION .text - -;------------------------------------------------------------------------------ -; VOID -; EFIAPI -; JumpToKernel ( -; VOID *KernelStart, -; VOID *KernelBootParams -; ); -;------------------------------------------------------------------------------ -global ASM_PFX(JumpToKernel) -ASM_PFX(JumpToKernel): - - mov esi, [esp + 8] - call DWORD [esp + 4] - ret - -;------------------------------------------------------------------------------ -; VOID -; EFIAPI -; JumpToUefiKernel ( -; EFI_HANDLE ImageHandle, -; EFI_SYSTEM_TABLE *SystemTable, -; VOID *KernelBootParams, -; VOID *KernelStart -; ); -;------------------------------------------------------------------------------ -global ASM_PFX(JumpToUefiKernel) -ASM_PFX(JumpToUefiKernel): - - mov eax, [esp + 12] - mov eax, [eax + 0x264] - add eax, [esp + 16] - jmp eax - diff --git a/OvmfPkg/Library/LoadLinuxLib/Linux.c b/OvmfPkg/Library/LoadLinuxLib/Linux.c deleted file mode 100644 index 9c996adfbb..0000000000 --- a/OvmfPkg/Library/LoadLinuxLib/Linux.c +++ /dev/null @@ -1,670 +0,0 @@ -/** @file - - Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "LoadLinuxLib.h" - - -/** - A simple check of the kernel setup image - - An assumption is made that the size of the data is at least the - size of struct boot_params. - - @param[in] KernelSetup - The kernel setup image - - @retval EFI_SUCCESS - The kernel setup looks valid and supported - @retval EFI_INVALID_PARAMETER - KernelSetup was NULL - @retval EFI_UNSUPPORTED - The kernel setup is not valid or supported - -**/ -STATIC -EFI_STATUS -EFIAPI -BasicKernelSetupCheck ( - IN VOID *KernelSetup - ) -{ - return LoadLinuxCheckKernelSetup(KernelSetup, sizeof (struct boot_params)); -} - - -EFI_STATUS -EFIAPI -LoadLinuxCheckKernelSetup ( - IN VOID *KernelSetup, - IN UINTN KernelSetupSize - ) -{ - struct boot_params *Bp; - - if (KernelSetup == NULL) { - return EFI_INVALID_PARAMETER; - } - - if (KernelSetupSize < sizeof (*Bp)) { - return EFI_UNSUPPORTED; - } - - Bp = (struct boot_params*) KernelSetup; - - if ((Bp->hdr.signature != 0xAA55) || // Check boot sector signature - (Bp->hdr.header != SETUP_HDR) || - (Bp->hdr.version < 0x205) || // We only support relocatable kernels - (!Bp->hdr.relocatable_kernel) - ) { - return EFI_UNSUPPORTED; - } else { - return EFI_SUCCESS; - } -} - - -UINTN -EFIAPI -LoadLinuxGetKernelSize ( - IN VOID *KernelSetup, - IN UINTN KernelSize - ) -{ - struct boot_params *Bp; - - if (EFI_ERROR (BasicKernelSetupCheck (KernelSetup))) { - return 0; - } - - Bp = (struct boot_params*) KernelSetup; - - if (Bp->hdr.version > 0x20a) { - return Bp->hdr.init_size; - } else { - // - // Add extra size for kernel decompression - // - return 3 * KernelSize; - } -} - - -VOID* -EFIAPI -LoadLinuxAllocateKernelSetupPages ( - IN UINTN Pages - ) -{ - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS Address; - - Address = BASE_1GB; - Status = gBS->AllocatePages ( - AllocateMaxAddress, - EfiLoaderData, - Pages, - &Address - ); - if (!EFI_ERROR (Status)) { - return (VOID*)(UINTN) Address; - } else { - return NULL; - } -} - -EFI_STATUS -EFIAPI -LoadLinuxInitializeKernelSetup ( - IN VOID *KernelSetup - ) -{ - EFI_STATUS Status; - UINTN SetupEnd; - struct boot_params *Bp; - - Status = BasicKernelSetupCheck (KernelSetup); - if (EFI_ERROR (Status)) { - return Status; - } - - Bp = (struct boot_params*) KernelSetup; - - SetupEnd = 0x202 + (Bp->hdr.jump & 0xff); - - // - // Clear all but the setup_header - // - ZeroMem (KernelSetup, 0x1f1); - ZeroMem (((UINT8 *)KernelSetup) + SetupEnd, 4096 - SetupEnd); - DEBUG ((EFI_D_INFO, "Cleared kernel setup 0-0x1f1, 0x%Lx-0x1000\n", - (UINT64)SetupEnd)); - - return EFI_SUCCESS; -} - -VOID* -EFIAPI -LoadLinuxAllocateKernelPages ( - IN VOID *KernelSetup, - IN UINTN Pages - ) -{ - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS KernelAddress; - UINT32 Loop; - struct boot_params *Bp; - - if (EFI_ERROR (BasicKernelSetupCheck (KernelSetup))) { - return NULL; - } - - Bp = (struct boot_params*) KernelSetup; - - for (Loop = 1; Loop < 512; Loop++) { - KernelAddress = MultU64x32 ( - 2 * Bp->hdr.kernel_alignment, - Loop - ); - Status = gBS->AllocatePages ( - AllocateAddress, - EfiLoaderData, - Pages, - &KernelAddress - ); - if (!EFI_ERROR (Status)) { - return (VOID*)(UINTN) KernelAddress; - } - } - - return NULL; -} - - -VOID* -EFIAPI -LoadLinuxAllocateCommandLinePages ( - IN UINTN Pages - ) -{ - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS Address; - - Address = 0xa0000; - Status = gBS->AllocatePages ( - AllocateMaxAddress, - EfiLoaderData, - Pages, - &Address - ); - if (!EFI_ERROR (Status)) { - return (VOID*)(UINTN) Address; - } else { - return NULL; - } -} - - -VOID* -EFIAPI -LoadLinuxAllocateInitrdPages ( - IN VOID *KernelSetup, - IN UINTN Pages - ) -{ - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS Address; - - struct boot_params *Bp; - - if (EFI_ERROR (BasicKernelSetupCheck (KernelSetup))) { - return NULL; - } - - Bp = (struct boot_params*) KernelSetup; - - Address = (EFI_PHYSICAL_ADDRESS)(UINTN) Bp->hdr.ramdisk_max; - Status = gBS->AllocatePages ( - AllocateMaxAddress, - EfiLoaderData, - Pages, - &Address - ); - if (!EFI_ERROR (Status)) { - return (VOID*)(UINTN) Address; - } else { - return NULL; - } -} - - -STATIC -VOID -SetupLinuxMemmap ( - IN OUT struct boot_params *Bp - ) -{ - EFI_STATUS Status; - UINT8 TmpMemoryMap[1]; - UINTN MapKey; - UINTN DescriptorSize; - UINT32 DescriptorVersion; - UINTN MemoryMapSize; - EFI_MEMORY_DESCRIPTOR *MemoryMap; - EFI_MEMORY_DESCRIPTOR *MemoryMapPtr; - UINTN Index; - struct efi_info *Efi; - struct e820_entry *LastE820; - struct e820_entry *E820; - UINTN E820EntryCount; - EFI_PHYSICAL_ADDRESS LastEndAddr; - - // - // Get System MemoryMapSize - // - MemoryMapSize = sizeof (TmpMemoryMap); - Status = gBS->GetMemoryMap ( - &MemoryMapSize, - (EFI_MEMORY_DESCRIPTOR *)TmpMemoryMap, - &MapKey, - &DescriptorSize, - &DescriptorVersion - ); - ASSERT (Status == EFI_BUFFER_TOO_SMALL); - // - // Enlarge space here, because we will allocate pool now. - // - MemoryMapSize += EFI_PAGE_SIZE; - Status = gBS->AllocatePool ( - EfiLoaderData, - MemoryMapSize, - (VOID **) &MemoryMap - ); - ASSERT_EFI_ERROR (Status); - - // - // Get System MemoryMap - // - Status = gBS->GetMemoryMap ( - &MemoryMapSize, - MemoryMap, - &MapKey, - &DescriptorSize, - &DescriptorVersion - ); - ASSERT_EFI_ERROR (Status); - - LastE820 = NULL; - E820 = &Bp->e820_map[0]; - E820EntryCount = 0; - LastEndAddr = 0; - MemoryMapPtr = MemoryMap; - for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) { - UINTN E820Type = 0; - - if (MemoryMap->NumberOfPages == 0) { - continue; - } - - switch(MemoryMap->Type) { - case EfiReservedMemoryType: - case EfiRuntimeServicesCode: - case EfiRuntimeServicesData: - case EfiMemoryMappedIO: - case EfiMemoryMappedIOPortSpace: - case EfiPalCode: - E820Type = E820_RESERVED; - break; - - case EfiUnusableMemory: - E820Type = E820_UNUSABLE; - break; - - case EfiACPIReclaimMemory: - E820Type = E820_ACPI; - break; - - case EfiLoaderCode: - case EfiLoaderData: - case EfiBootServicesCode: - case EfiBootServicesData: - case EfiConventionalMemory: - E820Type = E820_RAM; - break; - - case EfiACPIMemoryNVS: - E820Type = E820_NVS; - break; - - default: - DEBUG (( - EFI_D_ERROR, - "Invalid EFI memory descriptor type (0x%x)!\n", - MemoryMap->Type - )); - continue; - } - - if ((LastE820 != NULL) && - (LastE820->type == (UINT32) E820Type) && - (MemoryMap->PhysicalStart == LastEndAddr)) { - LastE820->size += EFI_PAGES_TO_SIZE ((UINTN) MemoryMap->NumberOfPages); - LastEndAddr += EFI_PAGES_TO_SIZE ((UINTN) MemoryMap->NumberOfPages); - } else { - if (E820EntryCount >= (sizeof (Bp->e820_map) / sizeof (Bp->e820_map[0]))) { - break; - } - E820->type = (UINT32) E820Type; - E820->addr = MemoryMap->PhysicalStart; - E820->size = EFI_PAGES_TO_SIZE ((UINTN) MemoryMap->NumberOfPages); - LastE820 = E820; - LastEndAddr = E820->addr + E820->size; - E820++; - E820EntryCount++; - } - - // - // Get next item - // - MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemoryMap + DescriptorSize); - } - Bp->e820_entries = (UINT8) E820EntryCount; - - Efi = &Bp->efi_info; - Efi->efi_systab = (UINT32)(UINTN) gST; - Efi->efi_memdesc_size = (UINT32) DescriptorSize; - Efi->efi_memdesc_version = DescriptorVersion; - Efi->efi_memmap = (UINT32)(UINTN) MemoryMapPtr; - Efi->efi_memmap_size = (UINT32) MemoryMapSize; -#ifdef MDE_CPU_IA32 - Efi->efi_loader_signature = SIGNATURE_32 ('E', 'L', '3', '2'); -#else - Efi->efi_systab_hi = (UINT32) (((UINT64)(UINTN) gST) >> 32); - Efi->efi_memmap_hi = (UINT32) (((UINT64)(UINTN) MemoryMapPtr) >> 32); - Efi->efi_loader_signature = SIGNATURE_32 ('E', 'L', '6', '4'); -#endif - - gBS->ExitBootServices (gImageHandle, MapKey); -} - - -EFI_STATUS -EFIAPI -LoadLinuxSetCommandLine ( - IN OUT VOID *KernelSetup, - IN CHAR8 *CommandLine - ) -{ - EFI_STATUS Status; - struct boot_params *Bp; - - Status = BasicKernelSetupCheck (KernelSetup); - if (EFI_ERROR (Status)) { - return Status; - } - - Bp = (struct boot_params*) KernelSetup; - - Bp->hdr.cmd_line_ptr = (UINT32)(UINTN) CommandLine; - - return EFI_SUCCESS; -} - - -EFI_STATUS -EFIAPI -LoadLinuxSetInitrd ( - IN OUT VOID *KernelSetup, - IN VOID *Initrd, - IN UINTN InitrdSize - ) -{ - EFI_STATUS Status; - struct boot_params *Bp; - - Status = BasicKernelSetupCheck (KernelSetup); - if (EFI_ERROR (Status)) { - return Status; - } - - Bp = (struct boot_params*) KernelSetup; - - Bp->hdr.ramdisk_start = (UINT32)(UINTN) Initrd; - Bp->hdr.ramdisk_len = (UINT32) InitrdSize; - - return EFI_SUCCESS; -} - - -STATIC VOID -FindBits ( - unsigned long Mask, - UINT8 *Pos, - UINT8 *Size - ) -{ - UINT8 First, Len; - - First = 0; - Len = 0; - - if (Mask) { - while (!(Mask & 0x1)) { - Mask = Mask >> 1; - First++; - } - - while (Mask & 0x1) { - Mask = Mask >> 1; - Len++; - } - } - *Pos = First; - *Size = Len; -} - - -STATIC -EFI_STATUS -SetupGraphicsFromGop ( - struct screen_info *Si, - EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop - ) -{ - EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; - EFI_STATUS Status; - UINTN Size; - - Status = Gop->QueryMode(Gop, Gop->Mode->Mode, &Size, &Info); - if (EFI_ERROR (Status)) { - return Status; - } - - /* We found a GOP */ - - /* EFI framebuffer */ - Si->orig_video_isVGA = 0x70; - - Si->orig_x = 0; - Si->orig_y = 0; - Si->orig_video_page = 0; - Si->orig_video_mode = 0; - Si->orig_video_cols = 0; - Si->orig_video_lines = 0; - Si->orig_video_ega_bx = 0; - Si->orig_video_points = 0; - - Si->lfb_base = (UINT32) Gop->Mode->FrameBufferBase; - Si->lfb_size = (UINT32) Gop->Mode->FrameBufferSize; - Si->lfb_width = (UINT16) Info->HorizontalResolution; - Si->lfb_height = (UINT16) Info->VerticalResolution; - Si->pages = 1; - Si->vesapm_seg = 0; - Si->vesapm_off = 0; - - if (Info->PixelFormat == PixelRedGreenBlueReserved8BitPerColor) { - Si->lfb_depth = 32; - Si->red_size = 8; - Si->red_pos = 0; - Si->green_size = 8; - Si->green_pos = 8; - Si->blue_size = 8; - Si->blue_pos = 16; - Si->rsvd_size = 8; - Si->rsvd_pos = 24; - Si->lfb_linelength = (UINT16) (Info->PixelsPerScanLine * 4); - - } else if (Info->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) { - Si->lfb_depth = 32; - Si->red_size = 8; - Si->red_pos = 16; - Si->green_size = 8; - Si->green_pos = 8; - Si->blue_size = 8; - Si->blue_pos = 0; - Si->rsvd_size = 8; - Si->rsvd_pos = 24; - Si->lfb_linelength = (UINT16) (Info->PixelsPerScanLine * 4); - } else if (Info->PixelFormat == PixelBitMask) { - FindBits(Info->PixelInformation.RedMask, - &Si->red_pos, &Si->red_size); - FindBits(Info->PixelInformation.GreenMask, - &Si->green_pos, &Si->green_size); - FindBits(Info->PixelInformation.BlueMask, - &Si->blue_pos, &Si->blue_size); - FindBits(Info->PixelInformation.ReservedMask, - &Si->rsvd_pos, &Si->rsvd_size); - Si->lfb_depth = Si->red_size + Si->green_size + - Si->blue_size + Si->rsvd_size; - Si->lfb_linelength = (UINT16) ((Info->PixelsPerScanLine * Si->lfb_depth) / 8); - } else { - Si->lfb_depth = 4; - Si->red_size = 0; - Si->red_pos = 0; - Si->green_size = 0; - Si->green_pos = 0; - Si->blue_size = 0; - Si->blue_pos = 0; - Si->rsvd_size = 0; - Si->rsvd_pos = 0; - Si->lfb_linelength = Si->lfb_width / 2; - } - - return Status; -} - - -STATIC -EFI_STATUS -SetupGraphics ( - IN OUT struct boot_params *Bp - ) -{ - EFI_STATUS Status; - EFI_HANDLE *HandleBuffer; - UINTN HandleCount; - UINTN Index; - EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop; - - ZeroMem ((VOID*)&Bp->screen_info, sizeof(Bp->screen_info)); - - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiGraphicsOutputProtocolGuid, - NULL, - &HandleCount, - &HandleBuffer - ); - if (!EFI_ERROR (Status)) { - for (Index = 0; Index < HandleCount; Index++) { - Status = gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiGraphicsOutputProtocolGuid, - (VOID*) &Gop - ); - if (EFI_ERROR (Status)) { - continue; - } - - Status = SetupGraphicsFromGop (&Bp->screen_info, Gop); - if (!EFI_ERROR (Status)) { - FreePool (HandleBuffer); - return EFI_SUCCESS; - } - } - - FreePool (HandleBuffer); - } - - return EFI_NOT_FOUND; -} - - -STATIC -EFI_STATUS -SetupLinuxBootParams ( - IN OUT struct boot_params *Bp - ) -{ - SetupGraphics (Bp); - - SetupLinuxMemmap (Bp); - - return EFI_SUCCESS; -} - - -EFI_STATUS -EFIAPI -LoadLinux ( - IN VOID *Kernel, - IN OUT VOID *KernelSetup - ) -{ - EFI_STATUS Status; - struct boot_params *Bp; - - Status = BasicKernelSetupCheck (KernelSetup); - if (EFI_ERROR (Status)) { - return Status; - } - - Bp = (struct boot_params *) KernelSetup; - - if (Bp->hdr.version < 0x205 || !Bp->hdr.relocatable_kernel) { - // - // We only support relocatable kernels - // - return EFI_UNSUPPORTED; - } - - InitLinuxDescriptorTables (); - - Bp->hdr.code32_start = (UINT32)(UINTN) Kernel; - if (Bp->hdr.version >= 0x20c && Bp->hdr.handover_offset && - (Bp->hdr.xloadflags & (sizeof (UINTN) == 4 ? BIT2 : BIT3))) { - DEBUG ((EFI_D_INFO, "Jumping to kernel EFI handover point at ofs %x\n", Bp->hdr.handover_offset)); - - DisableInterrupts (); - JumpToUefiKernel ((VOID*) gImageHandle, (VOID*) gST, KernelSetup, Kernel); - } - - // - // Old kernels without EFI handover protocol - // - SetupLinuxBootParams (KernelSetup); - - DEBUG ((EFI_D_INFO, "Jumping to kernel\n")); - DisableInterrupts (); - SetLinuxDescriptorTables (); - JumpToKernel (Kernel, (VOID*) KernelSetup); - - return EFI_SUCCESS; -} - diff --git a/OvmfPkg/Library/LoadLinuxLib/LinuxGdt.c b/OvmfPkg/Library/LoadLinuxLib/LinuxGdt.c deleted file mode 100644 index 4e20436246..0000000000 --- a/OvmfPkg/Library/LoadLinuxLib/LinuxGdt.c +++ /dev/null @@ -1,181 +0,0 @@ -/** @file - Initialize GDT for Linux. - - Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "LoadLinuxLib.h" - - -// -// Local structure definitions -// - -#pragma pack (1) - -// -// Global Descriptor Entry structures -// - -typedef struct _GDT_ENTRY { - UINT16 Limit15_0; - UINT16 Base15_0; - UINT8 Base23_16; - UINT8 Type; - UINT8 Limit19_16_and_flags; - UINT8 Base31_24; -} GDT_ENTRY; - -typedef -struct _GDT_ENTRIES { - GDT_ENTRY Null; - GDT_ENTRY Null2; - GDT_ENTRY Linear; - GDT_ENTRY LinearCode; - GDT_ENTRY TaskSegment; - GDT_ENTRY Spare4; - GDT_ENTRY Spare5; -} GDT_ENTRIES; - -#pragma pack () - -STATIC GDT_ENTRIES *mGdt = NULL; - -// -// Global descriptor table (GDT) Template -// -STATIC GDT_ENTRIES GdtTemplate = { - // - // Null - // - { - 0x0, // limit 15:0 - 0x0, // base 15:0 - 0x0, // base 23:16 - 0x0, // type - 0x0, // limit 19:16, flags - 0x0, // base 31:24 - }, - // - // Null2 - // - { - 0x0, // limit 15:0 - 0x0, // base 15:0 - 0x0, // base 23:16 - 0x0, // type - 0x0, // limit 19:16, flags - 0x0, // base 31:24 - }, - // - // Linear - // - { - 0x0FFFF, // limit 0xFFFFF - 0x0, // base 0 - 0x0, - 0x09A, // present, ring 0, data, expand-up, writable - 0x0CF, // page-granular, 32-bit - 0x0, - }, - // - // LinearCode - // - { - 0x0FFFF, // limit 0xFFFFF - 0x0, // base 0 - 0x0, - 0x092, // present, ring 0, data, expand-up, writable - 0x0CF, // page-granular, 32-bit - 0x0, - }, - // - // TaskSegment - // - { - 0x0, // limit 0 - 0x0, // base 0 - 0x0, - 0x089, // ? - 0x080, // ? - 0x0, - }, - // - // Spare4 - // - { - 0x0, // limit 0 - 0x0, // base 0 - 0x0, - 0x0, // present, ring 0, data, expand-up, writable - 0x0, // page-granular, 32-bit - 0x0, - }, - // - // Spare5 - // - { - 0x0, // limit 0 - 0x0, // base 0 - 0x0, - 0x0, // present, ring 0, data, expand-up, writable - 0x0, // page-granular, 32-bit - 0x0, - }, -}; - -/** - Initialize Global Descriptor Table. - -**/ -VOID -InitLinuxDescriptorTables ( - VOID - ) -{ - // - // Allocate Runtime Data for the GDT - // - mGdt = AllocateRuntimePool (sizeof (GdtTemplate) + 8); - ASSERT (mGdt != NULL); - mGdt = ALIGN_POINTER (mGdt, 8); - - // - // Initialize all GDT entries - // - CopyMem (mGdt, &GdtTemplate, sizeof (GdtTemplate)); - -} - -/** - Initialize Global Descriptor Table. - -**/ -VOID -SetLinuxDescriptorTables ( - VOID - ) -{ - IA32_DESCRIPTOR GdtPtr; - IA32_DESCRIPTOR IdtPtr; - - // - // Write GDT register - // - GdtPtr.Base = (UINT32)(UINTN)(VOID*) mGdt; - GdtPtr.Limit = (UINT16) (sizeof (GdtTemplate) - 1); - AsmWriteGdtr (&GdtPtr); - - IdtPtr.Base = (UINT32) 0; - IdtPtr.Limit = (UINT16) 0; - AsmWriteIdtr (&IdtPtr); -} - diff --git a/OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.h b/OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.h deleted file mode 100644 index 045cbf9b2f..0000000000 --- a/OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.h +++ /dev/null @@ -1,59 +0,0 @@ -/** @file - Boot UEFI Linux. - - Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef _LOAD_LINUX_LIB_INCLUDED_ -#define _LOAD_LINUX_LIB_INCLUDED_ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -VOID -EFIAPI -JumpToKernel ( - VOID *KernelStart, - VOID *KernelBootParams - ); - -VOID -EFIAPI -JumpToUefiKernel ( - EFI_HANDLE ImageHandle, - EFI_SYSTEM_TABLE *SystemTable, - VOID *KernelBootParams, - VOID *KernelStart - ); - -VOID -InitLinuxDescriptorTables ( - VOID - ); - -VOID -SetLinuxDescriptorTables ( - VOID - ); - -#endif - diff --git a/OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf b/OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf deleted file mode 100644 index 12d2f4f084..0000000000 --- a/OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf +++ /dev/null @@ -1,48 +0,0 @@ -## @file -# -# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = LoadLinuxLib - FILE_GUID = eaec1915-65a0-43a9-bf0b-a76438da61db - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = LoadLinuxLib - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 -# - -[Sources.common] - Linux.c - LinuxGdt.c - -[Sources.IA32] - Ia32/JumpToKernel.nasm - -[Sources.X64] - X64/JumpToKernel.nasm - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseLib - DebugLib - MemoryAllocationLib - BaseMemoryLib - diff --git a/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.nasm b/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.nasm deleted file mode 100644 index 128dcef0f6..0000000000 --- a/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.nasm +++ /dev/null @@ -1,93 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
-; -; This program and the accompanying materials -; are licensed and made available under the terms and conditions of the BSD License -; which accompanies this distribution. The full text of the license may be found at -; http://opensource.org/licenses/bsd-license.php. -; -; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -; -;------------------------------------------------------------------------------ - - DEFAULT REL - SECTION .text - -;------------------------------------------------------------------------------ -; VOID -; EFIAPI -; JumpToKernel ( -; VOID *KernelStart, // rcx -; VOID *KernelBootParams // rdx -; ); -;------------------------------------------------------------------------------ -global ASM_PFX(JumpToKernel) -ASM_PFX(JumpToKernel): - - ; Set up for executing kernel. BP in %esi, entry point on the stack - ; (64-bit when the 'ret' will use it as 32-bit, but we're little-endian) - mov rsi, rdx - push rcx - - ; Jump into the compatibility mode CS - push 0x10 - lea rax, [.0] - push rax - DB 0x48, 0xcb ; retfq - -.0: - ; Now in compatibility mode. - - DB 0xb8, 0x18, 0x0, 0x0, 0x0 ; movl $0x18, %eax - DB 0x8e, 0xd8 ; movl %eax, %ds - DB 0x8e, 0xc0 ; movl %eax, %es - DB 0x8e, 0xe0 ; movl %eax, %fs - DB 0x8e, 0xe8 ; movl %eax, %gs - DB 0x8e, 0xd0 ; movl %eax, %ss - - ; Disable paging - DB 0xf, 0x20, 0xc0 ; movl %cr0, %eax - DB 0xf, 0xba, 0xf8, 0x1f ; btcl $31, %eax - DB 0xf, 0x22, 0xc0 ; movl %eax, %cr0 - - ; Disable long mode in EFER - DB 0xb9, 0x80, 0x0, 0x0, 0xc0 ; movl $0x0c0000080, %ecx - DB 0xf, 0x32 ; rdmsr - DB 0xf, 0xba, 0xf8, 0x8 ; btcl $8, %eax - DB 0xf, 0x30 ; wrmsr - - ; Disable PAE - DB 0xf, 0x20, 0xe0 ; movl %cr4, %eax - DB 0xf, 0xba, 0xf8, 0x5 ; btcl $5, %eax - DB 0xf, 0x22, 0xe0 ; movl %eax, %cr4 - - DB 0x31, 0xed ; xor %ebp, %ebp - DB 0x31, 0xff ; xor %edi, %edi - DB 0x31, 0xdb ; xor %ebx, %ebx - DB 0xc3 ; ret - -;------------------------------------------------------------------------------ -; VOID -; EFIAPI -; JumpToUefiKernel ( -; EFI_HANDLE ImageHandle, // rcx -; EFI_SYSTEM_TABLE *SystemTable, // rdx -; VOID *KernelBootParams // r8 -; VOID *KernelStart, // r9 -; ); -;------------------------------------------------------------------------------ -global ASM_PFX(JumpToUefiKernel) -ASM_PFX(JumpToUefiKernel): - - mov rdi, rcx - mov rsi, rdx - mov rdx, r8 - xor rax, rax - mov eax, [r8 + 0x264] - add r9, rax - add r9, 0x200 - call r9 - ret - diff --git a/OvmfPkg/Library/LockBoxLib/LockBoxBase.c b/OvmfPkg/Library/LockBoxLib/LockBoxBase.c deleted file mode 100644 index 8f367701f3..0000000000 --- a/OvmfPkg/Library/LockBoxLib/LockBoxBase.c +++ /dev/null @@ -1,42 +0,0 @@ -/** @file - - Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php. - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include - -#include -#include - -/** - Allocates a buffer of type EfiACPIMemoryNVS. - - Allocates the number bytes specified by AllocationSize of type - EfiACPIMemoryNVS and returns a pointer to the allocated buffer. - If AllocationSize is 0, then a valid buffer of 0 size is - returned. If there is not enough memory remaining to satisfy - the request, then NULL is returned. - - @param AllocationSize The number of bytes to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateAcpiNvsPool ( - IN UINTN AllocationSize - ) -{ - ASSERT_EFI_ERROR (RETURN_UNSUPPORTED); - return NULL; -} diff --git a/OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf b/OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf deleted file mode 100644 index 7203d0777d..0000000000 --- a/OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf +++ /dev/null @@ -1,44 +0,0 @@ -## @file -# -# Library implementing the LockBox interface for OVMF -# -# Copyright (C) 2013, Red Hat, Inc. -# Copyright (c) 2014, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials are licensed and made available -# under the terms and conditions of the BSD License which accompanies this -# distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR -# IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = LockBoxBaseLib - FILE_GUID = 17CA9B37-5BAB-492C-A09C-7121FBE34CE6 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = LockBoxLib - - CONSTRUCTOR = LockBoxLibInitialize - -[Sources] - LockBoxBase.c - LockBoxLib.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseMemoryLib - DebugLib - -[Pcd] - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize diff --git a/OvmfPkg/Library/LockBoxLib/LockBoxDxe.c b/OvmfPkg/Library/LockBoxLib/LockBoxDxe.c deleted file mode 100644 index c8f2ec8a4e..0000000000 --- a/OvmfPkg/Library/LockBoxLib/LockBoxDxe.c +++ /dev/null @@ -1,119 +0,0 @@ -/** @file - - Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php. - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include - -#include -#include -#include -#include -#include - -/** - Allocate memory below 4G memory address. - - This function allocates memory below 4G memory address. - - @param MemoryType Memory type of memory to allocate. - @param Size Size of memory to allocate. - - @return Allocated address for output. - -**/ -STATIC -VOID * -AllocateMemoryBelow4G ( - IN EFI_MEMORY_TYPE MemoryType, - IN UINTN Size - ) -{ - UINTN Pages; - EFI_PHYSICAL_ADDRESS Address; - EFI_STATUS Status; - VOID* Buffer; - UINTN AllocRemaining; - - Pages = EFI_SIZE_TO_PAGES (Size); - Address = 0xffffffff; - - // - // Since we need to use gBS->AllocatePages to get a buffer below - // 4GB, there is a good chance that space will be wasted for very - // small allocation. We keep track of unused portions of the page - // allocations, and use these to allocate memory for small buffers. - // - ASSERT (mLockBoxGlobal->Signature == LOCK_BOX_GLOBAL_SIGNATURE); - if ((UINTN) mLockBoxGlobal->SubPageRemaining >= Size) { - Buffer = (VOID*)(UINTN) mLockBoxGlobal->SubPageBuffer; - mLockBoxGlobal->SubPageBuffer += (UINT32) Size; - mLockBoxGlobal->SubPageRemaining -= (UINT32) Size; - return Buffer; - } - - Status = gBS->AllocatePages ( - AllocateMaxAddress, - MemoryType, - Pages, - &Address - ); - if (EFI_ERROR (Status)) { - return NULL; - } - - Buffer = (VOID *) (UINTN) Address; - ZeroMem (Buffer, EFI_PAGES_TO_SIZE (Pages)); - - AllocRemaining = EFI_PAGES_TO_SIZE (Pages) - Size; - if (AllocRemaining > (UINTN) mLockBoxGlobal->SubPageRemaining) { - mLockBoxGlobal->SubPageBuffer = (UINT32) (Address + Size); - mLockBoxGlobal->SubPageRemaining = (UINT32) AllocRemaining; - } - - return Buffer; -} - - -/** - Allocates a buffer of type EfiACPIMemoryNVS. - - Allocates the number bytes specified by AllocationSize of type - EfiACPIMemoryNVS and returns a pointer to the allocated buffer. - If AllocationSize is 0, then a valid buffer of 0 size is - returned. If there is not enough memory remaining to satisfy - the request, then NULL is returned. - - @param AllocationSize The number of bytes to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateAcpiNvsPool ( - IN UINTN AllocationSize - ) -{ - return AllocateMemoryBelow4G (EfiACPIMemoryNVS, AllocationSize); -} - - -EFI_STATUS -EFIAPI -LockBoxDxeLibInitialize ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - return LockBoxLibInitialize (); -} diff --git a/OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf b/OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf deleted file mode 100644 index a4d27a598d..0000000000 --- a/OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf +++ /dev/null @@ -1,45 +0,0 @@ -## @file -# -# Library implementing the LockBox interface for OVMF -# -# Copyright (C) 2013, Red Hat, Inc. -# Copyright (c) 2014, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials are licensed and made available -# under the terms and conditions of the BSD License which accompanies this -# distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR -# IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = LockBoxDxeLib - FILE_GUID = f61c9a34-2e18-44ce-af2f-21a998e64fda - MODULE_TYPE = DXE_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = LockBoxLib - - CONSTRUCTOR = LockBoxDxeLibInitialize - -[Sources] - LockBoxDxe.c - LockBoxLib.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseMemoryLib - DebugLib - UefiBootServicesTableLib - -[Pcd] - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize diff --git a/OvmfPkg/Library/LockBoxLib/LockBoxLib.c b/OvmfPkg/Library/LockBoxLib/LockBoxLib.c deleted file mode 100644 index 89050ac87c..0000000000 --- a/OvmfPkg/Library/LockBoxLib/LockBoxLib.c +++ /dev/null @@ -1,376 +0,0 @@ -/** @file - - Library implementing the LockBox interface for OVMF - - Copyright (C) 2013, Red Hat, Inc. - Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.
- - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License which accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include -#include -#include -#include -#include -#include - -#pragma pack(1) -typedef struct { - EFI_GUID Guid; - EFI_PHYSICAL_ADDRESS OrigAddress; - EFI_PHYSICAL_ADDRESS CopyAddress; - UINT32 Size; - UINT64 Attributes; -} LOCK_BOX_ENTRY; -#pragma pack() - -LOCK_BOX_GLOBAL *mLockBoxGlobal = NULL; -STATIC LOCK_BOX_ENTRY *StartOfEntries = NULL; -STATIC LOCK_BOX_ENTRY *EndOfEntries = NULL; - -RETURN_STATUS -EFIAPI -LockBoxLibInitialize ( - VOID - ) -{ - UINTN NumEntries; - - if (PcdGet32 (PcdOvmfLockBoxStorageSize) < sizeof (LOCK_BOX_GLOBAL)) { - return RETURN_UNSUPPORTED; - } - - mLockBoxGlobal = (LOCK_BOX_GLOBAL *)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageBase); - StartOfEntries = ((LOCK_BOX_ENTRY *) (mLockBoxGlobal + 1)); - NumEntries = ((PcdGet32 (PcdOvmfLockBoxStorageSize) - sizeof (LOCK_BOX_GLOBAL)) / - sizeof (LOCK_BOX_ENTRY)); - EndOfEntries = StartOfEntries + NumEntries; - if (mLockBoxGlobal->Signature != LOCK_BOX_GLOBAL_SIGNATURE) { - // - // Note: This code depends on the lock box being cleared in early - // PEI before usage, so the SubPageBuffer and SubPageRemaining - // fields don't need to be set to 0. - // - mLockBoxGlobal->Signature = LOCK_BOX_GLOBAL_SIGNATURE; - } - return RETURN_SUCCESS; -} - - -/** - Find LockBox entry based on GUID. - - @param[in] Guid The GUID to search for. - - @return Address of the LOCK_BOX_ENTRY found. - - If NULL, then the item was not found, and there is no space - left to store a new item. - - If non-NULL and LOCK_BOX_ENTRY.Size == 0, then the item was not - found, but a new item can be inserted at the returned location. - - If non-NULL and LOCK_BOX_ENTRY.Size > 0, then the item was found. -**/ -STATIC -LOCK_BOX_ENTRY * -EFIAPI -FindHeaderByGuid ( - IN CONST EFI_GUID *Guid - ) -{ - LOCK_BOX_ENTRY *Header; - - for (Header = StartOfEntries; Header < EndOfEntries; Header++) { - if (Header->Size == 0 || CompareGuid (Guid, &Header->Guid)) { - return Header; - } - } - - return NULL; -} - - -/** - This function will save confidential information to lockbox. - - @param Guid the guid to identify the confidential information - @param Buffer the address of the confidential information - @param Length the length of the confidential information - - @retval RETURN_SUCCESS the information is saved successfully. - @retval RETURN_INVALID_PARAMETER the Guid is NULL, or Buffer is NULL, or - Length is 0 - @retval RETURN_ALREADY_STARTED the requested GUID already exist. - @retval RETURN_OUT_OF_RESOURCES no enough resource to save the information. - @retval RETURN_ACCESS_DENIED it is too late to invoke this interface - @retval RETURN_NOT_STARTED it is too early to invoke this interface - @retval RETURN_UNSUPPORTED the service is not supported by - implementaion. -**/ -RETURN_STATUS -EFIAPI -SaveLockBox ( - IN GUID *Guid, - IN VOID *Buffer, - IN UINTN Length - ) -{ - LOCK_BOX_ENTRY *Header; - VOID *CopyBuffer; - - DEBUG ((DEBUG_VERBOSE, "%a: Guid=%g Buffer=%p Length=0x%x\n", __FUNCTION__, - Guid, Buffer, (UINT32) Length)); - - if (Guid == NULL || Buffer == NULL || Length == 0) { - return RETURN_INVALID_PARAMETER; - } - - if (Length > 0xFFFFFFFF) { - return RETURN_OUT_OF_RESOURCES; - } - - Header = FindHeaderByGuid (Guid); - if (Header == NULL) { - return RETURN_OUT_OF_RESOURCES; - } - - if (Header->Size > 0) { - return RETURN_ALREADY_STARTED; - } - - CopyBuffer = AllocateAcpiNvsPool (Length); - if (CopyBuffer == NULL) { - return RETURN_OUT_OF_RESOURCES; - } - - // - // overwrite the current terminator header with new metadata - // - CopyGuid (&Header->Guid, Guid); - Header->OrigAddress = (UINTN) Buffer; - Header->CopyAddress = (UINTN) CopyBuffer; - Header->Size = (UINT32) Length; - Header->Attributes = 0; - - // - // copy contents - // - CopyMem (CopyBuffer, Buffer, Length); - - return RETURN_SUCCESS; -} - - -/** - This function will set lockbox attributes. - - @param Guid the guid to identify the confidential information - @param Attributes the attributes of the lockbox - - @retval RETURN_SUCCESS the information is saved successfully. - @retval RETURN_INVALID_PARAMETER attributes is invalid. - @retval RETURN_NOT_FOUND the requested GUID not found. - @retval RETURN_ACCESS_DENIED it is too late to invoke this interface - @retval RETURN_NOT_STARTED it is too early to invoke this interface - @retval RETURN_UNSUPPORTED the service is not supported by - implementaion. -**/ -RETURN_STATUS -EFIAPI -SetLockBoxAttributes ( - IN GUID *Guid, - IN UINT64 Attributes - ) -{ - LOCK_BOX_ENTRY *Header; - - DEBUG ((DEBUG_VERBOSE, "%a: Guid=%g Attributes=0x%Lx\n", __FUNCTION__, Guid, - Attributes)); - - if (Guid == NULL) { - return RETURN_INVALID_PARAMETER; - } - - Header = FindHeaderByGuid (Guid); - if (!Header || Header->Size == 0) { - return RETURN_NOT_FOUND; - } - Header->Attributes = Attributes; - - return RETURN_SUCCESS; -} - - -/** - This function will update confidential information to lockbox. - - @param Guid the guid to identify the original confidential information - @param Offset the offset of the original confidential information - @param Buffer the address of the updated confidential information - @param Length the length of the updated confidential information - - @retval RETURN_SUCCESS the information is saved successfully. - @retval RETURN_INVALID_PARAMETER the Guid is NULL, or Buffer is NULL, or - Length is 0. - @retval RETURN_NOT_FOUND the requested GUID not found. - @retval RETURN_BUFFER_TOO_SMALL the original buffer to too small to hold - new information. - @retval RETURN_ACCESS_DENIED it is too late to invoke this interface - @retval RETURN_NOT_STARTED it is too early to invoke this interface - @retval RETURN_UNSUPPORTED the service is not supported by - implementaion. -**/ -RETURN_STATUS -EFIAPI -UpdateLockBox ( - IN GUID *Guid, - IN UINTN Offset, - IN VOID *Buffer, - IN UINTN Length - ) -{ - LOCK_BOX_ENTRY *Header; - - DEBUG ((DEBUG_VERBOSE, "%a: Guid=%g Offset=0x%x Length=0x%x\n", __FUNCTION__, - Guid, (UINT32) Offset, (UINT32) Length)); - - if (Guid == NULL || Buffer == NULL || Length == 0) { - return RETURN_INVALID_PARAMETER; - } - - Header = FindHeaderByGuid (Guid); - if (!Header || Header->Size == 0) { - return RETURN_NOT_FOUND; - } - - if (Header->Size < Offset || - Length > Header->Size - Offset) { - return RETURN_BUFFER_TOO_SMALL; - } - - CopyMem ((UINT8 *)(UINTN) (Header->CopyAddress) + Offset, Buffer, Length); - - return RETURN_SUCCESS; -} - - -/** - This function will restore confidential information from lockbox. - - @param Guid the guid to identify the confidential information - @param Buffer the address of the restored confidential information - NULL means restored to original address, Length MUST be NULL at - same time. - @param Length the length of the restored confidential information - - @retval RETURN_SUCCESS the information is restored successfully. - @retval RETURN_INVALID_PARAMETER the Guid is NULL, or one of Buffer and - Length is NULL. - @retval RETURN_WRITE_PROTECTED Buffer and Length are NULL, but the LockBox - has no LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE - attribute. - @retval RETURN_BUFFER_TOO_SMALL the Length is too small to hold the - confidential information. - @retval RETURN_NOT_FOUND the requested GUID not found. - @retval RETURN_NOT_STARTED it is too early to invoke this interface - @retval RETURN_ACCESS_DENIED not allow to restore to the address - @retval RETURN_UNSUPPORTED the service is not supported by - implementaion. -**/ -RETURN_STATUS -EFIAPI -RestoreLockBox ( - IN GUID *Guid, - IN VOID *Buffer, OPTIONAL - IN OUT UINTN *Length OPTIONAL - ) -{ - LOCK_BOX_ENTRY *Header; - - DEBUG ((DEBUG_VERBOSE, "%a: Guid=%g Buffer=%p\n", __FUNCTION__, Guid, - Buffer)); - - if ((Guid == NULL) || - ((Buffer == NULL) && (Length != NULL)) || - ((Buffer != NULL) && (Length == NULL))) { - return EFI_INVALID_PARAMETER; - } - - Header = FindHeaderByGuid (Guid); - if (!Header || Header->Size == 0) { - return RETURN_NOT_FOUND; - } - - if (Buffer == NULL) { - if (!(Header->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE)) { - return RETURN_WRITE_PROTECTED; - } - if (Header->OrigAddress + (Header->Size - 1) > MAX_ADDRESS) { - return RETURN_UNSUPPORTED; - } - Buffer = (VOID *)(UINTN) Header->OrigAddress; - } - - // - // Set RestoreLength - // - if (Length != NULL) { - if (Header->Size > *Length) { - // - // Input buffer is too small to hold all data. - // - *Length = Header->Size; - return EFI_BUFFER_TOO_SMALL; - } - *Length = Header->Size; - } - - CopyMem (Buffer, (VOID*)(UINTN) Header->CopyAddress, Header->Size); - - return RETURN_SUCCESS; -} - - -/** - This function will restore confidential information from all lockbox which - have RestoreInPlace attribute. - - @retval RETURN_SUCCESS the information is restored successfully. - @retval RETURN_NOT_STARTED it is too early to invoke this interface - @retval RETURN_UNSUPPORTED the service is not supported by - implementaion. -**/ -RETURN_STATUS -EFIAPI -RestoreAllLockBoxInPlace ( - VOID - ) -{ - LOCK_BOX_ENTRY *Header; - - for (Header = StartOfEntries; - Header < EndOfEntries && Header->Size > 0; - Header++) { - if (Header->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) { - VOID *Buffer; - - if (Header->OrigAddress + (Header->Size - 1) > MAX_ADDRESS) { - return RETURN_UNSUPPORTED; - } - Buffer = (VOID *)(UINTN) Header->OrigAddress; - CopyMem (Buffer, (VOID*)(UINTN)Header->CopyAddress, Header->Size); - DEBUG ((DEBUG_VERBOSE, "%a: Guid=%g Buffer=%p\n", __FUNCTION__, - &Header->Guid, Buffer)); - } - } - return RETURN_SUCCESS; -} diff --git a/OvmfPkg/Library/LockBoxLib/LockBoxLib.h b/OvmfPkg/Library/LockBoxLib/LockBoxLib.h deleted file mode 100644 index 5adb65fef2..0000000000 --- a/OvmfPkg/Library/LockBoxLib/LockBoxLib.h +++ /dev/null @@ -1,60 +0,0 @@ -/** @file - - Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __LOCK_BOX_LIB_IMPL_H__ -#define __LOCK_BOX_LIB_IMPL_H__ - -#pragma pack(1) - -typedef struct { - UINT32 Signature; - UINT32 SubPageBuffer; - UINT32 SubPageRemaining; -} LOCK_BOX_GLOBAL; - -#define LOCK_BOX_GLOBAL_SIGNATURE SIGNATURE_32('L', 'B', 'G', 'S') - -extern LOCK_BOX_GLOBAL *mLockBoxGlobal; - -#pragma pack() - -/** - Allocates a buffer of type EfiACPIMemoryNVS. - - Allocates the number bytes specified by AllocationSize of type - EfiACPIMemoryNVS and returns a pointer to the allocated buffer. - If AllocationSize is 0, then a valid buffer of 0 size is - returned. If there is not enough memory remaining to satisfy - the request, then NULL is returned. - - @param AllocationSize The number of bytes to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateAcpiNvsPool ( - IN UINTN AllocationSize - ); - - -RETURN_STATUS -EFIAPI -LockBoxLibInitialize ( - VOID - ); - - -#endif diff --git a/OvmfPkg/Library/NvVarsFileLib/FsAccess.c b/OvmfPkg/Library/NvVarsFileLib/FsAccess.c deleted file mode 100644 index 5df8de4985..0000000000 --- a/OvmfPkg/Library/NvVarsFileLib/FsAccess.c +++ /dev/null @@ -1,517 +0,0 @@ -/** @file - File System Access for NvVarsFileLib - - Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "NvVarsFileLib.h" - -#include -#include -#include - - -/** - Open the NvVars file for reading or writing - - @param[in] FsHandle - Handle for a gEfiSimpleFileSystemProtocolGuid instance - @param[in] ReadingFile - TRUE: open the file for reading. FALSE: writing - @param[out] NvVarsFile - If EFI_SUCCESS is returned, then this is updated - with the opened NvVars file. - - @return EFI_SUCCESS if the file was opened - -**/ -EFI_STATUS -GetNvVarsFile ( - IN EFI_HANDLE FsHandle, - IN BOOLEAN ReadingFile, - OUT EFI_FILE_HANDLE *NvVarsFile - ) -{ - EFI_STATUS Status; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs; - EFI_FILE_HANDLE Root; - - // - // Get the FileSystem protocol on that handle - // - Status = gBS->HandleProtocol ( - FsHandle, - &gEfiSimpleFileSystemProtocolGuid, - (VOID **)&Fs - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Get the volume (the root directory) - // - Status = Fs->OpenVolume (Fs, &Root); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Attempt to open the NvVars file in the root directory - // - Status = Root->Open ( - Root, - NvVarsFile, - L"NvVars", - ReadingFile ? - EFI_FILE_MODE_READ : - ( - EFI_FILE_MODE_CREATE | - EFI_FILE_MODE_READ | - EFI_FILE_MODE_WRITE - ), - 0 - ); - if (EFI_ERROR (Status)) { - return Status; - } - - return Status; -} - - -/** - Open the NvVars file for reading or writing - - @param[in] File - The file to inspect - @param[out] Exists - Returns whether the file exists - @param[out] Size - Returns the size of the file - (0 if the file does not exist) - -**/ -VOID -NvVarsFileReadCheckup ( - IN EFI_FILE_HANDLE File, - OUT BOOLEAN *Exists, - OUT UINTN *Size - ) -{ - EFI_FILE_INFO *FileInfo; - - *Exists = FALSE; - *Size = 0; - - FileInfo = FileHandleGetInfo (File); - if (FileInfo == NULL) { - return; - } - - if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) != 0) { - FreePool (FileInfo); - return; - } - - *Exists = TRUE; - *Size = (UINTN) FileInfo->FileSize; - - FreePool (FileInfo); -} - - -/** - Open the NvVars file for reading or writing - - @param[in] File - The file to inspect - @param[out] Exists - Returns whether the file exists - @param[out] Size - Returns the size of the file - (0 if the file does not exist) - -**/ -EFI_STATUS -FileHandleEmpty ( - IN EFI_FILE_HANDLE File - ) -{ - EFI_STATUS Status; - EFI_FILE_INFO *FileInfo; - - // - // Retrieve the FileInfo structure - // - FileInfo = FileHandleGetInfo (File); - if (FileInfo == NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // If the path is a directory, then return an error - // - if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) != 0) { - FreePool (FileInfo); - return EFI_INVALID_PARAMETER; - } - - // - // If the file size is already 0, then it is empty, so - // we can return success. - // - if (FileInfo->FileSize == 0) { - FreePool (FileInfo); - return EFI_SUCCESS; - } - - // - // Set the file size to 0. - // - FileInfo->FileSize = 0; - Status = FileHandleSetInfo (File, FileInfo); - - FreePool (FileInfo); - - return Status; -} - - -/** - Reads a file to a newly allocated buffer - - @param[in] File - The file to read - @param[in] ReadSize - The size of data to read from the file - - @return Pointer to buffer allocated to hold the file - contents. NULL if an error occured. - -**/ -VOID* -FileHandleReadToNewBuffer ( - IN EFI_FILE_HANDLE FileHandle, - IN UINTN ReadSize - ) -{ - EFI_STATUS Status; - UINTN ActualReadSize; - VOID *FileContents; - - ActualReadSize = ReadSize; - FileContents = AllocatePool (ReadSize); - if (FileContents != NULL) { - Status = FileHandleRead ( - FileHandle, - &ReadSize, - FileContents - ); - if (EFI_ERROR (Status) || (ActualReadSize != ReadSize)) { - FreePool (FileContents); - return NULL; - } - } - - return FileContents; -} - - -/** - Reads the contents of the NvVars file on the file system - - @param[in] FsHandle - Handle for a gEfiSimpleFileSystemProtocolGuid instance - - @return EFI_STATUS based on the success or failure of the file read - -**/ -EFI_STATUS -ReadNvVarsFile ( - IN EFI_HANDLE FsHandle - ) -{ - EFI_STATUS Status; - EFI_FILE_HANDLE File; - UINTN FileSize; - BOOLEAN FileExists; - VOID *FileContents; - EFI_HANDLE SerializedVariables; - - Status = GetNvVarsFile (FsHandle, TRUE, &File); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_INFO, "FsAccess.c: Could not open NV Variables file on this file system\n")); - return Status; - } - - NvVarsFileReadCheckup (File, &FileExists, &FileSize); - if (FileSize == 0) { - FileHandleClose (File); - return EFI_UNSUPPORTED; - } - - FileContents = FileHandleReadToNewBuffer (File, FileSize); - if (FileContents == NULL) { - FileHandleClose (File); - return EFI_UNSUPPORTED; - } - - DEBUG (( - EFI_D_INFO, - "FsAccess.c: Read %Lu bytes from NV Variables file\n", - (UINT64)FileSize - )); - - Status = SerializeVariablesNewInstanceFromBuffer ( - &SerializedVariables, - FileContents, - FileSize - ); - if (!RETURN_ERROR (Status)) { - Status = SerializeVariablesSetSerializedVariables (SerializedVariables); - } - - FreePool (FileContents); - FileHandleClose (File); - - return Status; -} - - -/** - Writes a variable to indicate that the NV variables - have been loaded from the file system. - -**/ -STATIC -VOID -SetNvVarsVariable ( - VOID - ) -{ - BOOLEAN VarData; - UINTN Size; - - // - // Write a variable to indicate we've already loaded the - // variable data. If it is found, we skip the loading on - // subsequent attempts. - // - Size = sizeof (VarData); - VarData = TRUE; - gRT->SetVariable ( - L"NvVars", - &gEfiSimpleFileSystemProtocolGuid, - EFI_VARIABLE_NON_VOLATILE | - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, - Size, - (VOID*) &VarData - ); -} - - -/** - Loads the non-volatile variables from the NvVars file on the - given file system. - - @param[in] FsHandle - Handle for a gEfiSimpleFileSystemProtocolGuid instance - - @return EFI_STATUS based on the success or failure of load operation - -**/ -EFI_STATUS -LoadNvVarsFromFs ( - EFI_HANDLE FsHandle - ) -{ - EFI_STATUS Status; - BOOLEAN VarData; - UINTN Size; - - DEBUG ((EFI_D_INFO, "FsAccess.c: LoadNvVarsFromFs\n")); - - // - // We write a variable to indicate we've already loaded the - // variable data. If it is found, we skip the loading. - // - // This is relevent if the non-volatile variable have been - // able to survive a reboot operation. In that case, we don't - // want to re-load the file as it would overwrite newer changes - // made to the variables. - // - Size = sizeof (VarData); - VarData = TRUE; - Status = gRT->GetVariable ( - L"NvVars", - &gEfiSimpleFileSystemProtocolGuid, - NULL, - &Size, - (VOID*) &VarData - ); - if (Status == EFI_SUCCESS) { - DEBUG ((EFI_D_INFO, "NV Variables were already loaded\n")); - return EFI_ALREADY_STARTED; - } - - // - // Attempt to restore the variables from the NvVars file. - // - Status = ReadNvVarsFile (FsHandle); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_INFO, "Error while restoring NV variable data\n")); - return Status; - } - - // - // Write a variable to indicate we've already loaded the - // variable data. If it is found, we skip the loading on - // subsequent attempts. - // - SetNvVarsVariable(); - - DEBUG (( - EFI_D_INFO, - "FsAccess.c: Read NV Variables file (size=%Lu)\n", - (UINT64)Size - )); - - return Status; -} - - -STATIC -RETURN_STATUS -EFIAPI -IterateVariablesCallbackAddAllNvVariables ( - IN VOID *Context, - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - IN UINT32 Attributes, - IN UINTN DataSize, - IN VOID *Data - ) -{ - EFI_HANDLE Instance; - - Instance = (EFI_HANDLE) Context; - - // - // Only save non-volatile variables - // - if ((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) { - return RETURN_SUCCESS; - } - - return SerializeVariablesAddVariable ( - Instance, - VariableName, - VendorGuid, - Attributes, - DataSize, - Data - ); -} - - -/** - Saves the non-volatile variables into the NvVars file on the - given file system. - - @param[in] FsHandle - Handle for a gEfiSimpleFileSystemProtocolGuid instance - - @return EFI_STATUS based on the success or failure of load operation - -**/ -EFI_STATUS -SaveNvVarsToFs ( - EFI_HANDLE FsHandle - ) -{ - EFI_STATUS Status; - EFI_FILE_HANDLE File; - UINTN WriteSize; - UINTN VariableDataSize; - VOID *VariableData; - EFI_HANDLE SerializedVariables; - - SerializedVariables = NULL; - - Status = SerializeVariablesNewInstance (&SerializedVariables); - if (EFI_ERROR (Status)) { - return Status; - } - - Status = SerializeVariablesIterateSystemVariables ( - IterateVariablesCallbackAddAllNvVariables, - (VOID*) SerializedVariables - ); - if (EFI_ERROR (Status)) { - return Status; - } - - VariableData = NULL; - VariableDataSize = 0; - Status = SerializeVariablesToBuffer ( - SerializedVariables, - NULL, - &VariableDataSize - ); - if (Status == RETURN_BUFFER_TOO_SMALL) { - VariableData = AllocatePool (VariableDataSize); - if (VariableData == NULL) { - Status = EFI_OUT_OF_RESOURCES; - } else { - Status = SerializeVariablesToBuffer ( - SerializedVariables, - VariableData, - &VariableDataSize - ); - } - } - - SerializeVariablesFreeInstance (SerializedVariables); - - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Open the NvVars file for writing. - // - Status = GetNvVarsFile (FsHandle, FALSE, &File); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_INFO, "FsAccess.c: Unable to open file to saved NV Variables\n")); - return Status; - } - - // - // Empty the starting file contents. - // - Status = FileHandleEmpty (File); - if (EFI_ERROR (Status)) { - FileHandleClose (File); - return Status; - } - - WriteSize = VariableDataSize; - Status = FileHandleWrite (File, &WriteSize, VariableData); - if (EFI_ERROR (Status)) { - return Status; - } - - FileHandleClose (File); - - if (!EFI_ERROR (Status)) { - // - // Write a variable to indicate we've already loaded the - // variable data. If it is found, we skip the loading on - // subsequent attempts. - // - SetNvVarsVariable(); - - DEBUG ((EFI_D_INFO, "Saved NV Variables to NvVars file\n")); - } - - return Status; - -} - - diff --git a/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c b/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c deleted file mode 100644 index c89bb4af7d..0000000000 --- a/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c +++ /dev/null @@ -1,83 +0,0 @@ -/** @file - Save Non-Volatile Variables to a file system. - - Copyright (c) 2009, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "NvVarsFileLib.h" -#include -#include - -EFI_HANDLE mNvVarsFileLibFsHandle = NULL; - - -/** - Attempts to connect the NvVarsFileLib to the specified file system. - - @param[in] FsHandle - Handle for a gEfiSimpleFileSystemProtocolGuid instance - - @return The EFI_STATUS while attempting to connect the NvVarsFileLib - to the file system instance. - @retval EFI_SUCCESS - The given file system was connected successfully - -**/ -EFI_STATUS -EFIAPI -ConnectNvVarsToFileSystem ( - IN EFI_HANDLE FsHandle - ) -{ - EFI_STATUS Status; - - // - // We might fail to load the variable, since the file system initially - // will not have the NvVars file. - // - LoadNvVarsFromFs (FsHandle); - - // - // We must be able to save the variables successfully to the file system - // to have connected successfully. - // - Status = SaveNvVarsToFs (FsHandle); - if (!EFI_ERROR (Status)) { - mNvVarsFileLibFsHandle = FsHandle; - } - - return Status; -} - - -/** - Update non-volatile variables stored on the file system. - - @return The EFI_STATUS while attempting to update the variable on - the connected file system. - @retval EFI_SUCCESS - The non-volatile variables were saved to the disk - @retval EFI_NOT_STARTED - A file system has not been connected - -**/ -EFI_STATUS -EFIAPI -UpdateNvVarsOnFileSystem ( - ) -{ - if (mNvVarsFileLibFsHandle == NULL) { - // - // A file system had not been connected to the library. - // - return EFI_NOT_STARTED; - } else { - return SaveNvVarsToFs (mNvVarsFileLibFsHandle); - } -} - - diff --git a/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.h b/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.h deleted file mode 100644 index ac3a3d6363..0000000000 --- a/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.h +++ /dev/null @@ -1,61 +0,0 @@ -/** @file - Save Non-Volatile Variables to a file system. - - Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __NV_VARS_FILE_LIB_INSTANCE__ -#define __NV_VARS_FILE_LIB_INSTANCE__ - -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include - -/** - Loads the non-volatile variables from the NvVars file on the - given file system. - - @param[in] FsHandle - Handle for a gEfiSimpleFileSystemProtocolGuid instance - - @return EFI_STATUS based on the success or failure of load operation - -**/ -EFI_STATUS -LoadNvVarsFromFs ( - EFI_HANDLE FsHandle - ); - - -/** - Saves the non-volatile variables into the NvVars file on the - given file system. - - @param[in] FsHandle - Handle for a gEfiSimpleFileSystemProtocolGuid instance - - @return EFI_STATUS based on the success or failure of load operation - -**/ -EFI_STATUS -SaveNvVarsToFs ( - EFI_HANDLE FsHandle - ); - -#endif - diff --git a/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.inf b/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.inf deleted file mode 100644 index 76fbae0870..0000000000 --- a/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.inf +++ /dev/null @@ -1,60 +0,0 @@ -## @file -# NvVarsFileLib -# -# This library saves and restores non-volatile variables in a -# file within a file system. -# -# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = NvVarsFileLib - FILE_GUID = 9172fe8b-9a36-40f8-bba5-5e57a44390bd - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = NvVarsFileLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER UEFI_DRIVER - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources] - FsAccess.c - NvVarsFileLib.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - OvmfPkg/OvmfPkg.dec - ShellPkg/ShellPkg.dec - -[LibraryClasses] - BaseLib - BaseMemoryLib - DebugLib - FileHandleLib - MemoryAllocationLib - SerializeVariablesLib - -[Protocols] - gEfiSimpleFileSystemProtocolGuid ## CONSUMES - - -[Guids] - gEfiFileInfoGuid - -[Depex] - gEfiVariableWriteArchProtocolGuid - diff --git a/OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c b/OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c deleted file mode 100644 index 0abba98dfe..0000000000 --- a/OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c +++ /dev/null @@ -1,1597 +0,0 @@ -/** @file - Platform BDS customizations. - - Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "BdsPlatform.h" -#include - - -// -// Global data -// - -VOID *mEfiDevPathNotifyReg; -EFI_EVENT mEfiDevPathEvent; -VOID *mEmuVariableEventReg; -EFI_EVENT mEmuVariableEvent; -BOOLEAN mDetectVgaOnly; -UINT16 mHostBridgeDevId; - -// -// Table of host IRQs matching PCI IRQs A-D -// (for configuring PCI Interrupt Line register) -// -CONST UINT8 PciHostIrqs[] = { - 0x0a, 0x0a, 0x0b, 0x0b -}; - -// -// Array Size macro -// -#define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0])) - -// -// Type definitions -// - -typedef -EFI_STATUS -(EFIAPI *PROTOCOL_INSTANCE_CALLBACK)( - IN EFI_HANDLE Handle, - IN VOID *Instance, - IN VOID *Context - ); - -/** - @param[in] Handle - Handle of PCI device instance - @param[in] PciIo - PCI IO protocol instance - @param[in] Pci - PCI Header register block -**/ -typedef -EFI_STATUS -(EFIAPI *VISIT_PCI_INSTANCE_CALLBACK)( - IN EFI_HANDLE Handle, - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN PCI_TYPE00 *Pci - ); - - -// -// Function prototypes -// - -EFI_STATUS -VisitAllInstancesOfProtocol ( - IN EFI_GUID *Id, - IN PROTOCOL_INSTANCE_CALLBACK CallBackFunction, - IN VOID *Context - ); - -EFI_STATUS -VisitAllPciInstancesOfProtocol ( - IN VISIT_PCI_INSTANCE_CALLBACK CallBackFunction - ); - -VOID -InstallDevicePathCallback ( - VOID - ); - -// -// BDS Platform Functions -// -VOID -EFIAPI -PlatformBdsInit ( - VOID - ) -/*++ - -Routine Description: - - Platform Bds init. Incude the platform firmware vendor, revision - and so crc check. - -Arguments: - -Returns: - - None. - ---*/ -{ - DEBUG ((EFI_D_INFO, "PlatformBdsInit\n")); - InstallDevicePathCallback (); -} - - -EFI_STATUS -EFIAPI -ConnectRootBridge ( - IN EFI_HANDLE RootBridgeHandle, - IN VOID *Instance, - IN VOID *Context - ) -{ - EFI_STATUS Status; - - // - // Make the PCI bus driver connect the root bridge, non-recursively. This - // will produce a number of child handles with PciIo on them. - // - Status = gBS->ConnectController ( - RootBridgeHandle, // ControllerHandle - NULL, // DriverImageHandle - NULL, // RemainingDevicePath -- produce all - // children - FALSE // Recursive - ); - return Status; -} - - -EFI_STATUS -PrepareLpcBridgeDevicePath ( - IN EFI_HANDLE DeviceHandle - ) -/*++ - -Routine Description: - - Add IsaKeyboard to ConIn, - add IsaSerial to ConOut, ConIn, ErrOut. - LPC Bridge: 06 01 00 - -Arguments: - - DeviceHandle - Handle of PCIIO protocol. - -Returns: - - EFI_SUCCESS - LPC bridge is added to ConOut, ConIn, and ErrOut. - EFI_STATUS - No LPC bridge is added. - ---*/ -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; - CHAR16 *DevPathStr; - - DevicePath = NULL; - Status = gBS->HandleProtocol ( - DeviceHandle, - &gEfiDevicePathProtocolGuid, - (VOID*)&DevicePath - ); - if (EFI_ERROR (Status)) { - return Status; - } - TempDevicePath = DevicePath; - - // - // Register Keyboard - // - DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnpPs2KeyboardDeviceNode); - - BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL); - - // - // Register COM1 - // - DevicePath = TempDevicePath; - gPnp16550ComPortDeviceNode.UID = 0; - - DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnp16550ComPortDeviceNode); - DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode); - DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode); - - // - // Print Device Path - // - DevPathStr = DevicePathToStr(DevicePath); - if (DevPathStr != NULL) { - DEBUG(( - EFI_D_INFO, - "BdsPlatform.c+%d: COM%d DevPath: %s\n", - __LINE__, - gPnp16550ComPortDeviceNode.UID + 1, - DevPathStr - )); - FreePool(DevPathStr); - } - - BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL); - BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL); - BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL); - - // - // Register COM2 - // - DevicePath = TempDevicePath; - gPnp16550ComPortDeviceNode.UID = 1; - - DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnp16550ComPortDeviceNode); - DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode); - DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode); - - // - // Print Device Path - // - DevPathStr = DevicePathToStr(DevicePath); - if (DevPathStr != NULL) { - DEBUG(( - EFI_D_INFO, - "BdsPlatform.c+%d: COM%d DevPath: %s\n", - __LINE__, - gPnp16550ComPortDeviceNode.UID + 1, - DevPathStr - )); - FreePool(DevPathStr); - } - - BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL); - BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL); - BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL); - - return EFI_SUCCESS; -} - -EFI_STATUS -GetGopDevicePath ( - IN EFI_DEVICE_PATH_PROTOCOL *PciDevicePath, - OUT EFI_DEVICE_PATH_PROTOCOL **GopDevicePath - ) -{ - UINTN Index; - EFI_STATUS Status; - EFI_HANDLE PciDeviceHandle; - EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; - EFI_DEVICE_PATH_PROTOCOL *TempPciDevicePath; - UINTN GopHandleCount; - EFI_HANDLE *GopHandleBuffer; - - if (PciDevicePath == NULL || GopDevicePath == NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // Initialize the GopDevicePath to be PciDevicePath - // - *GopDevicePath = PciDevicePath; - TempPciDevicePath = PciDevicePath; - - Status = gBS->LocateDevicePath ( - &gEfiDevicePathProtocolGuid, - &TempPciDevicePath, - &PciDeviceHandle - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Try to connect this handle, so that GOP dirver could start on this - // device and create child handles with GraphicsOutput Protocol installed - // on them, then we get device paths of these child handles and select - // them as possible console device. - // - gBS->ConnectController (PciDeviceHandle, NULL, NULL, FALSE); - - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiGraphicsOutputProtocolGuid, - NULL, - &GopHandleCount, - &GopHandleBuffer - ); - if (!EFI_ERROR (Status)) { - // - // Add all the child handles as possible Console Device - // - for (Index = 0; Index < GopHandleCount; Index++) { - Status = gBS->HandleProtocol (GopHandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID*)&TempDevicePath); - if (EFI_ERROR (Status)) { - continue; - } - if (CompareMem ( - PciDevicePath, - TempDevicePath, - GetDevicePathSize (PciDevicePath) - END_DEVICE_PATH_LENGTH - ) == 0) { - // - // In current implementation, we only enable one of the child handles - // as console device, i.e. sotre one of the child handle's device - // path to variable "ConOut" - // In futhure, we could select all child handles to be console device - // - - *GopDevicePath = TempDevicePath; - - // - // Delete the PCI device's path that added by GetPlugInPciVgaDevicePath() - // Add the integrity GOP device path. - // - BdsLibUpdateConsoleVariable (VarConsoleOutDev, NULL, PciDevicePath); - BdsLibUpdateConsoleVariable (VarConsoleOutDev, TempDevicePath, NULL); - } - } - gBS->FreePool (GopHandleBuffer); - } - - return EFI_SUCCESS; -} - -EFI_STATUS -PreparePciVgaDevicePath ( - IN EFI_HANDLE DeviceHandle - ) -/*++ - -Routine Description: - - Add PCI VGA to ConOut. - PCI VGA: 03 00 00 - -Arguments: - - DeviceHandle - Handle of PCIIO protocol. - -Returns: - - EFI_SUCCESS - PCI VGA is added to ConOut. - EFI_STATUS - No PCI VGA device is added. - ---*/ -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - EFI_DEVICE_PATH_PROTOCOL *GopDevicePath; - - DevicePath = NULL; - GopDevicePath = NULL; - Status = gBS->HandleProtocol ( - DeviceHandle, - &gEfiDevicePathProtocolGuid, - (VOID*)&DevicePath - ); - if (EFI_ERROR (Status)) { - return Status; - } - - GetGopDevicePath (DevicePath, &GopDevicePath); - DevicePath = GopDevicePath; - - BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL); - - return EFI_SUCCESS; -} - -EFI_STATUS -PreparePciSerialDevicePath ( - IN EFI_HANDLE DeviceHandle - ) -/*++ - -Routine Description: - - Add PCI Serial to ConOut, ConIn, ErrOut. - PCI Serial: 07 00 02 - -Arguments: - - DeviceHandle - Handle of PCIIO protocol. - -Returns: - - EFI_SUCCESS - PCI Serial is added to ConOut, ConIn, and ErrOut. - EFI_STATUS - No PCI Serial device is added. - ---*/ -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - - DevicePath = NULL; - Status = gBS->HandleProtocol ( - DeviceHandle, - &gEfiDevicePathProtocolGuid, - (VOID*)&DevicePath - ); - if (EFI_ERROR (Status)) { - return Status; - } - - DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode); - DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode); - - BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL); - BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL); - BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL); - - return EFI_SUCCESS; -} - -EFI_STATUS -VisitAllInstancesOfProtocol ( - IN EFI_GUID *Id, - IN PROTOCOL_INSTANCE_CALLBACK CallBackFunction, - IN VOID *Context - ) -{ - EFI_STATUS Status; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - UINTN Index; - VOID *Instance; - - // - // Start to check all the PciIo to find all possible device - // - HandleCount = 0; - HandleBuffer = NULL; - Status = gBS->LocateHandleBuffer ( - ByProtocol, - Id, - NULL, - &HandleCount, - &HandleBuffer - ); - if (EFI_ERROR (Status)) { - return Status; - } - - for (Index = 0; Index < HandleCount; Index++) { - Status = gBS->HandleProtocol (HandleBuffer[Index], Id, &Instance); - if (EFI_ERROR (Status)) { - continue; - } - - Status = (*CallBackFunction) ( - HandleBuffer[Index], - Instance, - Context - ); - } - - gBS->FreePool (HandleBuffer); - - return EFI_SUCCESS; -} - - -EFI_STATUS -EFIAPI -VisitingAPciInstance ( - IN EFI_HANDLE Handle, - IN VOID *Instance, - IN VOID *Context - ) -{ - EFI_STATUS Status; - EFI_PCI_IO_PROTOCOL *PciIo; - PCI_TYPE00 Pci; - - PciIo = (EFI_PCI_IO_PROTOCOL*) Instance; - - // - // Check for all PCI device - // - Status = PciIo->Pci.Read ( - PciIo, - EfiPciIoWidthUint32, - 0, - sizeof (Pci) / sizeof (UINT32), - &Pci - ); - if (EFI_ERROR (Status)) { - return Status; - } - - return (*(VISIT_PCI_INSTANCE_CALLBACK)(UINTN) Context) ( - Handle, - PciIo, - &Pci - ); - -} - - - -EFI_STATUS -VisitAllPciInstances ( - IN VISIT_PCI_INSTANCE_CALLBACK CallBackFunction - ) -{ - return VisitAllInstancesOfProtocol ( - &gEfiPciIoProtocolGuid, - VisitingAPciInstance, - (VOID*)(UINTN) CallBackFunction - ); -} - - -/** - Do platform specific PCI Device check and add them to - ConOut, ConIn, ErrOut. - - @param[in] Handle - Handle of PCI device instance - @param[in] PciIo - PCI IO protocol instance - @param[in] Pci - PCI Header register block - - @retval EFI_SUCCESS - PCI Device check and Console variable update successfully. - @retval EFI_STATUS - PCI Device check or Console variable update fail. - -**/ -EFI_STATUS -EFIAPI -DetectAndPreparePlatformPciDevicePath ( - IN EFI_HANDLE Handle, - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN PCI_TYPE00 *Pci - ) -{ - EFI_STATUS Status; - - Status = PciIo->Attributes ( - PciIo, - EfiPciIoAttributeOperationEnable, - EFI_PCI_DEVICE_ENABLE, - NULL - ); - ASSERT_EFI_ERROR (Status); - - if (!mDetectVgaOnly) { - // - // Here we decide whether it is LPC Bridge - // - if ((IS_PCI_LPC (Pci)) || - ((IS_PCI_ISA_PDECODE (Pci)) && - (Pci->Hdr.VendorId == 0x8086) && - (Pci->Hdr.DeviceId == 0x7000) - ) - ) { - // - // Add IsaKeyboard to ConIn, - // add IsaSerial to ConOut, ConIn, ErrOut - // - DEBUG ((EFI_D_INFO, "Found LPC Bridge device\n")); - PrepareLpcBridgeDevicePath (Handle); - return EFI_SUCCESS; - } - // - // Here we decide which Serial device to enable in PCI bus - // - if (IS_PCI_16550SERIAL (Pci)) { - // - // Add them to ConOut, ConIn, ErrOut. - // - DEBUG ((EFI_D_INFO, "Found PCI 16550 SERIAL device\n")); - PreparePciSerialDevicePath (Handle); - return EFI_SUCCESS; - } - } - - // - // Here we decide which VGA device to enable in PCI bus - // - if (IS_PCI_VGA (Pci)) { - // - // Add them to ConOut. - // - DEBUG ((EFI_D_INFO, "Found PCI VGA device\n")); - PreparePciVgaDevicePath (Handle); - return EFI_SUCCESS; - } - - return Status; -} - - -/** - Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut - - @param[in] DetectVgaOnly - Only detect VGA device if it's TRUE. - - @retval EFI_SUCCESS - PCI Device check and Console variable update successfully. - @retval EFI_STATUS - PCI Device check or Console variable update fail. - -**/ -EFI_STATUS -DetectAndPreparePlatformPciDevicePaths ( - BOOLEAN DetectVgaOnly - ) -{ - mDetectVgaOnly = DetectVgaOnly; - return VisitAllPciInstances (DetectAndPreparePlatformPciDevicePath); -} - - -EFI_STATUS -PlatformBdsConnectConsole ( - IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole - ) -/*++ - -Routine Description: - - Connect the predefined platform default console device. Always try to find - and enable the vga device if have. - -Arguments: - - PlatformConsole - Predfined platform default console device array. - -Returns: - - EFI_SUCCESS - Success connect at least one ConIn and ConOut - device, there must have one ConOut device is - active vga device. - - EFI_STATUS - Return the status of - BdsLibConnectAllDefaultConsoles () - ---*/ -{ - EFI_STATUS Status; - UINTN Index; - EFI_DEVICE_PATH_PROTOCOL *VarConout; - EFI_DEVICE_PATH_PROTOCOL *VarConin; - UINTN DevicePathSize; - - // - // Connect RootBridge - // - VarConout = BdsLibGetVariableAndSize ( - VarConsoleOut, - &gEfiGlobalVariableGuid, - &DevicePathSize - ); - VarConin = BdsLibGetVariableAndSize ( - VarConsoleInp, - &gEfiGlobalVariableGuid, - &DevicePathSize - ); - - if (VarConout == NULL || VarConin == NULL) { - // - // Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut - // - DetectAndPreparePlatformPciDevicePaths (FALSE); - - // - // Have chance to connect the platform default console, - // the platform default console is the minimue device group - // the platform should support - // - for (Index = 0; PlatformConsole[Index].DevicePath != NULL; ++Index) { - // - // Update the console variable with the connect type - // - if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) { - BdsLibUpdateConsoleVariable (VarConsoleInp, PlatformConsole[Index].DevicePath, NULL); - } - if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) { - BdsLibUpdateConsoleVariable (VarConsoleOut, PlatformConsole[Index].DevicePath, NULL); - } - if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) { - BdsLibUpdateConsoleVariable (VarErrorOut, PlatformConsole[Index].DevicePath, NULL); - } - } - } else { - // - // Only detect VGA device and add them to ConOut - // - DetectAndPreparePlatformPciDevicePaths (TRUE); - } - - // - // Connect the all the default console with current cosole variable - // - Status = BdsLibConnectAllDefaultConsoles (); - if (EFI_ERROR (Status)) { - return Status; - } - - return EFI_SUCCESS; -} - - -/** - Configure PCI Interrupt Line register for applicable devices - Ported from SeaBIOS, src/fw/pciinit.c, *_pci_slot_get_irq() - - @param[in] Handle - Handle of PCI device instance - @param[in] PciIo - PCI IO protocol instance - @param[in] PciHdr - PCI Header register block - - @retval EFI_SUCCESS - PCI Interrupt Line register configured successfully. - -**/ -EFI_STATUS -EFIAPI -SetPciIntLine ( - IN EFI_HANDLE Handle, - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN PCI_TYPE00 *PciHdr - ) -{ - EFI_DEVICE_PATH_PROTOCOL *DevPathNode; - EFI_DEVICE_PATH_PROTOCOL *DevPath; - UINTN RootSlot; - UINTN Idx; - UINT8 IrqLine; - EFI_STATUS Status; - UINT32 RootBusNumber; - - Status = EFI_SUCCESS; - - if (PciHdr->Device.InterruptPin != 0) { - - DevPathNode = DevicePathFromHandle (Handle); - ASSERT (DevPathNode != NULL); - DevPath = DevPathNode; - - RootBusNumber = 0; - if (DevicePathType (DevPathNode) == ACPI_DEVICE_PATH && - DevicePathSubType (DevPathNode) == ACPI_DP && - ((ACPI_HID_DEVICE_PATH *)DevPathNode)->HID == EISA_PNP_ID(0x0A03)) { - RootBusNumber = ((ACPI_HID_DEVICE_PATH *)DevPathNode)->UID; - } - - // - // Compute index into PciHostIrqs[] table by walking - // the device path and adding up all device numbers - // - Status = EFI_NOT_FOUND; - RootSlot = 0; - Idx = PciHdr->Device.InterruptPin - 1; - while (!IsDevicePathEnd (DevPathNode)) { - if (DevicePathType (DevPathNode) == HARDWARE_DEVICE_PATH && - DevicePathSubType (DevPathNode) == HW_PCI_DP) { - - Idx += ((PCI_DEVICE_PATH *)DevPathNode)->Device; - - // - // Unlike SeaBIOS, which starts climbing from the leaf device - // up toward the root, we traverse the device path starting at - // the root moving toward the leaf node. - // The slot number of the top-level parent bridge is needed for - // Q35 cases with more than 24 slots on the root bus. - // - if (Status != EFI_SUCCESS) { - Status = EFI_SUCCESS; - RootSlot = ((PCI_DEVICE_PATH *)DevPathNode)->Device; - } - } - - DevPathNode = NextDevicePathNode (DevPathNode); - } - if (EFI_ERROR (Status)) { - return Status; - } - if (RootBusNumber == 0 && RootSlot == 0) { - DEBUG(( - EFI_D_ERROR, - "%a: PCI host bridge (00:00.0) should have no interrupts!\n", - __FUNCTION__ - )); - ASSERT (FALSE); - } - - // - // Final PciHostIrqs[] index calculation depends on the platform - // and should match SeaBIOS src/fw/pciinit.c *_pci_slot_get_irq() - // - switch (mHostBridgeDevId) { - case INTEL_82441_DEVICE_ID: - Idx -= 1; - break; - case INTEL_Q35_MCH_DEVICE_ID: - // - // SeaBIOS contains the following comment: - // "Slots 0-24 rotate slot:pin mapping similar to piix above, but - // with a different starting index - see q35-acpi-dsdt.dsl. - // - // Slots 25-31 all use LNKA mapping (or LNKE, but A:D = E:H)" - // - if (RootSlot > 24) { - // - // in this case, subtract back out RootSlot from Idx - // (SeaBIOS never adds it to begin with, but that would make our - // device path traversal loop above too awkward) - // - Idx -= RootSlot; - } - break; - default: - ASSERT (FALSE); // should never get here - } - Idx %= ARRAY_SIZE (PciHostIrqs); - IrqLine = PciHostIrqs[Idx]; - - DEBUG_CODE_BEGIN (); - { - CHAR16 *DevPathString; - STATIC CHAR16 Fallback[] = L""; - UINTN Segment, Bus, Device, Function; - - DevPathString = ConvertDevicePathToText (DevPath, FALSE, FALSE); - if (DevPathString == NULL) { - DevPathString = Fallback; - } - Status = PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Function); - ASSERT_EFI_ERROR (Status); - - DEBUG ((EFI_D_VERBOSE, "%a: [%02x:%02x.%x] %s -> 0x%02x\n", __FUNCTION__, - (UINT32)Bus, (UINT32)Device, (UINT32)Function, DevPathString, - IrqLine)); - - if (DevPathString != Fallback) { - FreePool (DevPathString); - } - } - DEBUG_CODE_END (); - - // - // Set PCI Interrupt Line register for this device to PciHostIrqs[Idx] - // - Status = PciIo->Pci.Write ( - PciIo, - EfiPciIoWidthUint8, - PCI_INT_LINE_OFFSET, - 1, - &IrqLine - ); - } - - return Status; -} - - -VOID -PciAcpiInitialization ( - ) -{ - UINTN Pmba; - - // - // Query Host Bridge DID to determine platform type - // - mHostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId); - switch (mHostBridgeDevId) { - case INTEL_82441_DEVICE_ID: - Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA); - // - // 00:01.0 ISA Bridge (PIIX4) LNK routing targets - // - PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x60), 0x0b); // A - PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x61), 0x0b); // B - PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x62), 0x0a); // C - PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x63), 0x0a); // D - break; - case INTEL_Q35_MCH_DEVICE_ID: - Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE); - // - // 00:1f.0 LPC Bridge (Q35) LNK routing targets - // - PciWrite8 (PCI_LIB_ADDRESS (0, 0x1f, 0, 0x60), 0x0a); // A - PciWrite8 (PCI_LIB_ADDRESS (0, 0x1f, 0, 0x61), 0x0a); // B - PciWrite8 (PCI_LIB_ADDRESS (0, 0x1f, 0, 0x62), 0x0b); // C - PciWrite8 (PCI_LIB_ADDRESS (0, 0x1f, 0, 0x63), 0x0b); // D - PciWrite8 (PCI_LIB_ADDRESS (0, 0x1f, 0, 0x68), 0x0a); // E - PciWrite8 (PCI_LIB_ADDRESS (0, 0x1f, 0, 0x69), 0x0a); // F - PciWrite8 (PCI_LIB_ADDRESS (0, 0x1f, 0, 0x6a), 0x0b); // G - PciWrite8 (PCI_LIB_ADDRESS (0, 0x1f, 0, 0x6b), 0x0b); // H - break; - default: - DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n", - __FUNCTION__, mHostBridgeDevId)); - ASSERT (FALSE); - return; - } - - // - // Initialize PCI_INTERRUPT_LINE for applicable present PCI devices - // - VisitAllPciInstances (SetPciIntLine); - - // - // Set ACPI SCI_EN bit in PMCNTRL - // - IoOr16 ((PciRead32 (Pmba) & ~BIT0) + 4, BIT0); -} - - -EFI_STATUS -EFIAPI -ConnectRecursivelyIfPciMassStorage ( - IN EFI_HANDLE Handle, - IN EFI_PCI_IO_PROTOCOL *Instance, - IN PCI_TYPE00 *PciHeader - ) -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - CHAR16 *DevPathStr; - - if (IS_CLASS1 (PciHeader, PCI_CLASS_MASS_STORAGE)) { - DevicePath = NULL; - Status = gBS->HandleProtocol ( - Handle, - &gEfiDevicePathProtocolGuid, - (VOID*)&DevicePath - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Print Device Path - // - DevPathStr = DevicePathToStr (DevicePath); - if (DevPathStr != NULL) { - DEBUG(( - EFI_D_INFO, - "Found Mass Storage device: %s\n", - DevPathStr - )); - FreePool(DevPathStr); - } - - Status = gBS->ConnectController (Handle, NULL, NULL, TRUE); - if (EFI_ERROR (Status)) { - return Status; - } - - } - - return EFI_SUCCESS; -} - - -/** - This notification function is invoked when the - EMU Variable FVB has been changed. - - @param Event The event that occured - @param Context For EFI compatiblity. Not used. - -**/ -VOID -EFIAPI -EmuVariablesUpdatedCallback ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - DEBUG ((EFI_D_INFO, "EmuVariablesUpdatedCallback\n")); - UpdateNvVarsOnFileSystem (); -} - - -EFI_STATUS -EFIAPI -VisitingFileSystemInstance ( - IN EFI_HANDLE Handle, - IN VOID *Instance, - IN VOID *Context - ) -{ - EFI_STATUS Status; - STATIC BOOLEAN ConnectedToFileSystem = FALSE; - - if (ConnectedToFileSystem) { - return EFI_ALREADY_STARTED; - } - - Status = ConnectNvVarsToFileSystem (Handle); - if (EFI_ERROR (Status)) { - return Status; - } - - ConnectedToFileSystem = TRUE; - mEmuVariableEvent = - EfiCreateProtocolNotifyEvent ( - &gEfiDevicePathProtocolGuid, - TPL_CALLBACK, - EmuVariablesUpdatedCallback, - NULL, - &mEmuVariableEventReg - ); - PcdSet64 (PcdEmuVariableEvent, (UINT64)(UINTN) mEmuVariableEvent); - - return EFI_SUCCESS; -} - - -VOID -PlatformBdsRestoreNvVarsFromHardDisk ( - ) -{ - VisitAllPciInstances (ConnectRecursivelyIfPciMassStorage); - VisitAllInstancesOfProtocol ( - &gEfiSimpleFileSystemProtocolGuid, - VisitingFileSystemInstance, - NULL - ); - -} - - -VOID -PlatformBdsConnectSequence ( - VOID - ) -/*++ - -Routine Description: - - Connect with predeined platform connect sequence, - the OEM/IBV can customize with their own connect sequence. - -Arguments: - - None. - -Returns: - - None. - ---*/ -{ - UINTN Index; - - DEBUG ((EFI_D_INFO, "PlatformBdsConnectSequence\n")); - - Index = 0; - - // - // Here we can get the customized platform connect sequence - // Notes: we can connect with new variable which record the - // last time boots connect device path sequence - // - while (gPlatformConnectSequence[Index] != NULL) { - // - // Build the platform boot option - // - BdsLibConnectDevicePath (gPlatformConnectSequence[Index]); - Index++; - } - - // - // Just use the simple policy to connect all devices - // - BdsLibConnectAll (); - - PciAcpiInitialization (); - - // - // Clear the logo after all devices are connected. - // - gST->ConOut->ClearScreen (gST->ConOut); -} - -VOID -PlatformBdsGetDriverOption ( - IN OUT LIST_ENTRY *BdsDriverLists - ) -/*++ - -Routine Description: - - Load the predefined driver option, OEM/IBV can customize this - to load their own drivers - -Arguments: - - BdsDriverLists - The header of the driver option link list. - -Returns: - - None. - ---*/ -{ - DEBUG ((EFI_D_INFO, "PlatformBdsGetDriverOption\n")); - return; -} - -VOID -PlatformBdsDiagnostics ( - IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel, - IN BOOLEAN QuietBoot, - IN BASEM_MEMORY_TEST BaseMemoryTest - ) -/*++ - -Routine Description: - - Perform the platform diagnostic, such like test memory. OEM/IBV also - can customize this fuction to support specific platform diagnostic. - -Arguments: - - MemoryTestLevel - The memory test intensive level - - QuietBoot - Indicate if need to enable the quiet boot - - BaseMemoryTest - A pointer to BaseMemoryTest() - -Returns: - - None. - ---*/ -{ - EFI_STATUS Status; - - DEBUG ((EFI_D_INFO, "PlatformBdsDiagnostics\n")); - - // - // Here we can decide if we need to show - // the diagnostics screen - // Notes: this quiet boot code should be remove - // from the graphic lib - // - if (QuietBoot) { - EnableQuietBoot (PcdGetPtr(PcdLogoFile)); - // - // Perform system diagnostic - // - Status = BaseMemoryTest (MemoryTestLevel); - if (EFI_ERROR (Status)) { - DisableQuietBoot (); - } - - return ; - } - // - // Perform system diagnostic - // - Status = BaseMemoryTest (MemoryTestLevel); -} - - -/** - Empty callback function executed when the EndOfDxe event group is signaled. - - We only need this function because we'd like to signal EndOfDxe, and for that - we need to create an event, with a callback function. - - @param[in] Event Event whose notification function is being invoked. - @param[in] Context The pointer to the notification function's context, which - is implementation-dependent. -**/ -STATIC -VOID -EFIAPI -OnEndOfDxe ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ -} - - -/** - Save the S3 boot script. - - Note that we trigger DxeSmmReadyToLock here -- otherwise the script wouldn't - be saved actually. Triggering this protocol installation event in turn locks - down SMM, so no further changes to LockBoxes or SMRAM are possible - afterwards. -**/ -STATIC -VOID -SaveS3BootScript ( - VOID - ) -{ - EFI_STATUS Status; - EFI_S3_SAVE_STATE_PROTOCOL *BootScript; - EFI_HANDLE Handle; - STATIC CONST UINT8 Info[] = { 0xDE, 0xAD, 0xBE, 0xEF }; - - Status = gBS->LocateProtocol (&gEfiS3SaveStateProtocolGuid, NULL, - (VOID **) &BootScript); - ASSERT_EFI_ERROR (Status); - - // - // Despite the opcode documentation in the PI spec, the protocol - // implementation embeds a deep copy of the info in the boot script, rather - // than storing just a pointer to runtime or NVS storage. - // - Status = BootScript->Write(BootScript, EFI_BOOT_SCRIPT_INFORMATION_OPCODE, - (UINT32) sizeof Info, - (EFI_PHYSICAL_ADDRESS)(UINTN) &Info); - ASSERT_EFI_ERROR (Status); - - Handle = NULL; - Status = gBS->InstallProtocolInterface (&Handle, - &gEfiDxeSmmReadyToLockProtocolGuid, EFI_NATIVE_INTERFACE, - NULL); - ASSERT_EFI_ERROR (Status); -} - - -VOID -EFIAPI -PlatformBdsPolicyBehavior ( - IN OUT LIST_ENTRY *DriverOptionList, - IN OUT LIST_ENTRY *BootOptionList, - IN PROCESS_CAPSULES ProcessCapsules, - IN BASEM_MEMORY_TEST BaseMemoryTest - ) -/*++ - -Routine Description: - - The function will excute with as the platform policy, current policy - is driven by boot mode. IBV/OEM can customize this code for their specific - policy action. - -Arguments: - - DriverOptionList - The header of the driver option link list - - BootOptionList - The header of the boot option link list - - ProcessCapsules - A pointer to ProcessCapsules() - - BaseMemoryTest - A pointer to BaseMemoryTest() - -Returns: - - None. - ---*/ -{ - EFI_STATUS Status; - EFI_BOOT_MODE BootMode; - EFI_EVENT EndOfDxeEvent; - - DEBUG ((EFI_D_INFO, "PlatformBdsPolicyBehavior\n")); - - VisitAllInstancesOfProtocol (&gEfiPciRootBridgeIoProtocolGuid, - ConnectRootBridge, NULL); - - // - // We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe triggers - // the preparation of S3 system information. That logic has a hard dependency - // on the presence of the FACS ACPI table. Since our ACPI tables are only - // installed after PCI enumeration completes, we must not trigger the S3 save - // earlier, hence we can't signal End-of-Dxe earlier. - // - Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_CALLBACK, OnEndOfDxe, - NULL /* NotifyContext */, &gEfiEndOfDxeEventGroupGuid, - &EndOfDxeEvent); - if (!EFI_ERROR (Status)) { - gBS->SignalEvent (EndOfDxeEvent); - gBS->CloseEvent (EndOfDxeEvent); - } - - if (QemuFwCfgS3Enabled ()) { - // - // Save the boot script too. Note that this requires/includes emitting the - // DxeSmmReadyToLock event, which in turn locks down SMM. - // - SaveS3BootScript (); - } - - if (PcdGetBool (PcdOvmfFlashVariablesEnable)) { - DEBUG ((EFI_D_INFO, "PlatformBdsPolicyBehavior: not restoring NvVars " - "from disk since flash variables appear to be supported.\n")); - } else { - // - // Try to restore variables from the hard disk early so - // they can be used for the other BDS connect operations. - // - PlatformBdsRestoreNvVarsFromHardDisk (); - } - - // - // Load the driver option as the driver option list - // - PlatformBdsGetDriverOption (DriverOptionList); - - // - // Get current Boot Mode - // - Status = BdsLibGetBootMode (&BootMode); - DEBUG ((EFI_D_ERROR, "Boot Mode:%x\n", BootMode)); - - // - // Go the different platform policy with different boot mode - // Notes: this part code can be change with the table policy - // - ASSERT (BootMode == BOOT_WITH_FULL_CONFIGURATION); - // - // Connect platform console - // - Status = PlatformBdsConnectConsole (gPlatformConsole); - if (EFI_ERROR (Status)) { - // - // Here OEM/IBV can customize with defined action - // - PlatformBdsNoConsoleAction (); - } - - // - // Memory test and Logo show - // - PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest); - - // - // Perform some platform specific connect sequence - // - PlatformBdsConnectSequence (); - - // - // Process QEMU's -kernel command line option - // - TryRunningQemuKernel (); - - DEBUG ((EFI_D_INFO, "BdsLibConnectAll\n")); - BdsLibConnectAll (); - BdsLibEnumerateAllBootOption (BootOptionList); - - SetBootOrderFromQemu (BootOptionList); - // - // The BootOrder variable may have changed, reload the in-memory list with - // it. - // - BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder"); - - PlatformBdsEnterFrontPage (GetFrontPageTimeoutFromQemu(), TRUE); -} - -VOID -EFIAPI -PlatformBdsBootSuccess ( - IN BDS_COMMON_OPTION *Option - ) -/*++ - -Routine Description: - - Hook point after a boot attempt succeeds. We don't expect a boot option to - return, so the EFI 1.0 specification defines that you will default to an - interactive mode and stop processing the BootOrder list in this case. This - is alos a platform implementation and can be customized by IBV/OEM. - -Arguments: - - Option - Pointer to Boot Option that succeeded to boot. - -Returns: - - None. - ---*/ -{ - CHAR16 *TmpStr; - - DEBUG ((EFI_D_INFO, "PlatformBdsBootSuccess\n")); - // - // If Boot returned with EFI_SUCCESS and there is not in the boot device - // select loop then we need to pop up a UI and wait for user input. - // - TmpStr = Option->StatusString; - if (TmpStr != NULL) { - BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL); - FreePool (TmpStr); - } -} - -VOID -EFIAPI -PlatformBdsBootFail ( - IN BDS_COMMON_OPTION *Option, - IN EFI_STATUS Status, - IN CHAR16 *ExitData, - IN UINTN ExitDataSize - ) -/*++ - -Routine Description: - - Hook point after a boot attempt fails. - -Arguments: - - Option - Pointer to Boot Option that failed to boot. - - Status - Status returned from failed boot. - - ExitData - Exit data returned from failed boot. - - ExitDataSize - Exit data size returned from failed boot. - -Returns: - - None. - ---*/ -{ - CHAR16 *TmpStr; - - DEBUG ((EFI_D_INFO, "PlatformBdsBootFail\n")); - - // - // If Boot returned with failed status then we need to pop up a UI and wait - // for user input. - // - TmpStr = Option->StatusString; - if (TmpStr != NULL) { - BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL); - FreePool (TmpStr); - } -} - -EFI_STATUS -PlatformBdsNoConsoleAction ( - VOID - ) -/*++ - -Routine Description: - - This function is remained for IBV/OEM to do some platform action, - if there no console device can be connected. - -Arguments: - - None. - -Returns: - - EFI_SUCCESS - Direct return success now. - ---*/ -{ - DEBUG ((EFI_D_INFO, "PlatformBdsNoConsoleAction\n")); - return EFI_SUCCESS; -} - -VOID -EFIAPI -PlatformBdsLockNonUpdatableFlash ( - VOID - ) -{ - DEBUG ((EFI_D_INFO, "PlatformBdsLockNonUpdatableFlash\n")); - return; -} - - -/** - This notification function is invoked when an instance of the - EFI_DEVICE_PATH_PROTOCOL is produced. - - @param Event The event that occured - @param Context For EFI compatiblity. Not used. - -**/ -VOID -EFIAPI -NotifyDevPath ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - EFI_HANDLE Handle; - EFI_STATUS Status; - UINTN BufferSize; - EFI_DEVICE_PATH_PROTOCOL *DevPathNode; - ATAPI_DEVICE_PATH *Atapi; - - // - // Examine all new handles - // - for (;;) { - // - // Get the next handle - // - BufferSize = sizeof (Handle); - Status = gBS->LocateHandle ( - ByRegisterNotify, - NULL, - mEfiDevPathNotifyReg, - &BufferSize, - &Handle - ); - - // - // If not found, we're done - // - if (EFI_NOT_FOUND == Status) { - break; - } - - if (EFI_ERROR (Status)) { - continue; - } - - // - // Get the DevicePath protocol on that handle - // - Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&DevPathNode); - ASSERT_EFI_ERROR (Status); - - while (!IsDevicePathEnd (DevPathNode)) { - // - // Find the handler to dump this device path node - // - if ( - (DevicePathType(DevPathNode) == MESSAGING_DEVICE_PATH) && - (DevicePathSubType(DevPathNode) == MSG_ATAPI_DP) - ) { - Atapi = (ATAPI_DEVICE_PATH*) DevPathNode; - PciOr16 ( - PCI_LIB_ADDRESS ( - 0, - 1, - 1, - (Atapi->PrimarySecondary == 1) ? 0x42: 0x40 - ), - BIT15 - ); - } - - // - // Next device path node - // - DevPathNode = NextDevicePathNode (DevPathNode); - } - } - - return; -} - - -VOID -InstallDevicePathCallback ( - VOID - ) -{ - DEBUG ((EFI_D_INFO, "Registered NotifyDevPath Event\n")); - mEfiDevPathEvent = EfiCreateProtocolNotifyEvent ( - &gEfiDevicePathProtocolGuid, - TPL_CALLBACK, - NotifyDevPath, - NULL, - &mEfiDevPathNotifyReg - ); -} - -/** - Lock the ConsoleIn device in system table. All key - presses will be ignored until the Password is typed in. The only way to - disable the password is to type it in to a ConIn device. - - @param Password Password used to lock ConIn device. - - @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully. - @retval EFI_UNSUPPORTED Password not found - -**/ -EFI_STATUS -EFIAPI -LockKeyboards ( - IN CHAR16 *Password - ) -{ - return EFI_UNSUPPORTED; -} - diff --git a/OvmfPkg/Library/PlatformBdsLib/BdsPlatform.h b/OvmfPkg/Library/PlatformBdsLib/BdsPlatform.h deleted file mode 100644 index 6ba0d48e80..0000000000 --- a/OvmfPkg/Library/PlatformBdsLib/BdsPlatform.h +++ /dev/null @@ -1,292 +0,0 @@ -/** @file - Platform BDS customizations include file. - - Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -Module Name: - - BdsPlatform.h - -Abstract: - - Head file for BDS Platform specific code - -**/ - -#ifndef _PLATFORM_SPECIFIC_BDS_PLATFORM_H_ -#define _PLATFORM_SPECIFIC_BDS_PLATFORM_H_ - - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -extern BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole[]; -extern EFI_DEVICE_PATH_PROTOCOL *gPlatformConnectSequence[]; -extern EFI_DEVICE_PATH_PROTOCOL *gPlatformDriverOption[]; -extern ACPI_HID_DEVICE_PATH gPnpPs2KeyboardDeviceNode; -extern ACPI_HID_DEVICE_PATH gPnp16550ComPortDeviceNode; -extern UART_DEVICE_PATH gUartDeviceNode; -extern VENDOR_DEVICE_PATH gTerminalTypeDeviceNode; -// -// -// -#define VarConsoleInpDev L"ConInDev" -#define VarConsoleInp L"ConIn" -#define VarConsoleOutDev L"ConOutDev" -#define VarConsoleOut L"ConOut" -#define VarErrorOutDev L"ErrOutDev" -#define VarErrorOut L"ErrOut" - -#define PCI_DEVICE_PATH_NODE(Func, Dev) \ - { \ - { \ - HARDWARE_DEVICE_PATH, \ - HW_PCI_DP, \ - { \ - (UINT8) (sizeof (PCI_DEVICE_PATH)), \ - (UINT8) ((sizeof (PCI_DEVICE_PATH)) >> 8) \ - } \ - }, \ - (Func), \ - (Dev) \ - } - -#define PNPID_DEVICE_PATH_NODE(PnpId) \ - { \ - { \ - ACPI_DEVICE_PATH, \ - ACPI_DP, \ - { \ - (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \ - (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \ - }, \ - }, \ - EISA_PNP_ID((PnpId)), \ - 0 \ - } - -#define gPciIsaBridge \ - PCI_DEVICE_PATH_NODE(0, 0x1f) - -#define gP2PBridge \ - PCI_DEVICE_PATH_NODE(0, 0x1e) - -#define gPnpPs2Keyboard \ - PNPID_DEVICE_PATH_NODE(0x0303) - -#define gPnp16550ComPort \ - PNPID_DEVICE_PATH_NODE(0x0501) - -#define gUart \ - { \ - { \ - MESSAGING_DEVICE_PATH, \ - MSG_UART_DP, \ - { \ - (UINT8) (sizeof (UART_DEVICE_PATH)), \ - (UINT8) ((sizeof (UART_DEVICE_PATH)) >> 8) \ - } \ - }, \ - 0, \ - 115200, \ - 8, \ - 1, \ - 1 \ - } - -#define gPcAnsiTerminal \ - { \ - { \ - MESSAGING_DEVICE_PATH, \ - MSG_VENDOR_DP, \ - { \ - (UINT8) (sizeof (VENDOR_DEVICE_PATH)), \ - (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) \ - } \ - }, \ - DEVICE_PATH_MESSAGING_PC_ANSI \ - } - -#define PCI_CLASS_SCC 0x07 -#define PCI_SUBCLASS_SERIAL 0x00 -#define PCI_IF_16550 0x02 -#define IS_PCI_16550SERIAL(_p) IS_CLASS3 (_p, PCI_CLASS_SCC, PCI_SUBCLASS_SERIAL, PCI_IF_16550) - -#define EFI_SYSTEM_TABLE_MAX_ADDRESS 0xFFFFFFFF -#define SYS_TABLE_PAD(ptr) (((~ptr) +1) & 0x07 ) - -#define IS_PCI_ISA_PDECODE(_p) IS_CLASS3 (_p, PCI_CLASS_BRIDGE, PCI_CLASS_BRIDGE_ISA_PDECODE, 0) - -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - PCI_DEVICE_PATH IsaBridge; - ACPI_HID_DEVICE_PATH Keyboard; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_DUMMY_ISA_KEYBOARD_DEVICE_PATH; - -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - PCI_DEVICE_PATH IsaBridge; - ACPI_HID_DEVICE_PATH IsaSerial; - UART_DEVICE_PATH Uart; - VENDOR_DEVICE_PATH TerminalType; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_DUMMY_ISA_SERIAL_DEVICE_PATH; - -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - PCI_DEVICE_PATH VgaDevice; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_DUMMY_PCI_VGA_DEVICE_PATH; - -typedef struct { - ACPI_HID_DEVICE_PATH PciRootBridge; - PCI_DEVICE_PATH PciBridge; - PCI_DEVICE_PATH SerialDevice; - UART_DEVICE_PATH Uart; - VENDOR_DEVICE_PATH TerminalType; - EFI_DEVICE_PATH_PROTOCOL End; -} PLATFORM_DUMMY_PCI_SERIAL_DEVICE_PATH; - -// -// the short form device path for Usb keyboard -// -#define CLASS_HID 3 -#define SUBCLASS_BOOT 1 -#define PROTOCOL_KEYBOARD 1 - -typedef struct { - USB_CLASS_DEVICE_PATH UsbClass; - EFI_DEVICE_PATH_PROTOCOL End; -} USB_CLASS_FORMAT_DEVICE_PATH; - -// -// Platform BDS Functions -// - -VOID -PlatformBdsGetDriverOption ( - IN LIST_ENTRY *BdsDriverLists - ); - -EFI_STATUS -BdsMemoryTest ( - EXTENDMEM_COVERAGE_LEVEL Level - ); - -EFI_STATUS -PlatformBdsShowProgress ( - EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground, - EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground, - CHAR16 *Title, - EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor, - UINTN Progress, - UINTN PreviousValue - ); - -VOID -PlatformBdsConnectSequence ( - VOID - ); - -EFI_STATUS -ProcessCapsules ( - EFI_BOOT_MODE BootMode - ); - -EFI_STATUS -PlatformBdsConnectConsole ( - IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole - ); - -EFI_STATUS -PlatformBdsNoConsoleAction ( - VOID - ); - -EFI_STATUS -ConvertMpsTable ( - IN OUT VOID **Table - ); - -EFI_STATUS -ConvertSmbiosTable ( - IN OUT VOID **Table - ); - -EFI_STATUS -ConvertAcpiTable ( - IN UINTN TableLen, - IN OUT VOID **Table - ); - -EFI_STATUS -ConvertSystemTable ( - IN EFI_GUID *TableGuid, - IN OUT VOID **Table - ); - -VOID -PlatformBdsEnterFrontPage ( - IN UINT16 TimeoutDefault, - IN BOOLEAN ConnectAllHappened - ); - -/** - Loads and boots UEFI Linux via the FwCfg interface. - - @retval EFI_NOT_FOUND - The Linux kernel was not found - -**/ -EFI_STATUS -TryRunningQemuKernel ( - VOID - ); - -#endif // _PLATFORM_SPECIFIC_BDS_PLATFORM_H_ diff --git a/OvmfPkg/Library/PlatformBdsLib/PlatformBdsLib.inf b/OvmfPkg/Library/PlatformBdsLib/PlatformBdsLib.inf deleted file mode 100644 index ab5468368d..0000000000 --- a/OvmfPkg/Library/PlatformBdsLib/PlatformBdsLib.inf +++ /dev/null @@ -1,72 +0,0 @@ -## @file -# Platform BDS customizations library. -# -# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.
-# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = PlatformBdsLib - FILE_GUID = F844172E-9985-44f2-BADE-0DD783462E95 - MODULE_TYPE = DXE_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = PlatformBdsLib|DXE_DRIVER - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources] - BdsPlatform.c - PlatformData.c - QemuKernel.c - BdsPlatform.h - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseLib - MemoryAllocationLib - UefiBootServicesTableLib - BaseMemoryLib - DebugLib - PcdLib - GenericBdsLib - PciLib - NvVarsFileLib - QemuFwCfgLib - LoadLinuxLib - QemuBootOrderLib - UefiLib - -[Pcd] - gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile - gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId - -[Pcd.IA32, Pcd.X64] - gEfiMdePkgTokenSpaceGuid.PcdFSBClock - -[Protocols] - gEfiDecompressProtocolGuid - gEfiPciRootBridgeIoProtocolGuid - gEfiS3SaveStateProtocolGuid # PROTOCOL SOMETIMES_CONSUMED - gEfiDxeSmmReadyToLockProtocolGuid # PROTOCOL SOMETIMES_PRODUCED - -[Guids] - gEfiEndOfDxeEventGroupGuid diff --git a/OvmfPkg/Library/PlatformBdsLib/PlatformData.c b/OvmfPkg/Library/PlatformBdsLib/PlatformData.c deleted file mode 100644 index f69c1a8714..0000000000 --- a/OvmfPkg/Library/PlatformBdsLib/PlatformData.c +++ /dev/null @@ -1,51 +0,0 @@ -/** @file - Defined the platform specific device path which will be used by - platform Bbd to perform the platform policy connect. - - Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "BdsPlatform.h" - -// -// Predefined platform default time out value -// -UINT16 gPlatformBootTimeOutDefault = 5; - -ACPI_HID_DEVICE_PATH gPnpPs2KeyboardDeviceNode = gPnpPs2Keyboard; -ACPI_HID_DEVICE_PATH gPnp16550ComPortDeviceNode = gPnp16550ComPort; -UART_DEVICE_PATH gUartDeviceNode = gUart; -VENDOR_DEVICE_PATH gTerminalTypeDeviceNode = gPcAnsiTerminal; - -// -// Platform specific keyboard device path -// - -// -// Predefined platform default console device path -// -BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole[] = { - { - NULL, - 0 - } -}; - -// -// Predefined platform specific driver option -// -EFI_DEVICE_PATH_PROTOCOL *gPlatformDriverOption[] = { NULL }; - -// -// Predefined platform connect sequence -// -EFI_DEVICE_PATH_PROTOCOL *gPlatformConnectSequence[] = { NULL }; - diff --git a/OvmfPkg/Library/PlatformBdsLib/QemuKernel.c b/OvmfPkg/Library/PlatformBdsLib/QemuKernel.c deleted file mode 100644 index ef728dfdeb..0000000000 --- a/OvmfPkg/Library/PlatformBdsLib/QemuKernel.c +++ /dev/null @@ -1,170 +0,0 @@ -/** @file - - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include - -#include -#include -#include -#include -#include -#include -#include - - -EFI_STATUS -TryRunningQemuKernel ( - VOID - ) -{ - EFI_STATUS Status; - UINTN KernelSize; - UINTN KernelInitialSize; - VOID *KernelBuf; - UINTN SetupSize; - VOID *SetupBuf; - UINTN CommandLineSize; - CHAR8 *CommandLine; - UINTN InitrdSize; - VOID* InitrdData; - - SetupBuf = NULL; - SetupSize = 0; - KernelBuf = NULL; - KernelInitialSize = 0; - CommandLine = NULL; - CommandLineSize = 0; - InitrdData = NULL; - InitrdSize = 0; - - if (!QemuFwCfgIsAvailable ()) { - return EFI_NOT_FOUND; - } - - QemuFwCfgSelectItem (QemuFwCfgItemKernelSize); - KernelSize = (UINTN) QemuFwCfgRead64 (); - - QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupSize); - SetupSize = (UINTN) QemuFwCfgRead64 (); - - if (KernelSize == 0 || SetupSize == 0) { - DEBUG ((EFI_D_INFO, "qemu -kernel was not used.\n")); - return EFI_NOT_FOUND; - } - - SetupBuf = LoadLinuxAllocateKernelSetupPages (EFI_SIZE_TO_PAGES (SetupSize)); - if (SetupBuf == NULL) { - DEBUG ((EFI_D_ERROR, "Unable to allocate memory for kernel setup!\n")); - return EFI_OUT_OF_RESOURCES; - } - - DEBUG ((EFI_D_INFO, "Setup size: 0x%x\n", (UINT32) SetupSize)); - DEBUG ((EFI_D_INFO, "Reading kernel setup image ...")); - QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupData); - QemuFwCfgReadBytes (SetupSize, SetupBuf); - DEBUG ((EFI_D_INFO, " [done]\n")); - - Status = LoadLinuxCheckKernelSetup (SetupBuf, SetupSize); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - Status = LoadLinuxInitializeKernelSetup (SetupBuf); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - KernelInitialSize = LoadLinuxGetKernelSize (SetupBuf, KernelSize); - if (KernelInitialSize == 0) { - Status = EFI_UNSUPPORTED; - goto FreeAndReturn; - } - - KernelBuf = LoadLinuxAllocateKernelPages ( - SetupBuf, - EFI_SIZE_TO_PAGES (KernelInitialSize)); - if (KernelBuf == NULL) { - DEBUG ((EFI_D_ERROR, "Unable to allocate memory for kernel!\n")); - Status = EFI_OUT_OF_RESOURCES; - goto FreeAndReturn; - } - - DEBUG ((EFI_D_INFO, "Kernel size: 0x%x\n", (UINT32) KernelSize)); - DEBUG ((EFI_D_INFO, "Reading kernel image ...")); - QemuFwCfgSelectItem (QemuFwCfgItemKernelData); - QemuFwCfgReadBytes (KernelSize, KernelBuf); - DEBUG ((EFI_D_INFO, " [done]\n")); - - QemuFwCfgSelectItem (QemuFwCfgItemCommandLineSize); - CommandLineSize = (UINTN) QemuFwCfgRead64 (); - - if (CommandLineSize > 0) { - CommandLine = LoadLinuxAllocateCommandLinePages ( - EFI_SIZE_TO_PAGES (CommandLineSize)); - QemuFwCfgSelectItem (QemuFwCfgItemCommandLineData); - QemuFwCfgReadBytes (CommandLineSize, CommandLine); - } else { - CommandLine = NULL; - } - - Status = LoadLinuxSetCommandLine (SetupBuf, CommandLine); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - QemuFwCfgSelectItem (QemuFwCfgItemInitrdSize); - InitrdSize = (UINTN) QemuFwCfgRead64 (); - - if (InitrdSize > 0) { - InitrdData = LoadLinuxAllocateInitrdPages ( - SetupBuf, - EFI_SIZE_TO_PAGES (InitrdSize) - ); - DEBUG ((EFI_D_INFO, "Initrd size: 0x%x\n", (UINT32) InitrdSize)); - DEBUG ((EFI_D_INFO, "Reading initrd image ...")); - QemuFwCfgSelectItem (QemuFwCfgItemInitrdData); - QemuFwCfgReadBytes (InitrdSize, InitrdData); - DEBUG ((EFI_D_INFO, " [done]\n")); - } else { - InitrdData = NULL; - } - - Status = LoadLinuxSetInitrd (SetupBuf, InitrdData, InitrdSize); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - // - // Signal the EVT_SIGNAL_READY_TO_BOOT event - // - EfiSignalEventReadyToBoot(); - - Status = LoadLinux (KernelBuf, SetupBuf); - -FreeAndReturn: - if (SetupBuf != NULL) { - FreePages (SetupBuf, EFI_SIZE_TO_PAGES (SetupSize)); - } - if (KernelBuf != NULL) { - FreePages (KernelBuf, EFI_SIZE_TO_PAGES (KernelInitialSize)); - } - if (CommandLine != NULL) { - FreePages (CommandLine, EFI_SIZE_TO_PAGES (CommandLineSize)); - } - if (InitrdData != NULL) { - FreePages (InitrdData, EFI_SIZE_TO_PAGES (InitrdSize)); - } - - return Status; -} - diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c b/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c deleted file mode 100644 index 44850a9dba..0000000000 --- a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c +++ /dev/null @@ -1,287 +0,0 @@ -/** @file - Base Debug library instance for QEMU debug port. - It uses PrintLib to send debug messages to a fixed I/O port. - - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
- Copyright (c) 2012, Red Hat, Inc.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php. - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// -// Define the maximum debug and assert message length that this library supports -// -#define MAX_DEBUG_MESSAGE_LENGTH 0x100 - -/** - This constructor function does not have to do anything. - - @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. - -**/ -RETURN_STATUS -EFIAPI -PlatformDebugLibIoPortConstructor ( - VOID - ) -{ - return EFI_SUCCESS; -} - -/** - Prints a debug message to the debug output device if the specified error level is enabled. - - If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function - GetDebugPrintErrorLevel (), then print the message specified by Format and the - associated variable argument list to the debug output device. - - If Format is NULL, then ASSERT(). - - @param ErrorLevel The error level of the debug message. - @param Format Format string for the debug message to print. - @param ... Variable argument list whose contents are accessed - based on the format string specified by Format. - -**/ -VOID -EFIAPI -DebugPrint ( - IN UINTN ErrorLevel, - IN CONST CHAR8 *Format, - ... - ) -{ - CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; - VA_LIST Marker; - UINT8 *Ptr; - - // - // If Format is NULL, then ASSERT(). - // - ASSERT (Format != NULL); - - // - // Check driver debug mask value and global mask - // - if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) { - return; - } - - // - // Convert the DEBUG() message to an ASCII String - // - VA_START (Marker, Format); - AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker); - VA_END (Marker); - - // - // Send the print string to the debug I/O port - // - for (Ptr = (UINT8 *) Buffer; *Ptr; Ptr++) { - IoWrite8 (PcdGet16(PcdDebugIoPort), *Ptr); - } -} - - -/** - Prints an assert message containing a filename, line number, and description. - This may be followed by a breakpoint or a dead loop. - - Print a message of the form "ASSERT (): \n" - to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of - PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if - DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then - CpuDeadLoop() is called. If neither of these bits are set, then this function - returns immediately after the message is printed to the debug output device. - DebugAssert() must actively prevent recursion. If DebugAssert() is called while - processing another DebugAssert(), then DebugAssert() must return immediately. - - If FileName is NULL, then a string of "(NULL) Filename" is printed. - If Description is NULL, then a string of "(NULL) Description" is printed. - - @param FileName The pointer to the name of the source file that generated the assert condition. - @param LineNumber The line number in the source file that generated the assert condition - @param Description The pointer to the description of the assert condition. - -**/ -VOID -EFIAPI -DebugAssert ( - IN CONST CHAR8 *FileName, - IN UINTN LineNumber, - IN CONST CHAR8 *Description - ) -{ - CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; - UINT8 *Ptr; - - // - // Generate the ASSERT() message in Ascii format - // - AsciiSPrint (Buffer, sizeof Buffer, "ASSERT %a(%Lu): %a\n", FileName, - (UINT64)LineNumber, Description); - - // - // Send the print string to the Console Output device - // - for (Ptr = (UINT8 *) Buffer; *Ptr; Ptr++) { - IoWrite8 (PcdGet16(PcdDebugIoPort), *Ptr); - } - - // - // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings - // - if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) { - CpuBreakpoint (); - } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) { - CpuDeadLoop (); - } -} - - -/** - Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer. - - This function fills Length bytes of Buffer with the value specified by - PcdDebugClearMemoryValue, and returns Buffer. - - If Buffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - - @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue. - @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. - - @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue. - -**/ -VOID * -EFIAPI -DebugClearMemory ( - OUT VOID *Buffer, - IN UINTN Length - ) -{ - // - // If Buffer is NULL, then ASSERT(). - // - ASSERT (Buffer != NULL); - - // - // SetMem() checks for the the ASSERT() condition on Length and returns Buffer - // - return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue)); -} - - -/** - Returns TRUE if ASSERT() macros are enabled. - - This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of - PcdDebugProperyMask is set. Otherwise FALSE is returned. - - @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set. - @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear. - -**/ -BOOLEAN -EFIAPI -DebugAssertEnabled ( - VOID - ) -{ - return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0); -} - - -/** - Returns TRUE if DEBUG() macros are enabled. - - This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of - PcdDebugProperyMask is set. Otherwise FALSE is returned. - - @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set. - @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear. - -**/ -BOOLEAN -EFIAPI -DebugPrintEnabled ( - VOID - ) -{ - return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0); -} - - -/** - Returns TRUE if DEBUG_CODE() macros are enabled. - - This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of - PcdDebugProperyMask is set. Otherwise FALSE is returned. - - @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set. - @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear. - -**/ -BOOLEAN -EFIAPI -DebugCodeEnabled ( - VOID - ) -{ - return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0); -} - - -/** - Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled. - - This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of - PcdDebugProperyMask is set. Otherwise FALSE is returned. - - @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set. - @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear. - -**/ -BOOLEAN -EFIAPI -DebugClearMemoryEnabled ( - VOID - ) -{ - return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0); -} - -/** - Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel. - - This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel. - - @retval TRUE Current ErrorLevel is supported. - @retval FALSE Current ErrorLevel is not supported. - -**/ -BOOLEAN -EFIAPI -DebugPrintLevelEnabled ( - IN CONST UINTN ErrorLevel - ) -{ - return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0); -} diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf b/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf deleted file mode 100644 index 0e74fe94cb..0000000000 --- a/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf +++ /dev/null @@ -1,51 +0,0 @@ -## @file -# Instance of Debug Library for the QEMU debug console port. -# It uses Print Library to produce formatted output strings. -# -# Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
-# Copyright (c) 2012, Red Hat, Inc.
-# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php. -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = PlatformDebugLibIoPort - FILE_GUID = DF934DA3-CD31-49FE-AF50-B3C87C79325F - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = DebugLib - CONSTRUCTOR = PlatformDebugLibIoPortConstructor - -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources] - DebugLib.c - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseMemoryLib - IoLib - PcdLib - PrintLib - BaseLib - DebugPrintErrorLevelLib - -[Pcd] - gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel ## CONSUMES - diff --git a/OvmfPkg/Library/PlatformFvbLibNull/PlatformFvbLibNull.c b/OvmfPkg/Library/PlatformFvbLibNull/PlatformFvbLibNull.c deleted file mode 100644 index ea5da6e0d6..0000000000 --- a/OvmfPkg/Library/PlatformFvbLibNull/PlatformFvbLibNull.c +++ /dev/null @@ -1,89 +0,0 @@ -/** @file - NULL PlatformFvbLib library instance - - Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "PiDxe.h" -#include - - -/** - This function will be called following a call to the - EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL Read function. - - @param[in] This The EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance. - @param[in] Lba The starting logical block index - from which to read. - @param[in] Offset Offset into the block at which to begin reading. - @param[in] NumBytes The number of bytes read. - @param[in] Buffer Pointer to the buffer that was read, and will be - returned to the caller. - -**/ -VOID -EFIAPI -PlatformFvbDataRead ( - IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, - IN EFI_LBA Lba, - IN UINTN Offset, - IN UINTN NumBytes, - IN UINT8 *Buffer - ) -{ -} - - -/** - This function will be called following a call to the - EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL Write function. - - @param[in] This EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance. - @param[in] Lba The starting logical block index to written to. - @param[in] Offset Offset into the block at which to begin writing. - @param[in] NumBytes The number of bytes written. - @param[in] Buffer Pointer to the buffer that was written. - -**/ -VOID -EFIAPI -PlatformFvbDataWritten ( - IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, - IN EFI_LBA Lba, - IN UINTN Offset, - IN UINTN NumBytes, - IN UINT8 *Buffer - ) -{ -} - - -/** - This function will be called following a call to the - EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL Erase function. - - @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL - instance. - @param List The variable argument list as documented for - the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL Erase - function. - -**/ -VOID -EFIAPI -PlatformFvbBlocksErased ( - IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, - IN VA_LIST List - ) -{ -} - - diff --git a/OvmfPkg/Library/PlatformFvbLibNull/PlatformFvbLibNull.inf b/OvmfPkg/Library/PlatformFvbLibNull/PlatformFvbLibNull.inf deleted file mode 100644 index 5f51391e82..0000000000 --- a/OvmfPkg/Library/PlatformFvbLibNull/PlatformFvbLibNull.inf +++ /dev/null @@ -1,39 +0,0 @@ -## @file -# NULL PlatformFvbLib library instance -# -# This library handles hooks for the EMU Variable FVB driver. -# -# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = PlatformFvbLibNull - FILE_GUID = 79263F9A-1701-4382-98C2-573F3558E6C8 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = PlatformFvbLib|DXE_RUNTIME_DRIVER - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources] - PlatformFvbLibNull.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - OvmfPkg/OvmfPkg.dec - diff --git a/OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.c b/OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.c deleted file mode 100644 index de0e4fa938..0000000000 --- a/OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.c +++ /dev/null @@ -1,40 +0,0 @@ -/** @file - Provides a platform-specific method to enable Secure Boot Custom Mode setup. - - Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ -#include - -/** - - This function provides a platform-specific method to detect whether the platform - is operating by a physically present user. - - Programmatic changing of platform security policy (such as disable Secure Boot, - or switch between Standard/Custom Secure Boot mode) MUST NOT be possible during - Boot Services or after exiting EFI Boot Services. Only a physically present user - is allowed to perform these operations. - - NOTE THAT: This function cannot depend on any EFI Variable Service since they are - not available when this function is called in AuthenticateVariable driver. - - @retval TRUE The platform is operated by a physically present user. - @retval FALSE The platform is NOT operated by a physically present user. - -**/ -BOOLEAN -EFIAPI -UserPhysicalPresent ( - VOID - ) -{ - return TRUE; -} diff --git a/OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf b/OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf deleted file mode 100644 index 267bc182b4..0000000000 --- a/OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf +++ /dev/null @@ -1,33 +0,0 @@ -## @file -# Provides a platform-specific method to enable Secure Boot Custom Mode setup. -# -# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = PlatformSecureLib - FILE_GUID = 4204D78D-EDBF-4cee-BE80-3881457CF344 - MODULE_TYPE = DXE_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = PlatformSecureLib|DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_DRIVER - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources] - PlatformSecureLib.c - -[Packages] - MdePkg/MdePkg.dec diff --git a/OvmfPkg/Library/QemuBootOrderLib/ExtraRootBusMap.c b/OvmfPkg/Library/QemuBootOrderLib/ExtraRootBusMap.c deleted file mode 100644 index ec422145c4..0000000000 --- a/OvmfPkg/Library/QemuBootOrderLib/ExtraRootBusMap.c +++ /dev/null @@ -1,313 +0,0 @@ -/** @file - Map positions of extra PCI root buses to bus numbers. - - Copyright (C) 2015, Red Hat, Inc. - - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License which accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#include -#include -#include -#include -#include -#include -#include - -#include "ExtraRootBusMap.h" - -// -// The BusNumbers field is an array with Count elements. The elements increase -// strictry monotonically. Zero is not an element (because the zero bus number -// belongs to the "main" root bus, never to an extra root bus). Offset N in the -// array maps the extra root bus with position (N+1) to its bus number (because -// the root bus with position 0 is always the main root bus, therefore we don't -// store it). -// -// If there are no extra root buses in the system, then Count is 0, and -// BusNumbers is NULL. -// -struct EXTRA_ROOT_BUS_MAP_STRUCT { - UINT32 *BusNumbers; - UINTN Count; -}; - - -/** - An ORDERED_COLLECTION_USER_COMPARE function that compares root bridge - protocol device paths based on UID. - - @param[in] UserStruct1 Pointer to the first ACPI_HID_DEVICE_PATH. - - @param[in] UserStruct2 Pointer to the second ACPI_HID_DEVICE_PATH. - - @retval <0 If UserStruct1 compares less than UserStruct2. - - @retval 0 If UserStruct1 compares equal to UserStruct2. - - @retval >0 If UserStruct1 compares greater than UserStruct2. -**/ -STATIC -INTN -EFIAPI -RootBridgePathCompare ( - IN CONST VOID *UserStruct1, - IN CONST VOID *UserStruct2 - ) -{ - CONST ACPI_HID_DEVICE_PATH *Acpi1; - CONST ACPI_HID_DEVICE_PATH *Acpi2; - - Acpi1 = UserStruct1; - Acpi2 = UserStruct2; - - return Acpi1->UID < Acpi2->UID ? -1 : - Acpi1->UID > Acpi2->UID ? 1 : - 0; -} - - -/** - An ORDERED_COLLECTION_KEY_COMPARE function that compares a root bridge - protocol device path against a UID. - - @param[in] StandaloneKey Pointer to the bare UINT32 UID. - - @param[in] UserStruct Pointer to the ACPI_HID_DEVICE_PATH with the - embedded UINT32 UID. - - @retval <0 If StandaloneKey compares less than UserStruct's key. - - @retval 0 If StandaloneKey compares equal to UserStruct's key. - - @retval >0 If StandaloneKey compares greater than UserStruct's key. -**/ -STATIC -INTN -EFIAPI -RootBridgePathKeyCompare ( - IN CONST VOID *StandaloneKey, - IN CONST VOID *UserStruct - ) -{ - CONST UINT32 *Uid; - CONST ACPI_HID_DEVICE_PATH *Acpi; - - Uid = StandaloneKey; - Acpi = UserStruct; - - return *Uid < Acpi->UID ? -1 : - *Uid > Acpi->UID ? 1 : - 0; -} - - -/** - Create a structure that maps the relative positions of PCI root buses to bus - numbers. - - In the "bootorder" fw_cfg file, QEMU refers to extra PCI root buses by their - positions, in relative root bus number order, not by their actual PCI bus - numbers. The ACPI HID device path nodes however that are associated with - PciRootBridgeIo protocol instances in the system have their UID fields set to - the bus numbers. Create a map that gives, for each extra PCI root bus's - position (ie. "serial number") its actual PCI bus number. - - @param[out] ExtraRootBusMap The data structure implementing the map. - - @retval EFI_SUCCESS ExtraRootBusMap has been populated. - - @retval EFI_OUT_OF_RESOURCES Memory allocation failed. - - @retval EFI_ALREADY_STARTED A duplicate root bus number has been found in - the system. (This should never happen.) - - @return Error codes returned by - gBS->LocateHandleBuffer() and - gBS->HandleProtocol(). - -**/ -EFI_STATUS -CreateExtraRootBusMap ( - OUT EXTRA_ROOT_BUS_MAP **ExtraRootBusMap - ) -{ - EFI_STATUS Status; - UINTN NumHandles; - EFI_HANDLE *Handles; - ORDERED_COLLECTION *Collection; - EXTRA_ROOT_BUS_MAP *Map; - UINTN Idx; - ORDERED_COLLECTION_ENTRY *Entry, *Entry2; - - // - // Handles and Collection are temporary / helper variables, while in Map we - // build the return value. - // - - Status = gBS->LocateHandleBuffer (ByProtocol, - &gEfiPciRootBridgeIoProtocolGuid, NULL /* SearchKey */, - &NumHandles, &Handles); - if (EFI_ERROR (Status)) { - return Status; - } - - Collection = OrderedCollectionInit (RootBridgePathCompare, - RootBridgePathKeyCompare); - if (Collection == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto FreeHandles; - } - - Map = AllocateZeroPool (sizeof *Map); - if (Map == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto FreeCollection; - } - - // - // Collect the ACPI device path protocols of the root bridges. - // - for (Idx = 0; Idx < NumHandles; ++Idx) { - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - - Status = gBS->HandleProtocol (Handles[Idx], &gEfiDevicePathProtocolGuid, - (VOID**)&DevicePath); - if (EFI_ERROR (Status)) { - goto FreeMap; - } - - // - // Examine if the device path is an ACPI HID one, and if so, if UID is - // nonzero (ie. the root bridge that the bus number belongs to is "extra", - // not the main one). In that case, link the device path into Collection. - // - if (DevicePathType (DevicePath) == ACPI_DEVICE_PATH && - DevicePathSubType (DevicePath) == ACPI_DP && - ((ACPI_HID_DEVICE_PATH *)DevicePath)->HID == EISA_PNP_ID(0x0A03) && - ((ACPI_HID_DEVICE_PATH *)DevicePath)->UID > 0) { - Status = OrderedCollectionInsert (Collection, NULL, DevicePath); - if (EFI_ERROR (Status)) { - goto FreeMap; - } - ++Map->Count; - } - } - - if (Map->Count > 0) { - // - // At least one extra PCI root bus exists. - // - Map->BusNumbers = AllocatePool (Map->Count * sizeof *Map->BusNumbers); - if (Map->BusNumbers == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto FreeMap; - } - } - - // - // Now collect the bus numbers of the extra PCI root buses into Map. - // - Idx = 0; - Entry = OrderedCollectionMin (Collection); - while (Idx < Map->Count) { - ACPI_HID_DEVICE_PATH *Acpi; - - ASSERT (Entry != NULL); - Acpi = OrderedCollectionUserStruct (Entry); - Map->BusNumbers[Idx] = Acpi->UID; - DEBUG ((EFI_D_VERBOSE, - "%a: extra bus position 0x%Lx maps to bus number (UID) 0x%x\n", - __FUNCTION__, (UINT64)(Idx + 1), Acpi->UID)); - ++Idx; - Entry = OrderedCollectionNext (Entry); - } - ASSERT (Entry == NULL); - - *ExtraRootBusMap = Map; - Status = EFI_SUCCESS; - - // - // Fall through in order to release temporaries. - // - -FreeMap: - if (EFI_ERROR (Status)) { - if (Map->BusNumbers != NULL) { - FreePool (Map->BusNumbers); - } - FreePool (Map); - } - -FreeCollection: - for (Entry = OrderedCollectionMin (Collection); Entry != NULL; - Entry = Entry2) { - Entry2 = OrderedCollectionNext (Entry); - OrderedCollectionDelete (Collection, Entry, NULL); - } - OrderedCollectionUninit (Collection); - -FreeHandles: - FreePool (Handles); - - return Status; -} - - -/** - Release a map created with CreateExtraRootBusMap(). - - @param[in] ExtraRootBusMap The map to release. -*/ -VOID -DestroyExtraRootBusMap ( - IN EXTRA_ROOT_BUS_MAP *ExtraRootBusMap - ) -{ - if (ExtraRootBusMap->BusNumbers != NULL) { - FreePool (ExtraRootBusMap->BusNumbers); - } - FreePool (ExtraRootBusMap); -} - -/** - Map the position (serial number) of an extra PCI root bus to its bus number. - - @param[in] ExtraRootBusMap The map created with CreateExtraRootBusMap(); - - @param[in] RootBusPos The extra PCI root bus position to map. - - @param[out] RootBusNr The bus number belonging to the extra PCI root - bus identified by RootBusPos. - - @retval EFI_INVALID_PARAMETER RootBusPos is zero. The zero position - identifies the main root bus, whose bus number - is always zero, and is therefore never - maintained in ExtraRootBusMap. - - @retval EFI_NOT_FOUND RootBusPos is not found in ExtraRootBusMap. - - @retval EFI_SUCCESS Mapping successful. -**/ -EFI_STATUS -MapRootBusPosToBusNr ( - IN CONST EXTRA_ROOT_BUS_MAP *ExtraRootBusMap, - IN UINT64 RootBusPos, - OUT UINT32 *RootBusNr - ) -{ - if (RootBusPos == 0) { - return EFI_INVALID_PARAMETER; - } - if (RootBusPos > ExtraRootBusMap->Count) { - return EFI_NOT_FOUND; - } - *RootBusNr = ExtraRootBusMap->BusNumbers[RootBusPos - 1]; - return EFI_SUCCESS; -} diff --git a/OvmfPkg/Library/QemuBootOrderLib/ExtraRootBusMap.h b/OvmfPkg/Library/QemuBootOrderLib/ExtraRootBusMap.h deleted file mode 100644 index e2dbc38ed8..0000000000 --- a/OvmfPkg/Library/QemuBootOrderLib/ExtraRootBusMap.h +++ /dev/null @@ -1,40 +0,0 @@ -/** @file - Map positions of extra PCI root buses to bus numbers. - - Copyright (C) 2015, Red Hat, Inc. - - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License which accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#ifndef __EXTRA_ROOT_BUS_MAP_H__ -#define __EXTRA_ROOT_BUS_MAP_H__ - -/** - Incomplete ("opaque") data type implementing the map. -**/ -typedef struct EXTRA_ROOT_BUS_MAP_STRUCT EXTRA_ROOT_BUS_MAP; - -EFI_STATUS -CreateExtraRootBusMap ( - OUT EXTRA_ROOT_BUS_MAP **ExtraRootBusMap - ); - -VOID -DestroyExtraRootBusMap ( - IN EXTRA_ROOT_BUS_MAP *ExtraRootBusMap - ); - -EFI_STATUS -MapRootBusPosToBusNr ( - IN CONST EXTRA_ROOT_BUS_MAP *ExtraRootBusMap, - IN UINT64 RootBusPos, - OUT UINT32 *RootBusNr - ); - -#endif diff --git a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c deleted file mode 100644 index 2e9634359d..0000000000 --- a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c +++ /dev/null @@ -1,1793 +0,0 @@ -/** @file - Rewrite the BootOrder NvVar based on QEMU's "bootorder" fw_cfg file. - - Copyright (C) 2012 - 2014, Red Hat, Inc. - Copyright (c) 2013, Intel Corporation. All rights reserved.
- - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License which accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ExtraRootBusMap.h" - -/** - OpenFirmware to UEFI device path translation output buffer size in CHAR16's. -**/ -#define TRANSLATION_OUTPUT_SIZE 0x100 - -/** - Output buffer size for OpenFirmware to UEFI device path fragment translation, - in CHAR16's, for a sequence of PCI bridges. -**/ -#define BRIDGE_TRANSLATION_OUTPUT_SIZE 0x40 - -/** - Numbers of nodes in OpenFirmware device paths that are required and examined. -**/ -#define REQUIRED_PCI_OFW_NODES 2 -#define REQUIRED_MMIO_OFW_NODES 1 -#define EXAMINED_OFW_NODES 6 - - -/** - Simple character classification routines, corresponding to POSIX class names - and ASCII encoding. -**/ -STATIC -BOOLEAN -IsAlnum ( - IN CHAR8 Chr - ) -{ - return (('0' <= Chr && Chr <= '9') || - ('A' <= Chr && Chr <= 'Z') || - ('a' <= Chr && Chr <= 'z') - ); -} - - -STATIC -BOOLEAN -IsDriverNamePunct ( - IN CHAR8 Chr - ) -{ - return (Chr == ',' || Chr == '.' || Chr == '_' || - Chr == '+' || Chr == '-' - ); -} - - -STATIC -BOOLEAN -IsPrintNotDelim ( - IN CHAR8 Chr - ) -{ - return (32 <= Chr && Chr <= 126 && - Chr != '/' && Chr != '@' && Chr != ':'); -} - - -/** - Utility types and functions. -**/ -typedef struct { - CONST CHAR8 *Ptr; // not necessarily NUL-terminated - UINTN Len; // number of non-NUL characters -} SUBSTRING; - - -/** - - Check if Substring and String have identical contents. - - The function relies on the restriction that a SUBSTRING cannot have embedded - NULs either. - - @param[in] Substring The SUBSTRING input to the comparison. - - @param[in] String The ASCII string input to the comparison. - - - @return Whether the inputs have identical contents. - -**/ -STATIC -BOOLEAN -SubstringEq ( - IN SUBSTRING Substring, - IN CONST CHAR8 *String - ) -{ - UINTN Pos; - CONST CHAR8 *Chr; - - Pos = 0; - Chr = String; - - while (Pos < Substring.Len && Substring.Ptr[Pos] == *Chr) { - ++Pos; - ++Chr; - } - - return (BOOLEAN)(Pos == Substring.Len && *Chr == '\0'); -} - - -/** - - Parse a comma-separated list of hexadecimal integers into the elements of an - UINT64 array. - - Whitespace, "0x" prefixes, leading or trailing commas, sequences of commas, - or an empty string are not allowed; they are rejected. - - The function relies on ASCII encoding. - - @param[in] UnitAddress The substring to parse. - - @param[out] Result The array, allocated by the caller, to receive - the parsed values. This parameter may be NULL if - NumResults is zero on input. - - @param[in out] NumResults On input, the number of elements allocated for - Result. On output, the number of elements it has - taken (or would have taken) to parse the string - fully. - - - @retval RETURN_SUCCESS UnitAddress has been fully parsed. - NumResults is set to the number of parsed - values; the corresponding elements have - been set in Result. The rest of Result's - elements are unchanged. - - @retval RETURN_BUFFER_TOO_SMALL UnitAddress has been fully parsed. - NumResults is set to the number of parsed - values, but elements have been stored only - up to the input value of NumResults, which - is less than what has been parsed. - - @retval RETURN_INVALID_PARAMETER Parse error. The contents of Results is - indeterminate. NumResults has not been - changed. - -**/ -STATIC -RETURN_STATUS -ParseUnitAddressHexList ( - IN SUBSTRING UnitAddress, - OUT UINT64 *Result, - IN OUT UINTN *NumResults - ) -{ - UINTN Entry; // number of entry currently being parsed - UINT64 EntryVal; // value being constructed for current entry - CHAR8 PrevChr; // UnitAddress character previously checked - UINTN Pos; // current position within UnitAddress - RETURN_STATUS Status; - - Entry = 0; - EntryVal = 0; - PrevChr = ','; - - for (Pos = 0; Pos < UnitAddress.Len; ++Pos) { - CHAR8 Chr; - INT8 Val; - - Chr = UnitAddress.Ptr[Pos]; - Val = ('a' <= Chr && Chr <= 'f') ? (Chr - 'a' + 10) : - ('A' <= Chr && Chr <= 'F') ? (Chr - 'A' + 10) : - ('0' <= Chr && Chr <= '9') ? (Chr - '0' ) : - -1; - - if (Val >= 0) { - if (EntryVal > 0xFFFFFFFFFFFFFFFull) { - return RETURN_INVALID_PARAMETER; - } - EntryVal = LShiftU64 (EntryVal, 4) | Val; - } else if (Chr == ',') { - if (PrevChr == ',') { - return RETURN_INVALID_PARAMETER; - } - if (Entry < *NumResults) { - Result[Entry] = EntryVal; - } - ++Entry; - EntryVal = 0; - } else { - return RETURN_INVALID_PARAMETER; - } - - PrevChr = Chr; - } - - if (PrevChr == ',') { - return RETURN_INVALID_PARAMETER; - } - if (Entry < *NumResults) { - Result[Entry] = EntryVal; - Status = RETURN_SUCCESS; - } else { - Status = RETURN_BUFFER_TOO_SMALL; - } - ++Entry; - - *NumResults = Entry; - return Status; -} - - -/** - A simple array of Boot Option ID's. -**/ -typedef struct { - UINT16 *Data; - UINTN Allocated; - UINTN Produced; -} BOOT_ORDER; - - -/** - Array element tracking an enumerated boot option that has the - LOAD_OPTION_ACTIVE attribute. -**/ -typedef struct { - CONST BDS_COMMON_OPTION *BootOption; // reference only, no ownership - BOOLEAN Appended; // has been added to a BOOT_ORDER? -} ACTIVE_OPTION; - - -/** - - Append an active boot option to BootOrder, reallocating the latter if needed. - - @param[in out] BootOrder The structure pointing to the array and holding - allocation and usage counters. - - @param[in] ActiveOption The active boot option whose ID should be - appended to the array. - - - @retval RETURN_SUCCESS ID of ActiveOption appended. - - @retval RETURN_OUT_OF_RESOURCES Memory reallocation failed. - -**/ -STATIC -RETURN_STATUS -BootOrderAppend ( - IN OUT BOOT_ORDER *BootOrder, - IN OUT ACTIVE_OPTION *ActiveOption - ) -{ - if (BootOrder->Produced == BootOrder->Allocated) { - UINTN AllocatedNew; - UINT16 *DataNew; - - ASSERT (BootOrder->Allocated > 0); - AllocatedNew = BootOrder->Allocated * 2; - DataNew = ReallocatePool ( - BootOrder->Allocated * sizeof (*BootOrder->Data), - AllocatedNew * sizeof (*DataNew), - BootOrder->Data - ); - if (DataNew == NULL) { - return RETURN_OUT_OF_RESOURCES; - } - BootOrder->Allocated = AllocatedNew; - BootOrder->Data = DataNew; - } - - BootOrder->Data[BootOrder->Produced++] = - ActiveOption->BootOption->BootCurrent; - ActiveOption->Appended = TRUE; - return RETURN_SUCCESS; -} - - -/** - - Create an array of ACTIVE_OPTION elements for a boot option list. - - @param[in] BootOptionList A boot option list, created with - BdsLibEnumerateAllBootOption(). - - @param[out] ActiveOption Pointer to the first element in the new array. - The caller is responsible for freeing the array - with FreePool() after use. - - @param[out] Count Number of elements in the new array. - - - @retval RETURN_SUCCESS The ActiveOption array has been created. - - @retval RETURN_NOT_FOUND No active entry has been found in - BootOptionList. - - @retval RETURN_OUT_OF_RESOURCES Memory allocation failed. - -**/ -STATIC -RETURN_STATUS -CollectActiveOptions ( - IN CONST LIST_ENTRY *BootOptionList, - OUT ACTIVE_OPTION **ActiveOption, - OUT UINTN *Count - ) -{ - UINTN ScanMode; - - *ActiveOption = NULL; - - // - // Scan the list twice: - // - count active entries, - // - store links to active entries. - // - for (ScanMode = 0; ScanMode < 2; ++ScanMode) { - CONST LIST_ENTRY *Link; - - Link = BootOptionList->ForwardLink; - *Count = 0; - while (Link != BootOptionList) { - CONST BDS_COMMON_OPTION *Current; - - Current = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE); - if (IS_LOAD_OPTION_TYPE (Current->Attribute, LOAD_OPTION_ACTIVE)) { - if (ScanMode == 1) { - (*ActiveOption)[*Count].BootOption = Current; - (*ActiveOption)[*Count].Appended = FALSE; - } - ++*Count; - } - Link = Link->ForwardLink; - } - - if (ScanMode == 0) { - if (*Count == 0) { - return RETURN_NOT_FOUND; - } - *ActiveOption = AllocatePool (*Count * sizeof **ActiveOption); - if (*ActiveOption == NULL) { - return RETURN_OUT_OF_RESOURCES; - } - } - } - return RETURN_SUCCESS; -} - - -/** - OpenFirmware device path node -**/ -typedef struct { - SUBSTRING DriverName; - SUBSTRING UnitAddress; - SUBSTRING DeviceArguments; -} OFW_NODE; - - -/** - - Parse an OpenFirmware device path node into the caller-allocated OFW_NODE - structure, and advance in the input string. - - The node format is mostly parsed after IEEE 1275-1994, 3.2.1.1 "Node names" - (a leading slash is expected and not returned): - - /driver-name@unit-address[:device-arguments][] - - A single trailing character is consumed but not returned. A trailing - or NUL character terminates the device path. - - The function relies on ASCII encoding. - - @param[in out] Ptr Address of the pointer pointing to the start of the - node string. After successful parsing *Ptr is set to - the byte immediately following the consumed - characters. On error it points to the byte that - caused the error. The input string is never modified. - - @param[out] OfwNode The members of this structure point into the input - string, designating components of the node. - Separators are never included. If "device-arguments" - is missing, then DeviceArguments.Ptr is set to NULL. - All components that are present have nonzero length. - - If the call doesn't succeed, the contents of this - structure is indeterminate. - - @param[out] IsFinal In case of successul parsing, this parameter signals - whether the node just parsed is the final node in the - device path. The call after a final node will attempt - to start parsing the next path. If the call doesn't - succeed, then this parameter is not changed. - - - @retval RETURN_SUCCESS Parsing successful. - - @retval RETURN_NOT_FOUND Parsing terminated. *Ptr was (and is) - pointing to an empty string. - - @retval RETURN_INVALID_PARAMETER Parse error. - -**/ -STATIC -RETURN_STATUS -ParseOfwNode ( - IN OUT CONST CHAR8 **Ptr, - OUT OFW_NODE *OfwNode, - OUT BOOLEAN *IsFinal - ) -{ - // - // A leading slash is expected. End of string is tolerated. - // - switch (**Ptr) { - case '\0': - return RETURN_NOT_FOUND; - - case '/': - ++*Ptr; - break; - - default: - return RETURN_INVALID_PARAMETER; - } - - // - // driver-name - // - OfwNode->DriverName.Ptr = *Ptr; - OfwNode->DriverName.Len = 0; - while (OfwNode->DriverName.Len < 32 && - (IsAlnum (**Ptr) || IsDriverNamePunct (**Ptr)) - ) { - ++*Ptr; - ++OfwNode->DriverName.Len; - } - - if (OfwNode->DriverName.Len == 0 || OfwNode->DriverName.Len == 32) { - return RETURN_INVALID_PARAMETER; - } - - - // - // unit-address - // - if (**Ptr != '@') { - return RETURN_INVALID_PARAMETER; - } - ++*Ptr; - - OfwNode->UnitAddress.Ptr = *Ptr; - OfwNode->UnitAddress.Len = 0; - while (IsPrintNotDelim (**Ptr)) { - ++*Ptr; - ++OfwNode->UnitAddress.Len; - } - - if (OfwNode->UnitAddress.Len == 0) { - return RETURN_INVALID_PARAMETER; - } - - - // - // device-arguments, may be omitted - // - OfwNode->DeviceArguments.Len = 0; - if (**Ptr == ':') { - ++*Ptr; - OfwNode->DeviceArguments.Ptr = *Ptr; - - while (IsPrintNotDelim (**Ptr)) { - ++*Ptr; - ++OfwNode->DeviceArguments.Len; - } - - if (OfwNode->DeviceArguments.Len == 0) { - return RETURN_INVALID_PARAMETER; - } - } - else { - OfwNode->DeviceArguments.Ptr = NULL; - } - - switch (**Ptr) { - case '\n': - ++*Ptr; - // - // fall through - // - - case '\0': - *IsFinal = TRUE; - break; - - case '/': - *IsFinal = FALSE; - break; - - default: - return RETURN_INVALID_PARAMETER; - } - - DEBUG (( - DEBUG_VERBOSE, - "%a: DriverName=\"%.*a\" UnitAddress=\"%.*a\" DeviceArguments=\"%.*a\"\n", - __FUNCTION__, - OfwNode->DriverName.Len, OfwNode->DriverName.Ptr, - OfwNode->UnitAddress.Len, OfwNode->UnitAddress.Ptr, - OfwNode->DeviceArguments.Len, - OfwNode->DeviceArguments.Ptr == NULL ? "" : OfwNode->DeviceArguments.Ptr - )); - return RETURN_SUCCESS; -} - - -/** - - Translate a PCI-like array of OpenFirmware device nodes to a UEFI device path - fragment. - - @param[in] OfwNode Array of OpenFirmware device nodes to - translate, constituting the beginning of an - OpenFirmware device path. - - @param[in] NumNodes Number of elements in OfwNode. - - @param[in] ExtraPciRoots An EXTRA_ROOT_BUS_MAP object created with - CreateExtraRootBusMap(), to be used for - translating positions of extra root buses to - bus numbers. - - @param[out] Translated Destination array receiving the UEFI path - fragment, allocated by the caller. If the - return value differs from RETURN_SUCCESS, its - contents is indeterminate. - - @param[in out] TranslatedSize On input, the number of CHAR16's in - Translated. On RETURN_SUCCESS this parameter - is assigned the number of non-NUL CHAR16's - written to Translated. In case of other return - values, TranslatedSize is indeterminate. - - - @retval RETURN_SUCCESS Translation successful. - - @retval RETURN_BUFFER_TOO_SMALL The translation does not fit into the number - of bytes provided. - - @retval RETURN_UNSUPPORTED The array of OpenFirmware device nodes can't - be translated in the current implementation. - - @retval RETURN_PROTOCOL_ERROR The initial OpenFirmware node refers to an - extra PCI root bus (by serial number) that - is invalid according to ExtraPciRoots. - -**/ -STATIC -RETURN_STATUS -TranslatePciOfwNodes ( - IN CONST OFW_NODE *OfwNode, - IN UINTN NumNodes, - IN CONST EXTRA_ROOT_BUS_MAP *ExtraPciRoots, - OUT CHAR16 *Translated, - IN OUT UINTN *TranslatedSize - ) -{ - UINT32 PciRoot; - CHAR8 *Comma; - UINTN FirstNonBridge; - CHAR16 Bridges[BRIDGE_TRANSLATION_OUTPUT_SIZE]; - UINTN BridgesLen; - UINT64 PciDevFun[2]; - UINTN NumEntries; - UINTN Written; - - // - // Resolve the PCI root bus number. - // - // The initial OFW node for the main root bus (ie. bus number 0) is: - // - // /pci@i0cf8 - // - // For extra root buses, the initial OFW node is - // - // /pci@i0cf8,4 - // ^ - // root bus serial number (not PCI bus number) - // - if (NumNodes < REQUIRED_PCI_OFW_NODES || - !SubstringEq (OfwNode[0].DriverName, "pci") - ) { - return RETURN_UNSUPPORTED; - } - - PciRoot = 0; - Comma = ScanMem8 (OfwNode[0].UnitAddress.Ptr, OfwNode[0].UnitAddress.Len, - ','); - if (Comma != NULL) { - SUBSTRING PciRootSerialSubString; - UINT64 PciRootSerial; - - // - // Parse the root bus serial number from the unit address after the comma. - // - PciRootSerialSubString.Ptr = Comma + 1; - PciRootSerialSubString.Len = OfwNode[0].UnitAddress.Len - - (PciRootSerialSubString.Ptr - - OfwNode[0].UnitAddress.Ptr); - NumEntries = 1; - if (RETURN_ERROR (ParseUnitAddressHexList (PciRootSerialSubString, - &PciRootSerial, &NumEntries))) { - return RETURN_UNSUPPORTED; - } - - // - // Map the extra root bus's serial number to its actual bus number. - // - if (EFI_ERROR (MapRootBusPosToBusNr (ExtraPciRoots, PciRootSerial, - &PciRoot))) { - return RETURN_PROTOCOL_ERROR; - } - } - - // - // Translate a sequence of PCI bridges. For each bridge, the OFW node is: - // - // pci-bridge@1e[,0] - // ^ ^ - // PCI slot & function on the parent, holding the bridge - // - // and the UEFI device path node is: - // - // Pci(0x1E,0x0) - // - FirstNonBridge = 1; - Bridges[0] = L'\0'; - BridgesLen = 0; - do { - UINT64 BridgeDevFun[2]; - UINTN BridgesFreeBytes; - - if (!SubstringEq (OfwNode[FirstNonBridge].DriverName, "pci-bridge")) { - break; - } - - BridgeDevFun[1] = 0; - NumEntries = sizeof BridgeDevFun / sizeof BridgeDevFun[0]; - if (ParseUnitAddressHexList (OfwNode[FirstNonBridge].UnitAddress, - BridgeDevFun, &NumEntries) != RETURN_SUCCESS) { - return RETURN_UNSUPPORTED; - } - - BridgesFreeBytes = sizeof Bridges - BridgesLen * sizeof Bridges[0]; - Written = UnicodeSPrintAsciiFormat (Bridges + BridgesLen, BridgesFreeBytes, - "/Pci(0x%Lx,0x%Lx)", BridgeDevFun[0], BridgeDevFun[1]); - BridgesLen += Written; - - // - // There's no way to differentiate between "completely used up without - // truncation" and "truncated", so treat the former as the latter. - // - if (BridgesLen + 1 == BRIDGE_TRANSLATION_OUTPUT_SIZE) { - return RETURN_UNSUPPORTED; - } - - ++FirstNonBridge; - } while (FirstNonBridge < NumNodes); - - if (FirstNonBridge == NumNodes) { - return RETURN_UNSUPPORTED; - } - - // - // Parse the OFW nodes starting with the first non-bridge node. - // - PciDevFun[1] = 0; - NumEntries = sizeof (PciDevFun) / sizeof (PciDevFun[0]); - if (ParseUnitAddressHexList ( - OfwNode[FirstNonBridge].UnitAddress, - PciDevFun, - &NumEntries - ) != RETURN_SUCCESS - ) { - return RETURN_UNSUPPORTED; - } - - if (NumNodes >= FirstNonBridge + 3 && - SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "ide") && - SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "drive") && - SubstringEq (OfwNode[FirstNonBridge + 2].DriverName, "disk") - ) { - // - // OpenFirmware device path (IDE disk, IDE CD-ROM): - // - // /pci@i0cf8/ide@1,1/drive@0/disk@0 - // ^ ^ ^ ^ ^ - // | | | | master or slave - // | | | primary or secondary - // | PCI slot & function holding IDE controller - // PCI root at system bus port, PIO - // - // UEFI device path: - // - // PciRoot(0x0)/Pci(0x1,0x1)/Ata(Primary,Master,0x0) - // ^ - // fixed LUN - // - UINT64 Secondary; - UINT64 Slave; - - NumEntries = 1; - if (ParseUnitAddressHexList ( - OfwNode[FirstNonBridge + 1].UnitAddress, - &Secondary, - &NumEntries - ) != RETURN_SUCCESS || - Secondary > 1 || - ParseUnitAddressHexList ( - OfwNode[FirstNonBridge + 2].UnitAddress, - &Slave, - &NumEntries // reuse after previous single-element call - ) != RETURN_SUCCESS || - Slave > 1 - ) { - return RETURN_UNSUPPORTED; - } - - Written = UnicodeSPrintAsciiFormat ( - Translated, - *TranslatedSize * sizeof (*Translated), // BufferSize in bytes - "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Ata(%a,%a,0x0)", - PciRoot, - Bridges, - PciDevFun[0], - PciDevFun[1], - Secondary ? "Secondary" : "Primary", - Slave ? "Slave" : "Master" - ); - } else if (NumNodes >= FirstNonBridge + 3 && - SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "isa") && - SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "fdc") && - SubstringEq (OfwNode[FirstNonBridge + 2].DriverName, "floppy") - ) { - // - // OpenFirmware device path (floppy disk): - // - // /pci@i0cf8/isa@1/fdc@03f0/floppy@0 - // ^ ^ ^ ^ - // | | | A: or B: - // | | ISA controller io-port (hex) - // | PCI slot holding ISA controller - // PCI root at system bus port, PIO - // - // UEFI device path: - // - // PciRoot(0x0)/Pci(0x1,0x0)/Floppy(0x0) - // ^ - // ACPI UID - // - UINT64 AcpiUid; - - NumEntries = 1; - if (ParseUnitAddressHexList ( - OfwNode[FirstNonBridge + 2].UnitAddress, - &AcpiUid, - &NumEntries - ) != RETURN_SUCCESS || - AcpiUid > 1 - ) { - return RETURN_UNSUPPORTED; - } - - Written = UnicodeSPrintAsciiFormat ( - Translated, - *TranslatedSize * sizeof (*Translated), // BufferSize in bytes - "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Floppy(0x%Lx)", - PciRoot, - Bridges, - PciDevFun[0], - PciDevFun[1], - AcpiUid - ); - } else if (NumNodes >= FirstNonBridge + 2 && - SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "scsi") && - SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "disk") - ) { - // - // OpenFirmware device path (virtio-blk disk): - // - // /pci@i0cf8/scsi@6[,3]/disk@0,0 - // ^ ^ ^ ^ ^ - // | | | fixed - // | | PCI function corresponding to disk (optional) - // | PCI slot holding disk - // PCI root at system bus port, PIO - // - // UEFI device path prefix: - // - // PciRoot(0x0)/Pci(0x6,0x0)/HD( -- if PCI function is 0 or absent - // PciRoot(0x0)/Pci(0x6,0x3)/HD( -- if PCI function is present and nonzero - // - Written = UnicodeSPrintAsciiFormat ( - Translated, - *TranslatedSize * sizeof (*Translated), // BufferSize in bytes - "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/HD(", - PciRoot, - Bridges, - PciDevFun[0], - PciDevFun[1] - ); - } else if (NumNodes >= FirstNonBridge + 3 && - SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "scsi") && - SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "channel") && - SubstringEq (OfwNode[FirstNonBridge + 2].DriverName, "disk") - ) { - // - // OpenFirmware device path (virtio-scsi disk): - // - // /pci@i0cf8/scsi@7[,3]/channel@0/disk@2,3 - // ^ ^ ^ ^ ^ - // | | | | LUN - // | | | target - // | | channel (unused, fixed 0) - // | PCI slot[, function] holding SCSI controller - // PCI root at system bus port, PIO - // - // UEFI device path prefix: - // - // PciRoot(0x0)/Pci(0x7,0x0)/Scsi(0x2,0x3) - // -- if PCI function is 0 or absent - // PciRoot(0x0)/Pci(0x7,0x3)/Scsi(0x2,0x3) - // -- if PCI function is present and nonzero - // - UINT64 TargetLun[2]; - - TargetLun[1] = 0; - NumEntries = sizeof (TargetLun) / sizeof (TargetLun[0]); - if (ParseUnitAddressHexList ( - OfwNode[FirstNonBridge + 2].UnitAddress, - TargetLun, - &NumEntries - ) != RETURN_SUCCESS - ) { - return RETURN_UNSUPPORTED; - } - - Written = UnicodeSPrintAsciiFormat ( - Translated, - *TranslatedSize * sizeof (*Translated), // BufferSize in bytes - "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Scsi(0x%Lx,0x%Lx)", - PciRoot, - Bridges, - PciDevFun[0], - PciDevFun[1], - TargetLun[0], - TargetLun[1] - ); - } else { - // - // Generic OpenFirmware device path for PCI devices: - // - // /pci@i0cf8/ethernet@3[,2] - // ^ ^ - // | PCI slot[, function] holding Ethernet card - // PCI root at system bus port, PIO - // - // UEFI device path prefix (dependent on presence of nonzero PCI function): - // - // PciRoot(0x0)/Pci(0x3,0x0) - // PciRoot(0x0)/Pci(0x3,0x2) - // - Written = UnicodeSPrintAsciiFormat ( - Translated, - *TranslatedSize * sizeof (*Translated), // BufferSize in bytes - "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)", - PciRoot, - Bridges, - PciDevFun[0], - PciDevFun[1] - ); - } - - // - // There's no way to differentiate between "completely used up without - // truncation" and "truncated", so treat the former as the latter, and return - // success only for "some room left unused". - // - if (Written + 1 < *TranslatedSize) { - *TranslatedSize = Written; - return RETURN_SUCCESS; - } - - return RETURN_BUFFER_TOO_SMALL; -} - - -// -// A type providing easy raw access to the base address of a virtio-mmio -// transport. -// -typedef union { - UINT64 Uint64; - UINT8 Raw[8]; -} VIRTIO_MMIO_BASE_ADDRESS; - - -/** - - Translate an MMIO-like array of OpenFirmware device nodes to a UEFI device - path fragment. - - @param[in] OfwNode Array of OpenFirmware device nodes to - translate, constituting the beginning of an - OpenFirmware device path. - - @param[in] NumNodes Number of elements in OfwNode. - - @param[out] Translated Destination array receiving the UEFI path - fragment, allocated by the caller. If the - return value differs from RETURN_SUCCESS, its - contents is indeterminate. - - @param[in out] TranslatedSize On input, the number of CHAR16's in - Translated. On RETURN_SUCCESS this parameter - is assigned the number of non-NUL CHAR16's - written to Translated. In case of other return - values, TranslatedSize is indeterminate. - - - @retval RETURN_SUCCESS Translation successful. - - @retval RETURN_BUFFER_TOO_SMALL The translation does not fit into the number - of bytes provided. - - @retval RETURN_UNSUPPORTED The array of OpenFirmware device nodes can't - be translated in the current implementation. - -**/ -STATIC -RETURN_STATUS -TranslateMmioOfwNodes ( - IN CONST OFW_NODE *OfwNode, - IN UINTN NumNodes, - OUT CHAR16 *Translated, - IN OUT UINTN *TranslatedSize - ) -{ - VIRTIO_MMIO_BASE_ADDRESS VirtioMmioBase; - CHAR16 VenHwString[60 + 1]; - UINTN NumEntries; - UINTN Written; - - // - // Get the base address of the virtio-mmio transport. - // - if (NumNodes < REQUIRED_MMIO_OFW_NODES || - !SubstringEq (OfwNode[0].DriverName, "virtio-mmio") - ) { - return RETURN_UNSUPPORTED; - } - NumEntries = 1; - if (ParseUnitAddressHexList ( - OfwNode[0].UnitAddress, - &VirtioMmioBase.Uint64, - &NumEntries - ) != RETURN_SUCCESS - ) { - return RETURN_UNSUPPORTED; - } - - UnicodeSPrintAsciiFormat (VenHwString, sizeof VenHwString, - "VenHw(%g,%02X%02X%02X%02X%02X%02X%02X%02X)", &gVirtioMmioTransportGuid, - VirtioMmioBase.Raw[0], VirtioMmioBase.Raw[1], VirtioMmioBase.Raw[2], - VirtioMmioBase.Raw[3], VirtioMmioBase.Raw[4], VirtioMmioBase.Raw[5], - VirtioMmioBase.Raw[6], VirtioMmioBase.Raw[7]); - - if (NumNodes >= 2 && - SubstringEq (OfwNode[1].DriverName, "disk")) { - // - // OpenFirmware device path (virtio-blk disk): - // - // /virtio-mmio@000000000a003c00/disk@0,0 - // ^ ^ ^ - // | fixed - // base address of virtio-mmio register block - // - // UEFI device path prefix: - // - // /HD( - // - Written = UnicodeSPrintAsciiFormat ( - Translated, - *TranslatedSize * sizeof (*Translated), // BufferSize in bytes - "%s/HD(", - VenHwString - ); - } else if (NumNodes >= 3 && - SubstringEq (OfwNode[1].DriverName, "channel") && - SubstringEq (OfwNode[2].DriverName, "disk")) { - // - // OpenFirmware device path (virtio-scsi disk): - // - // /virtio-mmio@000000000a003a00/channel@0/disk@2,3 - // ^ ^ ^ ^ - // | | | LUN - // | | target - // | channel (unused, fixed 0) - // base address of virtio-mmio register block - // - // UEFI device path prefix: - // - // /Scsi(0x2,0x3) - // - UINT64 TargetLun[2]; - - TargetLun[1] = 0; - NumEntries = sizeof (TargetLun) / sizeof (TargetLun[0]); - if (ParseUnitAddressHexList ( - OfwNode[2].UnitAddress, - TargetLun, - &NumEntries - ) != RETURN_SUCCESS - ) { - return RETURN_UNSUPPORTED; - } - - Written = UnicodeSPrintAsciiFormat ( - Translated, - *TranslatedSize * sizeof (*Translated), // BufferSize in bytes - "%s/Scsi(0x%Lx,0x%Lx)", - VenHwString, - TargetLun[0], - TargetLun[1] - ); - } else if (NumNodes >= 2 && - SubstringEq (OfwNode[1].DriverName, "ethernet-phy")) { - // - // OpenFirmware device path (virtio-net NIC): - // - // /virtio-mmio@000000000a003e00/ethernet-phy@0 - // ^ ^ - // | fixed - // base address of virtio-mmio register block - // - // UEFI device path prefix (dependent on presence of nonzero PCI function): - // - // /MAC( - // - Written = UnicodeSPrintAsciiFormat ( - Translated, - *TranslatedSize * sizeof (*Translated), // BufferSize in bytes - "%s/MAC(", - VenHwString - ); - } else { - return RETURN_UNSUPPORTED; - } - - // - // There's no way to differentiate between "completely used up without - // truncation" and "truncated", so treat the former as the latter, and return - // success only for "some room left unused". - // - if (Written + 1 < *TranslatedSize) { - *TranslatedSize = Written; - return RETURN_SUCCESS; - } - - return RETURN_BUFFER_TOO_SMALL; -} - - -/** - - Translate an array of OpenFirmware device nodes to a UEFI device path - fragment. - - @param[in] OfwNode Array of OpenFirmware device nodes to - translate, constituting the beginning of an - OpenFirmware device path. - - @param[in] NumNodes Number of elements in OfwNode. - - @param[in] ExtraPciRoots An EXTRA_ROOT_BUS_MAP object created with - CreateExtraRootBusMap(), to be used for - translating positions of extra root buses to - bus numbers. - - @param[out] Translated Destination array receiving the UEFI path - fragment, allocated by the caller. If the - return value differs from RETURN_SUCCESS, its - contents is indeterminate. - - @param[in out] TranslatedSize On input, the number of CHAR16's in - Translated. On RETURN_SUCCESS this parameter - is assigned the number of non-NUL CHAR16's - written to Translated. In case of other return - values, TranslatedSize is indeterminate. - - - @retval RETURN_SUCCESS Translation successful. - - @retval RETURN_BUFFER_TOO_SMALL The translation does not fit into the number - of bytes provided. - - @retval RETURN_UNSUPPORTED The array of OpenFirmware device nodes can't - be translated in the current implementation. - - @retval RETURN_PROTOCOL_ERROR The array of OpenFirmware device nodes has - been (partially) recognized, but it contains - a logic error / doesn't match system state. - -**/ -STATIC -RETURN_STATUS -TranslateOfwNodes ( - IN CONST OFW_NODE *OfwNode, - IN UINTN NumNodes, - IN CONST EXTRA_ROOT_BUS_MAP *ExtraPciRoots, - OUT CHAR16 *Translated, - IN OUT UINTN *TranslatedSize - ) -{ - RETURN_STATUS Status; - - Status = RETURN_UNSUPPORTED; - - if (FeaturePcdGet (PcdQemuBootOrderPciTranslation)) { - Status = TranslatePciOfwNodes (OfwNode, NumNodes, ExtraPciRoots, - Translated, TranslatedSize); - } - if (Status == RETURN_UNSUPPORTED && - FeaturePcdGet (PcdQemuBootOrderMmioTranslation)) { - Status = TranslateMmioOfwNodes (OfwNode, NumNodes, Translated, - TranslatedSize); - } - return Status; -} - -/** - - Translate an OpenFirmware device path fragment to a UEFI device path - fragment, and advance in the input string. - - @param[in out] Ptr Address of the pointer pointing to the start - of the path string. After successful - translation (RETURN_SUCCESS) or at least - successful parsing (RETURN_UNSUPPORTED, - RETURN_BUFFER_TOO_SMALL), *Ptr is set to the - byte immediately following the consumed - characters. In other error cases, it points to - the byte that caused the error. - - @param[in] ExtraPciRoots An EXTRA_ROOT_BUS_MAP object created with - CreateExtraRootBusMap(), to be used for - translating positions of extra root buses to - bus numbers. - - @param[out] Translated Destination array receiving the UEFI path - fragment, allocated by the caller. If the - return value differs from RETURN_SUCCESS, its - contents is indeterminate. - - @param[in out] TranslatedSize On input, the number of CHAR16's in - Translated. On RETURN_SUCCESS this parameter - is assigned the number of non-NUL CHAR16's - written to Translated. In case of other return - values, TranslatedSize is indeterminate. - - - @retval RETURN_SUCCESS Translation successful. - - @retval RETURN_BUFFER_TOO_SMALL The OpenFirmware device path was parsed - successfully, but its translation did not - fit into the number of bytes provided. - Further calls to this function are - possible. - - @retval RETURN_UNSUPPORTED The OpenFirmware device path was parsed - successfully, but it can't be translated in - the current implementation. Further calls - to this function are possible. - - @retval RETURN_PROTOCOL_ERROR The OpenFirmware device path has been - (partially) recognized, but it contains a - logic error / doesn't match system state. - Further calls to this function are - possible. - - @retval RETURN_NOT_FOUND Translation terminated. On input, *Ptr was - pointing to the empty string or "HALT". On - output, *Ptr points to the empty string - (ie. "HALT" is consumed transparently when - present). - - @retval RETURN_INVALID_PARAMETER Parse error. This is a permanent error. - -**/ -STATIC -RETURN_STATUS -TranslateOfwPath ( - IN OUT CONST CHAR8 **Ptr, - IN CONST EXTRA_ROOT_BUS_MAP *ExtraPciRoots, - OUT CHAR16 *Translated, - IN OUT UINTN *TranslatedSize - ) -{ - UINTN NumNodes; - RETURN_STATUS Status; - OFW_NODE Node[EXAMINED_OFW_NODES]; - BOOLEAN IsFinal; - OFW_NODE Skip; - - IsFinal = FALSE; - NumNodes = 0; - if (AsciiStrCmp (*Ptr, "HALT") == 0) { - *Ptr += 4; - Status = RETURN_NOT_FOUND; - } else { - Status = ParseOfwNode (Ptr, &Node[NumNodes], &IsFinal); - } - - if (Status == RETURN_NOT_FOUND) { - DEBUG ((DEBUG_VERBOSE, "%a: no more nodes\n", __FUNCTION__)); - return RETURN_NOT_FOUND; - } - - while (Status == RETURN_SUCCESS && !IsFinal) { - ++NumNodes; - Status = ParseOfwNode ( - Ptr, - (NumNodes < EXAMINED_OFW_NODES) ? &Node[NumNodes] : &Skip, - &IsFinal - ); - } - - switch (Status) { - case RETURN_SUCCESS: - ++NumNodes; - break; - - case RETURN_INVALID_PARAMETER: - DEBUG ((DEBUG_VERBOSE, "%a: parse error\n", __FUNCTION__)); - return RETURN_INVALID_PARAMETER; - - default: - ASSERT (0); - } - - Status = TranslateOfwNodes ( - Node, - NumNodes < EXAMINED_OFW_NODES ? NumNodes : EXAMINED_OFW_NODES, - ExtraPciRoots, - Translated, - TranslatedSize); - switch (Status) { - case RETURN_SUCCESS: - DEBUG ((DEBUG_VERBOSE, "%a: success: \"%s\"\n", __FUNCTION__, Translated)); - break; - - case RETURN_BUFFER_TOO_SMALL: - DEBUG ((DEBUG_VERBOSE, "%a: buffer too small\n", __FUNCTION__)); - break; - - case RETURN_UNSUPPORTED: - DEBUG ((DEBUG_VERBOSE, "%a: unsupported\n", __FUNCTION__)); - break; - - case RETURN_PROTOCOL_ERROR: - DEBUG ((DEBUG_VERBOSE, "%a: logic error / system state mismatch\n", - __FUNCTION__)); - break; - - default: - ASSERT (0); - } - return Status; -} - - -/** - - Convert the UEFI DevicePath to full text representation with DevPathToText, - then match the UEFI device path fragment in Translated against it. - - @param[in] Translated UEFI device path fragment, translated from - OpenFirmware format, to search for. - - @param[in] TranslatedLength The length of Translated in CHAR16's. - - @param[in] DevicePath Boot option device path whose textual rendering - to search in. - - @param[in] DevPathToText Binary-to-text conversion protocol for DevicePath. - - - @retval TRUE If Translated was found at the beginning of DevicePath after - converting the latter to text. - - @retval FALSE If DevicePath was NULL, or it could not be converted, or there - was no match. - -**/ -STATIC -BOOLEAN -Match ( - IN CONST CHAR16 *Translated, - IN UINTN TranslatedLength, - IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath - ) -{ - CHAR16 *Converted; - BOOLEAN Result; - - Converted = ConvertDevicePathToText ( - DevicePath, - FALSE, // DisplayOnly - FALSE // AllowShortcuts - ); - if (Converted == NULL) { - return FALSE; - } - - // - // Attempt to expand any relative UEFI device path starting with HD() to an - // absolute device path first. The logic imitates BdsLibBootViaBootOption(). - // We don't have to free the absolute device path, - // BdsExpandPartitionPartialDevicePathToFull() has internal caching. - // - Result = FALSE; - if (DevicePathType (DevicePath) == MEDIA_DEVICE_PATH && - DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP) { - EFI_DEVICE_PATH_PROTOCOL *AbsDevicePath; - CHAR16 *AbsConverted; - - AbsDevicePath = BdsExpandPartitionPartialDevicePathToFull ( - (HARDDRIVE_DEVICE_PATH *) DevicePath); - if (AbsDevicePath == NULL) { - goto Exit; - } - AbsConverted = ConvertDevicePathToText (AbsDevicePath, FALSE, FALSE); - if (AbsConverted == NULL) { - goto Exit; - } - DEBUG ((DEBUG_VERBOSE, - "%a: expanded relative device path \"%s\" for prefix matching\n", - __FUNCTION__, Converted)); - FreePool (Converted); - Converted = AbsConverted; - } - - // - // Is Translated a prefix of Converted? - // - Result = (BOOLEAN)(StrnCmp (Converted, Translated, TranslatedLength) == 0); - DEBUG (( - DEBUG_VERBOSE, - "%a: against \"%s\": %a\n", - __FUNCTION__, - Converted, - Result ? "match" : "no match" - )); -Exit: - FreePool (Converted); - return Result; -} - - -/** - Append some of the unselected active boot options to the boot order. - - This function should accommodate any further policy changes in "boot option - survival". Currently we're adding back everything that starts with neither - PciRoot() nor HD() nor a virtio-mmio VenHw() node. - - @param[in,out] BootOrder The structure holding the boot order to - complete. The caller is responsible for - initializing (and potentially populating) it - before calling this function. - - @param[in,out] ActiveOption The array of active boot options to scan. - Entries marked as Appended will be skipped. - Those of the rest that satisfy the survival - policy will be added to BootOrder with - BootOrderAppend(). - - @param[in] ActiveCount Number of elements in ActiveOption. - - - @retval RETURN_SUCCESS BootOrder has been extended with any eligible boot - options. - - @return Error codes returned by BootOrderAppend(). -**/ -STATIC -RETURN_STATUS -BootOrderComplete ( - IN OUT BOOT_ORDER *BootOrder, - IN OUT ACTIVE_OPTION *ActiveOption, - IN UINTN ActiveCount - ) -{ - RETURN_STATUS Status; - UINTN Idx; - - Status = RETURN_SUCCESS; - Idx = 0; - while (!RETURN_ERROR (Status) && Idx < ActiveCount) { - if (!ActiveOption[Idx].Appended) { - CONST BDS_COMMON_OPTION *Current; - CONST EFI_DEVICE_PATH_PROTOCOL *FirstNode; - - Current = ActiveOption[Idx].BootOption; - FirstNode = Current->DevicePath; - if (FirstNode != NULL) { - CHAR16 *Converted; - STATIC CHAR16 ConvFallBack[] = L""; - BOOLEAN Keep; - - Converted = ConvertDevicePathToText (FirstNode, FALSE, FALSE); - if (Converted == NULL) { - Converted = ConvFallBack; - } - - Keep = TRUE; - if (DevicePathType(FirstNode) == MEDIA_DEVICE_PATH && - DevicePathSubType(FirstNode) == MEDIA_HARDDRIVE_DP) { - // - // drop HD() - // - Keep = FALSE; - } else if (DevicePathType(FirstNode) == ACPI_DEVICE_PATH && - DevicePathSubType(FirstNode) == ACPI_DP) { - ACPI_HID_DEVICE_PATH *Acpi; - - Acpi = (ACPI_HID_DEVICE_PATH *) FirstNode; - if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST && - EISA_ID_TO_NUM (Acpi->HID) == 0x0a03) { - // - // drop PciRoot() if we enabled the user to select PCI-like boot - // options, by providing translation for such OFW device path - // fragments - // - Keep = !FeaturePcdGet (PcdQemuBootOrderPciTranslation); - } - } else if (DevicePathType(FirstNode) == HARDWARE_DEVICE_PATH && - DevicePathSubType(FirstNode) == HW_VENDOR_DP) { - VENDOR_DEVICE_PATH *VenHw; - - VenHw = (VENDOR_DEVICE_PATH *)FirstNode; - if (CompareGuid (&VenHw->Guid, &gVirtioMmioTransportGuid)) { - // - // drop virtio-mmio if we enabled the user to select boot options - // referencing such device paths - // - Keep = !FeaturePcdGet (PcdQemuBootOrderMmioTranslation); - } - } - - if (Keep) { - Status = BootOrderAppend (BootOrder, &ActiveOption[Idx]); - if (!RETURN_ERROR (Status)) { - DEBUG ((DEBUG_VERBOSE, "%a: keeping \"%s\"\n", __FUNCTION__, - Converted)); - } - } else { - DEBUG ((DEBUG_VERBOSE, "%a: dropping \"%s\"\n", __FUNCTION__, - Converted)); - } - - if (Converted != ConvFallBack) { - FreePool (Converted); - } - } - } - ++Idx; - } - return Status; -} - - -/** - Delete Boot#### variables that stand for such active boot options that have - been dropped (ie. have not been selected by either matching or "survival - policy"). - - @param[in] ActiveOption The array of active boot options to scan. Each - entry not marked as appended will trigger the - deletion of the matching Boot#### variable. - - @param[in] ActiveCount Number of elements in ActiveOption. -**/ -STATIC -VOID -PruneBootVariables ( - IN CONST ACTIVE_OPTION *ActiveOption, - IN UINTN ActiveCount - ) -{ - UINTN Idx; - - for (Idx = 0; Idx < ActiveCount; ++Idx) { - if (!ActiveOption[Idx].Appended) { - CHAR16 VariableName[9]; - - UnicodeSPrintAsciiFormat (VariableName, sizeof VariableName, "Boot%04x", - ActiveOption[Idx].BootOption->BootCurrent); - - // - // "The space consumed by the deleted variable may not be available until - // the next power cycle", but that's good enough. - // - gRT->SetVariable (VariableName, &gEfiGlobalVariableGuid, - 0, // Attributes, 0 means deletion - 0, // DataSize, 0 means deletion - NULL // Data - ); - } - } -} - - -/** - - Set the boot order based on configuration retrieved from QEMU. - - Attempt to retrieve the "bootorder" fw_cfg file from QEMU. Translate the - OpenFirmware device paths therein to UEFI device path fragments. Match the - translated fragments against BootOptionList, and rewrite the BootOrder NvVar - so that it corresponds to the order described in fw_cfg. - - @param[in] BootOptionList A boot option list, created with - BdsLibEnumerateAllBootOption (). - - - @retval RETURN_SUCCESS BootOrder NvVar rewritten. - - @retval RETURN_UNSUPPORTED QEMU's fw_cfg is not supported. - - @retval RETURN_NOT_FOUND Empty or nonexistent "bootorder" fw_cfg - file, or no match found between the - "bootorder" fw_cfg file and BootOptionList. - - @retval RETURN_INVALID_PARAMETER Parse error in the "bootorder" fw_cfg file. - - @retval RETURN_OUT_OF_RESOURCES Memory allocation failed. - - @return Values returned by gBS->LocateProtocol () - or gRT->SetVariable (). - -**/ -RETURN_STATUS -SetBootOrderFromQemu ( - IN CONST LIST_ENTRY *BootOptionList - ) -{ - RETURN_STATUS Status; - FIRMWARE_CONFIG_ITEM FwCfgItem; - UINTN FwCfgSize; - CHAR8 *FwCfg; - CONST CHAR8 *FwCfgPtr; - - BOOT_ORDER BootOrder; - ACTIVE_OPTION *ActiveOption; - UINTN ActiveCount; - - EXTRA_ROOT_BUS_MAP *ExtraPciRoots; - - UINTN TranslatedSize; - CHAR16 Translated[TRANSLATION_OUTPUT_SIZE]; - - Status = QemuFwCfgFindFile ("bootorder", &FwCfgItem, &FwCfgSize); - if (Status != RETURN_SUCCESS) { - return Status; - } - - if (FwCfgSize == 0) { - return RETURN_NOT_FOUND; - } - - FwCfg = AllocatePool (FwCfgSize); - if (FwCfg == NULL) { - return RETURN_OUT_OF_RESOURCES; - } - - QemuFwCfgSelectItem (FwCfgItem); - QemuFwCfgReadBytes (FwCfgSize, FwCfg); - if (FwCfg[FwCfgSize - 1] != '\0') { - Status = RETURN_INVALID_PARAMETER; - goto ErrorFreeFwCfg; - } - - DEBUG ((DEBUG_VERBOSE, "%a: FwCfg:\n", __FUNCTION__)); - DEBUG ((DEBUG_VERBOSE, "%a\n", FwCfg)); - DEBUG ((DEBUG_VERBOSE, "%a: FwCfg: \n", __FUNCTION__)); - FwCfgPtr = FwCfg; - - BootOrder.Produced = 0; - BootOrder.Allocated = 1; - BootOrder.Data = AllocatePool ( - BootOrder.Allocated * sizeof (*BootOrder.Data) - ); - if (BootOrder.Data == NULL) { - Status = RETURN_OUT_OF_RESOURCES; - goto ErrorFreeFwCfg; - } - - Status = CollectActiveOptions (BootOptionList, &ActiveOption, &ActiveCount); - if (RETURN_ERROR (Status)) { - goto ErrorFreeBootOrder; - } - - if (FeaturePcdGet (PcdQemuBootOrderPciTranslation)) { - Status = CreateExtraRootBusMap (&ExtraPciRoots); - if (EFI_ERROR (Status)) { - goto ErrorFreeActiveOption; - } - } else { - ExtraPciRoots = NULL; - } - - // - // translate each OpenFirmware path - // - TranslatedSize = sizeof (Translated) / sizeof (Translated[0]); - Status = TranslateOfwPath (&FwCfgPtr, ExtraPciRoots, Translated, - &TranslatedSize); - while (Status == RETURN_SUCCESS || - Status == RETURN_UNSUPPORTED || - Status == RETURN_PROTOCOL_ERROR || - Status == RETURN_BUFFER_TOO_SMALL) { - if (Status == RETURN_SUCCESS) { - UINTN Idx; - - // - // match translated OpenFirmware path against all active boot options - // - for (Idx = 0; Idx < ActiveCount; ++Idx) { - if (Match ( - Translated, - TranslatedSize, // contains length, not size, in CHAR16's here - ActiveOption[Idx].BootOption->DevicePath - ) - ) { - // - // match found, store ID and continue with next OpenFirmware path - // - Status = BootOrderAppend (&BootOrder, &ActiveOption[Idx]); - if (Status != RETURN_SUCCESS) { - goto ErrorFreeExtraPciRoots; - } - break; - } - } // scanned all active boot options - } // translation successful - - TranslatedSize = sizeof (Translated) / sizeof (Translated[0]); - Status = TranslateOfwPath (&FwCfgPtr, ExtraPciRoots, Translated, - &TranslatedSize); - } // scanning of OpenFirmware paths done - - if (Status == RETURN_NOT_FOUND && BootOrder.Produced > 0) { - // - // No more OpenFirmware paths, some matches found: rewrite BootOrder NvVar. - // Some of the active boot options that have not been selected over fw_cfg - // should be preserved at the end of the boot order. - // - Status = BootOrderComplete (&BootOrder, ActiveOption, ActiveCount); - if (RETURN_ERROR (Status)) { - goto ErrorFreeExtraPciRoots; - } - - // - // See Table 10 in the UEFI Spec 2.3.1 with Errata C for the required - // attributes. - // - Status = gRT->SetVariable ( - L"BootOrder", - &gEfiGlobalVariableGuid, - EFI_VARIABLE_NON_VOLATILE | - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, - BootOrder.Produced * sizeof (*BootOrder.Data), - BootOrder.Data - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: setting BootOrder: %r\n", __FUNCTION__, Status)); - goto ErrorFreeExtraPciRoots; - } - - DEBUG ((DEBUG_INFO, "%a: setting BootOrder: success\n", __FUNCTION__)); - PruneBootVariables (ActiveOption, ActiveCount); - } - -ErrorFreeExtraPciRoots: - if (ExtraPciRoots != NULL) { - DestroyExtraRootBusMap (ExtraPciRoots); - } - -ErrorFreeActiveOption: - FreePool (ActiveOption); - -ErrorFreeBootOrder: - FreePool (BootOrder.Data); - -ErrorFreeFwCfg: - FreePool (FwCfg); - - return Status; -} - - -/** - Calculate the number of seconds we should be showing the FrontPage progress - bar for. - - @return The TimeoutDefault argument for PlatformBdsEnterFrontPage(). -**/ -UINT16 -GetFrontPageTimeoutFromQemu ( - VOID - ) -{ - FIRMWARE_CONFIG_ITEM BootMenuWaitItem; - UINTN BootMenuWaitSize; - - QemuFwCfgSelectItem (QemuFwCfgItemBootMenu); - if (QemuFwCfgRead16 () == 0) { - // - // The user specified "-boot menu=off", or didn't specify "-boot - // menu=(on|off)" at all. Return the platform default. - // - return PcdGet16 (PcdPlatformBootTimeOut); - } - - if (RETURN_ERROR (QemuFwCfgFindFile ("etc/boot-menu-wait", &BootMenuWaitItem, - &BootMenuWaitSize)) || - BootMenuWaitSize != sizeof (UINT16)) { - // - // "-boot menu=on" was specified without "splash-time=N". In this case, - // return three seconds if the platform default would cause us to skip the - // front page, and return the platform default otherwise. - // - UINT16 Timeout; - - Timeout = PcdGet16 (PcdPlatformBootTimeOut); - if (Timeout == 0) { - Timeout = 3; - } - return Timeout; - } - - // - // "-boot menu=on,splash-time=N" was specified, where N is in units of - // milliseconds. The Intel BDS Front Page progress bar only supports whole - // seconds, round N up. - // - QemuFwCfgSelectItem (BootMenuWaitItem); - return (UINT16)((QemuFwCfgRead16 () + 999) / 1000); -} diff --git a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf deleted file mode 100644 index 102432848b..0000000000 --- a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf +++ /dev/null @@ -1,68 +0,0 @@ -## @file -# Rewrite the BootOrder NvVar based on QEMU's "bootorder" fw_cfg file. -# -# Copyright (C) 2012 - 2014, Red Hat, Inc. -# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials are licensed and made available -# under the terms and conditions of the BSD License which accompanies this -# distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR -# IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = QemuBootOrderLib - FILE_GUID = 4FFFA9E1-103D-4CF2-9C06-563BDD03050E - MODULE_TYPE = DXE_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = QemuBootOrderLib|DXE_DRIVER - -# -# The following information is for reference only and not required by the build -# tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC ARM AARCH64 -# - -[Sources] - QemuBootOrderLib.c - ExtraRootBusMap.c - -[Packages] - MdePkg/MdePkg.dec - IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - QemuFwCfgLib - DebugLib - MemoryAllocationLib - GenericBdsLib - UefiBootServicesTableLib - UefiRuntimeServicesTableLib - BaseLib - PrintLib - DevicePathLib - BaseMemoryLib - OrderedCollectionLib - -[Guids] - gEfiGlobalVariableGuid - gVirtioMmioTransportGuid - -[FeaturePcd] - gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation - gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation - -[Pcd] - gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut - -[Protocols] - gEfiDevicePathProtocolGuid ## CONSUMES - gEfiPciRootBridgeIoProtocolGuid ## CONSUMES diff --git a/OvmfPkg/Library/QemuFwCfgLib/Ia32/IoLibExAsm.nasm b/OvmfPkg/Library/QemuFwCfgLib/Ia32/IoLibExAsm.nasm deleted file mode 100644 index faa22e97d4..0000000000 --- a/OvmfPkg/Library/QemuFwCfgLib/Ia32/IoLibExAsm.nasm +++ /dev/null @@ -1,55 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
-; This program and the accompanying materials -; are licensed and made available under the terms and conditions of the BSD License -; which accompanies this distribution. The full text of the license may be found at -; http://opensource.org/licenses/bsd-license.php. -; -; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -; -;------------------------------------------------------------------------------ - - SECTION .text - -;------------------------------------------------------------------------------ -; VOID -; EFIAPI -; IoReadFifo8 ( -; IN UINTN Port, -; IN UINTN Size, -; IN VOID *Buffer -; ); -;------------------------------------------------------------------------------ -global ASM_PFX(IoReadFifo8) -ASM_PFX(IoReadFifo8): - - mov dx, [esp + 4] - mov ecx, [esp + 8] - push edi - mov edi, [esp + 16] -rep insb - pop edi - ret - -;------------------------------------------------------------------------------ -; VOID -; EFIAPI -; IoWriteFifo8 ( -; IN UINTN Port, -; IN UINTN Size, -; IN VOID *Buffer -; ); -;------------------------------------------------------------------------------ -global ASM_PFX(IoWriteFifo8) -ASM_PFX(IoWriteFifo8): - - mov dx, [esp + 4] - mov ecx, [esp + 8] - push esi - mov esi, [esp + 16] -rep outsb - pop esi - ret - diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c deleted file mode 100644 index 5c96d2af25..0000000000 --- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c +++ /dev/null @@ -1,325 +0,0 @@ -/** @file - - Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.
- Copyright (C) 2013, Red Hat, Inc. - - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "Uefi.h" -#include -#include -#include -#include -#include -#include -#include - - -/** - Reads an 8-bit I/O port fifo into a block of memory. - - Reads the 8-bit I/O fifo port specified by Port. - - The port is read Count times, and the read data is - stored in the provided Buffer. - - This function must guarantee that all I/O read and write operations are - serialized. - - If 8-bit I/O port operations are not supported, then ASSERT(). - - @param Port The I/O port to read. - @param Count The number of times to read I/O port. - @param Buffer The buffer to store the read data into. - -**/ -VOID -EFIAPI -IoReadFifo8 ( - IN UINTN Port, - IN UINTN Count, - OUT VOID *Buffer - ); - -/** - Writes an 8-bit I/O port fifo from a block of memory. - - Writes the 8-bit I/O fifo port specified by Port. - - The port is written Count times, and the data are obtained - from the provided Buffer. - - This function must guarantee that all I/O read and write operations are - serialized. - - If 8-bit I/O port operations are not supported, then ASSERT(). - - @param Port The I/O port to read. - @param Count The number of times to read I/O port. - @param Buffer The buffer to store the read data into. - -**/ -VOID -EFIAPI -IoWriteFifo8 ( - IN UINTN Port, - IN UINTN Count, - OUT VOID *Buffer - ); - - -/** - Selects a firmware configuration item for reading. - - Following this call, any data read from this item will start from - the beginning of the configuration item's data. - - @param[in] QemuFwCfgItem - Firmware Configuration item to read - -**/ -VOID -EFIAPI -QemuFwCfgSelectItem ( - IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem - ) -{ - DEBUG ((EFI_D_INFO, "Select Item: 0x%x\n", (UINT16)(UINTN) QemuFwCfgItem)); - IoWrite16 (0x510, (UINT16)(UINTN) QemuFwCfgItem); -} - - -/** - Reads firmware configuration bytes into a buffer - - @param[in] Size - Size in bytes to read - @param[in] Buffer - Buffer to store data into (OPTIONAL if Size is 0) - -**/ -VOID -EFIAPI -InternalQemuFwCfgReadBytes ( - IN UINTN Size, - IN VOID *Buffer OPTIONAL - ) -{ - IoReadFifo8 (0x511, Size, Buffer); -} - - -/** - Reads firmware configuration bytes into a buffer - - If called multiple times, then the data read will - continue at the offset of the firmware configuration - item where the previous read ended. - - @param[in] Size - Size in bytes to read - @param[in] Buffer - Buffer to store data into - -**/ -VOID -EFIAPI -QemuFwCfgReadBytes ( - IN UINTN Size, - IN VOID *Buffer - ) -{ - if (InternalQemuFwCfgIsAvailable ()) { - InternalQemuFwCfgReadBytes (Size, Buffer); - } else { - ZeroMem (Buffer, Size); - } -} - -/** - Write firmware configuration bytes from a buffer - - If called multiple times, then the data written will - continue at the offset of the firmware configuration - item where the previous write ended. - - @param[in] Size - Size in bytes to write - @param[in] Buffer - Buffer to read data from - -**/ -VOID -EFIAPI -QemuFwCfgWriteBytes ( - IN UINTN Size, - IN VOID *Buffer - ) -{ - if (InternalQemuFwCfgIsAvailable ()) { - IoWriteFifo8 (0x511, Size, Buffer); - } -} - - -/** - Reads a UINT8 firmware configuration value - - @return Value of Firmware Configuration item read - -**/ -UINT8 -EFIAPI -QemuFwCfgRead8 ( - VOID - ) -{ - UINT8 Result; - - QemuFwCfgReadBytes (sizeof (Result), &Result); - - return Result; -} - - -/** - Reads a UINT16 firmware configuration value - - @return Value of Firmware Configuration item read - -**/ -UINT16 -EFIAPI -QemuFwCfgRead16 ( - VOID - ) -{ - UINT16 Result; - - QemuFwCfgReadBytes (sizeof (Result), &Result); - - return Result; -} - - -/** - Reads a UINT32 firmware configuration value - - @return Value of Firmware Configuration item read - -**/ -UINT32 -EFIAPI -QemuFwCfgRead32 ( - VOID - ) -{ - UINT32 Result; - - QemuFwCfgReadBytes (sizeof (Result), &Result); - - return Result; -} - - -/** - Reads a UINT64 firmware configuration value - - @return Value of Firmware Configuration item read - -**/ -UINT64 -EFIAPI -QemuFwCfgRead64 ( - VOID - ) -{ - UINT64 Result; - - QemuFwCfgReadBytes (sizeof (Result), &Result); - - return Result; -} - - -/** - Find the configuration item corresponding to the firmware configuration file. - - @param[in] Name - Name of file to look up. - @param[out] Item - Configuration item corresponding to the file, to be passed - to QemuFwCfgSelectItem (). - @param[out] Size - Number of bytes in the file. - - @return RETURN_SUCCESS If file is found. - RETURN_NOT_FOUND If file is not found. - RETURN_UNSUPPORTED If firmware configuration is unavailable. - -**/ -RETURN_STATUS -EFIAPI -QemuFwCfgFindFile ( - IN CONST CHAR8 *Name, - OUT FIRMWARE_CONFIG_ITEM *Item, - OUT UINTN *Size - ) -{ - UINT32 Count; - UINT32 Idx; - - if (!InternalQemuFwCfgIsAvailable ()) { - return RETURN_UNSUPPORTED; - } - - QemuFwCfgSelectItem (QemuFwCfgItemFileDir); - Count = SwapBytes32 (QemuFwCfgRead32 ()); - - for (Idx = 0; Idx < Count; ++Idx) { - UINT32 FileSize; - UINT16 FileSelect; - UINT16 FileReserved; - CHAR8 FName[QEMU_FW_CFG_FNAME_SIZE]; - - FileSize = QemuFwCfgRead32 (); - FileSelect = QemuFwCfgRead16 (); - FileReserved = QemuFwCfgRead16 (); - (VOID) FileReserved; /* Force a do-nothing reference. */ - InternalQemuFwCfgReadBytes (sizeof (FName), FName); - - if (AsciiStrCmp (Name, FName) == 0) { - *Item = SwapBytes16 (FileSelect); - *Size = SwapBytes32 (FileSize); - return RETURN_SUCCESS; - } - } - - return RETURN_NOT_FOUND; -} - - -/** - Determine if S3 support is explicitly enabled. - - @retval TRUE if S3 support is explicitly enabled. - FALSE otherwise. This includes unavailability of the firmware - configuration interface. -**/ -BOOLEAN -EFIAPI -QemuFwCfgS3Enabled ( - VOID - ) -{ - RETURN_STATUS Status; - FIRMWARE_CONFIG_ITEM FwCfgItem; - UINTN FwCfgSize; - UINT8 SystemStates[6]; - - Status = QemuFwCfgFindFile ("etc/system-states", &FwCfgItem, &FwCfgSize); - if (Status != RETURN_SUCCESS || FwCfgSize != sizeof SystemStates) { - return FALSE; - } - QemuFwCfgSelectItem (FwCfgItem); - QemuFwCfgReadBytes (sizeof SystemStates, SystemStates); - return (BOOLEAN) (SystemStates[3] & BIT7); -} diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf deleted file mode 100644 index a95e1e730c..0000000000 --- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf +++ /dev/null @@ -1,54 +0,0 @@ -## @file -# -# Stateful, implicitly initialized fw_cfg library. -# -# Copyright (C) 2013, Red Hat, Inc. -# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = QemuFwCfgLib - FILE_GUID = fdd53716-31e1-4acc-9007-8bd5d877c96f - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = QemuFwCfgLib|PEIM DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER - - CONSTRUCTOR = QemuFwCfgInitialize - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 -# - -[Sources] - QemuFwCfgLib.c - QemuFwCfgPeiDxe.c - -[Sources.IA32] - Ia32/IoLibExAsm.nasm - -[Sources.X64] - X64/IoLibExAsm.nasm - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseLib - BaseMemoryLib - DebugLib - IoLib - MemoryAllocationLib - diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiDxe.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiDxe.c deleted file mode 100644 index f693cff29e..0000000000 --- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiDxe.c +++ /dev/null @@ -1,92 +0,0 @@ -/** @file - - Stateful and implicitly initialized fw_cfg library implementation. - - Copyright (C) 2013, Red Hat, Inc. - Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.
- - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License which accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#include -#include - -STATIC BOOLEAN mQemuFwCfgSupported = FALSE; - - -/** - Returns a boolean indicating if the firmware configuration interface - is available or not. - - This function may change fw_cfg state. - - @retval TRUE The interface is available - @retval FALSE The interface is not available - -**/ -BOOLEAN -EFIAPI -QemuFwCfgIsAvailable ( - VOID - ) -{ - return InternalQemuFwCfgIsAvailable (); -} - - -RETURN_STATUS -EFIAPI -QemuFwCfgInitialize ( - VOID - ) -{ - UINT32 Signature; - UINT32 Revision; - - // - // Enable the access routines while probing to see if it is supported. - // - mQemuFwCfgSupported = TRUE; - - QemuFwCfgSelectItem (QemuFwCfgItemSignature); - Signature = QemuFwCfgRead32 (); - DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature)); - QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion); - Revision = QemuFwCfgRead32 (); - DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision)); - if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) || - (Revision < 1) - ) { - DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n")); - mQemuFwCfgSupported = FALSE; - return RETURN_SUCCESS; - } - - DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n")); - return RETURN_SUCCESS; -} - - -/** - Returns a boolean indicating if the firmware configuration interface is - available for library-internal purposes. - - This function never changes fw_cfg state. - - @retval TRUE The interface is available internally. - @retval FALSE The interface is not available internally. -**/ -BOOLEAN -EFIAPI -InternalQemuFwCfgIsAvailable ( - VOID - ) -{ - return mQemuFwCfgSupported; -} diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c deleted file mode 100644 index 88c32ce89a..0000000000 --- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c +++ /dev/null @@ -1,81 +0,0 @@ -/** @file - - Stateless fw_cfg library implementation. - - Clients must call QemuFwCfgIsAvailable() first. - - Copyright (C) 2013, Red Hat, Inc. - Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.
- - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License which accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#include -#include - - -/** - Returns a boolean indicating if the firmware configuration interface - is available or not. - - This function may change fw_cfg state. - - @retval TRUE The interface is available - @retval FALSE The interface is not available - -**/ -BOOLEAN -EFIAPI -QemuFwCfgIsAvailable ( - VOID - ) -{ - UINT32 Signature; - UINT32 Revision; - - QemuFwCfgSelectItem (QemuFwCfgItemSignature); - Signature = QemuFwCfgRead32 (); - DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature)); - QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion); - Revision = QemuFwCfgRead32 (); - DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision)); - if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) || - (Revision < 1) - ) { - DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n")); - return FALSE; - } - - DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n")); - return TRUE; -} - - -/** - Returns a boolean indicating if the firmware configuration interface is - available for library-internal purposes. - - This function never changes fw_cfg state. - - @retval TRUE The interface is available internally. - @retval FALSE The interface is not available internally. -**/ -BOOLEAN -EFIAPI -InternalQemuFwCfgIsAvailable ( - VOID - ) -{ - // - // We always return TRUE, because the consumer of this library ought to have - // called QemuFwCfgIsAvailable before making other calls which would hit this - // path. - // - return TRUE; -} diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf deleted file mode 100644 index 03a659c9b0..0000000000 --- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf +++ /dev/null @@ -1,52 +0,0 @@ -## @file -# -# Stateless fw_cfg library that must be queried before use. -# -# Copyright (C) 2013, Red Hat, Inc. -# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = QemuFwCfgSecLib - FILE_GUID = 60a910e5-7443-413d-9a30-97e57497cd1b - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = QemuFwCfgLib|SEC - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 -# - -[Sources] - QemuFwCfgLib.c - QemuFwCfgSec.c - -[Sources.IA32] - Ia32/IoLibExAsm.nasm - -[Sources.X64] - X64/IoLibExAsm.nasm - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseLib - BaseMemoryLib - DebugLib - IoLib - MemoryAllocationLib - diff --git a/OvmfPkg/Library/QemuFwCfgLib/X64/IoLibExAsm.nasm b/OvmfPkg/Library/QemuFwCfgLib/X64/IoLibExAsm.nasm deleted file mode 100644 index f1078f2088..0000000000 --- a/OvmfPkg/Library/QemuFwCfgLib/X64/IoLibExAsm.nasm +++ /dev/null @@ -1,52 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
-; This program and the accompanying materials -; are licensed and made available under the terms and conditions of the BSD License -; which accompanies this distribution. The full text of the license may be found at -; http://opensource.org/licenses/bsd-license.php. -; -; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -; -;------------------------------------------------------------------------------ - - DEFAULT REL - SECTION .text - -;------------------------------------------------------------------------------ -; VOID -; EFIAPI -; IoReadFifo8 ( -; IN UINTN Port, // rcx -; IN UINTN Size, // rdx -; IN VOID *Buffer // r8 -; ); -;------------------------------------------------------------------------------ -global ASM_PFX(IoReadFifo8) -ASM_PFX(IoReadFifo8): - - xchg rcx, rdx - xchg rdi, r8 ; rdi: buffer address; r8: save rdi -rep insb - mov rdi, r8 ; restore rdi - ret - -;------------------------------------------------------------------------------ -; VOID -; EFIAPI -; IoWriteFifo8 ( -; IN UINTN Port, // rcx -; IN UINTN Size, // rdx -; IN VOID *Buffer // r8 -; ); -;------------------------------------------------------------------------------ -global ASM_PFX(IoWriteFifo8) -ASM_PFX(IoWriteFifo8): - - xchg rcx, rdx - xchg rsi, r8 ; rdi: buffer address; r8: save rdi -rep outsb - mov rsi, r8 ; restore rdi - ret - diff --git a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c b/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c deleted file mode 100644 index 6d149e84c2..0000000000 --- a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c +++ /dev/null @@ -1,108 +0,0 @@ -/** @file - Reset System Library functions for OVMF - - Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include - -#include -#include -#include -#include -#include - -VOID -AcpiPmControl ( - UINTN SuspendType - ) -{ - ASSERT (SuspendType < 6); - - IoBitFieldWrite16 (PcdGet16 (PcdAcpiPmBaseAddress) + 4, 10, 13, (UINT16) SuspendType); - IoOr16 (PcdGet16 (PcdAcpiPmBaseAddress) + 4, BIT13); - CpuDeadLoop (); -} - -/** - Calling this function causes a system-wide reset. This sets - all circuitry within the system to its initial state. This type of reset - is asynchronous to system operation and operates without regard to - cycle boundaries. - - System reset should not return, if it returns, it means the system does - not support cold reset. -**/ -VOID -EFIAPI -ResetCold ( - VOID - ) -{ - IoWrite8 (0xCF9, BIT2 | BIT1); // 1st choice: PIIX3 RCR, RCPU|SRST - MicroSecondDelay (50); - - IoWrite8 (0x64, 0xfe); // 2nd choice: keyboard controller - CpuDeadLoop (); -} - -/** - Calling this function causes a system-wide initialization. The processors - are set to their initial state, and pending cycles are not corrupted. - - System reset should not return, if it returns, it means the system does - not support warm reset. -**/ -VOID -EFIAPI -ResetWarm ( - VOID - ) -{ - IoWrite8 (0x64, 0xfe); - CpuDeadLoop (); -} - -/** - Calling this function causes the system to enter a power state equivalent - to the ACPI G2/S5 or G3 states. - - System shutdown should not return, if it returns, it means the system does - not support shut down reset. -**/ -VOID -EFIAPI -ResetShutdown ( - VOID - ) -{ - AcpiPmControl (0); - ASSERT (FALSE); -} - - -/** - Calling this function causes the system to enter a power state for capsule - update. - - Reset update should not return, if it returns, it means the system does - not support capsule update. - -**/ -VOID -EFIAPI -EnterS3WithImmediateWake ( - VOID - ) -{ - AcpiPmControl (1); - ASSERT (FALSE); -} diff --git a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf b/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf deleted file mode 100644 index b6a3ffe772..0000000000 --- a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf +++ /dev/null @@ -1,42 +0,0 @@ -## @file -# Library instance for ResetSystem library class for OVMF -# -# Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
-# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = ResetSystemLib - FILE_GUID = 66564872-21d4-4d2a-a68b-1e844f980820 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = ResetSystemLib - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF -# - -[Sources] - ResetSystemLib.c - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - DebugLib - IoLib - TimerLib - -[Pcd] - gUefiOvmfPkgTokenSpaceGuid.PcdAcpiPmBaseAddress \ No newline at end of file diff --git a/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.c b/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.c deleted file mode 100644 index 6822c5c725..0000000000 --- a/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.c +++ /dev/null @@ -1,870 +0,0 @@ -/** @file - Serialize Variables Library implementation - - Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "SerializeVariablesLib.h" - -/** - Serialization format: - - The SerializeVariablesLib interface does not specify a format - for the serialization of the variable data. This library uses - a packed array of a non-uniformly sized data structure elements. - - Each variable is stored (packed) as: - UINT32 VendorNameSize; // Name size in bytes - CHAR16 VendorName[?]; // The variable unicode name including the - // null terminating character. - EFI_GUID VendorGuid; // The variable GUID - UINT32 DataSize; // The size of variable data in bytes - UINT8 Data[?]; // The variable data - -**/ - - -/** - Unpacks the next variable from the buffer - - @param[in] Buffer - Buffer pointing to the next variable instance - On subsequent calls, the pointer should be incremented - by the returned SizeUsed value. - @param[in] MaxSize - Max allowable size for the variable data - On subsequent calls, this should be decremented - by the returned SizeUsed value. - @param[out] Name - Variable name string (address in Buffer) - @param[out] NameSize - Size of Name in bytes - @param[out] Guid - GUID of variable (address in Buffer) - @param[out] Attributes - Attributes of variable - @param[out] Data - Buffer containing Data for variable (address in Buffer) - @param[out] DataSize - Size of Data in bytes - @param[out] SizeUsed - Total size used for this variable instance in Buffer - - @return EFI_STATUS based on the success or failure of the operation - -**/ -STATIC -EFI_STATUS -UnpackVariableFromBuffer ( - IN VOID *Buffer, - IN UINTN MaxSize, - OUT CHAR16 **Name, - OUT UINT32 *NameSize, - OUT EFI_GUID **Guid, - OUT UINT32 *Attributes, - OUT UINT32 *DataSize, - OUT VOID **Data, - OUT UINTN *SizeUsed - ) -{ - UINT8 *BytePtr; - UINTN Offset; - - BytePtr = (UINT8*)Buffer; - Offset = 0; - - *NameSize = *(UINT32*) (BytePtr + Offset); - Offset = Offset + sizeof (UINT32); - - if (Offset > MaxSize) { - return EFI_INVALID_PARAMETER; - } - - *Name = (CHAR16*) (BytePtr + Offset); - Offset = Offset + *(UINT32*)BytePtr; - if (Offset > MaxSize) { - return EFI_INVALID_PARAMETER; - } - - *Guid = (EFI_GUID*) (BytePtr + Offset); - Offset = Offset + sizeof (EFI_GUID); - if (Offset > MaxSize) { - return EFI_INVALID_PARAMETER; - } - - *Attributes = *(UINT32*) (BytePtr + Offset); - Offset = Offset + sizeof (UINT32); - if (Offset > MaxSize) { - return EFI_INVALID_PARAMETER; - } - - *DataSize = *(UINT32*) (BytePtr + Offset); - Offset = Offset + sizeof (UINT32); - if (Offset > MaxSize) { - return EFI_INVALID_PARAMETER; - } - - *Data = (VOID*) (BytePtr + Offset); - Offset = Offset + *DataSize; - if (Offset > MaxSize) { - return EFI_INVALID_PARAMETER; - } - - *SizeUsed = Offset; - - return EFI_SUCCESS; -} - - -/** - Iterates through the variables in the buffer, and calls a callback - function for each variable found. - - @param[in] CallbackFunction - Function called for each variable instance - @param[in] Context - Passed to each call of CallbackFunction - @param[in] Buffer - Buffer containing serialized variables - @param[in] MaxSize - Size of Buffer in bytes - - @return EFI_STATUS based on the success or failure of the operation - -**/ -STATIC -EFI_STATUS -IterateVariablesInBuffer ( - IN VARIABLE_SERIALIZATION_ITERATION_CALLBACK CallbackFunction, - IN VOID *CallbackContext, - IN VOID *Buffer, - IN UINTN MaxSize - ) -{ - RETURN_STATUS Status; - UINTN TotalSizeUsed; - UINTN SizeUsed; - - CHAR16 *Name; - UINT32 NameSize; - CHAR16 *AlignedName; - UINT32 AlignedNameMaxSize; - EFI_GUID *Guid; - UINT32 Attributes; - UINT32 DataSize; - VOID *Data; - - SizeUsed = 0; - AlignedName = NULL; - AlignedNameMaxSize = 0; - Name = NULL; - Guid = NULL; - Attributes = 0; - DataSize = 0; - Data = NULL; - - for ( - Status = EFI_SUCCESS, TotalSizeUsed = 0; - !EFI_ERROR (Status) && (TotalSizeUsed < MaxSize); - ) { - Status = UnpackVariableFromBuffer ( - (VOID*) ((UINT8*) Buffer + TotalSizeUsed), - (MaxSize - TotalSizeUsed), - &Name, - &NameSize, - &Guid, - &Attributes, - &DataSize, - &Data, - &SizeUsed - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // We copy the name to a separately allocated buffer, - // to be sure it is 16-bit aligned. - // - if (NameSize > AlignedNameMaxSize) { - if (AlignedName != NULL) { - FreePool (AlignedName); - } - AlignedName = AllocatePool (NameSize); - } - if (AlignedName == NULL) { - return EFI_OUT_OF_RESOURCES; - } - CopyMem (AlignedName, Name, NameSize); - - TotalSizeUsed = TotalSizeUsed + SizeUsed; - - // - // Run the callback function - // - Status = (*CallbackFunction) ( - CallbackContext, - AlignedName, - Guid, - Attributes, - DataSize, - Data - ); - - } - - if (AlignedName != NULL) { - FreePool (AlignedName); - } - - // - // Make sure the entire buffer was used, or else return an error - // - if (TotalSizeUsed != MaxSize) { - DEBUG (( - EFI_D_ERROR, - "Deserialize variables error: TotalSizeUsed(%Lu) != MaxSize(%Lu)\n", - (UINT64)TotalSizeUsed, - (UINT64)MaxSize - )); - return EFI_INVALID_PARAMETER; - } - - return EFI_SUCCESS; -} - - -STATIC -RETURN_STATUS -EFIAPI -IterateVariablesCallbackNop ( - IN VOID *Context, - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - IN UINT32 Attributes, - IN UINTN DataSize, - IN VOID *Data - ) -{ - return RETURN_SUCCESS; -} - - -STATIC -RETURN_STATUS -EFIAPI -IterateVariablesCallbackSetInInstance ( - IN VOID *Context, - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - IN UINT32 Attributes, - IN UINTN DataSize, - IN VOID *Data - ) -{ - EFI_HANDLE Instance; - - Instance = (EFI_HANDLE) Context; - - return SerializeVariablesAddVariable ( - Instance, - VariableName, - VendorGuid, - Attributes, - DataSize, - Data - ); -} - - -STATIC -RETURN_STATUS -EFIAPI -IterateVariablesCallbackSetSystemVariable ( - IN VOID *Context, - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - IN UINT32 Attributes, - IN UINTN DataSize, - IN VOID *Data - ) -{ - EFI_STATUS Status; - STATIC CONST UINT32 AuthMask = - EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | - EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; - - Status = gRT->SetVariable ( - VariableName, - VendorGuid, - Attributes, - DataSize, - Data - ); - - if (Status == EFI_SECURITY_VIOLATION && (Attributes & AuthMask) != 0) { - DEBUG ((DEBUG_WARN, "%a: setting authenticated variable \"%s\" " - "failed with EFI_SECURITY_VIOLATION, ignoring\n", __FUNCTION__, - VariableName)); - Status = EFI_SUCCESS; - } - return Status; -} - - -STATIC -RETURN_STATUS -EnsureExtraBufferSpace ( - IN SV_INSTANCE *Instance, - IN UINTN Size - ) -{ - VOID *NewBuffer; - UINTN NewSize; - - NewSize = Instance->DataSize + Size; - if (NewSize <= Instance->BufferSize) { - return RETURN_SUCCESS; - } - - // - // Double the required size to lessen the need to re-allocate in the future - // - NewSize = 2 * NewSize; - - NewBuffer = AllocatePool (NewSize); - if (NewBuffer == NULL) { - return RETURN_OUT_OF_RESOURCES; - } - - if (Instance->BufferPtr != NULL) { - CopyMem (NewBuffer, Instance->BufferPtr, Instance->DataSize); - FreePool (Instance->BufferPtr); - } - - Instance->BufferPtr = NewBuffer; - Instance->BufferSize = NewSize; - - return RETURN_SUCCESS; -} - - -STATIC -VOID -AppendToBuffer ( - IN SV_INSTANCE *Instance, - IN VOID *Data, - IN UINTN Size - ) -{ - UINTN NewSize; - - ASSERT (Instance != NULL); - ASSERT (Data != NULL); - - NewSize = Instance->DataSize + Size; - ASSERT ((Instance->DataSize + Size) <= Instance->BufferSize); - - CopyMem ( - (VOID*) (((UINT8*) (Instance->BufferPtr)) + Instance->DataSize), - Data, - Size - ); - - Instance->DataSize = NewSize; -} - - -/** - Creates a new variable serialization instance - - @param[out] Handle - Handle for a variable serialization instance - - @retval RETURN_SUCCESS - The variable serialization instance was - successfully created. - @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to - create the variable serialization instance. - -**/ -RETURN_STATUS -EFIAPI -SerializeVariablesNewInstance ( - OUT EFI_HANDLE *Handle - ) -{ - SV_INSTANCE *New; - - New = AllocateZeroPool (sizeof (*New)); - if (New == NULL) { - return RETURN_OUT_OF_RESOURCES; - } - - New->Signature = SV_SIGNATURE; - - *Handle = (EFI_HANDLE) New; - return RETURN_SUCCESS; -} - - -/** - Free memory associated with a variable serialization instance - - @param[in] Handle - Handle for a variable serialization instance - - @retval RETURN_SUCCESS - The variable serialization instance was - successfully freed. - @retval RETURN_INVALID_PARAMETER - Handle was not a valid - variable serialization instance. - -**/ -RETURN_STATUS -EFIAPI -SerializeVariablesFreeInstance ( - IN EFI_HANDLE Handle - ) -{ - SV_INSTANCE *Instance; - - Instance = SV_FROM_HANDLE (Handle); - - if (Instance->Signature != SV_SIGNATURE) { - return RETURN_INVALID_PARAMETER; - } - - Instance->Signature = 0; - - if (Instance->BufferPtr != NULL) { - FreePool (Instance->BufferPtr); - } - - FreePool (Instance); - - return RETURN_SUCCESS; -} - - -/** - Creates a new variable serialization instance using the given - binary representation of the variables to fill the new instance - - @param[out] Handle - Handle for a variable serialization instance - @param[in] Buffer - A buffer with the serialized representation - of the variables. Must be the same format as produced - by SerializeVariablesToBuffer. - @param[in] Size - This is the size of the binary representation - of the variables. - - @retval RETURN_SUCCESS - The binary representation was successfully - imported into a new variable serialization instance - @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to - create the new variable serialization instance - -**/ -RETURN_STATUS -EFIAPI -SerializeVariablesNewInstanceFromBuffer ( - OUT EFI_HANDLE *Handle, - IN VOID *Buffer, - IN UINTN Size - ) -{ - RETURN_STATUS Status; - - Status = SerializeVariablesNewInstance (Handle); - if (RETURN_ERROR (Status)) { - return Status; - } - - Status = IterateVariablesInBuffer ( - IterateVariablesCallbackNop, - NULL, - Buffer, - Size - ); - if (RETURN_ERROR (Status)) { - SerializeVariablesFreeInstance (*Handle); - return Status; - } - - Status = IterateVariablesInBuffer ( - IterateVariablesCallbackSetInInstance, - (VOID*) *Handle, - Buffer, - Size - ); - if (RETURN_ERROR (Status)) { - SerializeVariablesFreeInstance (*Handle); - return Status; - } - - return Status; -} - - -/** - Iterates all variables found with RuntimeServices GetNextVariableName - - @param[in] CallbackFunction - Function called for each variable instance - @param[in] Context - Passed to each call of CallbackFunction - - @retval RETURN_SUCCESS - All variables were iterated without the - CallbackFunction returning an error - @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to - iterate through the variables - @return Any of RETURN_ERROR indicates an error reading the variable - or an error was returned from CallbackFunction - -**/ -RETURN_STATUS -EFIAPI -SerializeVariablesIterateSystemVariables ( - IN VARIABLE_SERIALIZATION_ITERATION_CALLBACK CallbackFunction, - IN VOID *Context - ) -{ - RETURN_STATUS Status; - UINTN VariableNameBufferSize; - UINTN VariableNameSize; - CHAR16 *VariableName; - EFI_GUID VendorGuid; - UINTN VariableDataBufferSize; - UINTN VariableDataSize; - VOID *VariableData; - UINT32 VariableAttributes; - VOID *NewBuffer; - - // - // Initialize the variable name and data buffer variables. - // - VariableNameBufferSize = sizeof (CHAR16); - VariableName = AllocateZeroPool (VariableNameBufferSize); - - VariableDataBufferSize = 0; - VariableData = NULL; - - for (;;) { - // - // Get the next variable name and guid - // - VariableNameSize = VariableNameBufferSize; - Status = gRT->GetNextVariableName ( - &VariableNameSize, - VariableName, - &VendorGuid - ); - if (Status == EFI_BUFFER_TOO_SMALL) { - // - // The currently allocated VariableName buffer is too small, - // so we allocate a larger buffer, and copy the old buffer - // to it. - // - NewBuffer = AllocatePool (VariableNameSize); - if (NewBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - break; - } - CopyMem (NewBuffer, VariableName, VariableNameBufferSize); - if (VariableName != NULL) { - FreePool (VariableName); - } - VariableName = NewBuffer; - VariableNameBufferSize = VariableNameSize; - - // - // Try to get the next variable name again with the larger buffer. - // - Status = gRT->GetNextVariableName ( - &VariableNameSize, - VariableName, - &VendorGuid - ); - } - - if (EFI_ERROR (Status)) { - if (Status == EFI_NOT_FOUND) { - Status = EFI_SUCCESS; - } - break; - } - - // - // Get the variable data and attributes - // - VariableDataSize = VariableDataBufferSize; - Status = gRT->GetVariable ( - VariableName, - &VendorGuid, - &VariableAttributes, - &VariableDataSize, - VariableData - ); - if (Status == EFI_BUFFER_TOO_SMALL) { - // - // The currently allocated VariableData buffer is too small, - // so we allocate a larger buffer. - // - if (VariableDataBufferSize != 0) { - FreePool (VariableData); - VariableData = NULL; - VariableDataBufferSize = 0; - } - VariableData = AllocatePool (VariableDataSize); - if (VariableData == NULL) { - Status = EFI_OUT_OF_RESOURCES; - break; - } - VariableDataBufferSize = VariableDataSize; - - // - // Try to read the variable again with the larger buffer. - // - Status = gRT->GetVariable ( - VariableName, - &VendorGuid, - &VariableAttributes, - &VariableDataSize, - VariableData - ); - } - if (EFI_ERROR (Status)) { - break; - } - - // - // Run the callback function - // - Status = (*CallbackFunction) ( - Context, - VariableName, - &VendorGuid, - VariableAttributes, - VariableDataSize, - VariableData - ); - if (EFI_ERROR (Status)) { - break; - } - - } - - if (VariableName != NULL) { - FreePool (VariableName); - } - - if (VariableData != NULL) { - FreePool (VariableData); - } - - return Status; -} - - -/** - Iterates all variables found in the variable serialization instance - - @param[in] Handle - Handle for a variable serialization instance - @param[in] CallbackFunction - Function called for each variable instance - @param[in] Context - Passed to each call of CallbackFunction - - @retval RETURN_SUCCESS - All variables were iterated without the - CallbackFunction returning an error - @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to - iterate through the variables - @return Any of RETURN_ERROR indicates an error reading the variable - or an error was returned from CallbackFunction - -**/ -RETURN_STATUS -EFIAPI -SerializeVariablesIterateInstanceVariables ( - IN EFI_HANDLE Handle, - IN VARIABLE_SERIALIZATION_ITERATION_CALLBACK CallbackFunction, - IN VOID *Context - ) -{ - SV_INSTANCE *Instance; - - Instance = SV_FROM_HANDLE (Handle); - - if ((Instance->BufferPtr != NULL) && (Instance->DataSize != 0)) { - return IterateVariablesInBuffer ( - CallbackFunction, - Context, - Instance->BufferPtr, - Instance->DataSize - ); - } else { - return RETURN_SUCCESS; - } -} - - -/** - Sets all variables found in the variable serialization instance - - @param[in] Handle - Handle for a variable serialization instance - - @retval RETURN_SUCCESS - All variables were set successfully - @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to - set all the variables - @return Any of RETURN_ERROR indicates an error reading the variables - or in attempting to set a variable - -**/ -RETURN_STATUS -EFIAPI -SerializeVariablesSetSerializedVariables ( - IN EFI_HANDLE Handle - ) -{ - return SerializeVariablesIterateInstanceVariables ( - Handle, - IterateVariablesCallbackSetSystemVariable, - NULL - ); -} - - -/** - Adds a variable to the variable serialization instance - - @param[in] Handle - Handle for a variable serialization instance - @param[in] VariableName - Refer to RuntimeServices GetVariable - @param[in] VendorGuid - Refer to RuntimeServices GetVariable - @param[in] Attributes - Refer to RuntimeServices GetVariable - @param[in] DataSize - Refer to RuntimeServices GetVariable - @param[in] Data - Refer to RuntimeServices GetVariable - - @retval RETURN_SUCCESS - All variables were set successfully - @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to - add the variable - @retval RETURN_INVALID_PARAMETER - Handle was not a valid - variable serialization instance or - VariableName, VariableGuid or Data are NULL. - -**/ -RETURN_STATUS -EFIAPI -SerializeVariablesAddVariable ( - IN EFI_HANDLE Handle, - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - IN UINT32 Attributes, - IN UINTN DataSize, - IN VOID *Data - ) -{ - RETURN_STATUS Status; - SV_INSTANCE *Instance; - UINT32 SerializedNameSize; - UINT32 SerializedDataSize; - UINTN SerializedSize; - - Instance = SV_FROM_HANDLE (Handle); - - if ((Instance->Signature != SV_SIGNATURE) || - (VariableName == NULL) || (VendorGuid == NULL) || (Data == NULL)) { - } - - SerializedNameSize = (UINT32) StrSize (VariableName); - - SerializedSize = - sizeof (SerializedNameSize) + - SerializedNameSize + - sizeof (*VendorGuid) + - sizeof (Attributes) + - sizeof (SerializedDataSize) + - DataSize; - - Status = EnsureExtraBufferSpace ( - Instance, - SerializedSize - ); - if (RETURN_ERROR (Status)) { - return Status; - } - - // - // Add name size (UINT32) - // - AppendToBuffer (Instance, (VOID*) &SerializedNameSize, sizeof (SerializedNameSize)); - - // - // Add variable unicode name string - // - AppendToBuffer (Instance, (VOID*) VariableName, SerializedNameSize); - - // - // Add variable GUID - // - AppendToBuffer (Instance, (VOID*) VendorGuid, sizeof (*VendorGuid)); - - // - // Add variable attributes - // - AppendToBuffer (Instance, (VOID*) &Attributes, sizeof (Attributes)); - - // - // Add variable data size (UINT32) - // - SerializedDataSize = (UINT32) DataSize; - AppendToBuffer (Instance, (VOID*) &SerializedDataSize, sizeof (SerializedDataSize)); - - // - // Add variable data - // - AppendToBuffer (Instance, Data, DataSize); - - return RETURN_SUCCESS; -} - - -/** - Serializes the variables known to this instance into the - provided buffer. - - @param[in] Handle - Handle for a variable serialization instance - @param[out] Buffer - A buffer to store the binary representation - of the variables. - @param[in,out] Size - On input this is the size of the buffer. - On output this is the size of the binary representation - of the variables. - - @retval RETURN_SUCCESS - The binary representation was successfully - completed and returned in the buffer. - @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to - save the variables to the buffer. - @retval RETURN_INVALID_PARAMETER - Handle was not a valid - variable serialization instance or - Size or Buffer were NULL. - @retval RETURN_BUFFER_TOO_SMALL - The Buffer size as indicated by - the Size parameter was too small for the serialized - variable data. Size is returned with the required size. - -**/ -RETURN_STATUS -EFIAPI -SerializeVariablesToBuffer ( - IN EFI_HANDLE Handle, - OUT VOID *Buffer, - IN OUT UINTN *Size - ) -{ - SV_INSTANCE *Instance; - - Instance = SV_FROM_HANDLE (Handle); - - if (Size == NULL) { - return RETURN_INVALID_PARAMETER; - } - - if (*Size < Instance->DataSize) { - *Size = Instance->DataSize; - return RETURN_BUFFER_TOO_SMALL; - } - - if (Buffer == NULL) { - return RETURN_INVALID_PARAMETER; - } - - *Size = Instance->DataSize; - CopyMem (Buffer, Instance->BufferPtr, Instance->DataSize); - - return RETURN_SUCCESS; -} - diff --git a/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.h b/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.h deleted file mode 100644 index 4d01fd6e7c..0000000000 --- a/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.h +++ /dev/null @@ -1,39 +0,0 @@ -/** @file - Serialize Variables Library implementation - - Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __SERIALIZE_VARIABLES_LIB_INSTANCE__ -#define __SERIALIZE_VARIABLES_LIB_INSTANCE__ - -#include - -#include -#include -#include -#include -#include -#include -#include - -#define SV_FROM_HANDLE(a) CR (a, SV_INSTANCE, Signature, SV_SIGNATURE) -#define SV_SIGNATURE SIGNATURE_32 ('S', 'V', 'A', 'R') - -typedef struct { - UINT32 Signature; - VOID *BufferPtr; - UINTN BufferSize; - UINTN DataSize; -} SV_INSTANCE; - -#endif - diff --git a/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf b/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf deleted file mode 100644 index b0c12b0ef6..0000000000 --- a/OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf +++ /dev/null @@ -1,41 +0,0 @@ -## @file -# Serialize Variables Library implementation -# -# This library serializes and deserializes UEFI variables -# -# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = DxeSerializeVariablesLib - FILE_GUID = 9515f92a-83ae-45fd-9d2e-e3dc15df52d0 - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = SerializeVariablesLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER UEFI_DRIVER - -[Sources] - SerializeVariablesLib.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - OvmfPkg/OvmfPkg.dec - ShellPkg/ShellPkg.dec - -[LibraryClasses] - BaseLib - BaseMemoryLib - DebugLib - MemoryAllocationLib - UefiBootServicesTableLib - UefiRuntimeServicesTableLib - diff --git a/OvmfPkg/Library/SmbiosVersionLib/DetectSmbiosVersionLib.c b/OvmfPkg/Library/SmbiosVersionLib/DetectSmbiosVersionLib.c deleted file mode 100644 index 950c3f7e0a..0000000000 --- a/OvmfPkg/Library/SmbiosVersionLib/DetectSmbiosVersionLib.c +++ /dev/null @@ -1,107 +0,0 @@ -/** @file - - A hook-in library for MdeModulePkg/Universal/SmbiosDxe, in order to set - gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion (and possibly other PCDs) - just before SmbiosDxe consumes them. - - Copyright (C) 2013, 2015, Red Hat, Inc. - Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
- - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License which accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include - -#include -#include -#include -#include -#include - -typedef union { - SMBIOS_TABLE_ENTRY_POINT V2; - SMBIOS_TABLE_3_0_ENTRY_POINT V3; -} QEMU_SMBIOS_ANCHOR; - -RETURN_STATUS -EFIAPI -DetectSmbiosVersion ( - VOID - ) -{ - FIRMWARE_CONFIG_ITEM Anchor, Tables; - UINTN AnchorSize, TablesSize; - QEMU_SMBIOS_ANCHOR QemuAnchor; - UINT16 SmbiosVersion; - - if (PcdGetBool (PcdQemuSmbiosValidated)) { - // - // Some other module, linked against this library, has already performed - // the task at hand. This should never happen, but it's easy to handle; - // just exit early. - // - return RETURN_SUCCESS; - } - - if (RETURN_ERROR (QemuFwCfgFindFile ( - "etc/smbios/smbios-anchor", &Anchor, &AnchorSize)) || - RETURN_ERROR (QemuFwCfgFindFile ( - "etc/smbios/smbios-tables", &Tables, &TablesSize)) || - TablesSize == 0) { - return RETURN_SUCCESS; - } - - QemuFwCfgSelectItem (Anchor); - - switch (AnchorSize) { - case sizeof QemuAnchor.V2: - QemuFwCfgReadBytes (AnchorSize, &QemuAnchor); - - if (QemuAnchor.V2.MajorVersion != 2 || - QemuAnchor.V2.TableLength != TablesSize || - CompareMem (QemuAnchor.V2.AnchorString, "_SM_", 4) != 0 || - CompareMem (QemuAnchor.V2.IntermediateAnchorString, "_DMI_", 5) != 0) { - return RETURN_SUCCESS; - } - SmbiosVersion = (UINT16)(QemuAnchor.V2.MajorVersion << 8 | - QemuAnchor.V2.MinorVersion); - break; - - case sizeof QemuAnchor.V3: - QemuFwCfgReadBytes (AnchorSize, &QemuAnchor); - - if (QemuAnchor.V3.MajorVersion != 3 || - QemuAnchor.V3.TableMaximumSize != TablesSize || - CompareMem (QemuAnchor.V3.AnchorString, "_SM3_", 5) != 0) { - return RETURN_SUCCESS; - } - SmbiosVersion = (UINT16)(QemuAnchor.V3.MajorVersion << 8 | - QemuAnchor.V3.MinorVersion); - - DEBUG ((EFI_D_INFO, "%a: SMBIOS 3.x DocRev from QEMU: 0x%02x\n", - __FUNCTION__, QemuAnchor.V3.DocRev)); - PcdSet8 (PcdSmbiosDocRev, QemuAnchor.V3.DocRev); - break; - - default: - return RETURN_SUCCESS; - } - - DEBUG ((EFI_D_INFO, "%a: SMBIOS version from QEMU: 0x%04x\n", __FUNCTION__, - SmbiosVersion)); - PcdSet16 (PcdSmbiosVersion, SmbiosVersion); - - // - // SMBIOS platform drivers can now fetch and install - // "etc/smbios/smbios-tables" from QEMU. - // - PcdSetBool (PcdQemuSmbiosValidated, TRUE); - return RETURN_SUCCESS; -} diff --git a/OvmfPkg/Library/SmbiosVersionLib/DetectSmbiosVersionLib.inf b/OvmfPkg/Library/SmbiosVersionLib/DetectSmbiosVersionLib.inf deleted file mode 100644 index 45d953a015..0000000000 --- a/OvmfPkg/Library/SmbiosVersionLib/DetectSmbiosVersionLib.inf +++ /dev/null @@ -1,53 +0,0 @@ -## @file -# -# A hook-in library for MdeModulePkg/Universal/SmbiosDxe, in order to set -# gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion (and possibly other PCDs) -# just before SmbiosDxe consumes them. -# -# Copyright (C) 2013, 2015, Red Hat, Inc. -# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials are licensed and made available -# under the terms and conditions of the BSD License which accompanies this -# distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT -# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = DetectSmbiosVersionLib - FILE_GUID = 6c633bb2-ae33-49ae-9f89-b5aa999fe3ae - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = SmbiosVersionLib|DXE_DRIVER - CONSTRUCTOR = DetectSmbiosVersion - -# -# The following information is for reference only and not required by the build -# tools. -# -# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64 -# - -[Sources] - DetectSmbiosVersionLib.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseMemoryLib - DebugLib - PcdLib - QemuFwCfgLib - -[Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion - gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev - gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.c b/OvmfPkg/Library/VirtioLib/VirtioLib.c deleted file mode 100644 index 54cf225c98..0000000000 --- a/OvmfPkg/Library/VirtioLib/VirtioLib.c +++ /dev/null @@ -1,319 +0,0 @@ -/** @file - - Utility functions used by virtio device drivers. - - Copyright (C) 2012, Red Hat, Inc. - Portion of Copyright (C) 2013, ARM Ltd. - - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License which accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include -#include -#include -#include -#include - -#include - - -/** - - Configure a virtio ring. - - This function sets up internal storage (the guest-host communication area) - and lays out several "navigation" (ie. no-ownership) pointers to parts of - that storage. - - Relevant sections from the virtio-0.9.5 spec: - - 1.1 Virtqueues, - - 2.3 Virtqueue Configuration. - - @param[in] The number of descriptors to allocate for the - virtio ring, as requested by the host. - - @param[out] Ring The virtio ring to set up. - - @retval EFI_OUT_OF_RESOURCES AllocatePages() failed to allocate contiguous - pages for the requested QueueSize. Fields of - Ring have indeterminate value. - - @retval EFI_SUCCESS Allocation and setup successful. Ring->Base - (and nothing else) is responsible for - deallocation. - -**/ -EFI_STATUS -EFIAPI -VirtioRingInit ( - IN UINT16 QueueSize, - OUT VRING *Ring - ) -{ - UINTN RingSize; - volatile UINT8 *RingPagesPtr; - - RingSize = ALIGN_VALUE ( - sizeof *Ring->Desc * QueueSize + - sizeof *Ring->Avail.Flags + - sizeof *Ring->Avail.Idx + - sizeof *Ring->Avail.Ring * QueueSize + - sizeof *Ring->Avail.UsedEvent, - EFI_PAGE_SIZE); - - RingSize += ALIGN_VALUE ( - sizeof *Ring->Used.Flags + - sizeof *Ring->Used.Idx + - sizeof *Ring->Used.UsedElem * QueueSize + - sizeof *Ring->Used.AvailEvent, - EFI_PAGE_SIZE); - - Ring->NumPages = EFI_SIZE_TO_PAGES (RingSize); - Ring->Base = AllocatePages (Ring->NumPages); - if (Ring->Base == NULL) { - return EFI_OUT_OF_RESOURCES; - } - SetMem (Ring->Base, RingSize, 0x00); - RingPagesPtr = Ring->Base; - - Ring->Desc = (volatile VOID *) RingPagesPtr; - RingPagesPtr += sizeof *Ring->Desc * QueueSize; - - Ring->Avail.Flags = (volatile VOID *) RingPagesPtr; - RingPagesPtr += sizeof *Ring->Avail.Flags; - - Ring->Avail.Idx = (volatile VOID *) RingPagesPtr; - RingPagesPtr += sizeof *Ring->Avail.Idx; - - Ring->Avail.Ring = (volatile VOID *) RingPagesPtr; - RingPagesPtr += sizeof *Ring->Avail.Ring * QueueSize; - - Ring->Avail.UsedEvent = (volatile VOID *) RingPagesPtr; - RingPagesPtr += sizeof *Ring->Avail.UsedEvent; - - RingPagesPtr = (volatile UINT8 *) Ring->Base + - ALIGN_VALUE (RingPagesPtr - (volatile UINT8 *) Ring->Base, - EFI_PAGE_SIZE); - - Ring->Used.Flags = (volatile VOID *) RingPagesPtr; - RingPagesPtr += sizeof *Ring->Used.Flags; - - Ring->Used.Idx = (volatile VOID *) RingPagesPtr; - RingPagesPtr += sizeof *Ring->Used.Idx; - - Ring->Used.UsedElem = (volatile VOID *) RingPagesPtr; - RingPagesPtr += sizeof *Ring->Used.UsedElem * QueueSize; - - Ring->Used.AvailEvent = (volatile VOID *) RingPagesPtr; - RingPagesPtr += sizeof *Ring->Used.AvailEvent; - - Ring->QueueSize = QueueSize; - return EFI_SUCCESS; -} - - -/** - - Tear down the internal resources of a configured virtio ring. - - The caller is responsible to stop the host from using this ring before - invoking this function: the VSTAT_DRIVER_OK bit must be clear in - VhdrDeviceStatus. - - @param[out] Ring The virtio ring to clean up. - -**/ -VOID -EFIAPI -VirtioRingUninit ( - IN OUT VRING *Ring - ) -{ - FreePages (Ring->Base, Ring->NumPages); - SetMem (Ring, sizeof *Ring, 0x00); -} - - -/** - - Turn off interrupt notifications from the host, and prepare for appending - multiple descriptors to the virtio ring. - - The calling driver must be in VSTAT_DRIVER_OK state. - - @param[in,out] Ring The virtio ring we intend to append descriptors to. - - @param[out] Indices The DESC_INDICES structure to initialize. - -**/ -VOID -EFIAPI -VirtioPrepare ( - IN OUT VRING *Ring, - OUT DESC_INDICES *Indices - ) -{ - // - // Prepare for virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device. - // We're going to poll the answer, the host should not send an interrupt. - // - *Ring->Avail.Flags = (UINT16) VRING_AVAIL_F_NO_INTERRUPT; - - // - // Prepare for virtio-0.9.5, 2.4.1 Supplying Buffers to the Device. - // - // Since we support only one in-flight descriptor chain, we can always build - // that chain starting at entry #0 of the descriptor table. - // - Indices->HeadDescIdx = 0; - Indices->NextDescIdx = Indices->HeadDescIdx; -} - - -/** - - Append a contiguous buffer for transmission / reception via the virtio ring. - - This function implements the following section from virtio-0.9.5: - - 2.4.1.1 Placing Buffers into the Descriptor Table - - Free space is taken as granted, since the individual drivers support only - synchronous requests and host side status is processed in lock-step with - request submission. It is the calling driver's responsibility to verify the - ring size in advance. - - The caller is responsible for initializing *Indices with VirtioPrepare() - first. - - @param[in,out] Ring The virtio ring to append the buffer to, as a - descriptor. - - @param[in] BufferPhysAddr (Guest pseudo-physical) start address of the - transmit / receive buffer. - - @param[in] BufferSize Number of bytes to transmit or receive. - - @param[in] Flags A bitmask of VRING_DESC_F_* flags. The caller - computes this mask dependent on further buffers to - append and transfer direction. - VRING_DESC_F_INDIRECT is unsupported. The - VRING_DESC.Next field is always set, but the host - only interprets it dependent on VRING_DESC_F_NEXT. - - @param[in,out] Indices Indices->HeadDescIdx is not accessed. - On input, Indices->NextDescIdx identifies the next - descriptor to carry the buffer. On output, - Indices->NextDescIdx is incremented by one, modulo - 2^16. - -**/ -VOID -EFIAPI -VirtioAppendDesc ( - IN OUT VRING *Ring, - IN UINTN BufferPhysAddr, - IN UINT32 BufferSize, - IN UINT16 Flags, - IN OUT DESC_INDICES *Indices - ) -{ - volatile VRING_DESC *Desc; - - Desc = &Ring->Desc[Indices->NextDescIdx++ % Ring->QueueSize]; - Desc->Addr = BufferPhysAddr; - Desc->Len = BufferSize; - Desc->Flags = Flags; - Desc->Next = Indices->NextDescIdx % Ring->QueueSize; -} - - -/** - - Notify the host about the descriptor chain just built, and wait until the - host processes it. - - @param[in] VirtIo The target virtio device to notify. - - @param[in] VirtQueueId Identifies the queue for the target device. - - @param[in,out] Ring The virtio ring with descriptors to submit. - - @param[in] Indices Indices->NextDescIdx is not accessed. - Indices->HeadDescIdx identifies the head descriptor - of the descriptor chain. - - - @return Error code from VirtIo->SetQueueNotify() if it fails. - - @retval EFI_SUCCESS Otherwise, the host processed all descriptors. - -**/ -EFI_STATUS -EFIAPI -VirtioFlush ( - IN VIRTIO_DEVICE_PROTOCOL *VirtIo, - IN UINT16 VirtQueueId, - IN OUT VRING *Ring, - IN DESC_INDICES *Indices - ) -{ - UINT16 NextAvailIdx; - EFI_STATUS Status; - UINTN PollPeriodUsecs; - - // - // virtio-0.9.5, 2.4.1.2 Updating the Available Ring - // - // It is not exactly clear from the wording of the virtio-0.9.5 - // specification, but each entry in the Available Ring references only the - // head descriptor of any given descriptor chain. - // - NextAvailIdx = *Ring->Avail.Idx; - Ring->Avail.Ring[NextAvailIdx++ % Ring->QueueSize] = - Indices->HeadDescIdx % Ring->QueueSize; - - // - // virtio-0.9.5, 2.4.1.3 Updating the Index Field - // - MemoryFence(); - *Ring->Avail.Idx = NextAvailIdx; - - // - // virtio-0.9.5, 2.4.1.4 Notifying the Device -- gratuitous notifications are - // OK. - // - MemoryFence(); - Status = VirtIo->SetQueueNotify (VirtIo, VirtQueueId); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device - // Wait until the host processes and acknowledges our descriptor chain. The - // condition we use for polling is greatly simplified and relies on the - // synchronous, lock-step progress. - // - // Keep slowing down until we reach a poll period of slightly above 1 ms. - // - PollPeriodUsecs = 1; - MemoryFence(); - while (*Ring->Used.Idx != NextAvailIdx) { - gBS->Stall (PollPeriodUsecs); // calls AcpiTimerLib::MicroSecondDelay - - if (PollPeriodUsecs < 1024) { - PollPeriodUsecs *= 2; - } - MemoryFence(); - } - - MemoryFence(); - return EFI_SUCCESS; -} diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.inf b/OvmfPkg/Library/VirtioLib/VirtioLib.inf deleted file mode 100644 index fb5897a88e..0000000000 --- a/OvmfPkg/Library/VirtioLib/VirtioLib.inf +++ /dev/null @@ -1,36 +0,0 @@ -## @file -# Library of virtio utility functions. -# -# Copyright (C) 2012, Red Hat, Inc. -# -# This program and the accompanying materials are licensed and made available -# under the terms and conditions of the BSD License which accompanies this -# distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT -# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = VirtioLib - FILE_GUID = 90CED1D9-18F2-47CC-BF24-41EC29406637 - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = VirtioLib - -[Sources] - VirtioLib.c - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseLib - BaseMemoryLib - DebugLib - MemoryAllocationLib - UefiBootServicesTableLib diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c deleted file mode 100644 index 4af9dd0ac2..0000000000 --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c +++ /dev/null @@ -1,224 +0,0 @@ -/** @file - - This driver produces Virtio Device Protocol instances for Virtio Mmio devices. - - Copyright (C) 2013, ARM Ltd. - - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License which accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include -#include -#include - -#include "VirtioMmioDevice.h" - -static VIRTIO_DEVICE_PROTOCOL mMmioDeviceProtocolTemplate = { - 0, // Revision - 0, // SubSystemDeviceId - VirtioMmioGetDeviceFeatures, // GetDeviceFeatures - VirtioMmioSetGuestFeatures, // SetGuestFeatures - VirtioMmioGetQueueAddress, // GetQueueAddress - VirtioMmioSetQueueAddress, // SetQueueAddress - VirtioMmioSetQueueSel, // SetQueueSel - VirtioMmioSetQueueNotify, // SetQueueNotify - VirtioMmioSetQueueAlignment, // SetQueueAlign - VirtioMmioSetPageSize, // SetPageSize - VirtioMmioGetQueueSize, // GetQueueNumMax - VirtioMmioSetQueueSize, // SetQueueNum - VirtioMmioGetDeviceStatus, // GetDeviceStatus - VirtioMmioSetDeviceStatus, // SetDeviceStatus - VirtioMmioDeviceWrite, // WriteDevice - VirtioMmioDeviceRead // ReadDevice -}; - -/** - - Initialize the VirtIo MMIO Device - - @param[in] BaseAddress Base Address of the VirtIo MMIO Device - - @param[in, out] Device The driver instance to configure. - - @retval EFI_SUCCESS Setup complete. - - @retval EFI_UNSUPPORTED The driver is not a VirtIo MMIO device. - -**/ -STATIC -EFI_STATUS -EFIAPI -VirtioMmioInit ( - IN PHYSICAL_ADDRESS BaseAddress, - IN OUT VIRTIO_MMIO_DEVICE *Device - ) -{ - UINT32 MagicValue; - UINT32 VendorId; - UINT32 Version; - - // - // Initialize VirtIo Mmio Device - // - CopyMem (&Device->VirtioDevice, &mMmioDeviceProtocolTemplate, - sizeof (VIRTIO_DEVICE_PROTOCOL)); - Device->BaseAddress = BaseAddress; - Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (0, 9, 5); - Device->VirtioDevice.SubSystemDeviceId = - MmioRead32 (BaseAddress + VIRTIO_MMIO_OFFSET_DEVICE_ID); - - // - // Double-check MMIO-specific values - // - MagicValue = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_MAGIC); - if (MagicValue != VIRTIO_MMIO_MAGIC) { - return EFI_UNSUPPORTED; - } - - Version = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_VERSION); - if (Version != 1) { - return EFI_UNSUPPORTED; - } - - // - // Double-check MMIO-specific values - // - VendorId = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_VENDOR_ID); - if (VendorId != VIRTIO_VENDOR_ID) { - // - // The ARM Base and Foundation Models do not report a valid VirtIo VendorId. - // They return a value of 0x0 for the VendorId. - // - DEBUG((EFI_D_WARN, "VirtioMmioInit: Warning: The VendorId (0x%X) does not " - "match the VirtIo VendorId (0x%X).\n", - VendorId, VIRTIO_VENDOR_ID)); - } - - return EFI_SUCCESS; -} - - -/** - - Uninitialize the internals of a virtio-mmio device that has been successfully - set up with VirtioMmioInit(). - - @param[in, out] Device The device to clean up. - -**/ - -STATIC -VOID -EFIAPI -VirtioMmioUninit ( - IN VIRTIO_MMIO_DEVICE *Device - ) -{ - // - // Note: This function mirrors VirtioMmioInit() that does not allocate any - // resources - there's nothing to free here. - // -} - -EFI_STATUS -VirtioMmioInstallDevice ( - IN PHYSICAL_ADDRESS BaseAddress, - IN EFI_HANDLE Handle - ) -{ - EFI_STATUS Status; - VIRTIO_MMIO_DEVICE *VirtIo; - - if (!BaseAddress) { - return EFI_INVALID_PARAMETER; - } - if (Handle == NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // Allocate VIRTIO_MMIO_DEVICE - // - VirtIo = AllocateZeroPool (sizeof (VIRTIO_MMIO_DEVICE)); - if (VirtIo == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - VirtIo->Signature = VIRTIO_MMIO_DEVICE_SIGNATURE; - - Status = VirtioMmioInit (BaseAddress, VirtIo); - if (EFI_ERROR (Status)) { - goto FreeVirtioMem; - } - - // - // Install VIRTIO_DEVICE_PROTOCOL to Handle - // - Status = gBS->InstallProtocolInterface (&Handle, - &gVirtioDeviceProtocolGuid, EFI_NATIVE_INTERFACE, - &VirtIo->VirtioDevice); - if (EFI_ERROR (Status)) { - goto UninitVirtio; - } - - return EFI_SUCCESS; - -UninitVirtio: - VirtioMmioUninit (VirtIo); - -FreeVirtioMem: - FreePool (VirtIo); - return Status; -} - -EFI_STATUS -VirtioMmioUninstallDevice ( - IN EFI_HANDLE DeviceHandle - ) -{ - VIRTIO_DEVICE_PROTOCOL *VirtioDevice; - VIRTIO_MMIO_DEVICE *MmioDevice; - EFI_STATUS Status; - - Status = gBS->OpenProtocol ( - DeviceHandle, // candidate device - &gVirtioDeviceProtocolGuid, // retrieve the VirtIo iface - (VOID **)&VirtioDevice, // target pointer - DeviceHandle, // requestor driver identity - DeviceHandle, // requesting lookup for dev. - EFI_OPEN_PROTOCOL_GET_PROTOCOL // lookup only, no ref. added - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Get the MMIO device from the VirtIo Device instance - // - MmioDevice = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (VirtioDevice); - - // - // Uninstall the protocol interface - // - Status = gBS->UninstallProtocolInterface (DeviceHandle, - &gVirtioDeviceProtocolGuid, &MmioDevice->VirtioDevice - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Uninitialize the VirtIo Device - // - VirtioMmioUninit (MmioDevice); - FreePool (MmioDevice); - - return EFI_SUCCESS; -} diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h deleted file mode 100644 index 3e4e5606cc..0000000000 --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h +++ /dev/null @@ -1,147 +0,0 @@ -/** @file - - Internal definitions for the VirtIo MMIO Device driver - - Copyright (C) 2013, ARM Ltd - - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License which accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef _VIRTIO_MMIO_DEVICE_INTERNAL_H_ -#define _VIRTIO_MMIO_DEVICE_INTERNAL_H_ - -#include - -#include - -#include -#include -#include -#include - -#define VIRTIO_MMIO_DEVICE_SIGNATURE SIGNATURE_32 ('V', 'M', 'I', 'O') - -typedef struct { - UINT32 Signature; - VIRTIO_DEVICE_PROTOCOL VirtioDevice; - PHYSICAL_ADDRESS BaseAddress; -} VIRTIO_MMIO_DEVICE; - -#define VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE(Device) \ - CR (Device, VIRTIO_MMIO_DEVICE, VirtioDevice, VIRTIO_MMIO_DEVICE_SIGNATURE) - -#define VIRTIO_CFG_WRITE(Device, Offset, Val) \ - (MmioWrite32 (Device->BaseAddress + (Offset), Val)) -#define VIRTIO_CFG_READ(Device, Offset) \ - (MmioRead32 (Device->BaseAddress + (Offset))) - -EFI_STATUS -EFIAPI -VirtioMmioDeviceRead ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINTN FieldOFfset, - IN UINTN FieldSize, - IN UINTN BufferSize, - OUT VOID* Buffer - ); - -EFI_STATUS -EFIAPI -VirtioMmioDeviceWrite ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINTN FieldOffset, - IN UINTN FieldSize, - IN UINT64 Value - ); - -EFI_STATUS -EFIAPI -VirtioMmioGetDeviceFeatures ( - IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT32 *DeviceFeatures - ); - -EFI_STATUS -EFIAPI -VirtioMmioGetQueueAddress ( - IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT32 *QueueAddress - ); - -EFI_STATUS -EFIAPI -VirtioMmioGetQueueSize ( - IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT16 *QueueNumMax - ); - -EFI_STATUS -EFIAPI -VirtioMmioGetDeviceStatus ( - IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT8 *DeviceStatus - ); - -EFI_STATUS -EFIAPI -VirtioMmioSetQueueSize ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT16 QueueSize - ); - -EFI_STATUS -EFIAPI -VirtioMmioSetDeviceStatus ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT8 DeviceStatus - ); - -EFI_STATUS -EFIAPI -VirtioMmioSetQueueNotify ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT16 QueueNotify - ); - -EFI_STATUS -EFIAPI -VirtioMmioSetQueueSel ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT16 Sel - ); - -EFI_STATUS -VirtioMmioSetQueueAddress ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT32 Address - ); - -EFI_STATUS -EFIAPI -VirtioMmioSetQueueAlignment ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT32 Alignment - ); - -EFI_STATUS -EFIAPI -VirtioMmioSetPageSize ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT32 PageSize - ); - -EFI_STATUS -EFIAPI -VirtioMmioSetGuestFeatures ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT32 Features - ); - -#endif // _VIRTIO_MMIO_DEVICE_INTERNAL_H_ diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c deleted file mode 100644 index 3950c07f7f..0000000000 --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c +++ /dev/null @@ -1,310 +0,0 @@ -/** @file - - This driver produces Virtio Device Protocol instances for Virtio MMIO devices. - - Copyright (C) 2012, Red Hat, Inc. - Copyright (c) 2012, Intel Corporation. All rights reserved.
- Copyright (C) 2013, ARM Ltd. - - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License which accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "VirtioMmioDevice.h" - -EFI_STATUS -EFIAPI -VirtioMmioGetDeviceFeatures ( - IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT32 *DeviceFeatures - ) -{ - VIRTIO_MMIO_DEVICE *Device; - - if (DeviceFeatures == NULL) { - return EFI_INVALID_PARAMETER; - } - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - *DeviceFeatures = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES); - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtioMmioGetQueueAddress ( - IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT32 *QueueAddress - ) -{ - VIRTIO_MMIO_DEVICE *Device; - - if (QueueAddress == NULL) { - return EFI_INVALID_PARAMETER; - } - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - *QueueAddress = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN); - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtioMmioGetQueueSize ( - IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT16 *QueueNumMax - ) -{ - VIRTIO_MMIO_DEVICE *Device; - - if (QueueNumMax == NULL) { - return EFI_INVALID_PARAMETER; - } - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - *QueueNumMax = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM_MAX) & 0xFFFF; - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtioMmioGetDeviceStatus ( - IN VIRTIO_DEVICE_PROTOCOL *This, - OUT UINT8 *DeviceStatus - ) -{ - VIRTIO_MMIO_DEVICE *Device; - - if (DeviceStatus == NULL) { - return EFI_INVALID_PARAMETER; - } - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - *DeviceStatus = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_STATUS) & 0xFF; - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtioMmioSetQueueSize ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT16 QueueSize - ) -{ - VIRTIO_MMIO_DEVICE *Device; - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM, QueueSize); - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtioMmioSetDeviceStatus ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT8 DeviceStatus - ) -{ - VIRTIO_MMIO_DEVICE *Device; - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_STATUS, DeviceStatus); - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtioMmioSetQueueNotify ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT16 QueueNotify - ) -{ - VIRTIO_MMIO_DEVICE *Device; - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_NOTIFY, QueueNotify); - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtioMmioSetQueueAlignment ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT32 Alignment - ) -{ - VIRTIO_MMIO_DEVICE *Device; - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_ALIGN, Alignment); - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtioMmioSetPageSize ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT32 PageSize - ) -{ - VIRTIO_MMIO_DEVICE *Device; - - if (PageSize != EFI_PAGE_SIZE) { - return EFI_UNSUPPORTED; - } - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_PAGE_SIZE, PageSize); - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtioMmioSetQueueSel ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT16 Sel - ) -{ - VIRTIO_MMIO_DEVICE *Device; - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_SEL, Sel); - - return EFI_SUCCESS; -} - -EFI_STATUS -VirtioMmioSetQueueAddress ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT32 Address - ) -{ - VIRTIO_MMIO_DEVICE *Device; - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN, Address); - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtioMmioSetGuestFeatures ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT32 Features - ) -{ - VIRTIO_MMIO_DEVICE *Device; - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES, Features); - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtioMmioDeviceWrite ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINTN FieldOffset, - IN UINTN FieldSize, - IN UINT64 Value - ) -{ - UINTN DstBaseAddress; - VIRTIO_MMIO_DEVICE *Device; - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - // - // Double-check fieldsize - // - if ((FieldSize != 1) && (FieldSize != 2) && - (FieldSize != 4) && (FieldSize != 8)) { - return EFI_INVALID_PARAMETER; - } - - // - // Compute base address - // - DstBaseAddress = Device->BaseAddress + - VIRTIO_DEVICE_SPECIFIC_CONFIGURATION_OFFSET_MMIO + FieldOffset; - - // - // The device-specific memory area of Virtio-MMIO can only be written in - // byte accesses. This is not currently in the Virtio spec. - // - MmioWriteBuffer8 (DstBaseAddress, FieldSize, (UINT8*)&Value); - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -VirtioMmioDeviceRead ( - IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINTN FieldOffset, - IN UINTN FieldSize, - IN UINTN BufferSize, - OUT VOID *Buffer - ) -{ - UINTN SrcBaseAddress; - VIRTIO_MMIO_DEVICE *Device; - - Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - - // - // Parameter validation - // - ASSERT (FieldSize == BufferSize); - - // - // Double-check fieldsize - // - if ((FieldSize != 1) && (FieldSize != 2) && - (FieldSize != 4) && (FieldSize != 8)) { - return EFI_INVALID_PARAMETER; - } - - // - // Compute base address - // - SrcBaseAddress = Device->BaseAddress + - VIRTIO_DEVICE_SPECIFIC_CONFIGURATION_OFFSET_MMIO + FieldOffset; - - // - // The device-specific memory area of Virtio-MMIO can only be read in - // byte reads. This is not currently in the Virtio spec. - // - MmioReadBuffer8 (SrcBaseAddress, BufferSize, Buffer); - - return EFI_SUCCESS; -} diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf deleted file mode 100644 index 2e266a9d45..0000000000 --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf +++ /dev/null @@ -1,42 +0,0 @@ -## @file -# This driver produces the VirtIo Device Protocol instances for VirtIo Mmio -# Device -# -# Copyright (C) 2013, ARM Ltd -# -# This program and the accompanying materials are licensed and made available -# under the terms and conditions of the BSD License which accompanies this -# distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT -# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010006 - BASE_NAME = VirtioMmioDeviceLib - FILE_GUID = 3b6ed966-b5d1-46a8-965b-867ff22d9c89 - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = VirtioMmioDeviceLib - -[Sources] - VirtioMmioDevice.c - VirtioMmioDeviceFunctions.c - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseMemoryLib - DebugLib - IoLib - MemoryAllocationLib - UefiBootServicesTableLib - UefiLib - -[Protocols] - gVirtioDeviceProtocolGuid ## PRODUCES diff --git a/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c b/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c deleted file mode 100644 index 2956963124..0000000000 --- a/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c +++ /dev/null @@ -1,302 +0,0 @@ -/** @file - Xen console SerialPortLib instance - - Copyright (c) 2015, Linaro Ltd. All rights reserved.
- Copyright (c) 2015, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include -#include - -#include -#include -#include - -#include -#include -#include - -// -// We can't use DebugLib due to a constructor dependency cycle between DebugLib -// and ourselves. -// -#define ASSERT(Expression) \ - do { \ - if (!(Expression)) { \ - CpuDeadLoop (); \ - } \ - } while (FALSE) - -// -// The code below expects these global variables to be mutable, even in the case -// that we have been incorporated into SEC or PEIM phase modules (which is -// allowed by our INF description). While this is a dangerous assumption to make -// in general, it is actually fine for the Xen domU (guest) environment that -// this module is intended for, as UEFI always executes from DRAM in that case. -// -STATIC evtchn_send_t mXenConsoleEventChain; -STATIC struct xencons_interface *mXenConsoleInterface; - -/** - Initialize the serial device hardware. - - If no initialization is required, then return RETURN_SUCCESS. - If the serial device was successfully initialized, then return RETURN_SUCCESS. - If the serial device could not be initialized, then return RETURN_DEVICE_ERROR. - - @retval RETURN_SUCCESS The serial device was initialized. - @retval RETURN_DEVICE_ERROR The serial device could not be initialized. - -**/ -RETURN_STATUS -EFIAPI -SerialPortInitialize ( - VOID - ) -{ - if (! XenHypercallIsAvailable ()) { - return RETURN_DEVICE_ERROR; - } - - if (!mXenConsoleInterface) { - mXenConsoleEventChain.port = (UINT32)XenHypercallHvmGetParam (HVM_PARAM_CONSOLE_EVTCHN); - mXenConsoleInterface = (struct xencons_interface *)(UINTN) - (XenHypercallHvmGetParam (HVM_PARAM_CONSOLE_PFN) << EFI_PAGE_SHIFT); - - // - // No point in ASSERT'ing here as we won't be seeing the output - // - } - return RETURN_SUCCESS; -} - -/** - Write data from buffer to serial device. - - Writes NumberOfBytes data bytes from Buffer to the serial device. - The number of bytes actually written to the serial device is returned. - If the return value is less than NumberOfBytes, then the write operation failed. - If Buffer is NULL, then ASSERT(). - If NumberOfBytes is zero, then return 0. - - @param Buffer Pointer to the data buffer to be written. - @param NumberOfBytes Number of bytes to written to the serial device. - - @retval 0 NumberOfBytes is 0. - @retval >0 The number of bytes written to the serial device. - If this value is less than NumberOfBytes, then the write operation failed. - -**/ -UINTN -EFIAPI -SerialPortWrite ( - IN UINT8 *Buffer, - IN UINTN NumberOfBytes - ) -{ - XENCONS_RING_IDX Consumer, Producer; - UINTN Sent; - - ASSERT (Buffer != NULL); - - if (NumberOfBytes == 0) { - return 0; - } - - if (!mXenConsoleInterface) { - return 0; - } - - Sent = 0; - do { - Consumer = mXenConsoleInterface->out_cons; - Producer = mXenConsoleInterface->out_prod; - - MemoryFence (); - - while (Sent < NumberOfBytes && ((Producer - Consumer) < sizeof (mXenConsoleInterface->out))) - mXenConsoleInterface->out[MASK_XENCONS_IDX(Producer++, mXenConsoleInterface->out)] = Buffer[Sent++]; - - MemoryFence (); - - mXenConsoleInterface->out_prod = Producer; - - XenHypercallEventChannelOp (EVTCHNOP_send, &mXenConsoleEventChain); - - } while (Sent < NumberOfBytes); - - return Sent; -} - -/** - Read data from serial device and save the datas in buffer. - - Reads NumberOfBytes data bytes from a serial device into the buffer - specified by Buffer. The number of bytes actually read is returned. - If Buffer is NULL, then ASSERT(). - If NumberOfBytes is zero, then return 0. - - @param Buffer Pointer to the data buffer to store the data read from the serial device. - @param NumberOfBytes Number of bytes which will be read. - - @retval 0 Read data failed, no data is to be read. - @retval >0 Actual number of bytes read from serial device. - -**/ -UINTN -EFIAPI -SerialPortRead ( - OUT UINT8 *Buffer, - IN UINTN NumberOfBytes -) -{ - XENCONS_RING_IDX Consumer, Producer; - UINTN Received; - - ASSERT (Buffer != NULL); - - if (NumberOfBytes == 0) { - return 0; - } - - if (!mXenConsoleInterface) { - return 0; - } - - Consumer = mXenConsoleInterface->in_cons; - Producer = mXenConsoleInterface->in_prod; - - MemoryFence (); - - Received = 0; - while (Received < NumberOfBytes && Consumer < Producer) - Buffer[Received++] = mXenConsoleInterface->in[MASK_XENCONS_IDX(Consumer++, mXenConsoleInterface->in)]; - - MemoryFence (); - - mXenConsoleInterface->in_cons = Consumer; - - XenHypercallEventChannelOp (EVTCHNOP_send, &mXenConsoleEventChain); - - return Received; -} - -/** - Polls a serial device to see if there is any data waiting to be read. - - @retval TRUE Data is waiting to be read from the serial device. - @retval FALSE There is no data waiting to be read from the serial device. - -**/ -BOOLEAN -EFIAPI -SerialPortPoll ( - VOID - ) -{ - return mXenConsoleInterface && - mXenConsoleInterface->in_cons != mXenConsoleInterface->in_prod; -} - -/** - Sets the control bits on a serial device. - - @param Control Sets the bits of Control that are settable. - - @retval RETURN_SUCCESS The new control bits were set on the serial device. - @retval RETURN_UNSUPPORTED The serial device does not support this operation. - @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly. - -**/ -RETURN_STATUS -EFIAPI -SerialPortSetControl ( - IN UINT32 Control - ) -{ - return RETURN_UNSUPPORTED; -} - -/** - Retrieve the status of the control bits on a serial device. - - @param Control A pointer to return the current control signals from the serial device. - - @retval RETURN_SUCCESS The control bits were read from the serial device. - @retval RETURN_UNSUPPORTED The serial device does not support this operation. - @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly. - -**/ -RETURN_STATUS -EFIAPI -SerialPortGetControl ( - OUT UINT32 *Control - ) -{ - if (!mXenConsoleInterface) { - return RETURN_UNSUPPORTED; - } - - *Control = 0; - if (!SerialPortPoll ()) { - *Control = EFI_SERIAL_INPUT_BUFFER_EMPTY; - } - return RETURN_SUCCESS; -} - -/** - Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, - data bits, and stop bits on a serial device. - - @param BaudRate The requested baud rate. A BaudRate value of 0 will use the - device's default interface speed. - On output, the value actually set. - @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the - serial interface. A ReceiveFifoDepth value of 0 will use - the device's default FIFO depth. - On output, the value actually set. - @param Timeout The requested time out for a single character in microseconds. - This timeout applies to both the transmit and receive side of the - interface. A Timeout value of 0 will use the device's default time - out value. - On output, the value actually set. - @param Parity The type of parity to use on this serial device. A Parity value of - DefaultParity will use the device's default parity value. - On output, the value actually set. - @param DataBits The number of data bits to use on the serial device. A DataBits - vaule of 0 will use the device's default data bit setting. - On output, the value actually set. - @param StopBits The number of stop bits to use on this serial device. A StopBits - value of DefaultStopBits will use the device's default number of - stop bits. - On output, the value actually set. - - @retval RETURN_SUCCESS The new attributes were set on the serial device. - @retval RETURN_UNSUPPORTED The serial device does not support this operation. - @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value. - @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly. - -**/ -RETURN_STATUS -EFIAPI -SerialPortSetAttributes ( - IN OUT UINT64 *BaudRate, - IN OUT UINT32 *ReceiveFifoDepth, - IN OUT UINT32 *Timeout, - IN OUT EFI_PARITY_TYPE *Parity, - IN OUT UINT8 *DataBits, - IN OUT EFI_STOP_BITS_TYPE *StopBits - ) -{ - return RETURN_UNSUPPORTED; -} - diff --git a/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf b/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf deleted file mode 100644 index 8a7411558f..0000000000 --- a/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf +++ /dev/null @@ -1,35 +0,0 @@ -#/** @file -# -# Component description file for XenConsoleSerialPortLib module -# -# Copyright (c) 2015, Linaro Ltd. All rights reserved.
-# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = XenConsoleSerialPortLib - FILE_GUID = 401406DD-BCAC-4B91-9F4E-72A7FEBE4762 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = SerialPortLib - CONSTRUCTOR = SerialPortInitialize - -[Sources.common] - XenConsoleSerialPortLib.c - -[LibraryClasses] - BaseLib - XenHypercallLib - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec diff --git a/OvmfPkg/Library/XenHypercallLib/Aarch64/Hypercall.S b/OvmfPkg/Library/XenHypercallLib/Aarch64/Hypercall.S deleted file mode 100644 index b1b5d4cc3f..0000000000 --- a/OvmfPkg/Library/XenHypercallLib/Aarch64/Hypercall.S +++ /dev/null @@ -1,26 +0,0 @@ - -/** @file - AArch64 implementation of XenHypercall2 - - Copyright (C) 2014, Linaro Ltd. - - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include - - .text - .global ASM_PFX(XenHypercall2) -ASM_PFX(XenHypercall2): - mov x16, x0 - mov x0, x1 - mov x1, x2 - hvc #XEN_HYPERCALL_TAG - ret diff --git a/OvmfPkg/Library/XenHypercallLib/Arm/Hypercall.S b/OvmfPkg/Library/XenHypercallLib/Arm/Hypercall.S deleted file mode 100644 index b38e1a8f18..0000000000 --- a/OvmfPkg/Library/XenHypercallLib/Arm/Hypercall.S +++ /dev/null @@ -1,25 +0,0 @@ -/** @file - ARM (AArch32) implementation of XenHypercall2 - - Copyright (C) 2014, Linaro Ltd. - - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include - - .text - .global ASM_PFX(XenHypercall2) -ASM_PFX(XenHypercall2): - mov r12, r0 - mov r0, r1 - mov r1, r2 - hvc #XEN_HYPERCALL_TAG - bx lr diff --git a/OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c b/OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c deleted file mode 100644 index 58cd3ec76b..0000000000 --- a/OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c +++ /dev/null @@ -1,44 +0,0 @@ -/** @file - Xen Hypercall Library implementation for ARM architecture - - Copyright (C) 2015, Red Hat, Inc. - Copyright (c) 2014, Linaro Ltd. All rights reserved.
- - This program and the accompanying materials are licensed and made available - under the terms and conditions of the BSD License that accompanies this - distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php. - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#include - -/** - Check if the Xen Hypercall library is able to make calls to the Xen - hypervisor. - - Client code should call further functions in this library only if, and after, - this function returns TRUE. - - @retval TRUE Hypercalls are available. - @retval FALSE Hypercalls are not available. -**/ -BOOLEAN -EFIAPI -XenHypercallIsAvailable ( - VOID - ) -{ - return TRUE; -} - -RETURN_STATUS -EFIAPI -XenHypercallLibInit ( - VOID - ) -{ - return RETURN_SUCCESS; -} diff --git a/OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm b/OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm deleted file mode 100644 index e0fa71bb5b..0000000000 --- a/OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm +++ /dev/null @@ -1,25 +0,0 @@ -SECTION .text - -; INTN -; EFIAPI -; __XenHypercall2 ( -; IN VOID *HypercallAddr, -; IN OUT INTN Arg1, -; IN OUT INTN Arg2 -; ); -global ASM_PFX(__XenHypercall2) -ASM_PFX(__XenHypercall2): - ; Save only ebx, ecx is supposed to be a scratch register and needs to be - ; saved by the caller - push ebx - ; Copy HypercallAddr to eax - mov eax, [esp + 8] - ; Copy Arg1 to the register expected by Xen - mov ebx, [esp + 12] - ; Copy Arg2 to the register expected by Xen - mov ecx, [esp + 16] - ; Call HypercallAddr - call eax - pop ebx - ret - diff --git a/OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm b/OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm deleted file mode 100644 index 5e6a0c05c5..0000000000 --- a/OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm +++ /dev/null @@ -1,26 +0,0 @@ -DEFAULT REL -SECTION .text - -; INTN -; EFIAPI -; __XenHypercall2 ( -; IN VOID *HypercallAddr, -; IN OUT INTN Arg1, -; IN OUT INTN Arg2 -; ); -global ASM_PFX(__XenHypercall2) -ASM_PFX(__XenHypercall2): - push rdi - push rsi - ; Copy HypercallAddr to rax - mov rax, rcx - ; Copy Arg1 to the register expected by Xen - mov rdi, rdx - ; Copy Arg2 to the register expected by Xen - mov rsi, r8 - ; Call HypercallAddr - call rax - pop rsi - pop rdi - ret - diff --git a/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c b/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c deleted file mode 100644 index 7cb7f46c9b..0000000000 --- a/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c +++ /dev/null @@ -1,102 +0,0 @@ -/** @file - Xen Hypercall Library implementation for Intel architecture - -Copyright (c) 2014, Linaro Ltd. All rights reserved.
-This program and the accompanying materials are licensed and made available under -the terms and conditions of the BSD License that accompanies this distribution. -The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php. - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include -#include -#include -#include - -STATIC VOID *HyperPage; - -/** - Check if the Xen Hypercall library is able to make calls to the Xen - hypervisor. - - Client code should call further functions in this library only if, and after, - this function returns TRUE. - - @retval TRUE Hypercalls are available. - @retval FALSE Hypercalls are not available. -**/ -BOOLEAN -EFIAPI -XenHypercallIsAvailable ( - VOID - ) -{ - return HyperPage != NULL; -} - -// -// Interface exposed by the ASM implementation of the core hypercall -// -INTN -EFIAPI -__XenHypercall2 ( - IN VOID *HypercallAddr, - IN OUT INTN Arg1, - IN OUT INTN Arg2 - ); - -/** - Library constructor: retrieves the Hyperpage address - from the gEfiXenInfoGuid HOB -**/ - -RETURN_STATUS -EFIAPI -XenHypercallLibInit ( - VOID - ) -{ - EFI_HOB_GUID_TYPE *GuidHob; - EFI_XEN_INFO *XenInfo; - - GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid); - if (GuidHob == NULL) { - // - // We don't fail library construction, since that has catastrophic - // consequences for client modules (whereas those modules may easily be - // running on a non-Xen platform). Instead, XenHypercallIsAvailable() above - // will return FALSE. - // - return RETURN_SUCCESS; - } - XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob); - HyperPage = XenInfo->HyperPages; - return RETURN_SUCCESS; -} - -/** - This function will put the two arguments in the right place (registers) and - invoke the hypercall identified by HypercallID. - - @param HypercallID The symbolic ID of the hypercall to be invoked - @param Arg1 First argument. - @param Arg2 Second argument. - - @return Return 0 if success otherwise it return an errno. -**/ -INTN -EFIAPI -XenHypercall2 ( - IN UINTN HypercallID, - IN OUT INTN Arg1, - IN OUT INTN Arg2 - ) -{ - ASSERT (HyperPage != NULL); - - return __XenHypercall2 ((UINT8*)HyperPage + HypercallID * 32, Arg1, Arg2); -} diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercall.c b/OvmfPkg/Library/XenHypercallLib/XenHypercall.c deleted file mode 100644 index 82cdbd9bdb..0000000000 --- a/OvmfPkg/Library/XenHypercallLib/XenHypercall.c +++ /dev/null @@ -1,63 +0,0 @@ -/** @file - Functions to make Xen hypercalls. - - Copyright (C) 2014, Citrix Ltd. - - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include - -#include -#include - -#include -#include - -UINT64 -XenHypercallHvmGetParam ( - IN UINT32 Index - ) -{ - xen_hvm_param_t Parameter; - INTN Error; - - Parameter.domid = DOMID_SELF; - Parameter.index = Index; - Error = XenHypercall2 (__HYPERVISOR_hvm_op, - HVMOP_get_param, (INTN) &Parameter); - if (Error != 0) { - DEBUG ((EFI_D_ERROR, - "XenHypercall: Error %Ld trying to get HVM parameter %d\n", - (INT64)Error, Index)); - return 0; - } - return Parameter.value; -} - -INTN -XenHypercallMemoryOp ( - IN UINTN Operation, - IN OUT VOID *Arguments - ) -{ - return XenHypercall2 (__HYPERVISOR_memory_op, - Operation, (INTN) Arguments); -} - -INTN -XenHypercallEventChannelOp ( - IN INTN Operation, - IN OUT VOID *Arguments - ) -{ - return XenHypercall2 (__HYPERVISOR_event_channel_op, - Operation, (INTN) Arguments); -} diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf b/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf deleted file mode 100644 index f4503a4b01..0000000000 --- a/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf +++ /dev/null @@ -1,66 +0,0 @@ -## @file -# Xen Hypercall abstraction lib for Intel and ARM architectures -# -# Copyright (c) 2014, Linaro Ltd. All rights reserved.
-# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = XenHypercallLib - FILE_GUID = B5EE9A32-CA5A-49A8-82E3-ADA4CCB77C7C - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - CONSTRUCTOR = XenHypercallLibInit - -[Defines.IA32, Defines.X64] - LIBRARY_CLASS = XenHypercallLib|DXE_DRIVER UEFI_DRIVER - -[Defines.ARM, Defines.AARCH64] - LIBRARY_CLASS = XenHypercallLib - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64 -# - -[Sources.IA32, Sources.X64] - X86XenHypercall.c - -[Sources.IA32] - Ia32/hypercall.nasm - -[Sources.X64] - X64/hypercall.nasm - -[Sources.ARM, Sources.AARCH64] - ArmXenHypercall.c - -[Sources.ARM] - Arm/Hypercall.S - -[Sources.AARCH64] - Aarch64/Hypercall.S - -[Sources] - XenHypercall.c - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses.IA32, LibraryClasses.X64] - BaseLib - HobLib - DebugLib - -[Guids.IA32, Guids.X64] - gEfiXenInfoGuid diff --git a/OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.c b/OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.c deleted file mode 100644 index c710e85865..0000000000 --- a/OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.c +++ /dev/null @@ -1,166 +0,0 @@ -/** @file -* Manage XenBus device path and I/O handles -* -* Copyright (c) 2015, Linaro Ltd. All rights reserved.
-* -* This program and the accompanying materials are -* licensed and made available under the terms and conditions of the BSD License -* which accompanies this distribution. The full text of the license may be found at -* http://opensource.org/licenses/bsd-license.php -* -* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -* -**/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#pragma pack (1) -typedef struct { - VENDOR_DEVICE_PATH Vendor; - EFI_PHYSICAL_ADDRESS GrantTableAddress; - EFI_DEVICE_PATH_PROTOCOL End; -} XENBUS_ROOT_DEVICE_PATH; -#pragma pack () - -STATIC CONST XENBUS_ROOT_DEVICE_PATH mXenBusRootDevicePathTemplate = { - { - { - HARDWARE_DEVICE_PATH, - HW_VENDOR_DP, - { sizeof (VENDOR_DEVICE_PATH) + sizeof (EFI_PHYSICAL_ADDRESS), 0 } - }, - XENBUS_ROOT_DEVICE_GUID, - }, - 0, - { - END_DEVICE_PATH_TYPE, - END_ENTIRE_DEVICE_PATH_SUBTYPE, - { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 } - } -}; - -/** - - Install the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols on - the handle pointed to by @Handle, or on a new handle if it points to - NULL - - @param Handle Pointer to the handle to install the protocols - on, may point to a NULL handle. - - @param GrantTableAddress The address of the Xen grant table - - @retval EFI_SUCCESS Protocols were installed successfully - - @retval EFI_OUT_OF_RESOURCES The function failed to allocate memory required - by the XenIo MMIO and device path protocols - - @return Status code returned by the boot service - InstallMultipleProtocolInterfaces () - -**/ -EFI_STATUS -XenIoMmioInstall ( - IN OUT EFI_HANDLE *Handle, - IN EFI_PHYSICAL_ADDRESS GrantTableAddress - ) -{ - EFI_STATUS Status; - XENIO_PROTOCOL *XenIo; - XENBUS_ROOT_DEVICE_PATH *XenBusDevicePath; - EFI_HANDLE OutHandle; - - ASSERT (Handle != NULL); - - OutHandle = *Handle; - - XenIo = AllocateZeroPool (sizeof *XenIo); - if (!XenIo) { - return EFI_OUT_OF_RESOURCES; - } - XenIo->GrantTableAddress = GrantTableAddress; - - XenBusDevicePath = AllocateCopyPool (sizeof *XenBusDevicePath, - &mXenBusRootDevicePathTemplate); - if (!XenBusDevicePath) { - DEBUG ((EFI_D_ERROR, "%a: Out of memory\n", __FUNCTION__)); - Status = EFI_OUT_OF_RESOURCES; - goto FreeXenIo; - } - XenBusDevicePath->GrantTableAddress = GrantTableAddress; - - Status = gBS->InstallMultipleProtocolInterfaces (&OutHandle, - &gEfiDevicePathProtocolGuid, XenBusDevicePath, - &gXenIoProtocolGuid, XenIo, - NULL); - if (!EFI_ERROR (Status)) { - *Handle = OutHandle; - return EFI_SUCCESS; - } - - DEBUG ((EFI_D_ERROR, "%a: Failed to install the EFI_DEVICE_PATH and " - "XENIO_PROTOCOL protocols on handle %p (Status == %r)\n", - __FUNCTION__, OutHandle, Status)); - - FreePool (XenBusDevicePath); - -FreeXenIo: - FreePool (XenIo); - return Status; -} - -/** - - Uninstall the XENBUS_ROOT_DEVICE_PATH and XENIO_PROTOCOL protocols - - @param Handle Handle onto which the protocols have been installed - earlier by XenIoMmioInstall () - - @retval EFI_SUCCESS Protocols were uninstalled successfully - - @return Status code returned by the boot service - UninstallMultipleProtocolInterfaces () - -**/ -EFI_STATUS -XenIoMmioUninstall ( - IN EFI_HANDLE Handle - ) -{ - EFI_STATUS Status; - VOID *XenIo; - VOID *XenBusDevicePath; - - XenBusDevicePath = NULL; - gBS->OpenProtocol (Handle, &gEfiDevicePathProtocolGuid, &XenBusDevicePath, - NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); - - XenIo = NULL; - gBS->OpenProtocol (Handle, &gXenIoProtocolGuid, &XenIo, - NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); - - Status = gBS->UninstallMultipleProtocolInterfaces (Handle, - &gEfiDevicePathProtocolGuid, XenBusDevicePath, - &gXenIoProtocolGuid, XenIo, - NULL); - - if (EFI_ERROR (Status)) { - return Status; - } - - FreePool (XenBusDevicePath); - FreePool (XenIo); - - return EFI_SUCCESS; -} diff --git a/OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf b/OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf deleted file mode 100644 index 16cc453035..0000000000 --- a/OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf +++ /dev/null @@ -1,39 +0,0 @@ -## @file -# Manage XenBus device path and I/O handles -# -# Copyright (c) 2015, Linaro Ltd. All rights reserved.
-# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php. -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = XenIoMmioLib - FILE_GUID = de9bdc19-8434-47bb-be3c-7f28f2101fd0 - MODULE_TYPE = DXE_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = XenIoMmioLib - -[Sources] - XenIoMmioLib.c - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseMemoryLib - -[Guids] - gXenBusRootDeviceGuid - -[Protocols] - gEfiDevicePathProtocolGuid - gXenIoProtocolGuid -- cgit v1.2.3