]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/Dxe/EfiScriptLib/EfiScriptLib.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Dxe / EfiScriptLib / EfiScriptLib.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 EfiScriptLib.c
15
16 Abstract:
17
18 Support for EFI script.
19
20 --*/
21
22 #include "EfiScriptLib.h"
23
24 EFI_BOOT_SCRIPT_SAVE_PROTOCOL *mBootScriptSave;
25
26 EFI_STATUS
27 BootScriptSaveInitialize (
28 IN EFI_HANDLE ImageHandle,
29 IN EFI_SYSTEM_TABLE *SystemTable
30 )
31 /*++
32
33 Routine Description:
34
35 Intialize Boot Script Lib if it has not yet been initialized.
36
37 Arguments:
38
39 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
40
41 Returns:
42
43 EFI_STATUS always returns EFI_SUCCESS
44
45 --*/
46 // GC_TODO: ImageHandle - add argument and description to function comment
47 // GC_TODO: SystemTable - add argument and description to function comment
48 {
49 EFI_STATUS Status;
50 EFI_BOOT_SERVICES *BS;
51
52 BS = SystemTable->BootServices;
53
54 Status = BS->LocateProtocol (&gEfiBootScriptSaveGuid, NULL, &mBootScriptSave);
55 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
56 mBootScriptSave = NULL;
57 }
58
59 return EFI_SUCCESS;
60 }
61
62 EFI_STATUS
63 BootScriptSaveIoWrite (
64 IN UINT16 TableName,
65 IN EFI_BOOT_SCRIPT_WIDTH Width,
66 IN UINT64 Address,
67 IN UINTN Count,
68 IN VOID *Buffer
69 )
70 /*++
71
72 Routine Description:
73
74 Save I/O write to boot script
75
76 Arguments:
77
78 TableName - Desired boot script table
79
80 (Standard EFI IO write script parameter)
81
82 Returns:
83
84 EFI_NOT_FOUND - BootScriptSave Protocol not exist.
85
86 EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
87
88 --*/
89 // GC_TODO: Width - add argument and description to function comment
90 // GC_TODO: Address - add argument and description to function comment
91 // GC_TODO: Count - add argument and description to function comment
92 // GC_TODO: Buffer - add argument and description to function comment
93 {
94 if (mBootScriptSave == NULL) {
95 return EFI_NOT_FOUND;
96 }
97
98 mBootScriptSave->Write (
99 mBootScriptSave,
100 TableName,
101 EFI_BOOT_SCRIPT_IO_WRITE_OPCODE,
102 Width,
103 Address,
104 Count,
105 Buffer
106 );
107
108 return EFI_SUCCESS;
109 }
110
111 EFI_STATUS
112 BootScriptSaveIoReadWrite (
113 IN UINT16 TableName,
114 IN EFI_BOOT_SCRIPT_WIDTH Width,
115 IN UINT64 Address,
116 IN VOID *Data,
117 IN VOID *DataMask
118 )
119 /*++
120
121 Routine Description:
122
123 Save I/O write to boot script
124
125 Arguments:
126
127 TableName - Desired boot script table
128
129 (Standard EFI IO read write script parameter)
130
131 Returns:
132
133 EFI_NOT_FOUND - BootScriptSave Protocol not exist.
134
135 EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
136
137 --*/
138 // GC_TODO: Width - add argument and description to function comment
139 // GC_TODO: Address - add argument and description to function comment
140 // GC_TODO: Data - add argument and description to function comment
141 // GC_TODO: DataMask - add argument and description to function comment
142 {
143 if (mBootScriptSave == NULL) {
144 return EFI_NOT_FOUND;
145 }
146
147 mBootScriptSave->Write (
148 mBootScriptSave,
149 TableName,
150 EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE,
151 Width,
152 Address,
153 Data,
154 DataMask
155 );
156
157 return EFI_SUCCESS;
158 }
159
160 EFI_STATUS
161 BootScriptSaveMemWrite (
162 IN UINT16 TableName,
163 IN EFI_BOOT_SCRIPT_WIDTH Width,
164 IN UINT64 Address,
165 IN UINTN Count,
166 IN VOID *Buffer
167 )
168 /*++
169
170 Routine Description:
171
172 Save I/O write to boot script
173
174 Arguments:
175
176 TableName - Desired boot script table
177
178 (Standard EFI MEM write script parameter)
179
180 Returns:
181
182 EFI_NOT_FOUND - BootScriptSave Protocol not exist.
183
184 EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
185
186 --*/
187 // GC_TODO: Width - add argument and description to function comment
188 // GC_TODO: Address - add argument and description to function comment
189 // GC_TODO: Count - add argument and description to function comment
190 // GC_TODO: Buffer - add argument and description to function comment
191 {
192 if (mBootScriptSave == NULL) {
193 return EFI_NOT_FOUND;
194 }
195
196 mBootScriptSave->Write (
197 mBootScriptSave,
198 TableName,
199 EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE,
200 Width,
201 Address,
202 Count,
203 Buffer
204 );
205
206 return EFI_SUCCESS;
207 }
208
209 EFI_STATUS
210 BootScriptSaveMemReadWrite (
211 IN UINT16 TableName,
212 IN EFI_BOOT_SCRIPT_WIDTH Width,
213 IN UINT64 Address,
214 IN VOID *Data,
215 IN VOID *DataMask
216 )
217 /*++
218
219 Routine Description:
220
221 Save I/O write to boot script
222
223 Arguments:
224
225 TableName - Desired boot script table
226
227 (Standard EFI MEM read write script parameter)
228
229 Returns:
230
231 EFI_NOT_FOUND - BootScriptSave Protocol not exist.
232
233 EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
234
235 --*/
236 // GC_TODO: Width - add argument and description to function comment
237 // GC_TODO: Address - add argument and description to function comment
238 // GC_TODO: Data - add argument and description to function comment
239 // GC_TODO: DataMask - add argument and description to function comment
240 {
241 if (mBootScriptSave == NULL) {
242 return EFI_NOT_FOUND;
243 }
244
245 mBootScriptSave->Write (
246 mBootScriptSave,
247 TableName,
248 EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE,
249 Width,
250 Address,
251 Data,
252 DataMask
253 );
254
255 return EFI_SUCCESS;
256 }
257
258 EFI_STATUS
259 BootScriptSavePciCfgWrite (
260 IN UINT16 TableName,
261 IN EFI_BOOT_SCRIPT_WIDTH Width,
262 IN UINT64 Address,
263 IN UINTN Count,
264 IN VOID *Buffer
265 )
266 /*++
267
268 Routine Description:
269
270 Save I/O write to boot script
271
272 Arguments:
273
274 TableName - Desired boot script table
275
276 (Standard EFI PCI write script parameter)
277
278 Returns:
279
280 EFI_NOT_FOUND - BootScriptSave Protocol not exist.
281
282 EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
283
284 --*/
285 // GC_TODO: Width - add argument and description to function comment
286 // GC_TODO: Address - add argument and description to function comment
287 // GC_TODO: Count - add argument and description to function comment
288 // GC_TODO: Buffer - add argument and description to function comment
289 {
290 if (mBootScriptSave == NULL) {
291 return EFI_NOT_FOUND;
292 }
293
294 mBootScriptSave->Write (
295 mBootScriptSave,
296 TableName,
297 EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE,
298 Width,
299 Address,
300 Count,
301 Buffer
302 );
303
304 return EFI_SUCCESS;
305 }
306
307 EFI_STATUS
308 BootScriptSavePciCfgReadWrite (
309 IN UINT16 TableName,
310 IN EFI_BOOT_SCRIPT_WIDTH Width,
311 IN UINT64 Address,
312 IN VOID *Data,
313 IN VOID *DataMask
314 )
315 /*++
316
317 Routine Description:
318
319 Save I/O write to boot script
320
321 Arguments:
322
323 TableName - Desired boot script table
324
325 (Standard EFI PCI read write script parameter)
326
327 Returns:
328
329 EFI_NOT_FOUND - BootScriptSave Protocol not exist.
330
331 EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
332
333 --*/
334 // GC_TODO: Width - add argument and description to function comment
335 // GC_TODO: Address - add argument and description to function comment
336 // GC_TODO: Data - add argument and description to function comment
337 // GC_TODO: DataMask - add argument and description to function comment
338 {
339 if (mBootScriptSave == NULL) {
340 return EFI_NOT_FOUND;
341 }
342
343 mBootScriptSave->Write (
344 mBootScriptSave,
345 TableName,
346 EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE,
347 Width,
348 Address,
349 Data,
350 DataMask
351 );
352
353 return EFI_SUCCESS;
354 }
355
356 EFI_STATUS
357 BootScriptSaveSmbusExecute (
358 IN UINT16 TableName,
359 IN EFI_SMBUS_DEVICE_ADDRESS SlaveAddress,
360 IN EFI_SMBUS_DEVICE_COMMAND Command,
361 IN EFI_SMBUS_OPERATION Operation,
362 IN BOOLEAN PecCheck,
363 IN UINTN *Length,
364 IN VOID *Buffer
365 )
366 /*++
367
368 Routine Description:
369
370 Save I/O write to boot script
371
372 Arguments:
373
374 TableName - Desired boot script table
375
376 (Standard EFI Smbus execute script parameter)
377
378 Returns:
379
380 EFI_NOT_FOUND - BootScriptSave Protocol not exist.
381
382 EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
383
384 --*/
385 // GC_TODO: SlaveAddress - add argument and description to function comment
386 // GC_TODO: Command - add argument and description to function comment
387 // GC_TODO: Operation - add argument and description to function comment
388 // GC_TODO: PecCheck - add argument and description to function comment
389 // GC_TODO: Length - add argument and description to function comment
390 // GC_TODO: Buffer - add argument and description to function comment
391 {
392 if (mBootScriptSave == NULL) {
393 return EFI_NOT_FOUND;
394 }
395
396 mBootScriptSave->Write (
397 mBootScriptSave,
398 TableName,
399 EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE,
400 SlaveAddress,
401 Command,
402 Operation,
403 PecCheck,
404 Length,
405 Buffer
406 );
407
408 return EFI_SUCCESS;
409 }
410
411 EFI_STATUS
412 BootScriptSaveStall (
413 IN UINT16 TableName,
414 IN UINTN Duration
415 )
416 /*++
417
418 Routine Description:
419
420 Save I/O write to boot script
421
422 Arguments:
423
424 TableName - Desired boot script table
425
426 (Standard EFI stall script parameter)
427
428 Returns:
429
430 EFI_NOT_FOUND - BootScriptSave Protocol not exist.
431
432 EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
433
434 --*/
435 // GC_TODO: Duration - add argument and description to function comment
436 {
437 if (mBootScriptSave == NULL) {
438 return EFI_NOT_FOUND;
439 }
440
441 mBootScriptSave->Write (
442 mBootScriptSave,
443 TableName,
444 EFI_BOOT_SCRIPT_STALL_OPCODE,
445 Duration
446 );
447
448 return EFI_SUCCESS;
449 }
450
451 EFI_STATUS
452 BootScriptSaveDispatch (
453 IN UINT16 TableName,
454 IN EFI_PHYSICAL_ADDRESS EntryPoint
455 )
456 /*++
457
458 Routine Description:
459
460 GC_TODO: Add function description
461
462 Arguments:
463
464 TableName - GC_TODO: add argument description
465 EntryPoint - GC_TODO: add argument description
466
467 Returns:
468
469 EFI_NOT_FOUND - GC_TODO: Add description for return value
470 EFI_SUCCESS - GC_TODO: Add description for return value
471
472 --*/
473 {
474 if (mBootScriptSave == NULL) {
475 return EFI_NOT_FOUND;
476 }
477
478 mBootScriptSave->Write (
479 mBootScriptSave,
480 TableName,
481 EFI_BOOT_SCRIPT_DISPATCH_OPCODE,
482 EntryPoint
483 );
484
485 return EFI_SUCCESS;
486
487 }
488
489 EFI_STATUS
490 EFIAPI
491 BootScriptSaveInformation (
492 IN UINT16 TableName,
493 IN UINT32 Length,
494 IN EFI_PHYSICAL_ADDRESS Buffer
495 )
496 /*++
497
498 Routine Description:
499
500 Save a Information Opcode record in table specified with TableName
501
502 Arguments:
503
504 TableName - Desired boot script table
505 Length - Length of information in bytes
506 Buffer - Content of information that will be saved in script table
507
508 Returns:
509
510 EFI_NOT_FOUND - BootScriptSave Protocol not exist.
511
512 EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
513
514 --*/
515 {
516 if (mBootScriptSave == NULL) {
517 return EFI_NOT_FOUND;
518 }
519
520 mBootScriptSave->Write (
521 mBootScriptSave,
522 TableName,
523 EFI_BOOT_SCRIPT_INFORMATION_OPCODE,
524 Length,
525 Buffer
526 );
527
528 return EFI_SUCCESS;
529
530 }
531
532 EFI_STATUS
533 EFIAPI
534 BootScriptSaveInformationUnicodeString (
535 IN UINT16 TableName,
536 IN CHAR16 *String
537 )
538 /*++
539
540 Routine Description:
541
542 Save a Information Opcode record in table specified with TableName, the information
543 is a unicode string.
544
545 Arguments:
546
547 TableName - Desired boot script table
548 String - The string that will be saved in script table
549
550 Returns:
551
552 EFI_NOT_FOUND - BootScriptSave Protocol not exist.
553
554 EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
555
556 --*/
557 {
558 return BootScriptSaveInformation (
559 TableName,
560 (UINT32) EfiStrLen (String) * 2 + 2,
561 (EFI_PHYSICAL_ADDRESS)String
562 );
563 }
564
565 EFI_STATUS
566 EFIAPI
567 BootScriptSaveInformationAsciiString (
568 IN UINT16 TableName,
569 IN CHAR8 *String
570 )
571 /*++
572
573 Routine Description:
574
575 Save a Information Opcode record in table specified with TableName, the information
576 is a ascii string.
577
578 Arguments:
579
580 TableName - Desired boot script table
581 String - The string that will be saved in script table
582
583 Returns:
584
585 EFI_NOT_FOUND - BootScriptSave Protocol not exist.
586
587 EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
588
589 --*/
590 {
591 return BootScriptSaveInformation (
592 TableName,
593 (UINT32) EfiAsciiStrLen (String) + 1,
594 (EFI_PHYSICAL_ADDRESS)String
595 );
596 }
597