]>
Commit | Line | Data |
---|---|---|
cdad7675 SZ |
1 | /** @file\r |
2 | Support routines for memory profile for PiSmmCore.\r | |
3 | \r | |
d1102dba | 4 | Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
cdad7675 SZ |
6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include <PiSmm.h>\r | |
10 | \r | |
11 | #include <Library/UefiBootServicesTableLib.h>\r | |
12 | #include <Library/DebugLib.h>\r | |
13 | \r | |
14 | #include <Guid/MemoryProfile.h>\r | |
15 | \r | |
16 | #include "PiSmmCoreMemoryProfileServices.h"\r | |
17 | \r | |
18 | EDKII_MEMORY_PROFILE_PROTOCOL *mLibProfileProtocol;\r | |
19 | \r | |
20 | /**\r | |
21 | Check whether the start address of buffer is within any of the SMRAM ranges.\r | |
22 | \r | |
23 | @param[in] Buffer The pointer to the buffer to be checked.\r | |
24 | \r | |
3b28e744 | 25 | @retval TRUE The buffer is in SMRAM ranges.\r |
cdad7675 SZ |
26 | @retval FALSE The buffer is out of SMRAM ranges.\r |
27 | **/\r | |
28 | BOOLEAN\r | |
29 | EFIAPI\r | |
30 | BufferInSmram (\r | |
31 | IN VOID *Buffer\r | |
32 | );\r | |
33 | \r | |
34 | /**\r | |
35 | The constructor function initializes memory profile for SMM phase.\r | |
36 | \r | |
37 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
38 | @param SystemTable A pointer to the EFI System Table.\r | |
39 | \r | |
40 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
41 | \r | |
42 | **/\r | |
43 | EFI_STATUS\r | |
44 | EFIAPI\r | |
45 | PiSmmCoreMemoryProfileLibConstructor (\r | |
46 | IN EFI_HANDLE ImageHandle,\r | |
47 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
48 | )\r | |
49 | {\r | |
50 | EFI_STATUS Status;\r | |
51 | \r | |
52 | //\r | |
53 | // Locate Profile Protocol\r | |
54 | //\r | |
55 | Status = gBS->LocateProtocol (\r | |
56 | &gEdkiiMemoryProfileGuid,\r | |
57 | NULL,\r | |
58 | (VOID **)&mLibProfileProtocol\r | |
59 | );\r | |
60 | if (EFI_ERROR (Status)) {\r | |
61 | mLibProfileProtocol = NULL;\r | |
62 | }\r | |
63 | \r | |
64 | return EFI_SUCCESS;\r | |
65 | }\r | |
66 | \r | |
67 | /**\r | |
68 | Record memory profile of multilevel caller.\r | |
69 | \r | |
70 | @param[in] CallerAddress Address of caller.\r | |
71 | @param[in] Action Memory profile action.\r | |
72 | @param[in] MemoryType Memory type.\r | |
73 | EfiMaxMemoryType means the MemoryType is unknown.\r | |
74 | @param[in] Buffer Buffer address.\r | |
75 | @param[in] Size Buffer size.\r | |
76 | @param[in] ActionString String for memory profile action.\r | |
77 | Only needed for user defined allocate action.\r | |
78 | \r | |
79 | @return EFI_SUCCESS Memory profile is updated.\r | |
80 | @return EFI_UNSUPPORTED Memory profile is unsupported,\r | |
81 | or memory profile for the image is not required,\r | |
82 | or memory profile for the memory type is not required.\r | |
83 | @return EFI_ACCESS_DENIED It is during memory profile data getting.\r | |
84 | @return EFI_ABORTED Memory profile recording is not enabled.\r | |
85 | @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.\r | |
86 | @return EFI_NOT_FOUND No matched allocate info found for free action.\r | |
87 | \r | |
88 | **/\r | |
89 | EFI_STATUS\r | |
90 | EFIAPI\r | |
91 | MemoryProfileLibRecord (\r | |
92 | IN PHYSICAL_ADDRESS CallerAddress,\r | |
93 | IN MEMORY_PROFILE_ACTION Action,\r | |
94 | IN EFI_MEMORY_TYPE MemoryType,\r | |
95 | IN VOID *Buffer,\r | |
96 | IN UINTN Size,\r | |
97 | IN CHAR8 *ActionString OPTIONAL\r | |
98 | )\r | |
99 | {\r | |
100 | if (BufferInSmram (Buffer)) {\r | |
101 | return SmmCoreUpdateProfile (CallerAddress, Action, MemoryType, Size, Buffer, ActionString);\r | |
102 | } else {\r | |
103 | if (mLibProfileProtocol == NULL) {\r | |
104 | return EFI_UNSUPPORTED;\r | |
105 | }\r | |
106 | return mLibProfileProtocol->Record (\r | |
107 | mLibProfileProtocol,\r | |
108 | CallerAddress,\r | |
109 | Action,\r | |
110 | MemoryType,\r | |
111 | Buffer,\r | |
112 | Size,\r | |
113 | ActionString\r | |
114 | );\r | |
115 | }\r | |
116 | }\r | |
117 | \r |