2015-10-26 15:58:39 +01:00
|
|
|
/** @file
|
|
|
|
OVMF support for QEMU system firmware flash device: functions specific to the
|
|
|
|
runtime DXE driver build.
|
|
|
|
|
|
|
|
Copyright (C) 2015, Red Hat, Inc.
|
|
|
|
Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
|
|
|
|
|
2019-04-04 01:06:33 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2015-10-26 15:58:39 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <Library/UefiRuntimeLib.h>
|
2020-08-12 22:21:42 +02:00
|
|
|
#include <Library/MemEncryptSevLib.h>
|
|
|
|
#include <Library/VmgExitLib.h>
|
|
|
|
#include <Register/Amd/Msr.h>
|
2015-10-26 15:58:39 +01:00
|
|
|
|
|
|
|
#include "QemuFlash.h"
|
|
|
|
|
|
|
|
VOID
|
|
|
|
QemuFlashConvertPointers (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EfiConvertPointer (0x0, (VOID **) &mFlashBase);
|
|
|
|
}
|
2018-03-09 17:06:03 +01:00
|
|
|
|
|
|
|
VOID
|
|
|
|
QemuFlashBeforeProbe (
|
|
|
|
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
|
|
|
IN UINTN FdBlockSize,
|
|
|
|
IN UINTN FdBlockCount
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Do nothing
|
|
|
|
//
|
|
|
|
}
|
2020-08-12 22:21:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Write to QEMU Flash
|
|
|
|
|
|
|
|
@param[in] Ptr Pointer to the location to write.
|
|
|
|
@param[in] Value The value to write.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
QemuFlashPtrWrite (
|
|
|
|
IN volatile UINT8 *Ptr,
|
|
|
|
IN UINT8 Value
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (MemEncryptSevEsIsEnabled ()) {
|
|
|
|
MSR_SEV_ES_GHCB_REGISTER Msr;
|
|
|
|
GHCB *Ghcb;
|
|
|
|
|
|
|
|
Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
|
|
|
|
Ghcb = Msr.Ghcb;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Writing to flash is emulated by the hypervisor through the use of write
|
|
|
|
// protection. This won't work for an SEV-ES guest because the write won't
|
|
|
|
// be recognized as a true MMIO write, which would result in the required
|
|
|
|
// #VC exception. Instead, use the the VMGEXIT MMIO write support directly
|
|
|
|
// to perform the update.
|
|
|
|
//
|
|
|
|
VmgInit (Ghcb);
|
|
|
|
Ghcb->SharedBuffer[0] = Value;
|
|
|
|
Ghcb->SaveArea.SwScratch = (UINT64) (UINTN) Ghcb->SharedBuffer;
|
2020-11-06 18:53:10 +01:00
|
|
|
VmgSetOffsetValid (Ghcb, GhcbSwScratch);
|
2020-08-12 22:21:42 +02:00
|
|
|
VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, (UINT64) (UINTN) Ptr, 1);
|
|
|
|
VmgDone (Ghcb);
|
|
|
|
} else {
|
|
|
|
*Ptr = Value;
|
|
|
|
}
|
|
|
|
}
|