Skip to content

Commit

Permalink
Works
Browse files Browse the repository at this point in the history
  • Loading branch information
os-d authored and vineelko committed Jan 24, 2025
1 parent 4591d4a commit cc5f1a7
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 34 deletions.
18 changes: 18 additions & 0 deletions MdeModulePkg/Include/Guid/CacheAttributesChangeEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** @file
Event group triggered when caching attributes are updated in the system.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
MU_CHANGE: WHOLE FILE
**/

#ifndef CACHE_ATTRIBUTES_CHANGE_EVENT_H_
#define CACHE_ATTRIBUTES_CHANGE_EVENT_H_

#define CACHE_ATTRIBUTES_CHANGE_EVENT_GUID \
{ 0XB8E477C7, 0X26A9, 0X4B9A, { 0XA7, 0XC9, 0X5F, 0X8F, 0X1F, 0X3D, 0X9C, 0X7B } }

extern EFI_GUID gCacheAttributesChangeEventGuid;

#endif
4 changes: 4 additions & 0 deletions MdeModulePkg/MdeModulePkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@
gEdk2JedecSfdpSpiDxeDriverGuid = { 0xBE71701E, 0xB63C, 0x4574, { 0x9C, 0x5C, 0x36, 0x29, 0xE8, 0xEA, 0xC4, 0x14 }}
gEdk2JedecSfdpSpiSmmDriverGuid = { 0x95A1E915, 0x195C, 0x477C, { 0x92, 0x6F, 0x7E, 0x24, 0x67, 0xC1, 0xB3, 0x1F }}

# MU_CHANGE START
gCacheAttributesChangeEventGuid = { 0XB8E477C7, 0X26A9, 0X4B9A, { 0XA7, 0XC9, 0X5F, 0X8F, 0X1F, 0X3D, 0X9C, 0X7B } }
# MU_CHANGE END

[Ppis]
## Include/Ppi/FirmwareVolumeShadowPpi.h
gEdkiiPeiFirmwareVolumeShadowPpiGuid = { 0x7dfe756c, 0xed8d, 0x4d77, {0x9e, 0xc4, 0x39, 0x9a, 0x8a, 0x81, 0x51, 0x16 } }
Expand Down
3 changes: 2 additions & 1 deletion UefiCpuPkg/MpDxe/LoongArch64/MpDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
MU_CHANGE: WHOLE FILE
**/

#include "MpDxe.h"
Expand Down Expand Up @@ -543,7 +545,6 @@ InitializeMpSupport (
ASSERT_EFI_ERROR (Status);
}


