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