SecMain.c 2.7 KB

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