summaryrefslogtreecommitdiff
path: root/Platform/BroxtonPlatformPkg/Common/FpdtPei/FpdtPei.c
blob: 7f58a1377b9739127c90efdf70c889233802ecf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/** @file
  This module collects FPDT boot records on S3 Resume boot path.
  And, updates the boot records into basic boot performance table.

  Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>

  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php.

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include <PiPei.h>
#include <Ppi/EndOfPeiPhase.h>
#include <Ppi/ReadOnlyVariable2.h>
#include <PeiFirmwarePerformance.h>
#include <Guid/FirmwarePerformance.h>
#include <Library/HobLib.h>
#include <Library/DebugLib.h>
#include <Library/PeimEntryPoint.h>
#include <Library/PeiServicesLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/PcdLib.h>
#include <Library/TimerLib.h>
#include <Guid/SetupVariable.h>
#include <ExtendedFirmwarePerformanceData.h>

/**
  Collect PEI boot records and update them into the basic boot performance table.

  @param[in] PeiServices       An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
  @param[in] NotifyDescriptor  Address of the notification descriptor data structure.
  @param[in] Ppi               Address of the PPI that was installed.

  @retval    EFI_SUCCESS       Successfully update the Boot records.
  @retval    EFI_NOT_FOUND     PEI boot records are not found or Basic boot performance table is not found.

**/
EFI_STATUS
EFIAPI
EndOfPeiSignalPpiNotifyCallback (
  IN EFI_PEI_SERVICES           **PeiServices,
  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,
  IN VOID                       *Ppi
  )
{
  EFI_STATUS                       Status;
  EFI_PEI_READ_ONLY_VARIABLE2_PPI  *VariableServices;
  UINTN                            VarSize;
  UINT8                            *BootPerformanceTable;
  GUID_EVENT_RECORD                *GuidEvent;
  UINT32                           Index;
  UINT32                           TableLength;
  PEI_FIRMWARE_PERFORMANCE_HOB     *FirmwarePerformanceHob;
  PEI_GUID_EVENT_RECORD            *PeiGuidRec;
  EFI_HOB_GUID_TYPE                *GuidHob;
  SYSTEM_CONFIGURATION             SystemConfiguration;
  FIRMWARE_PERFORMANCE_VARIABLE    PerformanceVariable;
  EFI_BOOT_MODE                    BootMode;

  Status = PeiServicesGetBootMode (&BootMode);
  ASSERT_EFI_ERROR (Status);

  if (BootMode == BOOT_ON_S3_RESUME) {
    Status = PeiServicesLocatePpi (
               &gEfiPeiReadOnlyVariable2PpiGuid,
               0,
               NULL,
               (VOID **) &VariableServices
               );
    ASSERT_EFI_ERROR (Status);

    //
    // Update S3 boot records into the basic boot performance table.
    //
    VarSize = sizeof (SystemConfiguration);

    Status = VariableServices->GetVariable (
                                 VariableServices,
                                 PLATFORM_SETUP_VARIABLE_NAME,
                                 &gEfiSetupVariableGuid,
                                 NULL,
                                 &VarSize,
                                 &SystemConfiguration
                                 );

    if (EFI_ERROR (Status)) {
      return Status;
    }
    PerformanceVariable.BootPerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) SystemConfiguration.BootPerformanceTablePointer;
    PerformanceVariable.S3PerformanceTablePointer   = (EFI_PHYSICAL_ADDRESS) (UINTN) SystemConfiguration.S3PerformanceTablePointer;
    BootPerformanceTable = (UINT8*) (UINTN) PerformanceVariable.BootPerformanceTablePointer;
    DEBUG ((DEBUG_INFO, "FPDT: Performance Boot Performance Table address = 0x%x\n", PerformanceVariable.BootPerformanceTablePointer));

    //
    // Get the table Length with table header and basic boot record.
    // S3 boot records will update into the basic boot performance table and override normal boot records.
    //
    TableLength = sizeof (BOOT_PERFORMANCE_TABLE);
    DEBUG ((DEBUG_INFO, "FPDT: Performance Boot Performance Table Raw size = 0x%x\n", TableLength));

    //
    // Dump PEI boot records
    //
    GuidEvent = (GUID_EVENT_RECORD *) (BootPerformanceTable + TableLength);
    GuidHob   = GetFirstGuidHob (&gPeiFirmwarePerformanceGuid);
    if (GuidHob != NULL) {
      FirmwarePerformanceHob = (PEI_FIRMWARE_PERFORMANCE_HOB *) GET_GUID_HOB_DATA (GuidHob);
      PeiGuidRec  = &(FirmwarePerformanceHob->GuidEventRecord[0]);

      for (Index = 0; Index < FirmwarePerformanceHob->NumberOfEntries; Index ++, PeiGuidRec ++, GuidEvent ++) {
        //
        // GUID Event Records from PEI phase
        //
        GuidEvent->Header.Type       = GUID_EVENT_TYPE;
        GuidEvent->Header.Length     = sizeof (GUID_EVENT_RECORD);
        GuidEvent->Header.Revision   = RECORD_REVISION_1;
        GuidEvent->ProgressID        = PeiGuidRec->ProgressID;
        GuidEvent->ApicID            = PeiGuidRec->ApicID;
        GuidEvent->Timestamp         = PeiGuidRec->Timestamp;
        CopyGuid (&GuidEvent->Guid, &PeiGuidRec->Guid);
      }

      DEBUG ((DEBUG_INFO, "FPDT: Performance S3 Boot Performance Record Number is 0x%x\n", FirmwarePerformanceHob->NumberOfEntries));
    }

    //
    // Update Table length.
    //
    ((BOOT_PERFORMANCE_TABLE *) BootPerformanceTable)->Header.Length = (UINT32)(UINTN)((UINT8 *) GuidEvent - BootPerformanceTable);
    DEBUG ((DEBUG_INFO, "FPDT: Performance Boot Performance Table updated size = 0x%x\n", ((BOOT_PERFORMANCE_TABLE *) BootPerformanceTable)->Header.Length));
  }

  return EFI_SUCCESS;
}


EFI_PEI_NOTIFY_DESCRIPTOR mEndOfPeiSignalPpiNotifyList[] = {
  {
    (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
    &gEfiEndOfPeiSignalPpiGuid,
    EndOfPeiSignalPpiNotifyCallback
  }
};


/**
  Main entry for Firmware Performance Data Table PEIM.
  It installs EndOfPeiSignalPpi Notify function on S3 boot path.

  @param[in]  FileHandle              Handle of the file being invoked.
  @param[in]  PeiServices             Pointer to PEI Services table.

  @retval     EFI_SUCCESS             Install Notify function successfully.

**/
EFI_STATUS
EFIAPI
FpdtPeiEntryPoint (
  IN       EFI_PEI_FILE_HANDLE  FileHandle,
  IN CONST EFI_PEI_SERVICES     **PeiServices
  )
{
  EFI_STATUS               Status;

  if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) {
    //
    // Register for a callback once memory has been initialized.
    //
    Status = PeiServicesNotifyPpi (&mEndOfPeiSignalPpiNotifyList[0]);
    ASSERT_EFI_ERROR (Status);
  }

  return EFI_SUCCESS;
}