UefiCpuPkg: Add NULL CPU Common Features Library instance
[mirror_edk2.git] / UefiCpuPkg / Library / CpuCommonFeaturesLib / X2Apic.c
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 Detects if X2Apci feature supported on current processor.
19
20 Detect if X2Apci has been already enabled.
21
22 @param[in] ProcessorNumber The index of the CPU executing this function.
23 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
24 structure for the CPU executing this function.
25 @param[in] ConfigData A pointer to the configuration buffer returned
26 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
27 CPU_FEATURE_GET_CONFIG_DATA was not provided in
28 RegisterCpuFeature().
29
30 @retval TRUE X2Apci feature is supported.
31 @retval FALSE X2Apci feature is not supported.
32
33 @note This service could be called by BSP/APs.
34 **/
35 BOOLEAN
36 EFIAPI
37 X2ApicSupport (
38 IN UINTN ProcessorNumber,
39 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
40 IN VOID *ConfigData OPTIONAL
41 )
42 {
43 return (GetApicMode () == LOCAL_APIC_MODE_X2APIC);
44 }
45
46 /**
47 Initializes X2Apci feature to specific state.
48
49 @param[in] ProcessorNumber The index of the CPU executing this function.
50 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
51 structure for the CPU executing this function.
52 @param[in] ConfigData A pointer to the configuration buffer returned
53 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
54 CPU_FEATURE_GET_CONFIG_DATA was not provided in
55 RegisterCpuFeature().
56 @param[in] State If TRUE, then the X2Apci feature must be enabled.
57 If FALSE, then the X2Apci feature must be disabled.
58
59 @retval RETURN_SUCCESS X2Apci feature is initialized.
60
61 @note This service could be called by BSP only.
62 **/
63 RETURN_STATUS
64 EFIAPI
65 X2ApicInitialize (
66 IN UINTN ProcessorNumber,
67 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
68 IN VOID *ConfigData, OPTIONAL
69 IN BOOLEAN State
70 )
71 {
72 PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD (
73 ProcessorNumber,
74 Msr,
75 MSR_IA32_APIC_BASE,
76 MSR_IA32_APIC_BASE_REGISTER,
77 Bits.EXTD,
78 (State) ? 1 : 0
79 );
80 return RETURN_SUCCESS;
81 }