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