代码拉取完成,页面将自动刷新
From 9c52c4e45c2fc51308628c8118edb3740bbfae47 Mon Sep 17 00:00:00 2001
From: Liu Zixing <liuzixing@hygon.cn>
Date: Fri, 25 Feb 2022 16:12:38 +0800
Subject: [PATCH 34/46] anolis: OvmfPkg/PlatformPei: Initialize CSV VM's memory
For CSV VM, the Secure Processor builds a temporary nested
page table to help the guest to run into the PEI phase.
In PEI phase, CSV VM detects the start address and size of the
guest physical memory.
The CSV VM sends the memory information to the Secure Processor
to build the permanent nested page table.
Signed-off-by: Xin Jiang <jiangxin@hygon.cn>
Change-Id: I853d17ffa4146037038018d934f224fcbf79be1a
---
OvmfPkg/PlatformPei/Csv.c | 81 +++++++++++++++++++++++++++++
OvmfPkg/PlatformPei/MemDetect.c | 2 -
OvmfPkg/PlatformPei/Platform.c | 2 +
OvmfPkg/PlatformPei/Platform.h | 14 +++++
OvmfPkg/PlatformPei/PlatformPei.inf | 4 ++
5 files changed, 101 insertions(+), 2 deletions(-)
create mode 100644 OvmfPkg/PlatformPei/Csv.c
diff --git a/OvmfPkg/PlatformPei/Csv.c b/OvmfPkg/PlatformPei/Csv.c
new file mode 100644
index 0000000..44e81e1
--- /dev/null
+++ b/OvmfPkg/PlatformPei/Csv.c
@@ -0,0 +1,81 @@
+/** @file
+
+ CSV initialization in PEI
+
+ Copyright (c) 2022, HYGON. All rights reserved.<BR>
+
+ 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 <Library/BaseLib.h>
+#include <Uefi/UefiBaseType.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/HobLib.h>
+#include <Library/CsvLib.h>
+#include <Library/MemEncryptSevLib.h>
+
+#include "Platform.h"
+
+VOID
+CsvInitializeMemInfo (
+ VOID
+ )
+{
+ UINT64 LowerMemorySize;
+ UINT64 UpperMemorySize;
+
+ if (!CsvIsEnabled ()) {
+ return ;
+ }
+
+ LowerMemorySize = GetSystemMemorySizeBelow4gb ();
+ UpperMemorySize = GetSystemMemorySizeAbove4gb ();
+
+ CsvUpdateMapLowerMemory (
+ 0,
+ LowerMemorySize >> EFI_PAGE_SHIFT
+ );
+
+ if (UpperMemorySize > 0) {
+ CsvUpdateMapUpperMemory (
+ BASE_4GB,
+ UpperMemorySize >> EFI_PAGE_SHIFT
+ );
+ }
+
+ BuildMemoryAllocationHob (
+ (EFI_PHYSICAL_ADDRESS)(UINTN) FixedPcdGet32 (PcdCsvDefaultSecureCallBase),
+ (UINT64)(UINTN) FixedPcdGet32 (PcdCsvDefaultSecureCallSize),
+ EfiReservedMemoryType
+ );
+}
+
+VOID
+CsvInitializeGhcb (
+ VOID
+ )
+{
+ RETURN_STATUS EncryptStatus;
+
+ if (!CsvIsEnabled ()) {
+ return ;
+ }
+
+ //
+ // Encrypt the SecGhcb as it's not a Ghcb any more
+ //
+ EncryptStatus = MemEncryptSevSetPageEncMask(
+ 0,
+ PcdGet32 (PcdOvmfSecGhcbBase),
+ 1
+ );
+ ASSERT_RETURN_ERROR (EncryptStatus);
+}
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index d736b85..c2c3cf7 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -301,8 +301,6 @@ GetSystemMemorySizeBelow4gb (
return (UINT32) (((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB);
}
-
-STATIC
UINT64
GetSystemMemorySizeAbove4gb (
)
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index d0e2c08..79bf4e7 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -743,6 +743,7 @@ InitializePlatform (
QemuUc32BaseInitialization ();
InitializeRamRegions ();
+ CsvInitializeMemInfo ();
if (mBootMode != BOOT_ON_S3_RESUME) {
if (!FeaturePcdGet (PcdSmmSmramRequire)) {
@@ -757,6 +758,7 @@ InitializePlatform (
InstallClearCacheCallback ();
AmdSevInitialize ();
+ CsvInitializeGhcb ();
MiscInitialization ();
InstallFeatureControlCallback ();
diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
index 8b1d270..89c3bd8 100644
--- a/OvmfPkg/PlatformPei/Platform.h
+++ b/OvmfPkg/PlatformPei/Platform.h
@@ -102,6 +102,20 @@ AmdSevInitialize (
VOID
);
+VOID
+CsvInitializeMemInfo (
+ VOID
+);
+
+VOID
+CsvInitializeGhcb (
+ VOID
+);
+
+UINT64
+GetSystemMemorySizeAbove4gb (
+);
+
extern EFI_BOOT_MODE mBootMode;
extern BOOLEAN mS3Supported;
diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf
index 69eb3ed..cb0582c 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -33,6 +33,7 @@
MemTypeInfo.c
Platform.c
Platform.h
+ Csv.c
[Packages]
EmbeddedPkg/EmbeddedPkg.dec
@@ -62,6 +63,7 @@
MtrrLib
MemEncryptSevLib
PcdLib
+ CsvLib
[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase
@@ -119,6 +121,8 @@
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaSize
+ gUefiOvmfPkgTokenSpaceGuid.PcdCsvDefaultSecureCallBase
+ gUefiOvmfPkgTokenSpaceGuid.PcdCsvDefaultSecureCallSize
[FeaturePcd]
gUefiOvmfPkgTokenSpaceGuid.PcdCsmEnable
--
2.17.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。