]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/RiscVVirt/Sec/SecMain.c
OvmfPkg/RiscVVirt: Add Stack HOB
[mirror_edk2.git] / OvmfPkg / RiscVVirt / Sec / SecMain.c
1 /** @file
2 RISC-V SEC phase module for Qemu Virt.
3
4 Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include "SecMain.h"
12
13 STATIC
14 EFI_STATUS
15 EFIAPI
16 SecInitializePlatform (
17 VOID
18 )
19 {
20 EFI_STATUS Status;
21
22 MemoryPeimInitialization ();
23
24 CpuPeimInitialization ();
25
26 // Set the Boot Mode
27 SetBootMode (BOOT_WITH_FULL_CONFIGURATION);
28
29 Status = PlatformPeimInitialization ();
30 ASSERT_EFI_ERROR (Status);
31
32 return EFI_SUCCESS;
33 }
34
35 /**
36
37 Entry point to the C language phase of SEC. After the SEC assembly
38 code has initialized some temporary memory and set up the stack,
39 the control is transferred to this function.
40
41
42 @param[in] BootHartId Hardware thread ID of boot hart.
43 @param[in] DeviceTreeAddress Pointer to Device Tree (DTB)
44 **/
45 VOID
46 NORETURN
47 EFIAPI
48 SecStartup (
49 IN UINTN BootHartId,
50 IN VOID *DeviceTreeAddress
51 )
52 {
53 EFI_HOB_HANDOFF_INFO_TABLE *HobList;
54 EFI_RISCV_FIRMWARE_CONTEXT FirmwareContext;
55 EFI_STATUS Status;
56 UINT64 UefiMemoryBase;
57 UINT64 StackBase;
58 UINT32 StackSize;
59
60 //
61 // Report Status Code to indicate entering SEC core
62 //
63 DEBUG ((
64 DEBUG_INFO,
65 "%a() BootHartId: 0x%x, DeviceTreeAddress=0x%x\n",
66 __FUNCTION__,
67 BootHartId,
68 DeviceTreeAddress
69 ));
70
71 FirmwareContext.BootHartId = BootHartId;
72 FirmwareContext.FlattenedDeviceTree = (UINT64)DeviceTreeAddress;
73 SetFirmwareContextPointer (&FirmwareContext);
74
75 StackBase = (UINT64)FixedPcdGet32 (PcdOvmfSecPeiTempRamBase);
76 StackSize = FixedPcdGet32 (PcdOvmfSecPeiTempRamSize);
77 UefiMemoryBase = StackBase + StackSize - SIZE_32MB;
78
79 // Declare the PI/UEFI memory region
80 HobList = HobConstructor (
81 (VOID *)UefiMemoryBase,
82 SIZE_32MB,
83 (VOID *)UefiMemoryBase,
84 (VOID *)StackBase // The top of the UEFI Memory is reserved for the stacks
85 );
86 PrePeiSetHobList (HobList);
87
88 SecInitializePlatform ();
89
90 BuildStackHob (StackBase, StackSize);
91
92 //
93 // Process all libraries constructor function linked to SecMain.
94 //
95 ProcessLibraryConstructorList ();
96
97 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
98 Status = DecompressFirstFv ();
99 ASSERT_EFI_ERROR (Status);
100
101 // Load the DXE Core and transfer control to it
102 Status = LoadDxeCoreFromFv (NULL, 0);
103 ASSERT_EFI_ERROR (Status);
104 //
105 // Should not come here.
106 //
107 UNREACHABLE ();
108 }