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