summaryrefslogtreecommitdiffstats
path: root/ArmVirtPkg/Library
Commit message (Collapse)AuthorAgeFilesLines
* ArmVirtPkg/FdtPciHostBridgeLib: Add extra pci root buses supportJiahui Cen via groups.io2021-01-201-18/+4
| | | | | | | | | | | | | | | | | | | | | In order to take advantages of extra pci root buses in ArmVirtPkg, it is necessary to scan extra root buses when getting root briges. And now PciHostBridgeUtilityLib already provides a set of utility functions that support for extra pci root buses, like PciHostBridgeUtilityGetRootBridges() / PciHostBridgeUtilityFreeRootBridges(). So let's rebase ArmVirtPkg/FdtPciHostBridgeLib to PciHostBridgeUtilityGetRootBridges() / PciHostBridgeUtilityFreeRootBridges() to extend ArmVirtPkg with extra pci root buses support. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059 Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com> Cc: Leif Lindholm <leif@nuviainc.com> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com> Signed-off-by: Yubo Miao <miaoyubo@huawei.com> Message-Id: <20210119011302.10908-11-cenjiahui@huawei.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/FdtPciHostBridgeLib: Refactor init/uninit of root bridgeJiahui Cen via groups.io2021-01-202-64/+61
| | | | | | | | | | | | | | | | Rebase ArmVirtPkg/FdtPciHostBridgeLib to the new PciHostBridgeUtilityInitRootBridge()/PciHostBridgeUtilityUninitRootBridge() utility functions. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059 Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com> Cc: Leif Lindholm <leif@nuviainc.com> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com> Signed-off-by: Yubo Miao <miaoyubo@huawei.com> Message-Id: <20210119011302.10908-7-cenjiahui@huawei.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg: Refactor with PciHostBridgeUtilityLibJiahui Cen via groups.io2021-01-202-41/+5
| | | | | | | | | | | | | | | | Eliminate currently duplicated code in ArmVirtPkg with the common utility class PciHostBridgeUtilityLib. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059 Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com> Signed-off-by: Yubo Miao <miaoyubo@huawei.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Message-Id: <20210119011302.10908-3-cenjiahui@huawei.com>
* ArmVirtPkg: Add Kvmtool Platform Pei LibSami Mujawar2020-10-162-0/+128
| | | | | | | | | | | | | The PlatformPeim() in the PlatformPeiLib is invoked by the PrePiMain() and provides the platform an opportunity to setup the plaform specific HOBs. This PlatfromPeiLib initialises the Kvmtool platform HOBs like the Fdt, 16550BaseAddress, etc. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Reviewed-by: Ard Biesheuvel <Ard.Biesheuvel@arm.com> Acked-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg: 16550 UART Platform hook librarySami Mujawar2020-10-165-0/+280
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The BaseSerialPort16550 library invokes the PlatformHookSerialPortInitialize() implemented as part of the PlatformHook library, to perform platform specific initialization required to enable use of the 16550 device. The BaseSerialPort16550 library uses the PcdSerialRegisterBase to obtain the base address of the UART for MMIO operations. Some VMMs like Kvmtool provide the base address of the console serial port in the platform device tree. This patch introduces two instances of the Platform Hook library: 1. EarlyFdt16550SerialPortHookLib - parses the platform device tree to extract the base address of the 16550 UART and update the PCD PcdSerialRegisterBase. 2. Fdt16550SerialPortHookLib - reads the GUID Hob gEarly16550UartBaseAddressGuid (that caches the base address of the 16550 UART discovered during early stages) and updates the PCD PcdSerialRegisterBase. Note: a. The PCD PcdSerialRegisterBase is configured as PatchableInModule. b. A separate patch introduces a PlatformPeiLib that trampolines the 16550 UART base address from the Pcd PcdSerialRegisterBase to the GUID Hob gEarly16550UartBaseAddressGuid. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Reviewed-by: Ard Biesheuvel <Ard.Biesheuvel@arm.com> Acked-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg: Add Kvmtool NOR flash libSami Mujawar2020-10-162-0/+384
| | | | | | | | | | | | | | | | | | | Kvmtool places the base address of the CFI flash in the device tree it passes to UEFI. This library parses the kvmtool device tree to read the CFI base address and initialise the PCDs use by the NOR flash driver and the variable storage. UEFI takes ownership of the CFI flash hardware, and exposes its functionality through the UEFI Runtime Variable Service. Therefore, disable the device tree node for the CFI flash used for storing the UEFI variables, to prevent the OS from attaching its device driver as well. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Acked-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
* ArmVirtPkg: kvmtool platform memory mapSami Mujawar2020-10-162-0/+140
| | | | | | | | | | | | | | | | | | Kvmtool is a virtual machine manager that enables hosting KVM guests. Kvmtool allows to vary the hardware configuration of the virtual platform it provides to the guest partition. It provides the current hardware configuration to the firmware by handing off a device tree containing the hardware information. This library parses the kvmtool provided device tree and populates the system memory map for the kvmtool virtual platform. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Reviewed-by: Ard Biesheuvel <Ard.Biesheuvel@arm.com> Acked-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg: Add Kvmtool RTC Fdt Client LibrarySami Mujawar2020-10-162-0/+272
| | | | | | | | | | | | | | | Add library that parses the Kvmtool device tree and updates the dynamic PCDs describing the RTC Memory map. It also maps the MMIO region used by the RTC as runtime memory so that the RTC registers are accessible post ExitBootServices. Since UEFI takes ownership of the RTC hardware disable the RTC node in the DT to prevent the OS from attaching its device driver as well. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Acked-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/NorFlashQemuLib: disable NOR flash DT nodes upon discoveryArd Biesheuvel2020-06-241-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Our UEFI guest firmware takes ownership of the emulated NOR flash in order to support the variable runtime services, and it does not expect the OS to interfere with the underlying storage directly. So disable the NOR flash DT nodes as we discover them, in a way similar to how we disable the PL031 RTC in the device tree when we attach our RTC runtime driver to it. Note that this also hides the NOR flash bank that carries the UEFI executable code, but this is not intended to be updatable from inside the guest anyway, and if it was, we should use capsule update to do so. Also, the first -pflash argument that defines the backing for this flash bank is often issued with the 'readonly' modifier, in order to prevent any changes whatsoever to be made to the executable firmware image by the guest. This issue has become relevant due to the following Linux changes, which enable the flash driver stack for default build configurations targetting arm64 and 32-bit ARM. ce693fc2a877 ("arm64: defconfig: Enable flash device drivers for QorIQ boards", 2020-03-16). 5f068190cc10 ("ARM: multi_v7_defconfig: Enable support for CFI NOR FLASH", 2019-04-03) Reviewed-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
* ArmVirtPkg/QemuFwCfgLib: allow UEFI_DRIVER modulesLaszlo Ersek2020-04-281-1/+1
| | | | | | | | | | | | | | | | | | | We don't distribute UEFI_DRIVER modules stand-alone that were built as part of an ArmVirtQemu* platform. ArmVirtQemu* UEFI_DRIVERs are allowed to inherit platform dependencies. By enabling UEFI_DRIVERs to consume QemuFwCfgLib, we can hook fw_cfg-based NULL class libraries into UEFI drivers, e.g. in order to set dynamic PCDs. Cc: Ard Biesheuvel <ard.biesheuvel@arm.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Per Sundstrom <per_sundstrom@yahoo.com> Cc: Philippe Mathieu-Daudé <philmd@redhat.com> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2681 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Message-Id: <20200424075353.8489-7-lersek@redhat.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* ArmVirtPkg/PlatformPeiLib: add dummy assignment to work around older GCCArd Biesheuvel2020-03-261-0/+5
| | | | | | | | | | | | | | | | | | | Older GCC (<= 4.9) fail to infer that Parent is never used unless it has been assigned before, and may throw an error like /work/git/edk2/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c: In function ‘PlatformPeim’: /work/git/edk2/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c:132:24: error: ‘Parent’ may be used uninitialized in this function [-Werror=maybe-uninitialized] RangesProp = fdt_getprop (Base, Parent, "ranges", &RangesLen); Set Parent to 0 at the start of the sequence to work around this. Link: https://bugzilla.tianocore.org/show_bug.cgi?id=2601 Fixes: 82662a3b5f56e974 ("ArmVirtPkg/PlatformPeiLib: discover the TPM base ...") Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg: fix ASSERT in ArmVirtGicArchLib with virtualization=onLeif Lindholm2020-03-171-1/+6
| | | | | | | | | | | | | | | | | | | ArmVirtGicArchLib was originally implemented before virtualization emulation was implemented in QEMU, and the GICv2 model implemented only the physical copy of control registers. Enabling virtualization emulation to QEMU adds also the virtual copy, doubling the RegSize returned by FindCompatibleNodeReg () in ArmVirtGicArchLibConstructor (). This triggered an ASSERT when running QEMU with -M virt,virtualization=on. Address this by testing for both possible valid values of RegSize. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2588 Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Leif Lindholm <leif@nuviainc.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/PlatformBootManagerLib: switch to separate QEMU loaderArd Biesheuvel2020-03-052-1063/+7
| | | | | | | | | | Drop the QEMU loader file system implementation inside this library, and switch to the separate QemuLoadImageLib library and the associated driver to expose the kernel and initrd passed via the QEMU command line. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2566 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/PlatformBootManagerLib: sync Timeout with PcdPlatformBootTimeOutLaszlo Ersek2020-03-052-2/+26
| | | | | | | | | | | | | | | | | | Set the Timeout global variable to the same value as PcdPlatformBootTimeOut. This way the "setvar" command in the UEFI shell, and the "efibootmgr" command in a Linux guest, can report the front page timeout that was requested on the QEMU command line (see GetFrontPageTimeoutFromQemu()). A DEBUG_VERBOSE message is logged on success too, for our QE team's sake. Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Laszlo Ersek <lersek@redhat.com> Message-Id: <20200304094413.19462-3-lersek@redhat.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
* ArmVirtPkg: implement ArmVirtPsciResetSystemPeiLibArd Biesheuvel2020-03-042-0/+271
| | | | | | | | | | | | | | | Implement a ArmVirtPkg specific version of the PSCI ResetSystemLib that is usable in the PEI phase, as the existing one relies on the FDT client protocol, making it unsuitable. Note that accessing the device tree passed by QEMU via its initial base address is guaranteed to be safe at any time during the PEI phase, so we can defer discovery of the PSCI method until the time the reset library is actually invoked (which is rarely) Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2560 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/PlatformPeiLib: discover the TPM base address from the DTArd Biesheuvel2020-03-042-14/+106
| | | | | | | | | | | | | | | | | Introduce a boolean PCD that tells us whether TPM support is enabled in the build, and if it is, record the TPM base address in the existing routine that traverses the device tree in the platform PEIM. If a TPM is found, install the gOvmfTpmDiscoveredPpiGuid signalling PPI that will unlock the dispatch of OvmfPkg's Tcg2ConfigPei. If TPM2 support is enabled in the build but no TPM2 device is found, install the gPeiTpmInitializationDonePpiGuid PPI, which is normally installed by Tcg2ConfigPei if no TPM2 is found, but in our case Tcg2ConfigPei will never run so let's do it here instead. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2560 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/PlatformPeiLib: make PcdLib dependency explicit in .INFArd Biesheuvel2020-03-041-0/+1
| | | | | | | | | | | | | | We currently include PcdLib.h in PlatformPeiLib, without declaring this dependency in its .INF description. Since all the PCDs we use resolve to fixed type in practice, this does not really matter at the moment, but since we will be adding dynamic PCD references in a subsequent patch, let's make the PcdLib dependency explicit, so that its dispatch is guaranteed to be ordered correctly with respect to the provider of the dynamic PCD PPI. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2560 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg: remove EnterS3WithImmediateWake () from ResetSystemLibArd Biesheuvel2020-01-101-14/+0
| | | | | | | | EnterS3WithImmediateWake () no longer has any callers, so remove it from ResetSystemLib. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/PlatformBootManagerLib: Don't update progress if Pcd is 0Pete Batard2019-10-161-3/+11
| | | | | | | | | | | | | | | | BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2266 Similar to what we now do for OVMF, we need to consider the possibility that PlatformBootManagerWaitCallback () may be called with a PcdPlatformBootTimeOut that was set to zero, in which case the call should simply return. We also change the initial timeout variable name to make the code explicit. Signed-off-by: Pete Batard <pete@akeo.ie> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com> Message-Id: <20191014150311.16740-3-pete@akeo.ie>
* ArmVirtPkg/PlatformBootManagerLib: unload image on EFI_SECURITY_VIOLATIONLaszlo Ersek2019-09-051-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The LoadImage() boot service is a bit unusual in that it allocates resources in a particular failure case; namely, it produces a valid "ImageHandle" when it returns EFI_SECURITY_VIOLATION. This is supposed to happen e.g. when Secure Boot verification fails for the image, but the platform policy for the particular image origin (such as "fixed media" or "removable media") is DEFER_EXECUTE_ON_SECURITY_VIOLATION. The return code allows platform logic to selectively override the verification failure, and launch the image nonetheless. ArmVirtPkg/PlatformBootManagerLib does not override EFI_SECURITY_VIOLATION for the kernel image loaded from fw_cfg -- any LoadImage() error is considered fatal. When we simply treat EFI_SECURITY_VIOLATION like any other LoadImage() error, we leak the resources associated with "KernelImageHandle". From a resource usage perspective, EFI_SECURITY_VIOLATION must be considered "success", and rolled back. Implement this rollback, without breaking the proper "nesting" of error handling jumps and labels. Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Dandan Bi <dandan.bi@intel.com> Cc: Leif Lindholm <leif.lindholm@linaro.org> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1992 Fixes: 23d04b58e27b382bbd3f9b16ba9adb1cb203dad5 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Dandan Bi <dandan.bi@intel.com> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
* OvmfPkg: Move XenRealTimeClockLib from ArmVirtPkgAnthony PERARD2019-08-212-223/+0
| | | | | | | | | | | Move XenRealTimeClockLib from ArmVirtPkg to OvmfPkg so it can be used from the OvmfPkg by the following patch, "OvmfPkg/OvmfXen: use RealTimeClockRuntimeDxe from EmbeddedPkg" Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689 Signed-off-by: Anthony PERARD <anthony.perard@citrix.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Message-Id: <20190813113119.14804-35-anthony.perard@citrix.com>
* ArmVirtPkg/PlatformBootManagerLib: Use EDKII_SERIAL_PORT_LIB_VENDOR_GUIDAnthony PERARD2019-06-141-6/+2
| | | | | | | | | | | | SERIAL_DXE_FILE_GUID is now defined in MdeModulePkg as EDKII_SERIAL_PORT_LIB_VENDOR_GUID, simply use it. Signed-off-by: Anthony PERARD <anthony.perard@citrix.com> Message-Id: <20190606131459.1464-3-anthony.perard@citrix.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [lersek@redhat.com: drop "from MdeModulePkg" from the subject] Reviewed-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/ArmVirtPsciResetSystemLib: Add a new API ResetSystemZhichao Gao2019-04-281-0/+44
| | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1460 Add a new API ResetSystem to this ResetSystemLib instance. It only adds the basic functions from ResetSystemRuntimeDxe. Lacking of this interface may cause link error, if some drivers use this new API and link to this library instance. Notes: This library API only provide a basic function of reset. Full function should use the instance in the MdeModulePkg and make sure the depex driver is dispatched. Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Liming Gao <liming.gao@intel.com> Signed-off-by: Zhichao Gao <zhichao.gao@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg: Replace BSD License with BSD+Patent LicenseMichael D Kinney2019-04-0942-292/+42
| | | | | | | | | | | | | | | | | | | | https://bugzilla.tianocore.org/show_bug.cgi?id=1373 Replace BSD 2-Clause License with BSD+Patent License. This change is based on the following emails: https://lists.01.org/pipermail/edk2-devel/2019-February/036260.html https://lists.01.org/pipermail/edk2-devel/2018-October/030385.html RFCs with detailed process for the license change: V3: https://lists.01.org/pipermail/edk2-devel/2019-March/038116.html V2: https://lists.01.org/pipermail/edk2-devel/2019-March/037669.html V1: https://lists.01.org/pipermail/edk2-devel/2019-March/037500.html Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/PlatformBootManagerLib: display boot option loading/startingLaszlo Ersek2019-02-252-0/+4
| | | | | | | | | | | | | Consume PlatformBmPrintScLib, added earlier in this series. When BdsDxe+UefiBootManagerLib report LoadImage() / StartImage() preparations and return statuses, print the reports to the UEFI console. This allows end-users better visibility into the boot process. Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1515418 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
* ArmVirtPkg: Fix various typosAntoine Coeur2019-02-075-11/+11
| | | | | | | | | Fix various typos in ArmVirtPkg. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Coeur <coeur@gmx.fr> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
* ArmVirtPkg/MemoryInitPeiLib: split memory HOB based on MAX_ALLOC_ADDRESSArd Biesheuvel2018-12-201-4/+4
| | | | | | | | | | | | | | | | | | The current ArmVirtMemoryInitPeiLib code splits the memory region passed via PcdSystemMemoryBase/PcdSystemMemorySize in two if the region extends beyond the MAX_ADDRESS limit. This was introduced for 32-bit ARM, which may support more than 4 GB of physical address space, but cannot address all of it via a 1:1 mapping, and a single region that is not mappable in its entirety is unusable by the PEI core. AArch64 is in a similar situation now: platforms may support more than 256 TB of physical address space, but only 256 TB is addressable by the CPU, and so a memory region that extends from below this limit to above it should be split. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/QemuVirtMemInfoLib: trim the MMIO region mappingArd Biesheuvel2018-12-033-9/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QEMU/mach-virt is rather unhelpful when it comes to tracking down NULL pointer dereferences that occur while running in UEFI: since we have NOR flash mapped at address 0x0, inadvertent reads go unnoticed, and even most writes are silently dropped, unless you're unlucky and the instruction in question is one that KVM cannot emulate, in which case you end up with a QEMU crash like this: error: kvm run failed Function not implemented PC=000000013f7ff804 X00=000000013f7ab108 X01=0000000000000064 X02=000000013f801988 X03=00000000800003c4 X04=0000000000000000 X05=0000000096000044 X06=fffffffffffd8270 X07=000000013f7ab4a0 X08=0000000000000001 X09=000000013f803b88 X10=000000013f7e88d0 X11=0000000000000009 X12=000000013f7ab554 X13=0000000000000008 X14=0000000000000002 X15=0000000000000000 X16=0000000000000000 X17=0000000000000000 X18=0000000000000000 X19=0000000000000000 X20=000000013f81c000 X21=000000013f7ab170 X22=000000013f81c000 X23=0000000009000018 X24=000000013f407020 X25=000000013f81c000 X26=000000013f803530 X27=000000013f802000 X28=000000013f7ab270 X29=000000013f7ab0d0 X30=000000013f7fee10 SP=000000013f7a6f30 PSTATE=800003c5 N--- EL1h and a warning in the host kernel log that load/store instruction decoding is not supported by KVM. Given that the first page of the flash device is not actually used anyway, let's reduce the mappings of the peripheral space and the flash device (both of which cover page #0) to only cover what is actually required: ArmVirtQemu.fdf: > 0x00001000|0x001ff000 > gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize ArmVirtQemuKernel.fdf: > 0x00008000|0x001f8000 > gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize For ArmVirtQemu, the resulting virtual mapping looks roughly like: - [0, 4K) : flash, unmapped - [4K, 2M) : flash, mapped as WB+X RAM - [2M, 64M) : flash, unmapped - [64M, 128M) : varstore flash, will be mapped by the NOR flash driver - [128M, 256M) : peripherals, mapped as device - [256M, 1GB) : 32-bit MMIO aperture, translated IO aperture, ECAM, will be mapped by the PCI host bridge driver - [1GB, ...) : RAM, mapped. After this change, any inadvertent read or write from/to the first physical page will trigger a translation fault inside the guest, regardless of the nature of the instruction, without crashing QEMU. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/NorFlashQemuLib: disregard our primary FVArd Biesheuvel2018-12-032-2/+16
| | | | | | | | | | | | | | | | | | The primary FV contains the firmware boot image, which is not runtime updatable in our case. So exposing it to the NOR flash driver is undesirable, since it may attempt to modify the NOR flash contents. It is also rather pointless, since we don't keep anything there that we care to expose. (the SEC and PEI phase modules are not executable from DXE context, and the contents of the embedded DXE phase FV are exposed by the DXE core directly via the FVB2 protocol) So let's disregard the NOR flash block that covers the primary FV. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/XenVirtMemInfoLib: refactor reading of the PA space sizeArd Biesheuvel2018-11-294-75/+7
| | | | | | | | | | Use the new ArmLib helper to read the CPU's physical address limit so we can drop our own homecooked one. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/QemuVirtMemInfoLib: remove 1:1 mapping of top of PA rangeArd Biesheuvel2018-11-295-97/+5
| | | | | | | | | | | | | | | | | Currently, we map DRAM as EFI_MEMORY_WB, and the remainder of the entire virtual address space is mapped with EFI_MEMORY_UC attributes, regardless of whether any devices actually reside there. Now that we are relaxing the address space limit to more than 40 bits, mapping all that address space actually takes up more space in page tables than we have so far made available as temporary RAM. So let's get rid of the mapping rather than increasing the available RAM, given that the mapping is not particularly useful anyway. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/FdtPciHostBridgeLib: map ECAM and I/O spaces in GCD memory mapArd Biesheuvel2018-11-292-1/+46
| | | | | | | | | | | | | | | | | | | | Up until now, we have been getting away with not declaring the ECAM and translated I/O spaces at all in the GCD memory map, simply because we map the entire address space with device attributes in the early PEI code, and so the ECAM space will be mapped wherever it ends up. Now that we are about to make changes to how ArmVirtQemu reasons about the size of the address space, it would be better to get rid of this mapping of the entire address space, since it can get arbitrarily large without real benefit. So start by mapping the ECAM and translated I/O spaces explicitly, instead of relying on the early PEI mapping. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/NorFlashQemuLib: discover NOR flash banks dynamicallyArd Biesheuvel2018-11-262-21/+69
| | | | | | | | | | | | | | | | | | | | | | | | NorFlashQemuLib is one of the last remaining drivers in ArmVirtPkg that are not based on the device tree received from QEMU. For ArmVirtQemu, this does not really matter, given that the NOR flash banks are always the same: the PEI code is linked to execute in place from flash bank #0, and the fixed varstore PCDs refer to flash bank #1 directly. However, ArmVirtQemuKernel can execute at any offset, permitting it to be used as an intermediary loader when running QEMU with secure world emulation enabled, in which case NOR flash bank #0 is secure only and contains the secure world firmware. In this case, NorFlashQemuLib should not expose the first flash bank at all. To prevent introducing too much internal knowledge about which flash bank is accessible under which circumstances, let's switch to using the DTB to decide which flash banks to expose to the NOR flash driver. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/PlatformBDS: Implement PlatformBootManagerUnableToBootRuiyu Ni2018-07-271-1/+61
| | | | | | | | Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Julien Grall <julien.grall@linaro.org>
* ArmVirtPkg: Removing ipf which is no longer supported from edk2.chenc22018-06-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Removing rules for Ipf sources file: * Remove the source file which path with "ipf" and also listed in [Sources.IPF] section of INF file. * Remove the source file which listed in [Components.IPF] section of DSC file and not listed in any other [Components] section. * Remove the embedded Ipf code for MDE_CPU_IPF. Removing rules for Inf file: * Remove IPF from VALID_ARCHITECTURES comments. * Remove DXE_SAL_DRIVER from LIBRARY_CLASS in [Defines] section. * Remove the INF which only listed in [Components.IPF] section in DSC. * Remove statements from [BuildOptions] that provide IPF specific flags. * Remove any IPF sepcific sections. Removing rules for Dec file: * Remove [Includes.IPF] section from Dec. Removing rules for Dsc file: * Remove IPF from SUPPORTED_ARCHITECTURES in [Defines] section of DSC. * Remove any IPF specific sections. * Remove statements from [BuildOptions] that provide IPF specific flags. Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Julien Grall <julien.grall@linaro.org> Cc: Michael D Kinney <michael.d.kinney@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Chen A Chen <chen.a.chen@intel.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
* ArmVirtPkg/PlatformBootManagerLib: add missing report status code callArd Biesheuvel2018-05-292-0/+5
| | | | | | | | | | | Consumers of status code reports may rely on a status code to be reported when the ReadyToBoot event is signalled. For instance, FirmwarePerformanceDxe will fail to install the FPDT ACPI table in this case. So add the missing call. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/PlatformBootManagerLib: connect Virtio RNG devices againLaszlo Ersek2018-05-182-0/+130
| | | | | | | | | | | | | | | | | | Virtio RNG devices are never boot devices, so in commit ff1d0fbfbaec we stopped connecting them. This is a problem because an OS boot loader may depend on EFI_RNG_PROTOCOL to seed the OS's RNG. Connect Virtio RNG devices again. And, while commit ff1d0fbfbaec removed that from PlatformBootManagerAfterConsole(), reintroduce it now to PlatformBootManagerBeforeConsole() -- this way Driver#### options launched between both functions may access EFI_RNG_PROTOCOL too. Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Fixes: ff1d0fbfbaec55038ccf888759588fa4e21516f4 Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1579518 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
* ArmVirtPkg: reinstate timer unmask quirk for XenArd Biesheuvel2018-04-262-0/+179
| | | | | | | | | | | | | | | | | | | | Commit 411a373ed642 ("ArmPkg/TimerDxe: remove workaround for KVM timer handling") removed the virtual timer handling quirk that cleared the mask bit in the control register when enabling the timer, under the assumption that only ancient KVM host implementations required it. However, Julien reports that Xen also masks the timer interrupt in the guest view of the timer control register, and therefore needs the same quirk. So let's reinstate it, but using a Xen specific implementation of the timer support library, so that other virt platforms remain unchanged. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Julien Grall <julien.grall@arm.com> Acked-by: Julien Grall <julien.grall@arm.com>
* ArmVirtPkg/PlatformBootManagerLib: return to "-kernel before boot devices"Laszlo Ersek2018-03-161-8/+8
| | | | | | | | | | | | | | | | | Move the TryRunningQemuKernel() call back to its original place. This improves the UEFI boot time for VMs that have "-kernel", many disks or NICs, and no "bootindex" properties. A well-known example is guestfish/libguestfs. For more info on the TryRunningQemuKernel() location, see the following commits: 23d04b58e27b, a78c4836ea0b, 158990b941e4. Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Xiang Zheng <xiang.zheng@linaro.org> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Richard W.M. Jones <rjones@redhat.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
* ArmVirtPkg/PlatformBootManagerLib: minimize the set of connected devicesLaszlo Ersek2018-03-141-2/+10
| | | | | | | | | | | | | | Prefer ConnectDevicesFromQemu() to EfiBootManagerConnectAll(). Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: Shannon Zhao <zhaoshenglong@huawei.com> Cc: Xiang Zheng <xiang.zheng@linaro.org> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> # ArmVirtQemu Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Tested-by: Xiang Zheng <xiang.zheng@linaro.org>
* ArmVirtPkg/PlatformBootManagerLib: list "PlatformBm.h" in INF fileLaszlo Ersek2018-03-131-0/+1
| | | | | | | | | | | | | The header file declares TryRunningQemuKernel(), defined in "QemuKernel.c" and called from "PlatformBm.c". Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Suggested-by: Michael Kinney <michael.d.kinney@intel.com> Ref: http://mid.mail-archive.com/E92EE9817A31E24EB0585FDF735412F56327F7D3@ORSMSX113.amr.corp.intel.com Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
* ArmVirtPkg: remove ArmPlatformLib implementationsArd Biesheuvel2017-11-2318-1685/+0
| | | | | | | | These libraries are no longer used, so remove them from the tree. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/ArmVirtMemoryInitPeiLib: move to ArmVirtMemInfoLibArd Biesheuvel2017-11-232-3/+4
| | | | | | | | | Move to the new ArmVirtMemInfoLib library to retrieve DRAM information from the platform, so that we can phase out ArmPlatformLib going forward. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg: create QemuVirtMemInfoLib version for ArmVirtQemuArd Biesheuvel2017-11-232-0/+164
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The QemuVirtMemInfoLib ArmVirtMemInfoLib implementation created for ArmVirtQemuKernel does exactly what we need for ArmVirtQemu, the only difference being that the latter is PrePeiCore based, and so it uses a different method to ensure that PcdSystemMemorySize is set when ArmVirtGetMemoryMap() is called. On ArmVirtQemu, we currently abuse the implied ordering guarantees provided by ArmPlatformLib, by implementing this as follows: ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf [ArmVirtPkg/ArmVirtQemu.dsc] InitializeMemory() [ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c] ArmPlatformInitializeSystemMemory() [ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c] // // set PcdSystemMemorySize from the DT // MemoryPeim() [ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c] InitMmu() [ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c] ArmPlatformGetVirtualMemoryMap() [ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c] // // consume PcdSystemMemorySize // Given that we are trying to get rid of ArmPlatformLib, or at least remove some of these API functions that are never used for their original purpose by any platforms, we need to move the PCD assignment elsewhere. So create a PEIM-only version of QemuVirtMemInfoLib especially for ArmVirtQemu, and add the PCD assignment code to its constructor. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/ArmVirtQemu: add ArmVirtMemInfoLib implementationArd Biesheuvel2017-11-234-0/+217
| | | | | | | | | | | | | | | | | | | Create a new ArmVirtMemInfoLib for ArmVirtQemuKernel by cloning the existing ArmPlatformGetVirtualMemoryMap () for this platform, (ArmQemuRelocatablePlatformLib *not* ArmVirtPlatformLib), and cleaning it up: - remove support for uncached DRAM mappings - replace EFI_D_xxx with DEBUG_xxx throughout - use a temp variable to hold the top of the physical address space - use AllocatePool () instead of AllocatePages (), given that we use 160 bytes only, and the memory is never freed. In a future patch, we will add this library to the ordinary ArmVirtQemu platform as well. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg/ArmVirtXen: add ArmVirtMemInfoLib implementationArd Biesheuvel2017-11-234-0/+167
| | | | | | | | | | | | Clone the existing ArmPlatformGetVirtualMemoryMap () for this platform, clean it up slightly (by using a static buffer rather than a heap allocation, and removing the support for uncached DRAM mappings), and turn it into a new ArmVirtMemInfoLib implementation. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Julien Grall <julien.grall@linaro.org>
* ArmVirtPkg/ArmVirtPlatformLib: remove support for uncached mappingsArd Biesheuvel2017-11-231-13/+2
| | | | | | | | | | QEMU/KVM has very little tolerance for using anything except writeback cacheable mappings of DRAM, so let's remove the 'feature' that allows us to select uncached mappings at build time. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg: switch to new PL011UartLib implementationArd Biesheuvel2017-11-172-4/+2
| | | | | | | | | | Switch to the new, cleaned up PL011UartLib implementation so we will be able to remove the old one. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg: remove ArmPlatformSysConfigLib dependencyArd Biesheuvel2017-11-167-7/+6
| | | | | | | | | | | | | Now that the PL031 RTC driver library no longer depends on the ARM platform specific ArmPlatformSysConfigLib, we no longer need to implement ArmPlatform.h or have a resolution for that library. This allows us to get rid of a rather dodgy practice of including platform headers using compiler flags, which is a bad idea at various levels. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* ArmVirtPkg ArmVirtDxeHobLib: Implement BuildFv3HobStar Zeng2017-10-101-1/+35
| | | | | | | | | Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>