Home | History | Annotate | Download | only in UefiMemoryAllocationProfileLib
      1 /** @file
      2   Support routines for memory profile for Dxe phase drivers.
      3 
      4   Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
      5   This program and the accompanying materials
      6   are licensed and made available under the terms and conditions of the BSD License
      7   which accompanies this distribution.  The full text of the license may be found at
      8   http://opensource.org/licenses/bsd-license.php.
      9 
     10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 
     13 **/
     14 
     15 
     16 #include <Uefi.h>
     17 
     18 
     19 #include <Library/UefiBootServicesTableLib.h>
     20 #include <Library/DebugLib.h>
     21 
     22 #include <Guid/MemoryProfile.h>
     23 
     24 EDKII_MEMORY_PROFILE_PROTOCOL *mLibProfileProtocol;
     25 
     26 /**
     27   The constructor function initializes memory profile for DXE phase.
     28 
     29   @param ImageHandle    The firmware allocated handle for the EFI image.
     30   @param SystemTable    A pointer to the EFI System Table.
     31 
     32   @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.
     33 
     34 **/
     35 EFI_STATUS
     36 EFIAPI
     37 MemoryProfileLibConstructor (
     38   IN EFI_HANDLE        ImageHandle,
     39   IN EFI_SYSTEM_TABLE  *SystemTable
     40   )
     41 {
     42   EFI_STATUS           Status;
     43 
     44   Status = gBS->LocateProtocol (
     45                   &gEdkiiMemoryProfileGuid,
     46                   NULL,
     47                   (VOID **) &mLibProfileProtocol
     48                   );
     49   if (EFI_ERROR (Status)) {
     50     mLibProfileProtocol = NULL;
     51   }
     52 
     53   return EFI_SUCCESS;
     54 }
     55 
     56 /**
     57   Record memory profile of multilevel caller.
     58 
     59   @param[in] CallerAddress      Address of caller.
     60   @param[in] Action             Memory profile action.
     61   @param[in] MemoryType         Memory type.
     62                                 EfiMaxMemoryType means the MemoryType is unknown.
     63   @param[in] Buffer             Buffer address.
     64   @param[in] Size               Buffer size.
     65   @param[in] ActionString       String for memory profile action.
     66                                 Only needed for user defined allocate action.
     67 
     68   @return EFI_SUCCESS           Memory profile is updated.
     69   @return EFI_UNSUPPORTED       Memory profile is unsupported,
     70                                 or memory profile for the image is not required,
     71                                 or memory profile for the memory type is not required.
     72   @return EFI_ACCESS_DENIED     It is during memory profile data getting.
     73   @return EFI_ABORTED           Memory profile recording is not enabled.
     74   @return EFI_OUT_OF_RESOURCES  No enough resource to update memory profile for allocate action.
     75   @return EFI_NOT_FOUND         No matched allocate info found for free action.
     76 
     77 **/
     78 EFI_STATUS
     79 EFIAPI
     80 MemoryProfileLibRecord (
     81   IN PHYSICAL_ADDRESS           CallerAddress,
     82   IN MEMORY_PROFILE_ACTION      Action,
     83   IN EFI_MEMORY_TYPE            MemoryType,
     84   IN VOID                       *Buffer,
     85   IN UINTN                      Size,
     86   IN CHAR8                      *ActionString OPTIONAL
     87   )
     88 {
     89   if (mLibProfileProtocol == NULL) {
     90     return EFI_UNSUPPORTED;
     91   }
     92   return mLibProfileProtocol->Record (
     93                                 mLibProfileProtocol,
     94                                 CallerAddress,
     95                                 Action,
     96                                 MemoryType,
     97                                 Buffer,
     98                                 Size,
     99                                 ActionString
    100                                 );
    101 }
    102 
    103