]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiCpuPkg / CpuFeatures / CpuFeaturesDxe.c
1 /** @file
2 CPU Features DXE driver to initialize CPU features.
3
4 Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiDxe.h>
10
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/UefiLib.h>
14 #include <Library/UefiBootServicesTableLib.h>
15 #include <Library/RegisterCpuFeaturesLib.h>
16 #include <Library/HobLib.h>
17
18 #include <Protocol/SmmConfiguration.h>
19 #include <Guid/CpuFeaturesInitDone.h>
20
21 /**
22 Worker function to perform CPU feature initialization.
23
24 **/
25 VOID
26 CpuFeaturesInitializeWorker (
27 VOID
28 )
29 {
30 EFI_STATUS Status;
31 EFI_HANDLE Handle;
32
33 CpuFeaturesDetect ();
34
35 CpuFeaturesInitialize ();
36
37 //
38 // Install CPU Features Init Done Protocol
39 //
40 Handle = NULL;
41 Status = gBS->InstallProtocolInterface (
42 &Handle,
43 &gEdkiiCpuFeaturesInitDoneGuid,
44 EFI_NATIVE_INTERFACE,
45 NULL
46 );
47 ASSERT_EFI_ERROR (Status);
48 }
49
50 /**
51 Event notification that initialize CPU features when gEfiSmmConfigurationProtocol installs.
52
53 @param[in] Event The Event that is being processed, not used.
54 @param[in] Context Event Context, not used.
55 **/
56 VOID
57 EFIAPI
58 SmmConfigurationEventNotify (
59 IN EFI_EVENT Event,
60 IN VOID *Context
61 )
62 {
63 EFI_STATUS Status;
64 EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration;
65
66 //
67 // Make sure this notification is for this handler
68 //
69 Status = gBS->LocateProtocol (&gEfiSmmConfigurationProtocolGuid, NULL, (VOID **)&SmmConfiguration);
70 if (EFI_ERROR (Status)) {
71 return;
72 }
73
74 CpuFeaturesInitializeWorker ();
75 }
76
77 /**
78 CPU Features driver entry point function.
79
80 If PcdCpuFeaturesInitAfterSmmRelocation is TRUE, it will register one
81 SMM Configuration Protocol notify function to perform CPU features
82 initialization. Otherwise, it will perform CPU features initialization
83 directly.
84
85 @param ImageHandle Image handle this driver.
86 @param SystemTable Pointer to the System Table.
87
88 @retval EFI_SUCCESS CPU Features is initialized successfully.
89 **/
90 EFI_STATUS
91 EFIAPI
92 CpuFeaturesDxeInitialize (
93 IN EFI_HANDLE ImageHandle,
94 IN EFI_SYSTEM_TABLE *SystemTable
95 )
96 {
97 VOID *Registration;
98 EFI_STATUS Status;
99 EFI_HANDLE Handle;
100
101 if (GetFirstGuidHob (&gEdkiiCpuFeaturesInitDoneGuid) != NULL) {
102 //
103 // Try to find HOB first. This HOB exist means CPU features have
104 // been initialized by CpuFeaturesPei driver, just install
105 // gEdkiiCpuFeaturesInitDoneGuid.
106 //
107 Handle = NULL;
108 Status = gBS->InstallProtocolInterface (
109 &Handle,
110 &gEdkiiCpuFeaturesInitDoneGuid,
111 EFI_NATIVE_INTERFACE,
112 NULL
113 );
114 ASSERT_EFI_ERROR (Status);
115 return Status;
116 }
117
118 if (PcdGetBool (PcdCpuFeaturesInitAfterSmmRelocation)) {
119 //
120 // Install notification callback on SMM Configuration Protocol
121 //
122 EfiCreateProtocolNotifyEvent (
123 &gEfiSmmConfigurationProtocolGuid,
124 TPL_CALLBACK,
125 SmmConfigurationEventNotify,
126 NULL,
127 &Registration
128 );
129 } else {
130 CpuFeaturesInitializeWorker ();
131 }
132
133 return EFI_SUCCESS;
134 }