AcpiGnvsInit.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /** @file
  2. Acpi Gnvs Init Library.
  3. Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Uefi.h>
  7. #include <Library/IoLib.h>
  8. #include <Library/PciLib.h>
  9. #include <Library/DebugLib.h>
  10. #include <Library/BaseMemoryLib.h>
  11. #include <Library/UefiBootServicesTableLib.h>
  12. #include <PchAccess.h>
  13. #include <Protocol/GlobalNvsArea.h>
  14. #include <Protocol/MpService.h>
  15. /**
  16. @brief
  17. Global NVS initialize.
  18. @param[in] GlobalNvs - Pointer of Global NVS area
  19. @retval EFI_SUCCESS - Allocate Global NVS completed.
  20. @retval EFI_OUT_OF_RESOURCES - Failed to allocate required page for GNVS.
  21. **/
  22. EFI_STATUS
  23. EFIAPI
  24. AcpiGnvsInit (
  25. IN OUT VOID **GlobalNvs
  26. )
  27. {
  28. UINTN Pages;
  29. EFI_PHYSICAL_ADDRESS Address;
  30. EFI_STATUS Status;
  31. EFI_GLOBAL_NVS_AREA_PROTOCOL *GNVS;
  32. EFI_MP_SERVICES_PROTOCOL *MpService;
  33. UINTN NumberOfCPUs;
  34. UINTN NumberOfEnabledCPUs;
  35. Pages = EFI_SIZE_TO_PAGES (sizeof (EFI_GLOBAL_NVS_AREA));
  36. Address = 0xffffffff; // allocate address below 4G.
  37. Status = gBS->AllocatePages (
  38. AllocateMaxAddress,
  39. EfiACPIMemoryNVS,
  40. Pages,
  41. &Address
  42. );
  43. ASSERT_EFI_ERROR (Status);
  44. if (EFI_ERROR(Status)) {
  45. return Status;
  46. }
  47. //
  48. // Locate the MP services protocol
  49. // Find the MP Protocol. This is an MP platform, so MP protocol must be there.
  50. //
  51. Status = gBS->LocateProtocol (
  52. &gEfiMpServiceProtocolGuid,
  53. NULL,
  54. (VOID **) &MpService
  55. );
  56. ASSERT_EFI_ERROR (Status);
  57. //
  58. // Determine the number of processors
  59. //
  60. MpService->GetNumberOfProcessors (
  61. MpService,
  62. &NumberOfCPUs,
  63. &NumberOfEnabledCPUs
  64. );
  65. *GlobalNvs = (VOID *) (UINTN) Address;
  66. SetMem (*GlobalNvs, sizeof (EFI_GLOBAL_NVS_AREA), 0);
  67. //
  68. // GNVS default value init here...
  69. //
  70. GNVS = (EFI_GLOBAL_NVS_AREA_PROTOCOL *) &Address;
  71. GNVS->Area->ThreadCount = (UINT8)NumberOfEnabledCPUs;
  72. //
  73. // Miscellaneous
  74. //
  75. GNVS->Area->PL1LimitCS = 0;
  76. GNVS->Area->PL1LimitCSValue = 4500;
  77. return EFI_SUCCESS;
  78. }