1 | /** @file
|
---|
2 | SMM profile internal header file.
|
---|
3 |
|
---|
4 | Copyright (c) 2012 - 2024, Intel Corporation. All rights reserved.<BR>
|
---|
5 | Copyright (c) 2020, AMD Incorporated. All rights reserved.<BR>
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #ifndef _SMM_PROFILE_INTERNAL_H_
|
---|
11 | #define _SMM_PROFILE_INTERNAL_H_
|
---|
12 |
|
---|
13 | #include <Protocol/SmmReadyToLock.h>
|
---|
14 | #include <Library/CpuLib.h>
|
---|
15 | #include <IndustryStandard/Acpi.h>
|
---|
16 |
|
---|
17 | #include "SmmProfileArch.h"
|
---|
18 |
|
---|
19 | //
|
---|
20 | // Configure the SMM_PROFILE DTS region size
|
---|
21 | //
|
---|
22 | #define SMM_PROFILE_DTS_SIZE (4 * 1024 * 1024) // 4M
|
---|
23 |
|
---|
24 | #define MAX_PF_PAGE_COUNT 0x2
|
---|
25 |
|
---|
26 | #define PEBS_RECORD_NUMBER 0x2
|
---|
27 |
|
---|
28 | #define MAX_PF_ENTRY_COUNT 10
|
---|
29 |
|
---|
30 | //
|
---|
31 | // This MACRO just enable unit test for the profile
|
---|
32 | // Please disable it.
|
---|
33 | //
|
---|
34 |
|
---|
35 | #define IA32_PF_EC_ID (1u << 4)
|
---|
36 |
|
---|
37 | #define SMM_PROFILE_NAME L"SmmProfileData"
|
---|
38 |
|
---|
39 | //
|
---|
40 | // CPU generic definition
|
---|
41 | //
|
---|
42 | #define MSR_EFER_XD 0x800
|
---|
43 |
|
---|
44 | #define CPUID1_EDX_BTS_AVAILABLE 0x200000
|
---|
45 |
|
---|
46 | #define DR6_SINGLE_STEP 0x4000
|
---|
47 |
|
---|
48 | #define MSR_DS_AREA 0x600
|
---|
49 |
|
---|
50 | #define HEAP_GUARD_NONSTOP_MODE \
|
---|
51 | ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT3|BIT2)) > BIT6)
|
---|
52 |
|
---|
53 | #define NULL_DETECTION_NONSTOP_MODE \
|
---|
54 | ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT6|BIT1)) > BIT6)
|
---|
55 |
|
---|
56 | typedef struct {
|
---|
57 | EFI_PHYSICAL_ADDRESS Base;
|
---|
58 | EFI_PHYSICAL_ADDRESS Top;
|
---|
59 | } MEMORY_RANGE;
|
---|
60 |
|
---|
61 | typedef struct {
|
---|
62 | MEMORY_RANGE Range;
|
---|
63 | BOOLEAN Present;
|
---|
64 | BOOLEAN Nx;
|
---|
65 | } MEMORY_PROTECTION_RANGE;
|
---|
66 |
|
---|
67 | typedef struct {
|
---|
68 | UINT64 HeaderSize;
|
---|
69 | UINT64 MaxDataEntries;
|
---|
70 | UINT64 MaxDataSize;
|
---|
71 | UINT64 CurDataEntries;
|
---|
72 | UINT64 CurDataSize;
|
---|
73 | UINT64 TsegStart;
|
---|
74 | UINT64 TsegSize;
|
---|
75 | UINT64 NumSmis;
|
---|
76 | UINT64 NumCpus;
|
---|
77 | } SMM_PROFILE_HEADER;
|
---|
78 |
|
---|
79 | typedef struct {
|
---|
80 | UINT64 SmiNum;
|
---|
81 | UINT64 CpuNum;
|
---|
82 | UINT64 ApicId;
|
---|
83 | UINT64 ErrorCode;
|
---|
84 | UINT64 Instruction;
|
---|
85 | UINT64 Address;
|
---|
86 | UINT64 SmiCmd;
|
---|
87 | } SMM_PROFILE_ENTRY;
|
---|
88 |
|
---|
89 | extern UINTN gSmiExceptionHandlers[];
|
---|
90 | extern BOOLEAN mXdSupported;
|
---|
91 | X86_ASSEMBLY_PATCH_LABEL gPatchXdSupported;
|
---|
92 | X86_ASSEMBLY_PATCH_LABEL gPatchMsrIa32MiscEnableSupported;
|
---|
93 | extern UINTN *mPFEntryCount;
|
---|
94 | extern UINT64 (*mLastPFEntryValue)[MAX_PF_ENTRY_COUNT];
|
---|
95 | extern UINT64 *(*mLastPFEntryPointer)[MAX_PF_ENTRY_COUNT];
|
---|
96 |
|
---|
97 | //
|
---|
98 | // Internal functions
|
---|
99 | //
|
---|
100 |
|
---|
101 | /**
|
---|
102 | Update IDT table to replace page fault handler and INT 1 handler.
|
---|
103 |
|
---|
104 | **/
|
---|
105 | VOID
|
---|
106 | InitIdtr (
|
---|
107 | VOID
|
---|
108 | );
|
---|
109 |
|
---|
110 | /**
|
---|
111 | Check if the memory address will be mapped by 4KB-page.
|
---|
112 |
|
---|
113 | @param Address The address of Memory.
|
---|
114 |
|
---|
115 | **/
|
---|
116 | BOOLEAN
|
---|
117 | IsAddressSplit (
|
---|
118 | IN EFI_PHYSICAL_ADDRESS Address
|
---|
119 | );
|
---|
120 |
|
---|
121 | /**
|
---|
122 | Check if the SMM profile page fault address above 4GB is in protected range or not.
|
---|
123 |
|
---|
124 | @param[in] Address The address of Memory.
|
---|
125 | @param[out] Nx The flag indicates if the memory is execute-disable.
|
---|
126 |
|
---|
127 | @retval TRUE The input address is in protected range.
|
---|
128 | @retval FALSE The input address is not in protected range.
|
---|
129 |
|
---|
130 | **/
|
---|
131 | BOOLEAN
|
---|
132 | IsSmmProfilePFAddressAbove4GValid (
|
---|
133 | IN EFI_PHYSICAL_ADDRESS Address,
|
---|
134 | OUT BOOLEAN *Nx
|
---|
135 | );
|
---|
136 |
|
---|
137 | /**
|
---|
138 | Allocate free Page for PageFault handler use.
|
---|
139 |
|
---|
140 | @return Page address.
|
---|
141 |
|
---|
142 | **/
|
---|
143 | UINT64
|
---|
144 | AllocPage (
|
---|
145 | VOID
|
---|
146 | );
|
---|
147 |
|
---|
148 | /**
|
---|
149 | Create new entry in page table for page fault address in SmmProfilePFHandler.
|
---|
150 |
|
---|
151 | **/
|
---|
152 | VOID
|
---|
153 | SmmProfileMapPFAddress (
|
---|
154 | VOID
|
---|
155 | );
|
---|
156 |
|
---|
157 | /**
|
---|
158 | Clear TF in FLAGS.
|
---|
159 |
|
---|
160 | @param SystemContext A pointer to the processor context when
|
---|
161 | the interrupt occurred on the processor.
|
---|
162 |
|
---|
163 | **/
|
---|
164 | VOID
|
---|
165 | ClearTrapFlag (
|
---|
166 | IN OUT EFI_SYSTEM_CONTEXT SystemContext
|
---|
167 | );
|
---|
168 |
|
---|
169 | #endif // _SMM_PROFILE_H_
|
---|