2 Install a callback when necessary for setting the Feature Control MSR on all
5 Copyright (C) 2016, Red Hat, Inc.
7 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/DebugLib.h>
11 #include <Library/HobLib.h>
12 #include <Library/PeiServicesLib.h>
13 #include <Library/QemuFwCfgLib.h>
14 #include <Ppi/MpServices.h>
15 #include <Register/ArchitecturalMsr.h>
16 #include <IndustryStandard/Tdx.h>
21 Write the Feature Control MSR on an Application Processor or the Boot
24 All APs execute this function in parallel. The BSP executes the function
27 @param[in,out] WorkSpace Pointer to the input/output argument workspace
28 shared by all processors.
34 IN OUT VOID
*WorkSpace
37 EFI_HOB_PLATFORM_INFO
*PlatformInfoHob
= WorkSpace
;
42 (UINT64
)MSR_IA32_FEATURE_CONTROL
,
43 PlatformInfoHob
->FeatureControlValue
,
50 MSR_IA32_FEATURE_CONTROL
,
51 PlatformInfoHob
->FeatureControlValue
57 Notification function called when EFI_PEI_MP_SERVICES_PPI becomes available.
59 @param[in] PeiServices Indirect reference to the PEI Services Table.
60 @param[in] NotifyDescriptor Address of the notification descriptor data
62 @param[in] Ppi Address of the PPI that was installed.
64 @return Status of the notification. The status code returned from this
70 OnMpServicesAvailable (
71 IN EFI_PEI_SERVICES
**PeiServices
,
72 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
76 EFI_PEI_MP_SERVICES_PPI
*MpServices
;
78 EFI_HOB_PLATFORM_INFO
*PlatformInfoHob
;
79 EFI_HOB_GUID_TYPE
*GuidHob
;
81 GuidHob
= GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid
);
82 if (GuidHob
== NULL
) {
83 return EFI_UNSUPPORTED
;
86 PlatformInfoHob
= (EFI_HOB_PLATFORM_INFO
*)GET_GUID_HOB_DATA (GuidHob
);
88 DEBUG ((DEBUG_VERBOSE
, "%a: %a\n", gEfiCallerBaseName
, __FUNCTION__
));
91 // Write the MSR on all the APs in parallel.
94 Status
= MpServices
->StartupAllAPs (
95 (CONST EFI_PEI_SERVICES
**)PeiServices
,
97 WriteFeatureControl
, // Procedure
98 FALSE
, // SingleThread
99 0, // TimeoutInMicroSeconds: inf.
100 PlatformInfoHob
// ProcedureArgument
102 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
103 DEBUG ((DEBUG_ERROR
, "%a: StartupAllAps(): %r\n", __FUNCTION__
, Status
));
108 // Now write the MSR on the BSP too.
110 WriteFeatureControl (PlatformInfoHob
);
115 // Notification object for registering the callback, for when
116 // EFI_PEI_MP_SERVICES_PPI becomes available.
118 STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mMpServicesNotify
= {
119 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| // Flags
120 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
121 &gEfiPeiMpServicesPpiGuid
, // Guid
122 OnMpServicesAvailable
// Notify
126 InstallFeatureControlCallback (
127 IN OUT EFI_HOB_PLATFORM_INFO
*PlatformInfoHob
131 FIRMWARE_CONFIG_ITEM FwCfgItem
;
134 Status
= QemuFwCfgFindFile (
135 "etc/msr_feature_control",
139 if (EFI_ERROR (Status
) || (FwCfgSize
!= sizeof (PlatformInfoHob
->FeatureControlValue
))) {
146 QemuFwCfgSelectItem (FwCfgItem
);
148 sizeof (PlatformInfoHob
->FeatureControlValue
),
149 &(PlatformInfoHob
->FeatureControlValue
)
152 Status
= PeiServicesNotifyPpi (&mMpServicesNotify
);
153 if (EFI_ERROR (Status
)) {
156 "%a: failed to set up MP Services callback: %r\n",