MonitorMwait.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /** @file
  2. MonitorMwait feature.
  3. Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "CpuCommonFeatures.h"
  7. /**
  8. Detects if MONITOR/MWAIT feature supported on current processor.
  9. @param[in] ProcessorNumber The index of the CPU executing this function.
  10. @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
  11. structure for the CPU executing this function.
  12. @param[in] ConfigData A pointer to the configuration buffer returned
  13. by CPU_FEATURE_GET_CONFIG_DATA. NULL if
  14. CPU_FEATURE_GET_CONFIG_DATA was not provided in
  15. RegisterCpuFeature().
  16. @retval TRUE MONITOR/MWAIT feature is supported.
  17. @retval FALSE MONITOR/MWAIT feature is not supported.
  18. @note This service could be called by BSP/APs.
  19. **/
  20. BOOLEAN
  21. EFIAPI
  22. MonitorMwaitSupport (
  23. IN UINTN ProcessorNumber,
  24. IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
  25. IN VOID *ConfigData OPTIONAL
  26. )
  27. {
  28. return (CpuInfo->CpuIdVersionInfoEcx.Bits.MONITOR == 1);
  29. }
  30. /**
  31. Initializes MONITOR/MWAIT feature to specific state.
  32. @param[in] ProcessorNumber The index of the CPU executing this function.
  33. @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
  34. structure for the CPU executing this function.
  35. @param[in] ConfigData A pointer to the configuration buffer returned
  36. by CPU_FEATURE_GET_CONFIG_DATA. NULL if
  37. CPU_FEATURE_GET_CONFIG_DATA was not provided in
  38. RegisterCpuFeature().
  39. @param[in] State If TRUE, then the MONITOR/MWAIT feature must be enabled.
  40. If FALSE, then the MONITOR/MWAIT feature must be disabled.
  41. @retval RETURN_SUCCESS MONITOR/MWAIT feature is initialized.
  42. @note This service could be called by BSP only.
  43. **/
  44. RETURN_STATUS
  45. EFIAPI
  46. MonitorMwaitInitialize (
  47. IN UINTN ProcessorNumber,
  48. IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
  49. IN VOID *ConfigData OPTIONAL,
  50. IN BOOLEAN State
  51. )
  52. {
  53. //
  54. // The scope of the MSR_IA32_MISC_ENABLE is core for below processor type, only program
  55. // MSR_IA32_MISC_ENABLE for thread 0 in each core.
  56. //
  57. if (IS_CORE2_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
  58. IS_ATOM_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
  59. IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
  60. IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
  61. IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
  62. IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
  63. {
  64. if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
  65. return RETURN_SUCCESS;
  66. }
  67. }
  68. CPU_REGISTER_TABLE_WRITE_FIELD (
  69. ProcessorNumber,
  70. Msr,
  71. MSR_IA32_MISC_ENABLE,
  72. MSR_IA32_MISC_ENABLE_REGISTER,
  73. Bits.MONITOR,
  74. (State) ? 1 : 0
  75. );
  76. return RETURN_SUCCESS;
  77. }