InternalCpuCacheInfoLib.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /** @file
  2. Internal header file for CPU Cache info Library.
  3. Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _INTERNAL_CPU_CACHE_INFO_LIB_H_
  7. #define _INTERNAL_CPU_CACHE_INFO_LIB_H_
  8. #include <PiPei.h>
  9. #include <Register/Cpuid.h>
  10. #include <Ppi/MpServices2.h>
  11. #include <Protocol/MpService.h>
  12. #include <Library/BaseLib.h>
  13. #include <Library/DebugLib.h>
  14. #include <Library/BaseMemoryLib.h>
  15. #include <Library/MemoryAllocationLib.h>
  16. #include <Library/CpuCacheInfoLib.h>
  17. typedef union {
  18. struct {
  19. //
  20. // Type of the cache that this package's this type of logical processor corresponds to.
  21. // Value = CPUID.04h:EAX[04:00]
  22. //
  23. UINT32 CacheType : 5;
  24. //
  25. // Level of the cache that this package's this type of logical processor corresponds to.
  26. // Value = CPUID.04h:EAX[07:05]
  27. //
  28. UINT32 CacheLevel : 3;
  29. //
  30. // Core type of logical processor.
  31. // Value = CPUID.1Ah:EAX[31:24]
  32. //
  33. UINT32 CoreType : 8;
  34. UINT32 Reserved : 16;
  35. //
  36. // Package number.
  37. //
  38. UINT32 Package;
  39. } Bits;
  40. UINT64 Uint64;
  41. } CPU_CACHE_INFO_COMPARATOR;
  42. typedef struct {
  43. //
  44. // Package ID, the information comes from
  45. // EFI_CPU_PHYSICAL_LOCATION.Package
  46. //
  47. UINT32 Package;
  48. //
  49. // APIC ID, the information comes from
  50. // EFI_PROCESSOR_INFORMATION.ProcessorId
  51. //
  52. UINT32 ApicId;
  53. //
  54. // Core type of logical processor.
  55. // Value = CPUID.1Ah:EAX[31:24]
  56. //
  57. UINT8 CoreType;
  58. } CPUID_PROCESSOR_INFO;
  59. typedef struct {
  60. //
  61. // Level of the cache.
  62. // Value = CPUID.04h:EAX[07:05]
  63. //
  64. UINT8 CacheLevel : 3;
  65. //
  66. // Type of the cache.
  67. // Value = CPUID.04h:EAX[04:00]
  68. //
  69. UINT8 CacheType : 5;
  70. //
  71. // Ways of associativity.
  72. // Value = CPUID.04h:EBX[31:22]
  73. //
  74. UINT16 CacheWays : 10;
  75. //
  76. // Fully associative cache.
  77. // Value = CPUID.04h:EAX[09]
  78. //
  79. UINT16 FullyAssociativeCache : 1;
  80. //
  81. // Direct mapped cache.
  82. // Value = CPUID.04h:EDX[02]
  83. //
  84. UINT16 DirectMappedCache : 1;
  85. UINT16 Reserved : 4;
  86. //
  87. // Cache share bits.
  88. // Value = CPUID.04h:EAX[25:14]
  89. //
  90. UINT16 CacheShareBits;
  91. //
  92. // Size of single cache.
  93. // Value = (CPUID.04h:EBX[31:22] + 1) * (CPUID.04h:EBX[21:12] + 1) *
  94. // (CPUID.04h:EBX[11:00] + 1) * (CPUID.04h:ECX[31:00] + 1)
  95. //
  96. UINT32 CacheSizeinKB;
  97. } CPUID_CACHE_DATA;
  98. typedef union {
  99. EDKII_PEI_MP_SERVICES2_PPI *Ppi;
  100. EFI_MP_SERVICES_PROTOCOL *Protocol;
  101. } MP_SERVICES;
  102. typedef struct {
  103. MP_SERVICES MpServices;
  104. CPUID_PROCESSOR_INFO *ProcessorInfo;
  105. CPUID_CACHE_DATA *CacheData;
  106. } COLLECT_CPUID_CACHE_DATA_CONTEXT;
  107. /*
  108. Defines the maximum count of Deterministic Cache Parameters Leaf of all APs and BSP.
  109. To save boot time, skip starting up all APs to calculate each AP's count of Deterministic
  110. Cache Parameters Leaf, so use a definition instead.
  111. Anyway, definition value will be checked in CpuCacheInfoCollectCoreAndCacheData function.
  112. */
  113. #define MAX_NUM_OF_CACHE_PARAMS_LEAF 6
  114. /*
  115. Defines the maximum count of packages.
  116. */
  117. #define MAX_NUM_OF_PACKAGE 100
  118. /**
  119. Get EDKII_PEI_MP_SERVICES2_PPI or EFI_MP_SERVICES_PROTOCOL pointer.
  120. @param[out] MpServices A pointer to the buffer where EDKII_PEI_MP_SERVICES2_PPI or
  121. EFI_MP_SERVICES_PROTOCOL is stored
  122. @retval EFI_SUCCESS EDKII_PEI_MP_SERVICES2_PPI or EFI_MP_SERVICES_PROTOCOL interface is returned
  123. @retval EFI_NOT_FOUND EDKII_PEI_MP_SERVICES2_PPI or EFI_MP_SERVICES_PROTOCOL interface is not found
  124. **/
  125. EFI_STATUS
  126. CpuCacheInfoGetMpServices (
  127. OUT MP_SERVICES *MpServices
  128. );
  129. /**
  130. Activate all of the logical processors.
  131. @param[in] MpServices MP_SERVICES structure.
  132. @param[in] Procedure A pointer to the function to be run on enabled logical processors.
  133. @param[in] ProcedureArgument The parameter passed into Procedure for all enabled logical processors.
  134. **/
  135. VOID
  136. CpuCacheInfoStartupAllCPUs (
  137. IN MP_SERVICES MpServices,
  138. IN EFI_AP_PROCEDURE Procedure,
  139. IN VOID *ProcedureArgument
  140. );
  141. /**
  142. Get detailed information of the requested logical processor.
  143. @param[in] MpServices MP_SERVICES structure.
  144. @param[in] ProcessorNum The requested logical processor number.
  145. @param[out] ProcessorInfo A pointer to the buffer where the processor information is stored
  146. **/
  147. VOID
  148. CpuCacheInfoGetProcessorInfo (
  149. IN MP_SERVICES MpServices,
  150. IN UINTN ProcessorNum,
  151. OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo
  152. );
  153. /**
  154. Get the logical processor number.
  155. @param[in] MpServices MP_SERVICES structure.
  156. @retval Return the logical processor number.
  157. **/
  158. UINT32
  159. CpuCacheInfoWhoAmI (
  160. IN MP_SERVICES MpServices
  161. );
  162. /**
  163. Get the total number of logical processors in the platform.
  164. @param[in] MpServices MP_SERVICES structure.
  165. @retval Return the total number of logical processors.
  166. **/
  167. UINT32
  168. CpuCacheInfoGetNumberOfProcessors (
  169. IN MP_SERVICES MpServices
  170. );
  171. #endif