1 | /** @file
|
---|
2 | X2Apic feature.
|
---|
3 |
|
---|
4 | Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
---|
5 | This program and the accompanying materials
|
---|
6 | are licensed and made available under the terms and conditions of the BSD License
|
---|
7 | which accompanies this distribution. The full text of the license may be found at
|
---|
8 | http://opensource.org/licenses/bsd-license.php
|
---|
9 |
|
---|
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
12 |
|
---|
13 | **/
|
---|
14 |
|
---|
15 | #include "CpuCommonFeatures.h"
|
---|
16 |
|
---|
17 | /**
|
---|
18 | Prepares for the data used by CPU feature detection and initialization.
|
---|
19 |
|
---|
20 | @param[in] NumberOfProcessors The number of CPUs in the platform.
|
---|
21 |
|
---|
22 | @return Pointer to a buffer of CPU related configuration data.
|
---|
23 |
|
---|
24 | @note This service could be called by BSP only.
|
---|
25 | **/
|
---|
26 | VOID *
|
---|
27 | EFIAPI
|
---|
28 | X2ApicGetConfigData (
|
---|
29 | IN UINTN NumberOfProcessors
|
---|
30 | )
|
---|
31 | {
|
---|
32 | BOOLEAN *ConfigData;
|
---|
33 |
|
---|
34 | ConfigData = AllocateZeroPool (sizeof (BOOLEAN) * NumberOfProcessors);
|
---|
35 | ASSERT (ConfigData != NULL);
|
---|
36 | return ConfigData;
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | Detects if X2Apci feature supported on current processor.
|
---|
41 |
|
---|
42 | Detect if X2Apci has been already enabled.
|
---|
43 |
|
---|
44 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
45 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
46 | structure for the CPU executing this function.
|
---|
47 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
48 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
49 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
50 | RegisterCpuFeature().
|
---|
51 |
|
---|
52 | @retval TRUE X2Apci feature is supported.
|
---|
53 | @retval FALSE X2Apci feature is not supported.
|
---|
54 |
|
---|
55 | @note This service could be called by BSP/APs.
|
---|
56 | **/
|
---|
57 | BOOLEAN
|
---|
58 | EFIAPI
|
---|
59 | X2ApicSupport (
|
---|
60 | IN UINTN ProcessorNumber,
|
---|
61 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
62 | IN VOID *ConfigData OPTIONAL
|
---|
63 | )
|
---|
64 | {
|
---|
65 | BOOLEAN *X2ApicEnabled;
|
---|
66 |
|
---|
67 | ASSERT (ConfigData != NULL);
|
---|
68 | X2ApicEnabled = (BOOLEAN *) ConfigData;
|
---|
69 | //
|
---|
70 | // *ConfigData indicates if X2APIC enabled on current processor
|
---|
71 | //
|
---|
72 | X2ApicEnabled[ProcessorNumber] = (GetApicMode () == LOCAL_APIC_MODE_X2APIC) ? TRUE : FALSE;
|
---|
73 |
|
---|
74 | return (CpuInfo->CpuIdVersionInfoEcx.Bits.x2APIC == 1);
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | Initializes X2Apci feature to specific state.
|
---|
79 |
|
---|
80 | @param[in] ProcessorNumber The index of the CPU executing this function.
|
---|
81 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
|
---|
82 | structure for the CPU executing this function.
|
---|
83 | @param[in] ConfigData A pointer to the configuration buffer returned
|
---|
84 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if
|
---|
85 | CPU_FEATURE_GET_CONFIG_DATA was not provided in
|
---|
86 | RegisterCpuFeature().
|
---|
87 | @param[in] State If TRUE, then the X2Apci feature must be enabled.
|
---|
88 | If FALSE, then the X2Apci feature must be disabled.
|
---|
89 |
|
---|
90 | @retval RETURN_SUCCESS X2Apci feature is initialized.
|
---|
91 |
|
---|
92 | @note This service could be called by BSP only.
|
---|
93 | **/
|
---|
94 | RETURN_STATUS
|
---|
95 | EFIAPI
|
---|
96 | X2ApicInitialize (
|
---|
97 | IN UINTN ProcessorNumber,
|
---|
98 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
|
---|
99 | IN VOID *ConfigData, OPTIONAL
|
---|
100 | IN BOOLEAN State
|
---|
101 | )
|
---|
102 | {
|
---|
103 | BOOLEAN *X2ApicEnabled;
|
---|
104 |
|
---|
105 | ASSERT (ConfigData != NULL);
|
---|
106 | X2ApicEnabled = (BOOLEAN *) ConfigData;
|
---|
107 | if (X2ApicEnabled[ProcessorNumber]) {
|
---|
108 | PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD (
|
---|
109 | ProcessorNumber,
|
---|
110 | Msr,
|
---|
111 | MSR_IA32_APIC_BASE,
|
---|
112 | MSR_IA32_APIC_BASE_REGISTER,
|
---|
113 | Bits.EXTD,
|
---|
114 | 1
|
---|
115 | );
|
---|
116 | } else {
|
---|
117 | //
|
---|
118 | // Enable X2APIC mode only if X2APIC is not enabled,
|
---|
119 | // Needn't to disabe X2APIC mode again if X2APIC is not enabled
|
---|
120 | //
|
---|
121 | if (State) {
|
---|
122 | CPU_REGISTER_TABLE_WRITE_FIELD (
|
---|
123 | ProcessorNumber,
|
---|
124 | Msr,
|
---|
125 | MSR_IA32_APIC_BASE,
|
---|
126 | MSR_IA32_APIC_BASE_REGISTER,
|
---|
127 | Bits.EXTD,
|
---|
128 | 1
|
---|
129 | );
|
---|
130 | }
|
---|
131 | }
|
---|
132 | return RETURN_SUCCESS;
|
---|
133 | }
|
---|