1 | /** @file
|
---|
2 | X64 processor specific header file to enable SMM profile.
|
---|
3 |
|
---|
4 | Copyright (c) 2012 - 2024, 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 | UINT64 BTSBufferBase;
|
---|
16 | UINT64 BTSIndex;
|
---|
17 | UINT64 BTSAbsoluteMaximum;
|
---|
18 | UINT64 BTSInterruptThreshold;
|
---|
19 | UINT64 PEBSBufferBase;
|
---|
20 | UINT64 PEBSIndex;
|
---|
21 | UINT64 PEBSAbsoluteMaximum;
|
---|
22 | UINT64 PEBSInterruptThreshold;
|
---|
23 | UINT64 PEBSCounterReset[2];
|
---|
24 | UINT64 Reserved;
|
---|
25 | } MSR_DS_AREA_STRUCT;
|
---|
26 |
|
---|
27 | typedef struct _BRANCH_TRACE_RECORD {
|
---|
28 | UINT64 LastBranchFrom;
|
---|
29 | UINT64 LastBranchTo;
|
---|
30 | UINT64 Rsvd0 : 4;
|
---|
31 | UINT64 BranchPredicted : 1;
|
---|
32 | UINT64 Rsvd1 : 59;
|
---|
33 | } BRANCH_TRACE_RECORD;
|
---|
34 |
|
---|
35 | typedef struct _PEBS_RECORD {
|
---|
36 | UINT64 Rflags;
|
---|
37 | UINT64 LinearIP;
|
---|
38 | UINT64 Rax;
|
---|
39 | UINT64 Rbx;
|
---|
40 | UINT64 Rcx;
|
---|
41 | UINT64 Rdx;
|
---|
42 | UINT64 Rsi;
|
---|
43 | UINT64 Rdi;
|
---|
44 | UINT64 Rbp;
|
---|
45 | UINT64 Rsp;
|
---|
46 | UINT64 R8;
|
---|
47 | UINT64 R9;
|
---|
48 | UINT64 R10;
|
---|
49 | UINT64 R11;
|
---|
50 | UINT64 R12;
|
---|
51 | UINT64 R13;
|
---|
52 | UINT64 R14;
|
---|
53 | UINT64 R15;
|
---|
54 | } PEBS_RECORD;
|
---|
55 |
|
---|
56 | #pragma pack ()
|
---|
57 |
|
---|
58 | extern BOOLEAN m1GPageTableSupport;
|
---|
59 |
|
---|
60 | #define PHYSICAL_ADDRESS_MASK ((1ull << 52) - SIZE_4KB)
|
---|
61 |
|
---|
62 | /**
|
---|
63 | Update page table to map the memory correctly in order to make the instruction
|
---|
64 | which caused page fault execute successfully. And it also save the original page
|
---|
65 | table to be restored in single-step exception.
|
---|
66 |
|
---|
67 | @param PageTable PageTable Address.
|
---|
68 | @param PFAddress The memory address which caused page fault exception.
|
---|
69 | @param CpuIndex The index of the processor.
|
---|
70 | @param ErrorCode The Error code of exception.
|
---|
71 | @param IsValidPFAddress The flag indicates if SMM profile data need be added.
|
---|
72 |
|
---|
73 | **/
|
---|
74 | VOID
|
---|
75 | RestorePageTableAbove4G (
|
---|
76 | UINT64 *PageTable,
|
---|
77 | UINT64 PFAddress,
|
---|
78 | UINTN CpuIndex,
|
---|
79 | UINTN ErrorCode,
|
---|
80 | BOOLEAN *IsValidPFAddress
|
---|
81 | );
|
---|
82 |
|
---|
83 | /**
|
---|
84 | Create SMM page table for S3 path.
|
---|
85 |
|
---|
86 | @param[out] Cr3 The base address of the page tables.
|
---|
87 |
|
---|
88 | **/
|
---|
89 | VOID
|
---|
90 | InitSmmS3Cr3 (
|
---|
91 | OUT UINTN *Cr3
|
---|
92 | );
|
---|
93 |
|
---|
94 | /**
|
---|
95 | Allocate pages for creating 4KB-page based on 2MB-page when page fault happens.
|
---|
96 |
|
---|
97 | **/
|
---|
98 | VOID
|
---|
99 | InitPagesForPFHandler (
|
---|
100 | VOID
|
---|
101 | );
|
---|
102 |
|
---|
103 | /**
|
---|
104 | Set sub-entries number in entry.
|
---|
105 |
|
---|
106 | @param[in, out] Entry Pointer to entry
|
---|
107 | @param[in] SubEntryNum Sub-entries number based on 0:
|
---|
108 | 0 means there is 1 sub-entry under this entry
|
---|
109 | 0x1ff means there is 512 sub-entries under this entry
|
---|
110 |
|
---|
111 | **/
|
---|
112 | VOID
|
---|
113 | SetSubEntriesNum (
|
---|
114 | IN OUT UINT64 *Entry,
|
---|
115 | IN UINT64 SubEntryNum
|
---|
116 | );
|
---|
117 |
|
---|
118 | /**
|
---|
119 | Return sub-entries number in entry.
|
---|
120 |
|
---|
121 | @param[in] Entry Pointer to entry
|
---|
122 |
|
---|
123 | @return Sub-entries number based on 0:
|
---|
124 | 0 means there is 1 sub-entry under this entry
|
---|
125 | 0x1ff means there is 512 sub-entries under this entry
|
---|
126 | **/
|
---|
127 | UINT64
|
---|
128 | GetSubEntriesNum (
|
---|
129 | IN UINT64 *Entry
|
---|
130 | );
|
---|
131 |
|
---|
132 | /**
|
---|
133 | Allocate free Page for PageFault handler use.
|
---|
134 |
|
---|
135 | @return Page address.
|
---|
136 |
|
---|
137 | **/
|
---|
138 | UINT64
|
---|
139 | AllocPage (
|
---|
140 | VOID
|
---|
141 | );
|
---|
142 |
|
---|
143 | /**
|
---|
144 | Set access record in entry.
|
---|
145 |
|
---|
146 | @param[in, out] Entry Pointer to entry
|
---|
147 | @param[in] Acc Access record value
|
---|
148 |
|
---|
149 | **/
|
---|
150 | VOID
|
---|
151 | SetAccNum (
|
---|
152 | IN OUT UINT64 *Entry,
|
---|
153 | IN UINT64 Acc
|
---|
154 | );
|
---|
155 |
|
---|
156 | #endif // _SMM_PROFILE_ARCH_H_
|
---|