UefiCpuPkg/CpuDxe: Enable protection for newly added page table
[mirror_edk2.git] / UefiCpuPkg / CpuFeatures / CpuFeaturesDxe.c
CommitLineData
80c4b236
JF
1/** @file\r
2 CPU Features DXE driver to initialize CPU features.\r
3\r
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiDxe.h>\r
16\r
17#include <Library/BaseLib.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/UefiLib.h>\r
20#include <Library/UefiBootServicesTableLib.h>\r
21#include <Library/RegisterCpuFeaturesLib.h>\r
bf5a306a 22#include <Library/HobLib.h>\r
80c4b236
JF
23\r
24#include <Protocol/SmmConfiguration.h>\r
25#include <Guid/CpuFeaturesInitDone.h>\r
26\r
27\r
28/**\r
29 Worker function to perform CPU feature initialization.\r
30\r
31**/\r
32VOID\r
33CpuFeaturesInitializeWorker (\r
34 VOID\r
35 )\r
36{\r
37 EFI_STATUS Status;\r
38 EFI_HANDLE Handle;\r
39\r
40 CpuFeaturesDetect ();\r
41\r
42 CpuFeaturesInitialize ();\r
43\r
44 //\r
45 // Install CPU Features Init Done Protocol\r
46 //\r
47 Handle = NULL;\r
48 Status = gBS->InstallProtocolInterface (\r
49 &Handle,\r
50 &gEdkiiCpuFeaturesInitDoneGuid,\r
51 EFI_NATIVE_INTERFACE,\r
52 NULL\r
53 );\r
54 ASSERT_EFI_ERROR (Status);\r
55}\r
56\r
57/**\r
58 Event notification that initialize CPU features when gEfiSmmConfigurationProtocol installs.\r
59\r
60 @param[in] Event The Event that is being processed, not used.\r
61 @param[in] Context Event Context, not used.\r
62**/\r
63VOID\r
64EFIAPI\r
65SmmConfigurationEventNotify (\r
66 IN EFI_EVENT Event,\r
67 IN VOID *Context\r
68 )\r
69{\r
70 EFI_STATUS Status;\r
71 EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration;\r
72\r
73 //\r
74 // Make sure this notification is for this handler\r
75 //\r
76 Status = gBS->LocateProtocol (&gEfiSmmConfigurationProtocolGuid, NULL, (VOID **)&SmmConfiguration);\r
77 if (EFI_ERROR (Status)) {\r
78 return;\r
79 }\r
80\r
81 CpuFeaturesInitializeWorker ();\r
82}\r
83\r
84/**\r
85 CPU Features driver entry point function.\r
86\r
87 If PcdCpuFeaturesInitAfterSmmRelocation is TRUE, it will register one\r
88 SMM Configuration Protocol notify function to perform CPU features\r
89 initialization. Otherwise, it will perform CPU features initialization\r
90 directly.\r
91\r
92 @param ImageHandle Image handle this driver.\r
93 @param SystemTable Pointer to the System Table.\r
94\r
95 @retval EFI_SUCCESS CPU Features is initialized successfully.\r
96**/\r
97EFI_STATUS\r
98EFIAPI\r
99CpuFeaturesDxeInitialize (\r
100 IN EFI_HANDLE ImageHandle,\r
101 IN EFI_SYSTEM_TABLE *SystemTable\r
102 )\r
103{\r
104 VOID *Registration;\r
bf5a306a
ED
105 EFI_STATUS Status;\r
106 EFI_HANDLE Handle;\r
107\r
108 if (GetFirstGuidHob (&gEdkiiCpuFeaturesInitDoneGuid) != NULL) {\r
109 //\r
110 // Try to find HOB first. This HOB exist means CPU features have \r
111 // been initialized by CpuFeaturesPei driver, just install \r
112 // gEdkiiCpuFeaturesInitDoneGuid.\r
113 //\r
114 Handle = NULL;\r
115 Status = gBS->InstallProtocolInterface (\r
116 &Handle,\r
117 &gEdkiiCpuFeaturesInitDoneGuid,\r
118 EFI_NATIVE_INTERFACE,\r
119 NULL\r
120 );\r
121 ASSERT_EFI_ERROR (Status);\r
122 return Status;\r
123 }\r
80c4b236
JF
124\r
125 if (PcdGetBool (PcdCpuFeaturesInitAfterSmmRelocation)) {\r
126 //\r
127 // Install notification callback on SMM Configuration Protocol\r
128 //\r
129 EfiCreateProtocolNotifyEvent (\r
130 &gEfiSmmConfigurationProtocolGuid,\r
131 TPL_CALLBACK,\r
132 SmmConfigurationEventNotify,\r
133 NULL,\r
134 &Registration\r
135 );\r
136 } else {\r
137 CpuFeaturesInitializeWorker ();\r
138 }\r
139\r
140 return EFI_SUCCESS;\r
141}\r
142\r