]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/UefiMemoryAllocationProfileLib/DxeMemoryProfileLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Library / UefiMemoryAllocationProfileLib / DxeMemoryProfileLib.c
1 /** @file
2 Support routines for memory profile for Dxe phase drivers.
3
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Uefi.h>
10
11 #include <Library/UefiBootServicesTableLib.h>
12 #include <Library/DebugLib.h>
13
14 #include <Guid/MemoryProfile.h>
15
16 EDKII_MEMORY_PROFILE_PROTOCOL *mLibProfileProtocol;
17
18 /**
19 The constructor function initializes memory profile for DXE phase.
20
21 @param ImageHandle The firmware allocated handle for the EFI image.
22 @param SystemTable A pointer to the EFI System Table.
23
24 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
25
26 **/
27 EFI_STATUS
28 EFIAPI
29 MemoryProfileLibConstructor (
30 IN EFI_HANDLE ImageHandle,
31 IN EFI_SYSTEM_TABLE *SystemTable
32 )
33 {
34 EFI_STATUS Status;
35
36 Status = gBS->LocateProtocol (
37 &gEdkiiMemoryProfileGuid,
38 NULL,
39 (VOID **)&mLibProfileProtocol
40 );
41 if (EFI_ERROR (Status)) {
42 mLibProfileProtocol = NULL;
43 }
44
45 return EFI_SUCCESS;
46 }
47
48 /**
49 Record memory profile of multilevel caller.
50
51 @param[in] CallerAddress Address of caller.
52 @param[in] Action Memory profile action.
53 @param[in] MemoryType Memory type.
54 EfiMaxMemoryType means the MemoryType is unknown.
55 @param[in] Buffer Buffer address.
56 @param[in] Size Buffer size.
57 @param[in] ActionString String for memory profile action.
58 Only needed for user defined allocate action.
59
60 @return EFI_SUCCESS Memory profile is updated.
61 @return EFI_UNSUPPORTED Memory profile is unsupported,
62 or memory profile for the image is not required,
63 or memory profile for the memory type is not required.
64 @return EFI_ACCESS_DENIED It is during memory profile data getting.
65 @return EFI_ABORTED Memory profile recording is not enabled.
66 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
67 @return EFI_NOT_FOUND No matched allocate info found for free action.
68
69 **/
70 EFI_STATUS
71 EFIAPI
72 MemoryProfileLibRecord (
73 IN PHYSICAL_ADDRESS CallerAddress,
74 IN MEMORY_PROFILE_ACTION Action,
75 IN EFI_MEMORY_TYPE MemoryType,
76 IN VOID *Buffer,
77 IN UINTN Size,
78 IN CHAR8 *ActionString OPTIONAL
79 )
80 {
81 if (mLibProfileProtocol == NULL) {
82 return EFI_UNSUPPORTED;
83 }
84
85 return mLibProfileProtocol->Record (
86 mLibProfileProtocol,
87 CallerAddress,
88 Action,
89 MemoryType,
90 Buffer,
91 Size,
92 ActionString
93 );
94 }