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