1 /** @file
2 IA-32 processor specific header file to enable SMM profile.
3 
4 Copyright (c) 2012 - 2015, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #ifndef _SMM_PROFILE_ARCH_H_
10 #define _SMM_PROFILE_ARCH_H_
11 
12 #pragma pack (1)
13 
14 typedef struct _MSR_DS_AREA_STRUCT {
15   UINT32  BTSBufferBase;
16   UINT32  BTSIndex;
17   UINT32  BTSAbsoluteMaximum;
18   UINT32  BTSInterruptThreshold;
19   UINT32  PEBSBufferBase;
20   UINT32  PEBSIndex;
21   UINT32  PEBSAbsoluteMaximum;
22   UINT32  PEBSInterruptThreshold;
23   UINT32  PEBSCounterReset[4];
24   UINT32  Reserved;
25 } MSR_DS_AREA_STRUCT;
26 
27 typedef struct _BRANCH_TRACE_RECORD {
28   UINT32  LastBranchFrom;
29   UINT32  LastBranchTo;
30   UINT32  Rsvd0 : 4;
31   UINT32  BranchPredicted : 1;
32   UINT32  Rsvd1 : 27;
33 } BRANCH_TRACE_RECORD;
34 
35 typedef struct _PEBS_RECORD {
36   UINT32  Eflags;
37   UINT32  LinearIP;
38   UINT32  Eax;
39   UINT32  Ebx;
40   UINT32  Ecx;
41   UINT32  Edx;
42   UINT32  Esi;
43   UINT32  Edi;
44   UINT32  Ebp;
45   UINT32  Esp;
46 } PEBS_RECORD;
47 
48 #pragma pack ()
49 
50 #define PHYSICAL_ADDRESS_MASK       ((1ull << 32) - SIZE_4KB)
51 
52 /**
53   Update page table to map the memory correctly in order to make the instruction
54   which caused page fault execute successfully. And it also save the original page
55   table to be restored in single-step exception. 32-bit firmware does not need it.
56 
57   @param  PageTable           PageTable Address.
58   @param  PFAddress           The memory address which caused page fault exception.
59   @param  CpuIndex            The index of the processor.
60   @param  ErrorCode           The Error code of exception.
61   @param  IsValidPFAddress    The flag indicates if SMM profile data need be added.
62 
63 **/
64 VOID
65 RestorePageTableAbove4G (
66   UINT64        *PageTable,
67   UINT64        PFAddress,
68   UINTN         CpuIndex,
69   UINTN         ErrorCode,
70   BOOLEAN       *IsValidPFAddress
71   );
72 
73 /**
74   Create SMM page table for S3 path.
75 
76 **/
77 VOID
78 InitSmmS3Cr3 (
79   VOID
80   );
81 
82 /**
83   Allocate pages for creating 4KB-page based on 2MB-page when page fault happens.
84 
85 **/
86 VOID
87 InitPagesForPFHandler (
88   VOID
89   );
90 
91 #endif // _SMM_PROFILE_ARCH_H_
92