RegisterCpuFeatures.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /** @file
  2. CPU Register Table Library definitions.
  3. Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _REGISTER_CPU_FEATURES_H_
  7. #define _REGISTER_CPU_FEATURES_H_
  8. #include <PiPei.h>
  9. #include <PiDxe.h>
  10. #include <Ppi/MpServices2.h>
  11. #include <Protocol/MpService.h>
  12. #include <Library/BaseLib.h>
  13. #include <Library/DebugLib.h>
  14. #include <Library/PcdLib.h>
  15. #include <Library/RegisterCpuFeaturesLib.h>
  16. #include <Library/BaseMemoryLib.h>
  17. #include <Library/MemoryAllocationLib.h>
  18. #include <Library/SynchronizationLib.h>
  19. #include <Library/IoLib.h>
  20. #include <Library/LocalApicLib.h>
  21. #include <AcpiCpuData.h>
  22. #define CPU_FEATURE_ENTRY_SIGNATURE SIGNATURE_32 ('C', 'F', 'E', 'S')
  23. #define CPU_FEATURE_NAME_SIZE 128
  24. typedef struct {
  25. REGISTER_CPU_FEATURE_INFORMATION CpuInfo;
  26. UINT8 *FeaturesSupportedMask;
  27. LIST_ENTRY OrderList;
  28. } CPU_FEATURES_INIT_ORDER;
  29. typedef struct {
  30. UINT32 Signature;
  31. LIST_ENTRY Link;
  32. UINT8 *FeatureMask;
  33. CHAR8 *FeatureName;
  34. CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc;
  35. CPU_FEATURE_SUPPORT SupportFunc;
  36. CPU_FEATURE_INITIALIZE InitializeFunc;
  37. UINT8 *ThreadBeforeFeatureBitMask;
  38. UINT8 *ThreadAfterFeatureBitMask;
  39. UINT8 *CoreBeforeFeatureBitMask;
  40. UINT8 *CoreAfterFeatureBitMask;
  41. UINT8 *PackageBeforeFeatureBitMask;
  42. UINT8 *PackageAfterFeatureBitMask;
  43. VOID *ConfigData;
  44. BOOLEAN BeforeAll;
  45. BOOLEAN AfterAll;
  46. } CPU_FEATURES_ENTRY;
  47. //
  48. // Flags used when program the register.
  49. //
  50. typedef struct {
  51. volatile UINTN MemoryMappedLock; // Spinlock used to program mmio
  52. volatile UINT32 *CoreSemaphoreCount; // Semaphore containers used to program Core semaphore.
  53. volatile UINT32 *PackageSemaphoreCount; // Semaphore containers used to program Package semaphore.
  54. } PROGRAM_CPU_REGISTER_FLAGS;
  55. typedef union {
  56. EFI_MP_SERVICES_PROTOCOL *Protocol;
  57. EDKII_PEI_MP_SERVICES2_PPI *Ppi;
  58. } MP_SERVICES;
  59. typedef struct {
  60. UINTN FeaturesCount;
  61. UINT32 BitMaskSize;
  62. LIST_ENTRY FeatureList;
  63. CPU_FEATURES_INIT_ORDER *InitOrder;
  64. UINT8 *CapabilityPcd;
  65. UINT8 *SettingPcd;
  66. UINT32 NumberOfCpus;
  67. ACPI_CPU_DATA *AcpiCpuData;
  68. CPU_REGISTER_TABLE *RegisterTable;
  69. CPU_REGISTER_TABLE *PreSmmRegisterTable;
  70. UINTN BspNumber;
  71. PROGRAM_CPU_REGISTER_FLAGS CpuFlags;
  72. MP_SERVICES MpService;
  73. } CPU_FEATURES_DATA;
  74. #define CPU_FEATURE_ENTRY_FROM_LINK(a) \
  75. CR ( \
  76. (a), \
  77. CPU_FEATURES_ENTRY, \
  78. Link, \
  79. CPU_FEATURE_ENTRY_SIGNATURE \
  80. )
  81. /**
  82. Worker function to get CPU_FEATURES_DATA pointer.
  83. @return Pointer to CPU_FEATURES_DATA.
  84. **/
  85. CPU_FEATURES_DATA *
  86. GetCpuFeaturesData (
  87. VOID
  88. );
  89. /**
  90. Worker function to return processor index.
  91. @param CpuFeaturesData Cpu Feature Data structure.
  92. @return The processor index.
  93. **/
  94. UINTN
  95. GetProcessorIndex (
  96. IN CPU_FEATURES_DATA *CpuFeaturesData
  97. );
  98. /**
  99. Gets detailed MP-related information on the requested processor at the
  100. instant this call is made.
  101. @param[in] ProcessorNumber The handle number of processor.
  102. @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
  103. the requested processor is deposited.
  104. @return Status of MpServices->GetProcessorInfo().
  105. **/
  106. EFI_STATUS
  107. GetProcessorInformation (
  108. IN UINTN ProcessorNumber,
  109. OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
  110. );
  111. /**
  112. Worker function to execute a caller provided function on all enabled APs.
  113. @param[in] Procedure A pointer to the function to be run on
  114. enabled APs of the system.
  115. @param[in] MpEvent A pointer to the event to be used later
  116. to check whether procedure has done.
  117. **/
  118. VOID
  119. StartupAllAPsWorker (
  120. IN EFI_AP_PROCEDURE Procedure,
  121. IN EFI_EVENT MpEvent
  122. );
  123. /**
  124. Worker function to retrieve the number of logical processor in the platform.
  125. @param[out] NumberOfCpus Pointer to the total number of logical
  126. processors in the system, including the BSP
  127. and disabled APs.
  128. @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
  129. processors that exist in system, including
  130. the BSP.
  131. **/
  132. VOID
  133. GetNumberOfProcessor (
  134. OUT UINTN *NumberOfCpus,
  135. OUT UINTN *NumberOfEnabledProcessors
  136. );
  137. /**
  138. Worker function to switch the requested AP to be the BSP from that point onward.
  139. @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
  140. **/
  141. VOID
  142. SwitchNewBsp (
  143. IN UINTN ProcessorNumber
  144. );
  145. /**
  146. Function that uses DEBUG() macros to display the contents of a a CPU feature bit mask.
  147. @param[in] FeatureMask A pointer to the CPU feature bit mask.
  148. @param[in] BitMaskSize CPU feature bits mask buffer size.
  149. **/
  150. VOID
  151. DumpCpuFeatureMask (
  152. IN UINT8 *FeatureMask,
  153. IN UINT32 BitMaskSize
  154. );
  155. /**
  156. Dump CPU feature name or CPU feature bit mask.
  157. @param[in] CpuFeature Pointer to CPU_FEATURES_ENTRY
  158. @param[in] BitMaskSize CPU feature bits mask buffer size.
  159. **/
  160. VOID
  161. DumpCpuFeature (
  162. IN CPU_FEATURES_ENTRY *CpuFeature,
  163. IN UINT32 BitMaskSize
  164. );
  165. /**
  166. Return feature dependence result.
  167. @param[in] CpuFeature Pointer to CPU feature.
  168. @param[in] Before Check before dependence or after.
  169. @param[in] NextCpuFeatureMask Pointer to next CPU feature Mask.
  170. @retval return the dependence result.
  171. **/
  172. CPU_FEATURE_DEPENDENCE_TYPE
  173. DetectFeatureScope (
  174. IN CPU_FEATURES_ENTRY *CpuFeature,
  175. IN BOOLEAN Before,
  176. IN UINT8 *NextCpuFeatureMask
  177. );
  178. /**
  179. Return feature dependence result.
  180. @param[in] CpuFeature Pointer to CPU feature.
  181. @param[in] Before Check before dependence or after.
  182. @param[in] FeatureList Pointer to CPU feature list.
  183. @retval return the dependence result.
  184. **/
  185. CPU_FEATURE_DEPENDENCE_TYPE
  186. DetectNoneNeighborhoodFeatureScope (
  187. IN CPU_FEATURES_ENTRY *CpuFeature,
  188. IN BOOLEAN Before,
  189. IN LIST_ENTRY *FeatureList
  190. );
  191. /**
  192. Programs registers for the calling processor.
  193. @param[in,out] Buffer The pointer to private data buffer.
  194. **/
  195. VOID
  196. EFIAPI
  197. SetProcessorRegister (
  198. IN OUT VOID *Buffer
  199. );
  200. /**
  201. Return ACPI_CPU_DATA data.
  202. @return Pointer to ACPI_CPU_DATA data.
  203. **/
  204. ACPI_CPU_DATA *
  205. GetAcpiCpuData (
  206. VOID
  207. );
  208. /**
  209. Worker function to get MP service pointer.
  210. @return MP_SERVICES variable.
  211. **/
  212. MP_SERVICES
  213. GetMpService (
  214. VOID
  215. );
  216. #endif