EFI_STATUS
EFIAPI
InitializeMp (
Expand Down
94 changes: 87 additions & 7 deletions UefiCpuPkg/MpDxe/MpDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
MU_CHANGE: WHOLE FILE
**/

#include "MpDxe.h"
#include <Guid/CacheAttributesChangeEvent.h>
#include <Library/MtrrLib.h>

EFI_HANDLE mMpServiceHandle = NULL;
UINTN mNumberOfProcessors = 1;
EFI_HANDLE mMpServiceHandle = NULL;
UINTN mNumberOfProcessors = 1;
EFI_EVENT mCacheAttributesChangeEvent = NULL;

EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate = {
GetNumberOfProcessors,
Expand All @@ -21,6 +25,49 @@ EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate = {
WhoAmI
};

/**
A minimal wrapper function that allows MtrrSetAllMtrrs() to be passed to
EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() as Procedure.
@param[in] Buffer Pointer to an MTRR_SETTINGS object, to be passed to
MtrrSetAllMtrrs().
**/
VOID
EFIAPI
SetMtrrsFromBuffer (
IN VOID *Buffer
)
{
MtrrSetAllMtrrs (Buffer);
}

// MU_CHANGE START: Cache Attribute Change Event
VOID
EFIAPI
CacheAttributesChangeCallback (
IN EFI_EVENT Event,
IN VOID *Context
)
{
MTRR_SETTINGS MtrrSettings;

DEBUG ((DEBUG_INFO, "MpDxe updating MTRRs with APs\n"));

MtrrGetAllMtrrs (&MtrrSettings);

MpInitLibStartupAllAPs (
SetMtrrsFromBuffer,
FALSE,
NULL,
0,
&MtrrSettings,
NULL
);
// we purposefully don't close the event here, because we want to be called for every update
}

// MU_CHANGE END: Cache Attribute Change Event

/**
This service retrieves the number of logical processor in the platform
and the number of those logical processors that are enabled on this boot.
Expand Down Expand Up @@ -752,14 +799,18 @@ InitializeMpExceptionHandlers (
VOID
)
{
// //
// // Enable non-stop mode for #PF triggered by Heap Guard or NULL Pointer
// // Detection.
// //
// MU_CHANGE START - These modes are only for testing - Commenting to untangle
// the dependency on DebugExceptionHandler/PageFaultExceptionHandler
//
// Enable non-stop mode for #PF triggered by Heap Guard or NULL Pointer
// Detection.
//
// if (HEAP_GUARD_NONSTOP_MODE || NULL_DETECTION_NONSTOP_MODE) {
// RegisterCpuInterruptHandler (EXCEPT_IA32_DEBUG, DebugExceptionHandler);
// RegisterCpuInterruptHandler (EXCEPT_IA32_PAGE_FAULT, PageFaultExceptionHandler);
// RegisterCpuInterruptHandler (EXCEPT_IA32_PAGE_FAULT,
// PageFaultExceptionHandler);
// }
// MU_CHANGE END

//
// Setup stack switch for Stack Guard feature.
Expand Down Expand Up @@ -816,6 +867,35 @@ InitializeMpSupport (
);
ASSERT_EFI_ERROR (Status);
}

// MU_CHANGE START: CacheAttributesChange Event
// Register for the CacheAttributesChangeEvent
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
CacheAttributesChangeCallback,
NULL,
&gCacheAttributesChangeEventGuid,
&mCacheAttributesChangeEvent
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed to create CacheAttributesChangeEvent\n"));
ASSERT_EFI_ERROR (Status);
}

// MU_CHANGE END: CacheAttributesChange Event
}

// MU_CHANGE End - CodeQL Change - unguardednullreturndereference

EFI_STATUS
EFIAPI
InitializeMp (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
InitializeMpSupport ();

return EFI_SUCCESS;
}
7 changes: 4 additions & 3 deletions UefiCpuPkg/MpDxe/MpDxe.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
MU_CHANGE: WHOLE FILE
**/

#ifndef _MP_DXE_H_
#define _MP_DXE_H_
#ifndef MP_DXE_H_
#define MP_DXE_H_

#include <PiDxe.h>

Expand Down Expand Up @@ -489,4 +490,4 @@ WhoAmI (
OUT UINTN *ProcessorNumber
);

#endif // _MP_DXE_H_
#endif // MP_DXE_H_
26 changes: 3 additions & 23 deletions UefiCpuPkg/MpDxe/MpDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
# MU_CHANGE: WHOLE FILE
##

[Defines]
Expand Down Expand Up @@ -61,35 +62,14 @@

[Protocols]
gEfiMpServiceProtocolGuid ## PRODUCES
# gEfiCpuArchProtocolGuid ## CONSUMES
# gEfiMemoryAttributeProtocolGuid ## TCBZ3519 MU_CHANGE PRODUCES
# gEfiSmmBase2ProtocolGuid ## SOMETIMES_CONSUMES
# gMemoryProtectionNonstopModeProtocolGuid ## MU_CHANGE: PRODUCES
# gEdkiiGcdSyncCompleteProtocolGuid ## MU_CHANGE: PRODUCES
# gEfiCpuArchProtocolGuid ## PRODUCES

# [Guids]
# gIdleLoopEventGuid ## CONSUMES ## Event
# gEfiVectorHandoffTableGuid ## SOMETIMES_CONSUMES ## SystemTable
[Guids]
gCacheAttributesChangeEventGuid ## CONSUMES

[Ppis]
gEfiSecPlatformInformation2PpiGuid ## UNDEFINED # HOB
gEfiSecPlatformInformationPpiGuid ## UNDEFINED # HOB

# [Pcd]
# gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ## CONSUMES
# # MU_CHANGE START Remove memory protection PCD references
# # gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## CONSUMES
# # gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ## CONSUMES
# # gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ## CONSUMES
# # MU_CHANGE END
# gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask ## CONSUMES
# gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList ## CONSUMES
# gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize ## CONSUMES

# [Pcd.LoongArch64]
# gUefiCpuPkgTokenSpaceGuid.PcdLoongArchExceptionVectorBaseAddress ## CONSUMES

[Depex]
gEfiCpuArchProtocolGuid

Expand Down
1 change: 1 addition & 0 deletions UefiCpuPkg/MpDxe/MpDxe.uni
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// MU_CHANGE: WHOLE FILE
// **/


Expand Down
1 change: 1 addition & 0 deletions UefiCpuPkg/MpDxe/MpDxeExtra.uni
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// MU_CHANGE: WHOLE FILE
// **/

#string STR_PROPERTIES_MODULE_NAME
Expand Down

0 comments on commit cc5f1a7

Please sign in to comment.