]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryProfileLib.c
MdeModulePkg UsbBusPei: Fix wrong buffer length used to read hub desc
[mirror_edk2.git] / MdeModulePkg / Library / PiSmmCoreMemoryAllocationLib / PiSmmCoreMemoryProfileLib.c
CommitLineData
cdad7675
SZ
1/** @file\r
2 Support routines for memory profile for PiSmmCore.\r
3\r
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials \r
6 are licensed and made available under the terms and conditions of the BSD License \r
7 which accompanies this distribution. The full text of the license may be found at \r
8 http://opensource.org/licenses/bsd-license.php. \r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13**/\r
14\r
15#include <PiSmm.h>\r
16\r
17#include <Library/UefiBootServicesTableLib.h>\r
18#include <Library/DebugLib.h>\r
19\r
20#include <Guid/MemoryProfile.h>\r
21\r
22#include "PiSmmCoreMemoryProfileServices.h"\r
23\r
24EDKII_MEMORY_PROFILE_PROTOCOL *mLibProfileProtocol;\r
25\r
26/**\r
27 Check whether the start address of buffer is within any of the SMRAM ranges.\r
28\r
29 @param[in] Buffer The pointer to the buffer to be checked.\r
30\r
3b28e744 31 @retval TRUE The buffer is in SMRAM ranges.\r
cdad7675
SZ
32 @retval FALSE The buffer is out of SMRAM ranges.\r
33**/\r
34BOOLEAN\r
35EFIAPI\r
36BufferInSmram (\r
37 IN VOID *Buffer\r
38 );\r
39\r
40/**\r
41 The constructor function initializes memory profile for SMM phase.\r
42\r
43 @param ImageHandle The firmware allocated handle for the EFI image.\r
44 @param SystemTable A pointer to the EFI System Table.\r
45\r
46 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
47\r
48**/\r
49EFI_STATUS\r
50EFIAPI\r
51PiSmmCoreMemoryProfileLibConstructor (\r
52 IN EFI_HANDLE ImageHandle,\r
53 IN EFI_SYSTEM_TABLE *SystemTable\r
54 )\r
55{\r
56 EFI_STATUS Status;\r
57\r
58 //\r
59 // Locate Profile Protocol\r
60 //\r
61 Status = gBS->LocateProtocol (\r
62 &gEdkiiMemoryProfileGuid,\r
63 NULL,\r
64 (VOID **)&mLibProfileProtocol\r
65 );\r
66 if (EFI_ERROR (Status)) {\r
67 mLibProfileProtocol = NULL;\r
68 }\r
69\r
70 return EFI_SUCCESS;\r
71}\r
72\r
73/**\r
74 Record memory profile of multilevel caller.\r
75\r
76 @param[in] CallerAddress Address of caller.\r
77 @param[in] Action Memory profile action.\r
78 @param[in] MemoryType Memory type.\r
79 EfiMaxMemoryType means the MemoryType is unknown.\r
80 @param[in] Buffer Buffer address.\r
81 @param[in] Size Buffer size.\r
82 @param[in] ActionString String for memory profile action.\r
83 Only needed for user defined allocate action.\r
84\r
85 @return EFI_SUCCESS Memory profile is updated.\r
86 @return EFI_UNSUPPORTED Memory profile is unsupported,\r
87 or memory profile for the image is not required,\r
88 or memory profile for the memory type is not required.\r
89 @return EFI_ACCESS_DENIED It is during memory profile data getting.\r
90 @return EFI_ABORTED Memory profile recording is not enabled.\r
91 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.\r
92 @return EFI_NOT_FOUND No matched allocate info found for free action.\r
93\r
94**/\r
95EFI_STATUS\r
96EFIAPI\r
97MemoryProfileLibRecord (\r
98 IN PHYSICAL_ADDRESS CallerAddress,\r
99 IN MEMORY_PROFILE_ACTION Action,\r
100 IN EFI_MEMORY_TYPE MemoryType,\r
101 IN VOID *Buffer,\r
102 IN UINTN Size,\r
103 IN CHAR8 *ActionString OPTIONAL\r
104 )\r
105{\r
106 if (BufferInSmram (Buffer)) {\r
107 return SmmCoreUpdateProfile (CallerAddress, Action, MemoryType, Size, Buffer, ActionString);\r
108 } else {\r
109 if (mLibProfileProtocol == NULL) {\r
110 return EFI_UNSUPPORTED;\r
111 }\r
112 return mLibProfileProtocol->Record (\r
113 mLibProfileProtocol,\r
114 CallerAddress,\r
115 Action,\r
116 MemoryType,\r
117 Buffer,\r
118 Size,\r
119 ActionString\r
120 );\r
121 }\r
122}\r
123\r