1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
/** @file
Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Module Name:
SmmScriptSave.c
Abstract:
ScriptTableSave module at run time
--*/
#include "SmmScriptSave.h"
//
// internal functions
//
EFI_STATUS
BootScriptIoWrite (
IN EFI_SMM_SCRIPT_TABLE *ScriptTable,
IN VA_LIST Marker
);
EFI_STATUS
BootScriptPciCfgWrite (
IN EFI_SMM_SCRIPT_TABLE *ScriptTable,
IN VA_LIST Marker
);
VOID
SmmCopyMem (
IN UINT8 *Destination,
IN UINT8 *Source,
IN UINTN ByteCount
);
//
// Function implementations
//
EFI_STATUS
SmmBootScriptWrite (
IN OUT EFI_SMM_SCRIPT_TABLE *ScriptTable,
IN UINTN Type,
IN UINT16 OpCode,
...
)
{
EFI_STATUS Status;
VA_LIST Marker;
if (ScriptTable == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Build script according to opcode
//
switch ( OpCode ) {
case EFI_BOOT_SCRIPT_IO_WRITE_OPCODE:
VA_START(Marker, OpCode);
Status = BootScriptIoWrite (ScriptTable, Marker);
VA_END(Marker);
break;
case EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE:
VA_START(Marker, OpCode);
Status = BootScriptPciCfgWrite(ScriptTable, Marker);
VA_END(Marker);
break;
default:
Status = EFI_SUCCESS;
break;
}
return Status;
}
EFI_STATUS
SmmBootScriptCreateTable (
IN OUT EFI_SMM_SCRIPT_TABLE *ScriptTable,
IN UINTN Type
)
{
BOOT_SCRIPT_POINTERS Script;
UINT8 *Buffer;
if (ScriptTable == NULL) {
return EFI_INVALID_PARAMETER;
}
Buffer = (UINT8*) ((UINTN)(*ScriptTable));
//
// Fill Table Header
//
Script.Raw = Buffer;
Script.TableInfo->OpCode = EFI_BOOT_SCRIPT_TABLE_OPCODE;
Script.TableInfo->Length = sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER);
Script.TableInfo->TableLength = sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER);
//
// Update current table pointer
//
*ScriptTable = *ScriptTable + sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER);
return EFI_SUCCESS;
}
EFI_STATUS
SmmBootScriptCloseTable (
IN EFI_SMM_SCRIPT_TABLE ScriptTableBase,
IN EFI_SMM_SCRIPT_TABLE ScriptTablePtr,
IN UINTN Type
)
{
BOOT_SCRIPT_POINTERS Script;
//
// Add final "termination" node to script table
//
Script.Raw = (UINT8*) ((UINTN)ScriptTablePtr);
Script.Terminate->OpCode = EFI_BOOT_SCRIPT_TERMINATE_OPCODE;
Script.Terminate->Length = sizeof (EFI_BOOT_SCRIPT_TERMINATE);
ScriptTablePtr += sizeof (EFI_BOOT_SCRIPT_TERMINATE);
//
// Update Table Header
//
Script.Raw = (UINT8*) ((UINTN)ScriptTableBase);
Script.TableInfo->OpCode = EFI_BOOT_SCRIPT_TABLE_OPCODE;
Script.TableInfo->Length = sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER);
Script.TableInfo->TableLength = (UINT32)(ScriptTablePtr - ScriptTableBase);
return EFI_SUCCESS;
}
EFI_STATUS
BootScriptIoWrite (
IN EFI_SMM_SCRIPT_TABLE *ScriptTable,
IN VA_LIST Marker
)
{
BOOT_SCRIPT_POINTERS Script;
EFI_BOOT_SCRIPT_WIDTH Width;
UINTN Address;
UINTN Count;
UINT8 *Buffer;
UINTN NodeLength;
UINT8 WidthInByte;
Width = VA_ARG(Marker, EFI_BOOT_SCRIPT_WIDTH);
Address = VA_ARG(Marker, UINTN);
Count = VA_ARG(Marker, UINTN);
Buffer = VA_ARG(Marker, UINT8*);
WidthInByte = (UINT8)(0x01 << (Width & 0x03));
Script.Raw = (UINT8*) ((UINTN)(*ScriptTable));
NodeLength = sizeof (EFI_BOOT_SCRIPT_IO_WRITE) + (WidthInByte * Count);
//
// Build script data
//
Script.IoWrite->OpCode = EFI_BOOT_SCRIPT_IO_WRITE_OPCODE;
Script.IoWrite->Length = (UINT8)(NodeLength);
Script.IoWrite->Width = Width;
Script.IoWrite->Address = Address;
Script.IoWrite->Count = (UINT32)Count;
SmmCopyMem (
(UINT8*)(Script.Raw + sizeof (EFI_BOOT_SCRIPT_IO_WRITE)),
Buffer,
WidthInByte * Count
);
//
// Update Script table pointer
//
*ScriptTable = *ScriptTable + NodeLength;
return EFI_SUCCESS;
}
EFI_STATUS
BootScriptPciCfgWrite (
IN EFI_SMM_SCRIPT_TABLE *ScriptTable,
IN VA_LIST Marker
)
{
BOOT_SCRIPT_POINTERS Script;
EFI_BOOT_SCRIPT_WIDTH Width;
UINT64 Address;
UINTN Count;
UINT8 *Buffer;
UINTN NodeLength;
UINT8 WidthInByte;
Width = VA_ARG(Marker, EFI_BOOT_SCRIPT_WIDTH);
Address = VA_ARG(Marker, UINT64);
Count = VA_ARG(Marker, UINTN);
Buffer = VA_ARG(Marker, UINT8*);
WidthInByte = (UINT8)(0x01 << (Width & 0x03));
Script.Raw = (UINT8*) ((UINTN)(*ScriptTable));
NodeLength = sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE) + (WidthInByte * Count);
//
// Build script data
//
Script.PciWrite->OpCode = EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE;
Script.PciWrite->Length = (UINT8)(NodeLength);
Script.PciWrite->Width = Width;
Script.PciWrite->Address = Address;
Script.PciWrite->Count = (UINT32)Count;
SmmCopyMem (
(UINT8*)(Script.Raw + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE)),
Buffer,
WidthInByte * Count
);
//
// Update Script table pointer
//
*ScriptTable = *ScriptTable + NodeLength;
return EFI_SUCCESS;
}
VOID
SmmCopyMem (
IN UINT8 *Destination,
IN UINT8 *Source,
IN UINTN ByteCount
)
{
UINTN Index;
for (Index = 0; Index < ByteCount; Index++, Destination++, Source++) {
*Destination = *Source;
}
}
|