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