Home | History | Annotate | Download | only in SecPeiFspPlatformSecLibSample
      1 /** @file
      2   Sample to provide SecGetPerformance function.
      3 
      4   Copyright (c) 2014, 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 #include <PiPei.h>
     16 
     17 #include <Ppi/SecPerformance.h>
     18 #include <Ppi/TopOfTemporaryRam.h>
     19 
     20 #include <Library/BaseMemoryLib.h>
     21 #include <Library/TimerLib.h>
     22 #include <Library/DebugLib.h>
     23 
     24 /**
     25   This interface conveys performance information out of the Security (SEC) phase into PEI.
     26 
     27   This service is published by the SEC phase. The SEC phase handoff has an optional
     28   EFI_PEI_PPI_DESCRIPTOR list as its final argument when control is passed from SEC into the
     29   PEI Foundation. As such, if the platform supports collecting performance data in SEC,
     30   this information is encapsulated into the data structure abstracted by this service.
     31   This information is collected for the boot-strap processor (BSP) on IA-32.
     32 
     33   @param[in]  PeiServices  The pointer to the PEI Services Table.
     34   @param[in]  This         The pointer to this instance of the PEI_SEC_PERFORMANCE_PPI.
     35   @param[out] Performance  The pointer to performance data collected in SEC phase.
     36 
     37   @retval EFI_SUCCESS  The data was successfully returned.
     38 
     39 **/
     40 EFI_STATUS
     41 EFIAPI
     42 SecGetPerformance (
     43   IN CONST EFI_PEI_SERVICES          **PeiServices,
     44   IN       PEI_SEC_PERFORMANCE_PPI   *This,
     45   OUT      FIRMWARE_SEC_PERFORMANCE  *Performance
     46   )
     47 {
     48   UINT32      Size;
     49   UINT32      Count;
     50   UINT32      TopOfTemporaryRam;
     51   UINT64      Ticker;
     52   VOID        *TopOfTemporaryRamPpi;
     53   EFI_STATUS  Status;
     54 
     55   DEBUG ((DEBUG_INFO, "SecGetPerformance\n"));
     56 
     57   Status = (*PeiServices)->LocatePpi (
     58                              PeiServices,
     59                              &gTopOfTemporaryRamPpiGuid,
     60                              0,
     61                              NULL,
     62                              (VOID **) &TopOfTemporaryRamPpi
     63                              );
     64   if (EFI_ERROR (Status)) {
     65     return EFI_NOT_FOUND;
     66   }
     67 
     68   //
     69   // |--------------| <- TopOfTemporaryRam
     70   // |Number of BSPs|
     71   // |--------------|
     72   // |     BIST     |
     73   // |--------------|
     74   // |     ....     |
     75   // |--------------|
     76   // |  TSC[63:32]  |
     77   // |--------------|
     78   // |  TSC[31:00]  |
     79   // |--------------|
     80   //
     81   TopOfTemporaryRam = (UINT32)(UINTN)TopOfTemporaryRamPpi - sizeof(UINT32);
     82   TopOfTemporaryRam -= sizeof(UINT32) * 2;
     83   Count             = *(UINT32 *) (UINTN) (TopOfTemporaryRam - sizeof (UINT32));
     84   Size              = Count * sizeof (UINT64);
     85 
     86   Ticker = *(UINT64 *) (UINTN) (TopOfTemporaryRam - sizeof (UINT32) - Size - sizeof (UINT32) * 2);
     87   Performance->ResetEnd = GetTimeInNanoSecond (Ticker);
     88 
     89   return EFI_SUCCESS;
     90 }
     91