]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h
UefiCpuPkg/PiSmmCpuDxeSmm: Enable/Restore XD in SMM
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / SmmProfileInternal.h
CommitLineData
529a5a86
MK
1/** @file\r
2SMM profile internal header file.\r
3\r
4Copyright (c) 2012 - 2015, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef _SMM_PROFILE_INTERNAL_H_\r
16#define _SMM_PROFILE_INTERNAL_H_\r
17\r
18#include <Guid/GlobalVariable.h>\r
19#include <Guid/Acpi.h>\r
20#include <Protocol/SmmReadyToLock.h>\r
21#include <Library/UefiRuntimeServicesTableLib.h>\r
22#include <Library/DxeServicesTableLib.h>\r
23#include <Library/CpuLib.h>\r
24#include <IndustryStandard/Acpi.h>\r
25\r
26#include "SmmProfileArch.h"\r
27\r
28//\r
29// Configure the SMM_PROFILE DTS region size\r
30//\r
31#define SMM_PROFILE_DTS_SIZE (4 * 1024 * 1024) // 4M\r
32\r
33#define MAX_PF_PAGE_COUNT 0x2\r
34\r
35#define PEBS_RECORD_NUMBER 0x2\r
36\r
37#define MAX_PF_ENTRY_COUNT 10\r
38\r
39//\r
40// This MACRO just enable unit test for the profile\r
41// Please disable it.\r
42//\r
43\r
44#define IA32_PF_EC_P (1u << 0)\r
45#define IA32_PF_EC_WR (1u << 1)\r
46#define IA32_PF_EC_US (1u << 2)\r
47#define IA32_PF_EC_RSVD (1u << 3)\r
48#define IA32_PF_EC_ID (1u << 4)\r
49\r
50#define SMM_PROFILE_NAME L"SmmProfileData"\r
51\r
52//\r
53// CPU generic definition\r
54//\r
55#define CPUID1_EDX_XD_SUPPORT 0x100000\r
56#define MSR_EFER 0xc0000080\r
57#define MSR_EFER_XD 0x800\r
58\r
59#define CPUID1_EDX_BTS_AVAILABLE 0x200000\r
60\r
61#define DR6_SINGLE_STEP 0x4000\r
62#define RFLAG_TF 0x100\r
63\r
64#define MSR_DEBUG_CTL 0x1D9\r
65#define MSR_DEBUG_CTL_LBR 0x1\r
66#define MSR_DEBUG_CTL_TR 0x40\r
67#define MSR_DEBUG_CTL_BTS 0x80\r
68#define MSR_DEBUG_CTL_BTINT 0x100\r
69#define MSR_LASTBRANCH_TOS 0x1C9\r
70#define MSR_LER_FROM_LIP 0x1DD\r
71#define MSR_LER_TO_LIP 0x1DE\r
72#define MSR_DS_AREA 0x600\r
73\r
74typedef struct {\r
75 EFI_PHYSICAL_ADDRESS Base;\r
76 EFI_PHYSICAL_ADDRESS Top;\r
77} MEMORY_RANGE;\r
78\r
79typedef struct {\r
80 MEMORY_RANGE Range;\r
81 BOOLEAN Present;\r
82 BOOLEAN Nx;\r
83} MEMORY_PROTECTION_RANGE;\r
84\r
85typedef struct {\r
86 UINT64 HeaderSize;\r
87 UINT64 MaxDataEntries;\r
88 UINT64 MaxDataSize;\r
89 UINT64 CurDataEntries;\r
90 UINT64 CurDataSize;\r
91 UINT64 TsegStart;\r
92 UINT64 TsegSize;\r
93 UINT64 NumSmis;\r
94 UINT64 NumCpus;\r
95} SMM_PROFILE_HEADER;\r
96\r
97typedef struct {\r
98 UINT64 SmiNum;\r
99 UINT64 CpuNum;\r
100 UINT64 ApicId;\r
101 UINT64 ErrorCode;\r
102 UINT64 Instruction;\r
103 UINT64 Address;\r
104 UINT64 SmiCmd;\r
105} SMM_PROFILE_ENTRY;\r
106\r
107extern SMM_S3_RESUME_STATE *mSmmS3ResumeState;\r
108extern UINTN gSmiExceptionHandlers[];\r
109extern BOOLEAN mXdSupported;\r
110extern UINTN *mPFEntryCount;\r
111extern UINT64 (*mLastPFEntryValue)[MAX_PF_ENTRY_COUNT];\r
112extern UINT64 *(*mLastPFEntryPointer)[MAX_PF_ENTRY_COUNT];\r
113\r
114//\r
115// Internal functions\r
116//\r
117\r
118/**\r
119 Update IDT table to replace page fault handler and INT 1 handler.\r
120\r
121**/\r
122VOID\r
123InitIdtr (\r
124 VOID\r
125 );\r
126\r
127/**\r
128 Check if the memory address will be mapped by 4KB-page.\r
129\r
130 @param Address The address of Memory.\r
131\r
132**/\r
133BOOLEAN\r
134IsAddressSplit (\r
135 IN EFI_PHYSICAL_ADDRESS Address\r
136 );\r
137\r
138/**\r
139 Check if the memory address will be mapped by 4KB-page.\r
140\r
141 @param Address The address of Memory.\r
142 @param Nx The flag indicates if the memory is execute-disable.\r
143\r
144**/\r
145BOOLEAN\r
146IsAddressValid (\r
147 IN EFI_PHYSICAL_ADDRESS Address,\r
148 IN BOOLEAN *Nx\r
149 );\r
150\r
151/**\r
152 Page Fault handler for SMM use.\r
153\r
154**/\r
155VOID\r
156SmiDefaultPFHandler (\r
157 VOID\r
158 );\r
159\r
160/**\r
161 Clear TF in FLAGS.\r
162\r
163 @param SystemContext A pointer to the processor context when\r
164 the interrupt occurred on the processor.\r
165\r
166**/\r
167VOID\r
168ClearTrapFlag (\r
169 IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
170 );\r
171\r
172#endif // _SMM_PROFILE_H_\r