|
@@ -1,7 +1,7 @@
|
|
|
/** @file
|
|
|
RISC-V SEC phase module.
|
|
|
|
|
|
- Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
|
|
|
+ Copyright (c) 2021-2022, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
|
|
|
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
|
|
|
@@ -28,8 +28,8 @@
|
|
|
//
|
|
|
// Indicates the boot hart (PcdBootHartId) OpenSBI initialization is done.
|
|
|
//
|
|
|
-atomic_t BootHartDone = ATOMIC_INITIALIZER(0);
|
|
|
-atomic_t NonBootHartMessageLock = ATOMIC_INITIALIZER(0);
|
|
|
+atomic_t BootHartDone = ATOMIC_INITIALIZER (0);
|
|
|
+atomic_t NonBootHartMessageLock = ATOMIC_INITIALIZER (0);
|
|
|
|
|
|
/**
|
|
|
Locates a section within a series of sections
|
|
@@ -51,34 +51,35 @@ atomic_t NonBootHartMessageLock = ATOMIC_INITIALIZER(0);
|
|
|
**/
|
|
|
EFI_STATUS
|
|
|
FindFfsSectionInstance (
|
|
|
- IN VOID *Sections,
|
|
|
- IN UINTN SizeOfSections,
|
|
|
- IN EFI_SECTION_TYPE SectionType,
|
|
|
- IN UINTN Instance,
|
|
|
- OUT EFI_COMMON_SECTION_HEADER **FoundSection
|
|
|
+ IN VOID *Sections,
|
|
|
+ IN UINTN SizeOfSections,
|
|
|
+ IN EFI_SECTION_TYPE SectionType,
|
|
|
+ IN UINTN Instance,
|
|
|
+ OUT EFI_COMMON_SECTION_HEADER **FoundSection
|
|
|
)
|
|
|
{
|
|
|
- EFI_PHYSICAL_ADDRESS CurrentAddress;
|
|
|
- UINT32 Size;
|
|
|
- EFI_PHYSICAL_ADDRESS EndOfSections;
|
|
|
- EFI_COMMON_SECTION_HEADER *Section;
|
|
|
- EFI_PHYSICAL_ADDRESS EndOfSection;
|
|
|
+ EFI_PHYSICAL_ADDRESS CurrentAddress;
|
|
|
+ UINT32 Size;
|
|
|
+ EFI_PHYSICAL_ADDRESS EndOfSections;
|
|
|
+ EFI_COMMON_SECTION_HEADER *Section;
|
|
|
+ EFI_PHYSICAL_ADDRESS EndOfSection;
|
|
|
|
|
|
//
|
|
|
// Loop through the FFS file sections within the PEI Core FFS file
|
|
|
//
|
|
|
- EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN) Sections;
|
|
|
+ EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN)Sections;
|
|
|
EndOfSections = EndOfSection + SizeOfSections;
|
|
|
- for (;;) {
|
|
|
+ for ( ; ;) {
|
|
|
if (EndOfSection == EndOfSections) {
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
CurrentAddress = (EndOfSection + 3) & ~(3ULL);
|
|
|
if (CurrentAddress >= EndOfSections) {
|
|
|
return EFI_VOLUME_CORRUPTED;
|
|
|
}
|
|
|
|
|
|
- Section = (EFI_COMMON_SECTION_HEADER*)(UINTN) CurrentAddress;
|
|
|
+ Section = (EFI_COMMON_SECTION_HEADER *)(UINTN)CurrentAddress;
|
|
|
|
|
|
Size = SECTION_SIZE (Section);
|
|
|
if (Size < sizeof (*Section)) {
|
|
@@ -122,10 +123,10 @@ FindFfsSectionInstance (
|
|
|
**/
|
|
|
EFI_STATUS
|
|
|
FindFfsSectionInSections (
|
|
|
- IN VOID *Sections,
|
|
|
- IN UINTN SizeOfSections,
|
|
|
- IN EFI_SECTION_TYPE SectionType,
|
|
|
- OUT EFI_COMMON_SECTION_HEADER **FoundSection
|
|
|
+ IN VOID *Sections,
|
|
|
+ IN UINTN SizeOfSections,
|
|
|
+ IN EFI_SECTION_TYPE SectionType,
|
|
|
+ OUT EFI_COMMON_SECTION_HEADER **FoundSection
|
|
|
)
|
|
|
{
|
|
|
return FindFfsSectionInstance (
|
|
@@ -153,18 +154,18 @@ FindFfsSectionInSections (
|
|
|
**/
|
|
|
EFI_STATUS
|
|
|
FindFfsFileAndSection (
|
|
|
- IN EFI_FIRMWARE_VOLUME_HEADER *Fv,
|
|
|
- IN EFI_FV_FILETYPE FileType,
|
|
|
- IN EFI_SECTION_TYPE SectionType,
|
|
|
- OUT EFI_COMMON_SECTION_HEADER **FoundSection
|
|
|
+ IN EFI_FIRMWARE_VOLUME_HEADER *Fv,
|
|
|
+ IN EFI_FV_FILETYPE FileType,
|
|
|
+ IN EFI_SECTION_TYPE SectionType,
|
|
|
+ OUT EFI_COMMON_SECTION_HEADER **FoundSection
|
|
|
)
|
|
|
{
|
|
|
- EFI_STATUS Status;
|
|
|
- EFI_PHYSICAL_ADDRESS CurrentAddress;
|
|
|
- EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume;
|
|
|
- EFI_FFS_FILE_HEADER *File;
|
|
|
- UINT32 Size;
|
|
|
- EFI_PHYSICAL_ADDRESS EndOfFile;
|
|
|
+ EFI_STATUS Status;
|
|
|
+ EFI_PHYSICAL_ADDRESS CurrentAddress;
|
|
|
+ EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume;
|
|
|
+ EFI_FFS_FILE_HEADER *File;
|
|
|
+ UINT32 Size;
|
|
|
+ EFI_PHYSICAL_ADDRESS EndOfFile;
|
|
|
|
|
|
DEBUG ((DEBUG_INFO, "%a: DBT FV at 0x%x\n", __FUNCTION__, Fv));
|
|
|
|
|
@@ -173,22 +174,21 @@ FindFfsFileAndSection (
|
|
|
return EFI_VOLUME_CORRUPTED;
|
|
|
}
|
|
|
|
|
|
- CurrentAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Fv;
|
|
|
+ CurrentAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Fv;
|
|
|
EndOfFirmwareVolume = CurrentAddress + Fv->FvLength;
|
|
|
|
|
|
//
|
|
|
// Loop through the FFS files in the Boot Firmware Volume
|
|
|
//
|
|
|
for (EndOfFile = CurrentAddress + Fv->HeaderLength; ; ) {
|
|
|
-
|
|
|
CurrentAddress = (EndOfFile + 7) & ~(7ULL);
|
|
|
if (CurrentAddress > EndOfFirmwareVolume) {
|
|
|
DEBUG ((DEBUG_ERROR, "%a: FV corrupted\n", __FUNCTION__));
|
|
|
return EFI_VOLUME_CORRUPTED;
|
|
|
}
|
|
|
|
|
|
- File = (EFI_FFS_FILE_HEADER*)(UINTN) CurrentAddress;
|
|
|
- Size = *(UINT32*) File->Size & 0xffffff;
|
|
|
+ File = (EFI_FFS_FILE_HEADER *)(UINTN)CurrentAddress;
|
|
|
+ Size = *(UINT32 *)File->Size & 0xffffff;
|
|
|
if (Size < (sizeof (*File) + sizeof (EFI_COMMON_SECTION_HEADER))) {
|
|
|
DEBUG ((DEBUG_ERROR, "%a: FV corrupted\n", __FUNCTION__));
|
|
|
return EFI_VOLUME_CORRUPTED;
|
|
@@ -209,19 +209,21 @@ FindFfsFileAndSection (
|
|
|
}
|
|
|
|
|
|
Status = FindFfsSectionInSections (
|
|
|
- (VOID*) (File + 1),
|
|
|
- (UINTN) EndOfFile - (UINTN) (File + 1),
|
|
|
+ (VOID *)(File + 1),
|
|
|
+ (UINTN)EndOfFile - (UINTN)(File + 1),
|
|
|
SectionType,
|
|
|
FoundSection
|
|
|
);
|
|
|
- if (!EFI_ERROR(Status)) {
|
|
|
+ if (!EFI_ERROR (Status)) {
|
|
|
DEBUG ((DEBUG_INFO, "%a: Get firmware file section\n", __FUNCTION__));
|
|
|
return Status;
|
|
|
}
|
|
|
+
|
|
|
if (Status == EFI_VOLUME_CORRUPTED) {
|
|
|
DEBUG ((DEBUG_ERROR, "%a: FV corrupted\n", __FUNCTION__));
|
|
|
return Status;
|
|
|
}
|
|
|
+
|
|
|
DEBUG ((DEBUG_INFO, "%a: Find next FFS\n", __FUNCTION__));
|
|
|
}
|
|
|
}
|
|
@@ -239,12 +241,12 @@ FindFfsFileAndSection (
|
|
|
**/
|
|
|
EFI_STATUS
|
|
|
FindPeiCoreImageBaseInFv (
|
|
|
- IN EFI_FIRMWARE_VOLUME_HEADER *Fv,
|
|
|
- OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase
|
|
|
+ IN EFI_FIRMWARE_VOLUME_HEADER *Fv,
|
|
|
+ OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase
|
|
|
)
|
|
|
{
|
|
|
- EFI_STATUS Status;
|
|
|
- EFI_COMMON_SECTION_HEADER *Section;
|
|
|
+ EFI_STATUS Status;
|
|
|
+ EFI_COMMON_SECTION_HEADER *Section;
|
|
|
|
|
|
Status = FindFfsFileAndSection (
|
|
|
Fv,
|
|
@@ -264,6 +266,7 @@ FindPeiCoreImageBaseInFv (
|
|
|
return Status;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
DEBUG ((DEBUG_INFO, "%a: PeiCoreImageBase found\n", __FUNCTION__));
|
|
|
*PeiCoreImageBase = (EFI_PHYSICAL_ADDRESS)(UINTN)(Section + 1);
|
|
|
return EFI_SUCCESS;
|
|
@@ -278,8 +281,8 @@ FindPeiCoreImageBaseInFv (
|
|
|
**/
|
|
|
VOID
|
|
|
FindPeiCoreImageBase (
|
|
|
- IN OUT EFI_FIRMWARE_VOLUME_HEADER **BootFv,
|
|
|
- OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase
|
|
|
+ IN OUT EFI_FIRMWARE_VOLUME_HEADER **BootFv,
|
|
|
+ OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase
|
|
|
)
|
|
|
{
|
|
|
*PeiCoreImageBase = 0;
|
|
@@ -301,12 +304,12 @@ FindPeiCoreImageBase (
|
|
|
**/
|
|
|
VOID
|
|
|
FindAndReportEntryPoints (
|
|
|
- IN EFI_FIRMWARE_VOLUME_HEADER **BootFirmwareVolumePtr,
|
|
|
- OUT EFI_PEI_CORE_ENTRY_POINT *PeiCoreEntryPoint
|
|
|
+ IN EFI_FIRMWARE_VOLUME_HEADER **BootFirmwareVolumePtr,
|
|
|
+ OUT EFI_PEI_CORE_ENTRY_POINT *PeiCoreEntryPoint
|
|
|
)
|
|
|
{
|
|
|
- EFI_STATUS Status;
|
|
|
- EFI_PHYSICAL_ADDRESS PeiCoreImageBase;
|
|
|
+ EFI_STATUS Status;
|
|
|
+ EFI_PHYSICAL_ADDRESS PeiCoreImageBase;
|
|
|
|
|
|
DEBUG ((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));
|
|
|
|
|
@@ -314,10 +317,11 @@ FindAndReportEntryPoints (
|
|
|
//
|
|
|
// Find PEI Core entry point
|
|
|
//
|
|
|
- Status = PeCoffLoaderGetEntryPoint ((VOID *) (UINTN) PeiCoreImageBase, (VOID**) PeiCoreEntryPoint);
|
|
|
- if (EFI_ERROR(Status)) {
|
|
|
+ Status = PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)PeiCoreImageBase, (VOID **)PeiCoreEntryPoint);
|
|
|
+ if (EFI_ERROR (Status)) {
|
|
|
*PeiCoreEntryPoint = 0;
|
|
|
}
|
|
|
+
|
|
|
DEBUG ((DEBUG_INFO, "%a: PeCoffLoaderGetEntryPoint success: %x\n", __FUNCTION__, *PeiCoreEntryPoint));
|
|
|
|
|
|
return;
|
|
@@ -341,36 +345,36 @@ FindAndReportEntryPoints (
|
|
|
**/
|
|
|
int
|
|
|
SbiEcallFirmwareHandler (
|
|
|
- IN unsigned long ExtId,
|
|
|
- IN unsigned long FuncId,
|
|
|
- IN CONST struct sbi_trap_regs *TrapRegs,
|
|
|
- OUT unsigned long *OutVal,
|
|
|
- OUT struct sbi_trap_info *OutTrap
|
|
|
+ IN unsigned long ExtId,
|
|
|
+ IN unsigned long FuncId,
|
|
|
+ IN CONST struct sbi_trap_regs *TrapRegs,
|
|
|
+ OUT unsigned long *OutVal,
|
|
|
+ OUT struct sbi_trap_info *OutTrap
|
|
|
)
|
|
|
{
|
|
|
- int Ret;
|
|
|
+ int Ret;
|
|
|
|
|
|
Ret = SBI_OK;
|
|
|
switch (FuncId) {
|
|
|
case SBI_EXT_FW_MSCRATCH_FUNC:
|
|
|
- *OutVal = (unsigned long) sbi_scratch_thishart_ptr();
|
|
|
+ *OutVal = (unsigned long)sbi_scratch_thishart_ptr ();
|
|
|
break;
|
|
|
case SBI_EXT_FW_MSCRATCH_HARTID_FUNC:
|
|
|
- *OutVal = (unsigned long) sbi_hartid_to_scratch (TrapRegs->a0);
|
|
|
+ *OutVal = (unsigned long)sbi_hartid_to_scratch (TrapRegs->a0);
|
|
|
break;
|
|
|
default:
|
|
|
Ret = SBI_ENOTSUPP;
|
|
|
DEBUG ((DEBUG_ERROR, "%a: Called SBI firmware ecall with invalid function ID\n", __FUNCTION__));
|
|
|
ASSERT (FALSE);
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
return Ret;
|
|
|
}
|
|
|
|
|
|
-struct sbi_ecall_extension FirmwareEcall = {
|
|
|
+struct sbi_ecall_extension FirmwareEcall = {
|
|
|
.extid_start = SBI_EDK2_FW_EXT,
|
|
|
- .extid_end = SBI_EDK2_FW_EXT,
|
|
|
- .handle = SbiEcallFirmwareHandler,
|
|
|
+ .extid_end = SBI_EDK2_FW_EXT,
|
|
|
+ .handle = SbiEcallFirmwareHandler,
|
|
|
};
|
|
|
|
|
|
/** Register EDK2's SBI extension with OpenSBI
|
|
@@ -388,20 +392,20 @@ RegisterFirmwareSbiExtension (
|
|
|
VOID
|
|
|
)
|
|
|
{
|
|
|
- UINTN Ret;
|
|
|
- Ret = sbi_ecall_register_extension(&FirmwareEcall);
|
|
|
+ UINTN Ret;
|
|
|
+
|
|
|
+ Ret = sbi_ecall_register_extension (&FirmwareEcall);
|
|
|
if (Ret) {
|
|
|
//
|
|
|
// Only fails if the extension ID is invalid or already is registered.
|
|
|
//
|
|
|
DEBUG ((DEBUG_ERROR, "Failed to register SBI Firmware Extension for EDK2\n"));
|
|
|
- ASSERT(FALSE);
|
|
|
+ ASSERT (FALSE);
|
|
|
}
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/** Transion from SEC phase to PEI phase.
|
|
|
|
|
|
This function transits to S-mode PEI phase from M-mode SEC phase.
|
|
@@ -413,24 +417,24 @@ RegisterFirmwareSbiExtension (
|
|
|
VOID
|
|
|
EFIAPI
|
|
|
PeiCore (
|
|
|
- IN UINTN BootHartId,
|
|
|
- IN struct sbi_scratch *Scratch
|
|
|
+ IN UINTN BootHartId,
|
|
|
+ IN struct sbi_scratch *Scratch
|
|
|
)
|
|
|
{
|
|
|
- EFI_SEC_PEI_HAND_OFF SecCoreData;
|
|
|
- EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;
|
|
|
- EFI_FIRMWARE_VOLUME_HEADER *BootFv;
|
|
|
- EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT FirmwareContext;
|
|
|
- struct sbi_platform *ThisSbiPlatform;
|
|
|
+ EFI_SEC_PEI_HAND_OFF SecCoreData;
|
|
|
+ EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;
|
|
|
+ EFI_FIRMWARE_VOLUME_HEADER *BootFv;
|
|
|
+ EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT FirmwareContext;
|
|
|
+ struct sbi_platform *ThisSbiPlatform;
|
|
|
|
|
|
- BootFv = (EFI_FIRMWARE_VOLUME_HEADER *)FixedPcdGet32(PcdRiscVPeiFvBase);
|
|
|
+ BootFv = (EFI_FIRMWARE_VOLUME_HEADER *)FixedPcdGet32 (PcdRiscVPeiFvBase);
|
|
|
FindAndReportEntryPoints (&BootFv, &PeiCoreEntryPoint);
|
|
|
|
|
|
- SecCoreData.DataSize = sizeof(EFI_SEC_PEI_HAND_OFF);
|
|
|
+ SecCoreData.DataSize = sizeof (EFI_SEC_PEI_HAND_OFF);
|
|
|
SecCoreData.BootFirmwareVolumeBase = BootFv;
|
|
|
- SecCoreData.BootFirmwareVolumeSize = (UINTN) BootFv->FvLength;
|
|
|
- SecCoreData.TemporaryRamBase = (VOID*)(UINT64) FixedPcdGet32(PcdTemporaryRamBase);
|
|
|
- SecCoreData.TemporaryRamSize = (UINTN) FixedPcdGet32(PcdTemporaryRamSize);
|
|
|
+ SecCoreData.BootFirmwareVolumeSize = (UINTN)BootFv->FvLength;
|
|
|
+ SecCoreData.TemporaryRamBase = (VOID *)(UINT64)FixedPcdGet32 (PcdTemporaryRamBase);
|
|
|
+ SecCoreData.TemporaryRamSize = (UINTN)FixedPcdGet32 (PcdTemporaryRamSize);
|
|
|
SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;
|
|
|
SecCoreData.PeiTemporaryRamSize = SecCoreData.TemporaryRamSize >> 1;
|
|
|
SecCoreData.StackBase = (UINT8 *)SecCoreData.TemporaryRamBase + (SecCoreData.TemporaryRamSize >> 1);
|
|
@@ -442,21 +446,26 @@ PeiCore (
|
|
|
// temporary RAM migration.
|
|
|
//
|
|
|
ZeroMem ((VOID *)&FirmwareContext, sizeof (EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT));
|
|
|
- ThisSbiPlatform = (struct sbi_platform *)sbi_platform_ptr(Scratch);
|
|
|
+ ThisSbiPlatform = (struct sbi_platform *)sbi_platform_ptr (Scratch);
|
|
|
if (ThisSbiPlatform->opensbi_version > OPENSBI_VERSION) {
|
|
|
- DEBUG ((DEBUG_ERROR, "%a: OpenSBI platform table version 0x%x is newer than OpenSBI version 0x%x.\n"
|
|
|
- "There maybe be some backward compatable issues.\n",
|
|
|
- __FUNCTION__,
|
|
|
- ThisSbiPlatform->opensbi_version,
|
|
|
- OPENSBI_VERSION
|
|
|
- ));
|
|
|
- ASSERT(FALSE);
|
|
|
+ DEBUG ((
|
|
|
+ DEBUG_ERROR,
|
|
|
+ "%a: OpenSBI platform table version 0x%x is newer than OpenSBI version 0x%x.\n"
|
|
|
+ "There maybe be some backward compatable issues.\n",
|
|
|
+ __FUNCTION__,
|
|
|
+ ThisSbiPlatform->opensbi_version,
|
|
|
+ OPENSBI_VERSION
|
|
|
+ ));
|
|
|
+ ASSERT (FALSE);
|
|
|
}
|
|
|
- DEBUG ((DEBUG_INFO, "%a: OpenSBI platform table at address: 0x%x\nFirmware Context is located at 0x%x\n",
|
|
|
- __FUNCTION__,
|
|
|
- ThisSbiPlatform,
|
|
|
- &FirmwareContext
|
|
|
- ));
|
|
|
+
|
|
|
+ DEBUG ((
|
|
|
+ DEBUG_INFO,
|
|
|
+ "%a: OpenSBI platform table at address: 0x%x\nFirmware Context is located at 0x%x\n",
|
|
|
+ __FUNCTION__,
|
|
|
+ ThisSbiPlatform,
|
|
|
+ &FirmwareContext
|
|
|
+ ));
|
|
|
ThisSbiPlatform->firmware_context = (unsigned long)&FirmwareContext;
|
|
|
|
|
|
//
|
|
@@ -481,7 +490,7 @@ PeiCore (
|
|
|
Scratch->next_addr = (UINTN)(PeiCoreEntryPoint);
|
|
|
Scratch->next_mode = PRV_S;
|
|
|
DEBUG ((DEBUG_INFO, "%a: Initializing OpenSBI library for booting hart %d\n", __FUNCTION__, BootHartId));
|
|
|
- sbi_init(Scratch);
|
|
|
+ sbi_init (Scratch);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -498,8 +507,8 @@ PeiCore (
|
|
|
VOID
|
|
|
EFIAPI
|
|
|
LaunchPeiCore (
|
|
|
- IN UINTN ThisHartId,
|
|
|
- IN struct sbi_scratch *Scratch
|
|
|
+ IN UINTN ThisHartId,
|
|
|
+ IN struct sbi_scratch *Scratch
|
|
|
)
|
|
|
{
|
|
|
RegisterFirmwareSbiExtension ();
|
|
@@ -522,14 +531,14 @@ LaunchPeiCore (
|
|
|
VOID
|
|
|
EFIAPI
|
|
|
RiscVOpenSbiHartSwitchMode (
|
|
|
- IN UINTN FuncArg0,
|
|
|
- IN UINTN FuncArg1,
|
|
|
- IN UINTN NextAddr,
|
|
|
- IN UINTN NextMode,
|
|
|
- IN BOOLEAN NextVirt
|
|
|
+ IN UINTN FuncArg0,
|
|
|
+ IN UINTN FuncArg1,
|
|
|
+ IN UINTN NextAddr,
|
|
|
+ IN UINTN NextMode,
|
|
|
+ IN BOOLEAN NextVirt
|
|
|
)
|
|
|
{
|
|
|
- sbi_hart_switch_mode(FuncArg0, FuncArg1, NextAddr, NextMode, NextVirt);
|
|
|
+ sbi_hart_switch_mode (FuncArg0, FuncArg1, NextAddr, NextMode, NextVirt);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -543,34 +552,37 @@ GetDeviceTreeAddress (
|
|
|
VOID
|
|
|
)
|
|
|
{
|
|
|
- EFI_STATUS Status;
|
|
|
- EFI_COMMON_SECTION_HEADER *FoundSection;
|
|
|
+ EFI_STATUS Status;
|
|
|
+ EFI_COMMON_SECTION_HEADER *FoundSection;
|
|
|
|
|
|
if (FixedPcdGet32 (PcdDeviceTreeAddress)) {
|
|
|
- DEBUG ((DEBUG_INFO, "Use fixed address of DBT from PcdDeviceTreeAddress 0x%x 0x%x.\n", FixedPcdGet32 (PcdDeviceTreeAddress), *((unsigned long *)FixedPcdGet32 (PcdDeviceTreeAddress))));
|
|
|
- //
|
|
|
- // Device tree address is pointed by PcdDeviceTreeAddress.
|
|
|
- //
|
|
|
- return (VOID *)*((unsigned long *)FixedPcdGet32 (PcdDeviceTreeAddress));
|
|
|
+ DEBUG ((DEBUG_INFO, "Use fixed address of DBT from PcdDeviceTreeAddress 0x%x 0x%x.\n", FixedPcdGet32 (PcdDeviceTreeAddress), *((unsigned long *)FixedPcdGet32 (PcdDeviceTreeAddress))));
|
|
|
+ //
|
|
|
+ // Device tree address is pointed by PcdDeviceTreeAddress.
|
|
|
+ //
|
|
|
+ return (VOID *)*((unsigned long *)FixedPcdGet32 (PcdDeviceTreeAddress));
|
|
|
} else if (FixedPcdGet32 (PcdRiscVDtbFvBase)) {
|
|
|
- DEBUG ((DEBUG_INFO, "Use DBT FV\n"));
|
|
|
- Status = FindFfsFileAndSection (
|
|
|
- (EFI_FIRMWARE_VOLUME_HEADER *)FixedPcdGet32 (PcdRiscVDtbFvBase),
|
|
|
- EFI_FV_FILETYPE_FREEFORM,
|
|
|
- EFI_SECTION_RAW,
|
|
|
- &FoundSection
|
|
|
- );
|
|
|
- if (EFI_ERROR(Status)) {
|
|
|
- return NULL;
|
|
|
- }
|
|
|
- FoundSection ++;
|
|
|
- return (VOID *)FoundSection;
|
|
|
+ DEBUG ((DEBUG_INFO, "Use DBT FV\n"));
|
|
|
+ Status = FindFfsFileAndSection (
|
|
|
+ (EFI_FIRMWARE_VOLUME_HEADER *)FixedPcdGet32 (PcdRiscVDtbFvBase),
|
|
|
+ EFI_FV_FILETYPE_FREEFORM,
|
|
|
+ EFI_SECTION_RAW,
|
|
|
+ &FoundSection
|
|
|
+ );
|
|
|
+ if (EFI_ERROR (Status)) {
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ FoundSection++;
|
|
|
+ return (VOID *)FoundSection;
|
|
|
} else {
|
|
|
- DEBUG ((DEBUG_ERROR, "Must use DTB either from memory or compiled in FW. PCDs configured incorrectly.\n"));
|
|
|
- ASSERT (FALSE);
|
|
|
+ DEBUG ((DEBUG_ERROR, "Must use DTB either from memory or compiled in FW. PCDs configured incorrectly.\n"));
|
|
|
+ ASSERT (FALSE);
|
|
|
}
|
|
|
+
|
|
|
return NULL;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
Overwrite hart_index2id array if platform would like to use the
|
|
|
bootable harts other than those declared in Device Tree
|
|
@@ -580,21 +592,22 @@ GetDeviceTreeAddress (
|
|
|
**/
|
|
|
VOID
|
|
|
Edk2PlatformHartIndex2Id (
|
|
|
- IN struct sbi_platform *SbiPlatform
|
|
|
+ IN struct sbi_platform *SbiPlatform
|
|
|
)
|
|
|
{
|
|
|
- UINT32 Index;
|
|
|
- UINT32 *HartIndexToId;
|
|
|
- UINT32 BootableHartCount;
|
|
|
- UINT8 *PlatformHartIndex2IdArray;
|
|
|
+ UINT32 Index;
|
|
|
+ UINT32 *HartIndexToId;
|
|
|
+ UINT32 BootableHartCount;
|
|
|
+ UINT8 *PlatformHartIndex2IdArray;
|
|
|
|
|
|
- BootableHartCount = FixedPcdGet32(PcdBootableHartNumber);
|
|
|
+ BootableHartCount = FixedPcdGet32 (PcdBootableHartNumber);
|
|
|
if (BootableHartCount != 0) {
|
|
|
- HartIndexToId = (UINT32 *)SbiPlatform->hart_index2id;
|
|
|
+ HartIndexToId = (UINT32 *)SbiPlatform->hart_index2id;
|
|
|
PlatformHartIndex2IdArray = (UINT8 *)FixedPcdGetPtr (PcdBootableHartIndexToId);
|
|
|
for (Index = 0; Index < BootableHartCount; Index++) {
|
|
|
*(HartIndexToId + Index) = (UINT32)(*(PlatformHartIndex2IdArray + Index));
|
|
|
}
|
|
|
+
|
|
|
SbiPlatform->hart_count = BootableHartCount;
|
|
|
}
|
|
|
}
|
|
@@ -631,51 +644,53 @@ Edk2PlatformHartIndex2Id (
|
|
|
**/
|
|
|
VOID
|
|
|
EFIAPI
|
|
|
-SecCoreStartUpWithStack(
|
|
|
- IN UINTN HartId,
|
|
|
- IN struct sbi_scratch *Scratch
|
|
|
+SecCoreStartUpWithStack (
|
|
|
+ IN UINTN HartId,
|
|
|
+ IN struct sbi_scratch *Scratch
|
|
|
)
|
|
|
{
|
|
|
- UINT32 HardIndex;
|
|
|
- UINT64 BootHartDoneSbiInit;
|
|
|
- UINT64 NonBootHartMessageLockValue;
|
|
|
- struct sbi_platform *ThisSbiPlatform;
|
|
|
- EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *HartFirmwareContext;
|
|
|
+ UINT32 HardIndex;
|
|
|
+ UINT64 BootHartDoneSbiInit;
|
|
|
+ UINT64 NonBootHartMessageLockValue;
|
|
|
+ struct sbi_platform *ThisSbiPlatform;
|
|
|
+ EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *HartFirmwareContext;
|
|
|
|
|
|
- //DEBUG ((DEBUG_INFO, "HART ID: 0x%x enter SecCoreStartUpWithStack\n", HartId));
|
|
|
+ // DEBUG ((DEBUG_INFO, "HART ID: 0x%x enter SecCoreStartUpWithStack\n", HartId));
|
|
|
|
|
|
//
|
|
|
// Setup EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC for each hart.
|
|
|
//
|
|
|
- HartFirmwareContext = (EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *)((UINT8 *)Scratch - FIRMWARE_CONTEXT_HART_SPECIFIC_SIZE);
|
|
|
- HartFirmwareContext->IsaExtensionSupported = RiscVReadMachineIsa ();
|
|
|
+ HartFirmwareContext = (EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *)((UINT8 *)Scratch - FIRMWARE_CONTEXT_HART_SPECIFIC_SIZE);
|
|
|
+ HartFirmwareContext->IsaExtensionSupported = RiscVReadMachineIsa ();
|
|
|
HartFirmwareContext->MachineVendorId.Value64_L = RiscVReadMachineVendorId ();
|
|
|
HartFirmwareContext->MachineVendorId.Value64_H = 0;
|
|
|
- HartFirmwareContext->MachineArchId.Value64_L = RiscVReadMachineArchitectureId ();
|
|
|
- HartFirmwareContext->MachineArchId.Value64_H = 0;
|
|
|
- HartFirmwareContext->MachineImplId.Value64_L = RiscVReadMachineImplementId ();
|
|
|
- HartFirmwareContext->MachineImplId.Value64_H = 0;
|
|
|
- HartFirmwareContext->HartSwitchMode = RiscVOpenSbiHartSwitchMode;
|
|
|
+ HartFirmwareContext->MachineArchId.Value64_L = RiscVReadMachineArchitectureId ();
|
|
|
+ HartFirmwareContext->MachineArchId.Value64_H = 0;
|
|
|
+ HartFirmwareContext->MachineImplId.Value64_L = RiscVReadMachineImplementId ();
|
|
|
+ HartFirmwareContext->MachineImplId.Value64_H = 0;
|
|
|
+ HartFirmwareContext->HartSwitchMode = RiscVOpenSbiHartSwitchMode;
|
|
|
|
|
|
//
|
|
|
// Hook platform_ops with EDK2 one. Thus we can have interface
|
|
|
// call out to OEM EDK2 platform code in M-mode before switching
|
|
|
// to S-mode in opensbi init.
|
|
|
//
|
|
|
- ThisSbiPlatform = (struct sbi_platform *)sbi_platform_ptr(Scratch);
|
|
|
+ ThisSbiPlatform = (struct sbi_platform *)sbi_platform_ptr (Scratch);
|
|
|
ThisSbiPlatform->platform_ops_addr = (unsigned long)&Edk2OpensbiPlatformOps;
|
|
|
- Scratch->next_arg1 = (unsigned long)GetDeviceTreeAddress ();
|
|
|
- if (HartId == FixedPcdGet32(PcdBootHartId)) {
|
|
|
+ Scratch->next_arg1 = (unsigned long)GetDeviceTreeAddress ();
|
|
|
+ if (HartId == FixedPcdGet32 (PcdBootHartId)) {
|
|
|
if (Scratch->next_arg1 == (unsigned long)NULL) {
|
|
|
DEBUG ((DEBUG_ERROR, "Platform Device Tree is not found on boot hart\n"));
|
|
|
ASSERT (FALSE);
|
|
|
}
|
|
|
+
|
|
|
DEBUG ((DEBUG_INFO, "Device Tree at 0x%x\n", Scratch->next_arg1));
|
|
|
DEBUG ((DEBUG_INFO, "HART number: 0x%x\n", ThisSbiPlatform->hart_count));
|
|
|
DEBUG ((DEBUG_INFO, "HART index to HART ID:\n"));
|
|
|
- for (HardIndex = 0; HardIndex < ThisSbiPlatform->hart_count; HardIndex ++) {
|
|
|
- DEBUG ((DEBUG_INFO, " Index: %d -> Hard ID: %x\n", HardIndex, ThisSbiPlatform->hart_index2id [HardIndex]));
|
|
|
+ for (HardIndex = 0; HardIndex < ThisSbiPlatform->hart_count; HardIndex++) {
|
|
|
+ DEBUG ((DEBUG_INFO, " Index: %d -> Hard ID: %x\n", HardIndex, ThisSbiPlatform->hart_index2id[HardIndex]));
|
|
|
}
|
|
|
+
|
|
|
LaunchPeiCore (HartId, Scratch);
|
|
|
}
|
|
|
|
|
@@ -693,25 +708,26 @@ SecCoreStartUpWithStack(
|
|
|
CpuPause ();
|
|
|
} while (BootHartDoneSbiInit != (UINT64)TRUE);
|
|
|
|
|
|
- NonBootHartMessageLockValue = atomic_xchg(&NonBootHartMessageLock, TRUE);
|
|
|
+ NonBootHartMessageLockValue = atomic_xchg (&NonBootHartMessageLock, TRUE);
|
|
|
while (NonBootHartMessageLockValue == TRUE) {
|
|
|
CpuPause ();
|
|
|
CpuPause ();
|
|
|
CpuPause ();
|
|
|
- NonBootHartMessageLockValue = atomic_xchg(&NonBootHartMessageLock, TRUE);
|
|
|
- };
|
|
|
- DEBUG((DEBUG_INFO, "%a: Non boot hart %d initialization.\n", __FUNCTION__, HartId));
|
|
|
+ NonBootHartMessageLockValue = atomic_xchg (&NonBootHartMessageLock, TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ DEBUG ((DEBUG_INFO, "%a: Non boot hart %d initialization.\n", __FUNCTION__, HartId));
|
|
|
if (Scratch->next_arg1 == (unsigned long)NULL) {
|
|
|
DEBUG ((DEBUG_ERROR, "Platform Device Tree is not found\n"));
|
|
|
ASSERT (FALSE);
|
|
|
}
|
|
|
- DEBUG((DEBUG_INFO, "%a: Non boot hart %d DTB is at 0x%x.\n", __FUNCTION__, HartId, Scratch->next_arg1));
|
|
|
- NonBootHartMessageLockValue = atomic_xchg(&NonBootHartMessageLock, FALSE);
|
|
|
+
|
|
|
+ DEBUG ((DEBUG_INFO, "%a: Non boot hart %d DTB is at 0x%x.\n", __FUNCTION__, HartId, Scratch->next_arg1));
|
|
|
+ NonBootHartMessageLockValue = atomic_xchg (&NonBootHartMessageLock, FALSE);
|
|
|
//
|
|
|
// Non boot hart wiil be halted waiting for SBI_HART_STARTING.
|
|
|
// Use HSM ecall to start non boot hart (SBI_EXT_HSM_HART_START) later on,
|
|
|
//
|
|
|
Scratch->next_mode = PRV_S;
|
|
|
- sbi_init(Scratch);
|
|
|
+ sbi_init (Scratch);
|
|
|
}
|
|
|
-
|