OvmfPkg/RiscVVirt: Add PlatformSecLib library

Create PlatformSecLib library to support both PEIless and PEI booting
modes.

Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
This commit is contained in:
Tuan Phan
2025-05-06 11:38:30 -07:00
committed by mergify[bot]
parent dbe17c79e7
commit 977b68aa1e
16 changed files with 621 additions and 421 deletions

View File

@@ -0,0 +1,31 @@
/** @file
Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "PlatformSecLib.h"
/**
Perform CPU initialization.
@param FdtPointer The pointer to the device tree.
@return EFI_SUCCESS The platform initialized successfully.
@retval Others - As the error code indicates
**/
EFI_STATUS
EFIAPI
CpuInitialization (
VOID *FdtPointer
)
{
//
// for MMU type >= sv39
//
BuildCpuHob (56, 32);
return EFI_SUCCESS;
}

View File

@@ -1,41 +1,39 @@
/** @file
Memory Detection for Virtual Machines.
Memory Detection for RiscVVirt Machines.
Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Module Name:
MemDetect.c
**/
//
// The package level header files this module uses
//
#include <PiPei.h>
//
// The Library classes this module consumes
//
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/FdtLib.h>
#include <Library/HobLib.h>
#include <Library/IoLib.h>
#include <Library/PcdLib.h>
#include <Library/ResourcePublicationLib.h>
#include <Library/BaseRiscVSbiLib.h>
#include <Register/RiscV64/RiscVEncoding.h>
#include <Library/PrePiLib.h>
#include <Guid/FdtHob.h>
#include "PlatformSecLib.h"
VOID
BuildMemoryTypeInformationHob (
BuildMemoryTypeHob (
VOID
);
)
{
EFI_MEMORY_TYPE_INFORMATION Info[6];
Info[0].Type = EfiACPIReclaimMemory;
Info[0].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);
Info[1].Type = EfiACPIMemoryNVS;
Info[1].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);
Info[2].Type = EfiReservedMemoryType;
Info[2].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiReservedMemoryType);
Info[3].Type = EfiRuntimeServicesData;
Info[3].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData);
Info[4].Type = EfiRuntimeServicesCode;
Info[4].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode);
// Terminator for the list
Info[5].Type = EfiMaxMemoryType;
Info[5].NumberOfPages = 0;
BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));
}
/**
Create memory range resource HOB using the memory base
@@ -235,37 +233,25 @@ AddReservedMemoryMap (
}
/**
Initialize memory hob based on the DTB information.
Perform Memory initialization.
@return EFI_SUCCESS The memory hob added successfully.
@param FdtPointer The pointer to the device tree.
@return EFI_SUCCESS The platform initialized successfully.
@retval Others - As the error code indicates
**/
EFI_STATUS
MemoryPeimInitialization (
VOID
EFIAPI
MemoryInitialization (
VOID *FdtPointer
)
{
EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext;
CONST UINT64 *RegProp;
CONST CHAR8 *Type;
UINT64 CurBase, CurSize;
INT32 Node, Prev;
INT32 Len;
VOID *FdtPointer;
FirmwareContext = NULL;
GetFirmwareContextPointer (&FirmwareContext);
if (FirmwareContext == NULL) {
DEBUG ((DEBUG_ERROR, "%a: Firmware Context is NULL\n", __func__));
return EFI_UNSUPPORTED;
}
FdtPointer = (VOID *)FirmwareContext->FlattenedDeviceTree;
if (FdtPointer == NULL) {
DEBUG ((DEBUG_ERROR, "%a: Invalid FDT pointer\n", __func__));
return EFI_UNSUPPORTED;
}
CONST UINT64 *RegProp;
CONST CHAR8 *Type;
UINT64 CurBase, CurSize;
INT32 Node, Prev;
INT32 Len;
// Look for the lowest memory node
for (Prev = 0; ; Prev = Node) {
@@ -311,7 +297,7 @@ MemoryPeimInitialization (
/* Make sure SEC is booting with bare mode */
ASSERT ((RiscVGetSupervisorAddressTranslationRegister () & SATP64_MODE) == (SATP_MODE_OFF << SATP64_MODE_SHIFT));
BuildMemoryTypeInformationHob ();
BuildMemoryTypeHob ();
return EFI_SUCCESS;
}

View File

@@ -1,25 +1,12 @@
/** @file
The library call to pass the device tree to DXE via HOB.
Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
//
//// The package level header files this module uses
////
#include <PiPei.h>
#include <Library/DebugLib.h>
#include <Library/FdtLib.h>
#include <Library/HobLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseRiscVSbiLib.h>
#include <Library/PcdLib.h>
#include <Include/Library/PrePiLib.h>
#include <Guid/FdtHob.h>
#include "PlatformSecLib.h"
/**
Build memory map I/O range resource HOB using the
@@ -80,36 +67,27 @@ PopulateIoResources (
}
/**
@retval EFI_SUCCESS The address of FDT is passed in HOB.
EFI_UNSUPPORTED Can't locate FDT.
Perform Platform initialization.
@param FdtPointer The pointer to the device tree.
@return EFI_SUCCESS The platform initialized successfully.
@retval Others - As the error code indicates
**/
EFI_STATUS
EFIAPI
PlatformPeimInitialization (
VOID
PlatformInitialization (
VOID *FdtPointer
)
{
EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext;
VOID *FdtPointer;
VOID *Base;
VOID *NewBase;
UINTN FdtSize;
UINTN FdtPages;
UINT64 *FdtHobData;
VOID *Base;
VOID *NewBase;
UINTN FdtSize;
UINTN FdtPages;
UINT64 *FdtHobData;
FirmwareContext = NULL;
GetFirmwareContextPointer (&FirmwareContext);
if (FirmwareContext == NULL) {
DEBUG ((DEBUG_ERROR, "%a: Firmware Context is NULL\n", __func__));
return EFI_UNSUPPORTED;
}
FdtPointer = (VOID *)FirmwareContext->FlattenedDeviceTree;
if (FdtPointer == NULL) {
DEBUG ((DEBUG_ERROR, "%a: Invalid FDT pointer\n", __func__));
return EFI_UNSUPPORTED;
}
SerialPortInitialize ();
DEBUG ((DEBUG_INFO, "%a: Build FDT HOB - FDT at address: 0x%x \n", __func__, FdtPointer));
Base = FdtPointer;
@@ -136,8 +114,6 @@ PlatformPeimInitialization (
*FdtHobData = (UINTN)NewBase;
BuildFvHob (PcdGet32 (PcdOvmfDxeMemFvBase), PcdGet32 (PcdOvmfDxeMemFvSize));
PopulateIoResources (Base, "ns16550a");
PopulateIoResources (Base, "qemu,fw-cfg-mmio");
PopulateIoResources (Base, "virtio,mmio");

View File

@@ -0,0 +1,341 @@
/** @file
An instance of Platform Sec Lib.
Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "PlatformSecLib.h"
typedef struct {
EFI_HOB_GUID_TYPE HobGuidHeader;
RISCV_SEC_HANDOFF_DATA SecHandoffData;
EFI_HOB_GENERIC_HEADER HobEnd;
} SEC_HOBLIST_DATA;
EFI_STATUS
EFIAPI
RiscVSecGetHobData (
IN CONST EFI_SEC_HOB_DATA_PPI *This,
OUT EFI_HOB_GENERIC_HEADER **HobList
);
STATIC EFI_SEC_HOB_DATA_PPI mSecHobDataPpi = {
RiscVSecGetHobData
};
STATIC EFI_PEI_PPI_DESCRIPTOR mPpiSecHobData = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiSecHobDataPpiGuid,
&mSecHobDataPpi
};
VOID
EFIAPI
ProcessLibraryConstructorList (
VOID
);
/**
After the SEC assembly code has initialized some temporary memory and set up
the stack, the control is transferred to this function for PEI booting.
@param SizeOfRam Size of the temporary memory available for use.
@param TempRamBase Base address of temporary ram
@param BootFirmwareVolume Base address of the Boot Firmware Volume.
**/
VOID
NORETURN
EFIAPI
SecStartup (
IN UINT32 SizeOfRam,
IN UINT32 TempRamBase,
IN VOID *BootFirmwareVolume
);
STATIC
VOID *
GetSecHobData (
VOID
)
{
return (VOID *)(FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize) - SEC_HANDOFF_DATA_RESERVE_SIZE);
}
#ifndef RISCVVIRT_PEI_BOOTING
/**
After the SEC assembly code has initialized some temporary memory and set up
the stack, the control is transferred to this function for PEIless booting.
@param SizeOfRam Size of the temporary memory available for use.
@param TempRamBase Base address of temporary ram
@param BootFirmwareVolume Base address of the Boot Firmware Volume.
**/
STATIC
VOID
NORETURN
SecPEIlessStartup (
IN UINT32 SizeOfRam,
IN UINT32 TempRamBase,
IN VOID *BootFirmwareVolume
)
{
EFI_STATUS Status;
EFI_HOB_HANDOFF_INFO_TABLE *HobList;
UINTN SecStackBase;
UINTN SecStackSize;
EFI_PEI_FILE_HANDLE FileHandle = NULL;
DEBUG ((
DEBUG_INFO,
"%a(): TempRAM Base: 0x%x, TempRAM Size: 0x%x\n",
__func__,
TempRamBase,
SizeOfRam
));
SecStackSize = SIZE_16KB;
SecStackBase = TempRamBase + SizeOfRam - SecStackSize;
//
// Initialize floating point operating environment
// to be compliant with UEFI spec.
//
InitializeFloatingPointUnits ();
//
// Setup the default exception handlers
//
Status = InitializeCpuExceptionHandlers (NULL);
ASSERT_EFI_ERROR (Status);
DEBUG ((
DEBUG_INFO,
"%a() BFV Base: 0x%p, StackBase: 0x%x, StackSize: 0x%x\n",
__func__,
BootFirmwareVolume,
SecStackBase,
SecStackSize
));
//
// Declare the temporary memory region
//
HobList = HobConstructor (
(VOID *)(UINTN)TempRamBase,
SizeOfRam,
(VOID *)(UINTN)TempRamBase,
(VOID *)SecStackBase
);
PrePeiSetHobList (HobList);
BuildStackHob (SecStackBase, SecStackSize);
//
// Initialize platform devices
//
SecPlatformMain (NULL);
//
// Process all libraries constructor function linked to SecMain.
//
ProcessLibraryConstructorList ();
//
// Decompress BFV first
//
Status = FfsFindNextFile (
EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,
(EFI_PEI_FV_HANDLE)BootFirmwareVolume,
&FileHandle
);
ASSERT_EFI_ERROR (Status);
Status = FfsProcessFvFile (FileHandle);
ASSERT_EFI_ERROR (Status);
//
// Load the DXE Core and transfer control to it
//
Status = LoadDxeCoreFromFv (NULL, 0);
ASSERT_EFI_ERROR (Status);
//
// Should not come here.
//
UNREACHABLE ();
}
#endif /* RISCVVIRT_PEI_BOOTING */
/**
Entry point to the C language phase of SEC for this platform. After the SEC assembly
code has initialized some temporary memory and set up the stack,
the control is transferred to this function.
@param BootHartId The hardware thread (Hart) ID of the current CPU.
@param DeviceTreeAddress Address of the device tree provided to the SEC phase.
@param TempRamBase Base address of the temporary memory.
@param TempRamSize Size of the temporary memory region.
**/
VOID
NORETURN
EFIAPI
SecStartupPlatform (
IN UINTN BootHartId,
IN VOID *DeviceTreeAddress,
IN UINT32 TempRamBase,
IN UINT32 TempRamSize
)
{
SEC_HOBLIST_DATA *SecHobList;
DEBUG ((
DEBUG_INFO,
"%a() BootHartId: 0x%x, DeviceTreeAddress=0x%p\n",
__func__,
BootHartId,
DeviceTreeAddress
));
//
// Set hob list data that will be passed to PEI
//
SecHobList = (SEC_HOBLIST_DATA *)GetSecHobData ();
SecHobList->SecHandoffData.BootHartId = BootHartId;
SecHobList->SecHandoffData.FdtPointer = DeviceTreeAddress;
TempRamSize -= SEC_HANDOFF_DATA_RESERVE_SIZE;
#ifdef RISCVVIRT_PEI_BOOTING
SecStartup (TempRamSize, TempRamBase, (VOID *)(UINTN)PcdGet32 (PcdOvmfDxeMemFvBase));
#else
// Default PEIless booting
SecPEIlessStartup (TempRamSize, TempRamBase, (VOID *)(UINTN)PcdGet32 (PcdOvmfDxeMemFvBase));
#endif
//
// Should not come here.
//
UNREACHABLE ();
}
/**
A developer supplied function to perform platform specific operations.
It's a developer supplied function to perform any operations appropriate to a
given platform. It's invoked just before passing control to PEI/DXE core by SEC
core. Platform developer may modify the SecCoreData passed to PEI Core.
It returns a platform specific PPI list that platform wishes to pass to PEI core.
The Generic SEC core module will merge this list to join the final list passed to
PEI core.
@param SecCoreData The same parameter as passing to PEI core. It
could be overridden by this function.
@return The platform specific PPI list to be passed to PEI core or
NULL if there is no need of such platform specific PPI list.
**/
EFI_PEI_PPI_DESCRIPTOR *
EFIAPI
SecPlatformMain (
IN OUT EFI_SEC_PEI_HAND_OFF *SecCoreData
)
{
SEC_HOBLIST_DATA *SecHobList;
const EFI_GUID SecHobDataGuid = RISCV_SEC_HANDOFF_HOB_GUID;
SecHobList = (SEC_HOBLIST_DATA *)GetSecHobData ();
if (SecCoreData == NULL) {
//
// PEIless booting, initializing platform devices now
//
SetBootMode (BOOT_WITH_FULL_CONFIGURATION);
MemoryInitialization (SecHobList->SecHandoffData.FdtPointer);
CpuInitialization (SecHobList->SecHandoffData.FdtPointer);
PlatformInitialization (SecHobList->SecHandoffData.FdtPointer);
//
// Pass Sec Hob data to DXE
//
BuildGuidDataHob (&SecHobDataGuid, &SecHobList->SecHandoffData, sizeof (SecHobList->SecHandoffData));
return NULL;
}
//
// Public our PEI PPI
//
return &mPpiSecHobData;
}
/**
This interface conveys state information out of the Security (SEC) phase into PEI.
@param PeiServices Pointer to the PEI Services Table.
@param StructureSize Pointer to the variable describing size of the input buffer.
@param PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.
@retval EFI_SUCCESS The data was successfully returned.
@retval EFI_BUFFER_TOO_SMALL The buffer was too small.
**/
EFI_STATUS
EFIAPI
SecPlatformInformation (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN OUT UINT64 *StructureSize,
OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord
)
{
//
// Not available for RISC-V
//
return EFI_SUCCESS;
}
/**
This interface disables temporary memory in SEC Phase.
**/
VOID
EFIAPI
SecPlatformDisableTemporaryMemory (
VOID
)
{
//
// Not available
//
}
EFI_STATUS
EFIAPI
RiscVSecGetHobData (
IN CONST EFI_SEC_HOB_DATA_PPI *This,
OUT EFI_HOB_GENERIC_HEADER **HobList
)
{
SEC_HOBLIST_DATA *SecHobList;
const EFI_GUID SecHobDataGuid = RISCV_SEC_HANDOFF_HOB_GUID;
SecHobList = (SEC_HOBLIST_DATA *)GetSecHobData ();
SecHobList->HobGuidHeader.Header.HobType = EFI_HOB_TYPE_GUID_EXTENSION;
SecHobList->HobGuidHeader.Header.HobLength = sizeof (SecHobList->HobGuidHeader) + sizeof (SecHobList->SecHandoffData);
SecHobList->HobGuidHeader.Header.Reserved = 0;
CopyGuid (&(SecHobList->HobGuidHeader.Name), &SecHobDataGuid);
SecHobList->HobEnd.HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
SecHobList->HobEnd.HobLength = sizeof (SecHobList->HobEnd);
SecHobList->HobEnd.Reserved = 0;
*HobList = (EFI_HOB_GENERIC_HEADER *)&(SecHobList->HobGuidHeader);
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,102 @@
/** @file
Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef PLATFORM_SEC_LIB_
#define PLATFORM_SEC_LIB_
#include <PiPei.h>
#include <Ppi/SecHobData.h>
#include <Ppi/SecPlatformInformation.h>
#include <Guid/FdtHob.h>
#include <Guid/MemoryTypeInformation.h>
#include <Guid/RiscVSecHobData.h>
#include <Register/RiscV64/RiscVImpl.h>
#include <Library/CpuLib.h>
#include <Library/CpuExceptionHandlerLib.h>
#include <Library/DebugLib.h>
#include <Library/FdtLib.h>
#include <Library/HobLib.h>
#include <Library/PlatformSecLib.h>
#include <Library/PrePiHobListPointerLib.h>
#include <Library/PcdLib.h>
#include <Library/PrePiLib.h>
#include <Library/SerialPortLib.h>
#include <Library/BaseRiscVSbiLib.h>
#include <Library/BaseMemoryLib.h>
//
// Size temporary region to store SEC handoff data for PEI
//
#define SEC_HANDOFF_DATA_RESERVE_SIZE SIZE_4KB
/**
Entry point to the C language phase of SEC for this platform. After the SEC assembly
code has initialized some temporary memory and set up the stack,
the control is transferred to this function.
@param BootHartId The hardware thread (Hart) ID of the current CPU.
@param DeviceTreeAddress Address of the device tree provided to the SEC phase.
@param TempRamBase Base address of the temporary memory.
@param TempRamSize Size of the temporary memory region.
**/
VOID
NORETURN
EFIAPI
SecStartupPlatform (
IN UINTN BootHartId,
IN VOID *DeviceTreeAddress,
IN UINT32 TempRamBase,
IN UINT32 TempRamSize
);
/**
Perform Platform initialization.
@param FdtPointer The pointer to the device tree.
@return EFI_SUCCESS The platform initialized successfully.
@retval Others - As the error code indicates
**/
EFI_STATUS
EFIAPI
PlatformInitialization (
VOID *FdtPointer
);
/**
Perform Memory initialization.
@param FdtPointer The pointer to the device tree.
@return EFI_SUCCESS Memory initialized successfully.
@retval Others - As the error code indicates
**/
EFI_STATUS
EFIAPI
MemoryInitialization (
VOID *FdtPointer
);
/**
Perform CPU initialization.
@param FdtPointer The pointer to the device tree.
@return EFI_SUCCESS CPU initialized successfully.
@retval Others - As the error code indicates
**/
EFI_STATUS
EFIAPI
CpuInitialization (
VOID *FdtPointer
);
#endif /* PLATFORM_SEC_LIB_ */

View File

@@ -0,0 +1,61 @@
## @file
# Library functions for PlatformSecLib.
#
# Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 1.30
BASE_NAME = PlatformSecLib
FILE_GUID = dddcaa5e-26e4-4922-9bcc-50e1a1bd0aac
MODULE_TYPE = SEC
VERSION_STRING = 1.0
LIBRARY_CLASS = PlatformSecLib
[Sources]
Cpu.c
Memory.c
Platform.c
PlatformSecLib.c
SecEntry.S
[LibraryClasses]
BaseLib
BaseMemoryLib
CpuExceptionHandlerLib
CpuLib
DebugLib
FdtLib
RiscVSbiLib
HobLib
StackCheckLib
PcdLib
PrePiLib
[Packages]
EmbeddedPkg/EmbeddedPkg.dec
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UefiCpuPkg/UefiCpuPkg.dec
OvmfPkg/OvmfPkg.dec
[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode
[Ppis]
gEfiSecHobDataPpiGuid
[Guids]
gFdtHobGuid
gEfiMemoryTypeInformationGuid

View File

@@ -0,0 +1,22 @@
/*
Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
*/
#include "PlatformSecLib.h"
ASM_FUNC (_ModuleEntryPoint)
/* Use Temp memory as the stack for calling to C code */
li a2, FixedPcdGet32 (PcdOvmfSecPeiTempRamBase)
li a3, FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)
/* Reserve region to store handoff data
li a4, SEC_HANDOFF_DATA_RESERVE_SIZE
sub a3, a3, a4
/* Use Temp memory as the stack for calling to C code */
add sp, a2, a3
call SecStartupPlatform

View File

@@ -148,7 +148,6 @@
PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.inf
PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf
HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf
PrePiHobListPointerLib|OvmfPkg/RiscVVirt/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf

View File

@@ -34,5 +34,5 @@ DEFINE VARS_FTW_WORKING_SIZE = 0x00040000
DEFINE VARS_FTW_SPARE_OFFSET = $(VARS_FTW_WORKING_OFFSET) + $(VARS_FTW_WORKING_SIZE)
DEFINE VARS_FTW_SPARE_SIZE = 0x00040000
SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase = 0x83FF0000
SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize = 0x00010000
SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase = 0x82000000
SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize = 0x02000000

View File

@@ -92,6 +92,8 @@
!include MdePkg/MdeLibs.dsc.inc
[LibraryClasses.common]
PlatformSecLib|OvmfPkg/RiscVVirt/Library/PlatformSecLib/PlatformSecLib.inf
# Virtio Support
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf
@@ -294,10 +296,10 @@
#
# SEC Phase modules
#
OvmfPkg/RiscVVirt/Sec/SecMain.inf {
UefiCpuPkg/SecCore/SecCoreNative.inf {
<LibraryClasses>
ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf
LzmaDecompressLib|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf
PrePiHobListPointerLib|OvmfPkg/RiscVVirt/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf

View File

@@ -247,7 +247,7 @@ READ_LOCK_CAP = TRUE
READ_LOCK_STATUS = TRUE
FvNameGuid = 27A72E80-3118-4c0c-8673-AA5B4EFA9613
INF OvmfPkg/RiscVVirt/Sec/SecMain.inf
INF UefiCpuPkg/SecCore/SecCoreNative.inf
FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

View File

@@ -1,33 +0,0 @@
/** @file
The library call to pass the device tree to DXE via HOB.
Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
//
//// The package level header files this module uses
////
#include <PiPei.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
/**
Cpu Peim initialization.
**/
EFI_STATUS
CpuPeimInitialization (
VOID
)
{
//
// for MMU type >= sv39
//
BuildCpuHob (56, 32);
return EFI_SUCCESS;
}

View File

@@ -1,18 +0,0 @@
/*
Copyright (c) 2022 Ventana Micro Systems Inc.
SPDX-License-Identifier: BSD-2-Clause-Patent
*/
#include "SecMain.h"
ASM_FUNC (_ModuleEntryPoint)
/* Use Temp memory as the stack for calling to C code */
li a4, FixedPcdGet32 (PcdOvmfSecPeiTempRamBase)
li a5, FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)
/* Use Temp memory as the stack for calling to C code */
add sp, a4, a5
call SecStartup

View File

@@ -1,110 +0,0 @@
/** @file
RISC-V SEC phase module for Qemu Virt.
Copyright (c) 2008 - 2023, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "SecMain.h"
STATIC
EFI_STATUS
EFIAPI
SecInitializePlatform (
VOID
)
{
EFI_STATUS Status;
MemoryPeimInitialization ();
CpuPeimInitialization ();
// Set the Boot Mode
SetBootMode (BOOT_WITH_FULL_CONFIGURATION);
Status = PlatformPeimInitialization ();
ASSERT_EFI_ERROR (Status);
return EFI_SUCCESS;
}
/**
Entry point to the C language phase of SEC. After the SEC assembly
code has initialized some temporary memory and set up the stack,
the control is transferred to this function.
@param[in] BootHartId Hardware thread ID of boot hart.
@param[in] DeviceTreeAddress Pointer to Device Tree (DTB)
**/
VOID
NORETURN
EFIAPI
SecStartup (
IN UINTN BootHartId,
IN VOID *DeviceTreeAddress
)
{
EFI_HOB_HANDOFF_INFO_TABLE *HobList;
EFI_RISCV_FIRMWARE_CONTEXT FirmwareContext;
EFI_STATUS Status;
UINT64 UefiMemoryBase;
UINT64 StackBase;
UINT32 StackSize;
SerialPortInitialize ();
//
// Report Status Code to indicate entering SEC core
//
DEBUG ((
DEBUG_INFO,
"%a() BootHartId: 0x%x, DeviceTreeAddress=0x%x\n",
__func__,
BootHartId,
DeviceTreeAddress
));
FirmwareContext.BootHartId = BootHartId;
FirmwareContext.FlattenedDeviceTree = (UINT64)DeviceTreeAddress;
SetFirmwareContextPointer (&FirmwareContext);
StackBase = (UINT64)FixedPcdGet32 (PcdOvmfSecPeiTempRamBase);
StackSize = FixedPcdGet32 (PcdOvmfSecPeiTempRamSize);
UefiMemoryBase = StackBase + StackSize - SIZE_32MB;
// Declare the PI/UEFI memory region
HobList = HobConstructor (
(VOID *)UefiMemoryBase,
SIZE_32MB,
(VOID *)UefiMemoryBase,
(VOID *)StackBase // The top of the UEFI Memory is reserved for the stacks
);
PrePeiSetHobList (HobList);
SecInitializePlatform ();
BuildStackHob (StackBase, StackSize);
//
// Process all libraries constructor function linked to SecMain.
//
ProcessLibraryConstructorList ();
// Assume the FV that contains the SEC (our code) also contains a compressed FV.
Status = DecompressFirstFv ();
ASSERT_EFI_ERROR (Status);
// Load the DXE Core and transfer control to it
Status = LoadDxeCoreFromFv (NULL, 0);
ASSERT_EFI_ERROR (Status);
//
// Should not come here.
//
UNREACHABLE ();
}

View File

@@ -1,91 +0,0 @@
/** @file
Master header file for SecCore.
Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef SEC_MAIN_H_
#define SEC_MAIN_H_
#include <PiPei.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugAgentLib.h>
#include <Library/DebugLib.h>
#include <Library/ExtractGuidedSectionLib.h>
#include <Library/IoLib.h>
#include <Library/HobLib.h>
#include <Library/PcdLib.h>
#include <Library/PeCoffExtraActionLib.h>
#include <Library/PeCoffGetEntryPointLib.h>
#include <Library/PeCoffLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/PeiServicesTablePointerLib.h>
#include <Library/DebugPrintErrorLevelLib.h>
#include <Library/PrintLib.h>
#include <Library/BaseRiscVSbiLib.h>
#include <Library/PrePiLib.h>
#include <Library/PlatformInitLib.h>
#include <Library/PrePiHobListPointerLib.h>
#include <Library/SerialPortLib.h>
#include <Register/RiscV64/RiscVImpl.h>
/**
Entry point to the C language phase of SEC. After the SEC assembly
code has initialized some temporary memory and set up the stack,
the control is transferred to this function.
@param SizeOfRam Size of the temporary memory available for use.
@param TempRamBase Base address of temporary ram
@param BootFirmwareVolume Base address of the Boot Firmware Volume.
**/
VOID
NORETURN
EFIAPI
SecStartup (
IN UINTN BootHartId,
IN VOID *DeviceTreeAddress
);
/**
Perform Platform PEIM initialization.
@return EFI_SUCCESS The platform initialized successfully.
@retval Others - As the error code indicates
**/
EFI_STATUS
EFIAPI
PlatformPeimInitialization (
VOID
);
/**
Perform Memory PEIM initialization.
@return EFI_SUCCESS The platform initialized successfully.
@retval Others - As the error code indicates
**/
EFI_STATUS
EFIAPI
MemoryPeimInitialization (
VOID
);
/**
Perform CPU PEIM initialization.
@return EFI_SUCCESS The platform initialized successfully.
@retval Others - As the error code indicates
**/
EFI_STATUS
EFIAPI
CpuPeimInitialization (
VOID
);
#endif

View File

@@ -1,68 +0,0 @@
## @file
# SEC Driver for RISC-V
#
# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 1.30
BASE_NAME = SecMainRiscV64
FILE_GUID = 16740C0A-AA84-4F62-A06D-AE328057AE07
MODULE_TYPE = SEC
VERSION_STRING = 1.0
ENTRY_POINT = SecMain
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = RISCV64
#
[Sources]
SecEntry.S
SecMain.c
SecMain.h
Cpu.c
Memory.c
Platform.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UefiCpuPkg/UefiCpuPkg.dec
OvmfPkg/OvmfPkg.dec
EmbeddedPkg/EmbeddedPkg.dec
[LibraryClasses]
BaseLib
DebugLib
PcdLib
IoLib
PeCoffLib
LzmaDecompressLib
RiscVSbiLib
PrePiLib
FdtLib
MemoryAllocationLib
HobLib
SerialPortLib
StackCheckLib
[Ppis]
gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED
gEfiTemporaryRamDonePpiGuid ## PRODUCES
[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress
[Guids]
gFdtHobGuid