DxeCpuCacheInfoLib.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /** @file
  2. Provides cache info for each package, core type, cache level and cache type.
  3. Copyright (c) 2020 Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiDxe.h>
  7. #include <Library/BaseLib.h>
  8. #include <Library/DebugLib.h>
  9. #include <Library/UefiBootServicesTableLib.h>
  10. #include <Library/CpuCacheInfoLib.h>
  11. #include <InternalCpuCacheInfoLib.h>
  12. /**
  13. Get EFI_MP_SERVICES_PROTOCOL pointer.
  14. @param[out] MpServices A pointer to the buffer where EFI_MP_SERVICES_PROTOCOL is stored
  15. @retval EFI_SUCCESS EFI_MP_SERVICES_PROTOCOL interface is returned
  16. @retval EFI_NOT_FOUND EFI_MP_SERVICES_PROTOCOL interface is not found
  17. **/
  18. EFI_STATUS
  19. CpuCacheInfoGetMpServices (
  20. OUT MP_SERVICES *MpServices
  21. )
  22. {
  23. EFI_STATUS Status;
  24. Status = gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpServices->Protocol);
  25. ASSERT_EFI_ERROR (Status);
  26. return Status;
  27. }
  28. /**
  29. Activate all of the logical processors.
  30. @param[in] MpServices MP_SERVICES structure.
  31. @param[in] Procedure A pointer to the function to be run on enabled logical processors.
  32. @param[in] ProcedureArgument The parameter passed into Procedure for all enabled logical processors.
  33. **/
  34. VOID
  35. CpuCacheInfoStartupAllCPUs (
  36. IN MP_SERVICES MpServices,
  37. IN EFI_AP_PROCEDURE Procedure,
  38. IN VOID *ProcedureArgument
  39. )
  40. {
  41. EFI_STATUS Status;
  42. Status = MpServices.Protocol->StartupAllAPs (MpServices.Protocol, Procedure, FALSE, NULL, 0, ProcedureArgument, NULL);
  43. if (Status == EFI_NOT_STARTED) {
  44. //
  45. // EFI_NOT_STARTED is returned when there is no enabled AP.
  46. // Treat this case as EFI_SUCCESS.
  47. //
  48. Status = EFI_SUCCESS;
  49. }
  50. ASSERT_EFI_ERROR (Status);
  51. Procedure (ProcedureArgument);
  52. }
  53. /**
  54. Get detailed information of the requested logical processor.
  55. @param[in] MpServices MP_SERVICES structure.
  56. @param[in] ProcessorNum The requested logical processor number.
  57. @param[out] ProcessorInfo A pointer to the buffer where the processor information is stored
  58. **/
  59. VOID
  60. CpuCacheInfoGetProcessorInfo (
  61. IN MP_SERVICES MpServices,
  62. IN UINTN ProcessorNum,
  63. OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo
  64. )
  65. {
  66. EFI_STATUS Status;
  67. Status = MpServices.Protocol->GetProcessorInfo (MpServices.Protocol, ProcessorNum, ProcessorInfo);
  68. ASSERT_EFI_ERROR (Status);
  69. }
  70. /**
  71. Get the logical processor number.
  72. @param[in] MpServices MP_SERVICES structure.
  73. @retval Return the logical processor number.
  74. **/
  75. UINT32
  76. CpuCacheInfoWhoAmI (
  77. IN MP_SERVICES MpServices
  78. )
  79. {
  80. EFI_STATUS Status;
  81. UINTN ProcessorNum;
  82. Status = MpServices.Protocol->WhoAmI (MpServices.Protocol, &ProcessorNum);
  83. ASSERT_EFI_ERROR (Status);
  84. return (UINT32)ProcessorNum;
  85. }
  86. /**
  87. Get the total number of logical processors in the platform.
  88. @param[in] MpServices MP_SERVICES structure.
  89. @retval Return the total number of logical processors.
  90. **/
  91. UINT32
  92. CpuCacheInfoGetNumberOfProcessors (
  93. IN MP_SERVICES MpServices
  94. )
  95. {
  96. EFI_STATUS Status;
  97. UINTN NumberOfProcessor;
  98. UINTN NumberOfEnabledProcessor;
  99. Status = MpServices.Protocol->GetNumberOfProcessors (MpServices.Protocol, &NumberOfProcessor, &NumberOfEnabledProcessor);
  100. ASSERT_EFI_ERROR (Status);
  101. return (UINT32)NumberOfProcessor;
  102. }