1 /** @file
2   Pending Break feature.
3 
4   Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5   SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #include "CpuCommonFeatures.h"
10 
11 /**
12   Detects if Pending Break feature supported on current processor.
13 
14   @param[in]  ProcessorNumber  The index of the CPU executing this function.
15   @param[in]  CpuInfo          A pointer to the REGISTER_CPU_FEATURE_INFORMATION
16                                structure for the CPU executing this function.
17   @param[in]  ConfigData       A pointer to the configuration buffer returned
18                                by CPU_FEATURE_GET_CONFIG_DATA.  NULL if
19                                CPU_FEATURE_GET_CONFIG_DATA was not provided in
20                                RegisterCpuFeature().
21 
22   @retval TRUE     Pending Break feature is supported.
23   @retval FALSE    Pending Break feature is not supported.
24 
25   @note This service could be called by BSP/APs.
26 **/
27 BOOLEAN
28 EFIAPI
PendingBreakSupport(IN UINTN ProcessorNumber,IN REGISTER_CPU_FEATURE_INFORMATION * CpuInfo,IN VOID * ConfigData OPTIONAL)29 PendingBreakSupport (
30   IN UINTN                             ProcessorNumber,
31   IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,
32   IN VOID                              *ConfigData  OPTIONAL
33   )
34 {
35   if (IS_ATOM_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
36       IS_CORE2_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
37       IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
38       IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
39       IS_PENTIUM_M_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
40     return (CpuInfo->CpuIdVersionInfoEdx.Bits.PBE == 1);
41   }
42   return FALSE;
43 }
44 
45 /**
46   Initializes Pending Break feature to specific state.
47 
48   @param[in]  ProcessorNumber  The index of the CPU executing this function.
49   @param[in]  CpuInfo          A pointer to the REGISTER_CPU_FEATURE_INFORMATION
50                                structure for the CPU executing this function.
51   @param[in]  ConfigData       A pointer to the configuration buffer returned
52                                by CPU_FEATURE_GET_CONFIG_DATA.  NULL if
53                                CPU_FEATURE_GET_CONFIG_DATA was not provided in
54                                RegisterCpuFeature().
55   @param[in]  State            If TRUE, then the Pending Break feature must be enabled.
56                                If FALSE, then the Pending Break feature must be disabled.
57 
58   @retval RETURN_SUCCESS       Pending Break feature is initialized.
59 
60   @note This service could be called by BSP only.
61 **/
62 RETURN_STATUS
63 EFIAPI
PendingBreakInitialize(IN UINTN ProcessorNumber,IN REGISTER_CPU_FEATURE_INFORMATION * CpuInfo,IN VOID * ConfigData,OPTIONAL IN BOOLEAN State)64 PendingBreakInitialize (
65   IN UINTN                             ProcessorNumber,
66   IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,
67   IN VOID                              *ConfigData,  OPTIONAL
68   IN BOOLEAN                           State
69   )
70 {
71   //
72   // The scope of the MSR_ATOM_IA32_MISC_ENABLE is core for below processor type, only program
73   // MSR_ATOM_IA32_MISC_ENABLE for thread 0 in each core.
74   //
75   // Support function has check the processer type for this feature, no need to check again
76   // here.
77   //
78   if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
79     return RETURN_SUCCESS;
80   }
81 
82   //
83   // ATOM, CORE2, CORE, PENTIUM_4 and IS_PENTIUM_M_PROCESSOR have the same MSR index,
84   // Simply use MSR_ATOM_IA32_MISC_ENABLE here
85   //
86   CPU_REGISTER_TABLE_WRITE_FIELD (
87     ProcessorNumber,
88     Msr,
89     MSR_ATOM_IA32_MISC_ENABLE,
90     MSR_ATOM_IA32_MISC_ENABLE_REGISTER,
91     Bits.FERR,
92     (State) ? 1 : 0
93     );
94   return RETURN_SUCCESS;
95 }
96