xref: /netbsd-src/sys/external/bsd/gnu-efi/dist/inc/efilib.h (revision 35ff39e48f27cc4d27af726cb651cda505a965b4)
1 /*	$NetBSD: efilib.h,v 1.3 2021/09/30 19:02:47 jmcneill Exp $	*/
2 
3 #ifndef _EFILIB_INCLUDE_
4 #define _EFILIB_INCLUDE_
5 
6 /*++
7 
8 Copyright (c) 2000  Intel Corporation
9 
10 Module Name:
11 
12     efilib.h
13 
14 Abstract:
15 
16     EFI library functions
17 
18 
19 
20 Revision History
21 
22 --*/
23 
24 #include "efidebug.h"
25 #include "efipart.h"
26 #if defined(_M_X64) || defined(__x86_64__) || defined(__amd64__)
27 #include "x86_64/efilibplat.h"
28 #elif defined(_M_IX86) || defined(__i386__)
29 #include "ia32/efilibplat.h"
30 #elif defined(_M_IA64) || defined(__ia64__)
31 #include "ia64/efilibplat.h"
32 #elif defined (_M_ARM64) || defined(__aarch64__)
33 #include "aarch64/efilibplat.h"
34 #elif defined (_M_ARM) || defined(__arm__)
35 #include "arm/efilibplat.h"
36 #elif defined (_M_MIPS64) || defined(__mips64__)
37 #include "mips64el/efilibplat.h"
38 #elif defined (__riscv) && __riscv_xlen == 64
39 #include "riscv64/efilibplat.h"
40 #endif
41 #include "efilink.h"
42 #include "efirtlib.h"
43 #include "efistdarg.h"
44 #include "pci22.h"
45 #include "libsmbios.h"
46 
47 //
48 // Public read-only data in the EFI library
49 //
50 
51 extern EFI_SYSTEM_TABLE         *ST;
52 #define gST                      ST
53 extern EFI_BOOT_SERVICES        *BS;
54 #define gBS                      BS
55 extern EFI_RUNTIME_SERVICES     *RT;
56 #define gRT                      RT
57 
58 extern EFI_GUID gEfiDevicePathProtocolGuid;
59 #define DevicePathProtocol gEfiDevicePathProtocolGuid
60 extern EFI_GUID gEfiDevicePathToTextProtocolGuid;
61 #define DevicePathToTextProtocol gEfiDevicePathToTextProtocolGuid
62 extern EFI_GUID gEfiDevicePathFromTextProtocolGuid;
63 #define DevicePathFromTextProtocol gEfiDevicePathFromTextProtocolGuid
64 extern EFI_GUID gEfiDevicePathUtilitiesProtocolGuid;
65 #define DevicePathUtilitiesProtocol gEfiDevicePathUtilitiesProtocolGuid
66 extern EFI_GUID gEfiLoadedImageProtocolGuid;
67 #define LoadedImageProtocol gEfiLoadedImageProtocolGuid
68 extern EFI_GUID gEfiSimpleTextInProtocolGuid;
69 #define TextInProtocol gEfiSimpleTextInProtocolGuid
70 extern EFI_GUID gEfiSimpleTextOutProtocolGuid;
71 #define TextOutProtocol gEfiSimpleTextOutProtocolGuid
72 extern EFI_GUID gEfiGraphicsOutputProtocolGuid;
73 #define GraphicsOutputProtocol gEfiGraphicsOutputProtocolGuid
74 extern EFI_GUID gEfiEdidDiscoveredProtocolGuid;
75 #define EdidDiscoveredProtocol gEfiEdidDiscoveredProtocolGuid
76 extern EFI_GUID gEfiEdidActiveProtocolGuid;
77 #define EdidActiveProtocol gEfiEdidActiveProtocolGuid
78 extern EFI_GUID gEfiEdidOverrideProtocolGuid;
79 #define EdidOverrideProtocol gEfiEdidOverrideProtocolGuid
80 extern EFI_GUID gEfiBlockIoProtocolGuid;
81 #define BlockIoProtocol gEfiBlockIoProtocolGuid
82 extern EFI_GUID gEfiBlockIo2ProtocolGuid;
83 #define BlockIo2Protocol gEfiBlockIo2ProtocolGuid
84 extern EFI_GUID gEfiDiskIoProtocolGuid;
85 #define DiskIoProtocol gEfiDiskIoProtocolGuid
86 extern EFI_GUID gEfiDiskIo2ProtocolGuid;
87 #define DiskIo2Protocol gEfiDiskIo2ProtocolGuid
88 extern EFI_GUID gEfiSimpleFileSystemProtocolGuid;
89 #define FileSystemProtocol gEfiSimpleFileSystemProtocolGuid
90 extern EFI_GUID gEfiLoadFileProtocolGuid;
91 #define LoadFileProtocol gEfiLoadFileProtocolGuid
92 extern EFI_GUID gEfiDeviceIoProtocolGuid;
93 #define DeviceIoProtocol gEfiDeviceIoProtocolGuid
94 extern EFI_GUID VariableStoreProtocol;
95 extern EFI_GUID LegacyBootProtocol;
96 extern EFI_GUID gEfiUnicodeCollationProtocolGuid;
97 #define UnicodeCollationProtocol gEfiUnicodeCollationProtocolGuid
98 extern EFI_GUID gEfiSerialIoProtocolGuid;
99 #define SerialIoProtocol gEfiSerialIoProtocolGuid
100 extern EFI_GUID VgaClassProtocol;
101 extern EFI_GUID TextOutSpliterProtocol;
102 extern EFI_GUID ErrorOutSpliterProtocol;
103 extern EFI_GUID TextInSpliterProtocol;
104 extern EFI_GUID gEfiSimpleNetworkProtocolGuid;
105 #define SimpleNetworkProtocol gEfiSimpleNetworkProtocolGuid
106 extern EFI_GUID gEfiPxeBaseCodeProtocolGuid;
107 #define PxeBaseCodeProtocol gEfiPxeBaseCodeProtocolGuid
108 extern EFI_GUID gEfiPxeBaseCodeCallbackProtocolGuid;
109 #define PxeCallbackProtocol gEfiPxeBaseCodeCallbackProtocolGuid
110 extern EFI_GUID gEfiNetworkInterfaceIdentifierProtocolGuid;
111 #define NetworkInterfaceIdentifierProtocol gEfiNetworkInterfaceIdentifierProtocolGuid
112 extern EFI_GUID gEFiUiInterfaceProtocolGuid;
113 #define UiProtocol gEFiUiInterfaceProtocolGuid
114 extern EFI_GUID InternalShellProtocol;
115 extern EFI_GUID gEfiPciIoProtocolGuid;
116 #define PciIoProtocol gEfiPciIoProtocolGuid
117 extern EFI_GUID gEfiPciRootBridgeIoProtocolGuid;
118 extern EFI_GUID gEfiDriverBindingProtocolGuid;
119 #define DriverBindingProtocol gEfiDriverBindingProtocolGuid
120 extern EFI_GUID gEfiComponentNameProtocolGuid;
121 #define ComponentNameProtocol gEfiComponentNameProtocolGuid
122 extern EFI_GUID gEfiComponentName2ProtocolGuid;
123 #define ComponentName2Protocol gEfiComponentName2ProtocolGuid
124 extern EFI_GUID gEfiHashProtocolGuid;
125 #define HashProtocol gEfiHashProtocolGuid
126 extern EFI_GUID gEfiPlatformDriverOverrideProtocolGuid;
127 #define PlatformDriverOverrideProtocol gEfiPlatformDriverOverrideProtocolGuid
128 extern EFI_GUID gEfiBusSpecificDriverOverrideProtocolGuid;
129 #define BusSpecificDriverOverrideProtocol gEfiBusSpecificDriverOverrideProtocolGuid
130 extern EFI_GUID gEfiDriverFamilyOverrideProtocolGuid;
131 #define DriverFamilyOverrideProtocol gEfiDriverFamilyOverrideProtocolGuid
132 extern EFI_GUID gEfiEbcProtocolGuid;
133 
134 extern EFI_GUID gEfiGlobalVariableGuid;
135 #define EfiGlobalVariable gEfiGlobalVariableGuid
136 extern EFI_GUID gEfiFileInfoGuid;
137 #define GenericFileInfo gEfiFileInfoGuid
138 extern EFI_GUID gEfiFileSystemInfoGuid;
139 #define FileSystemInfo gEfiFileSystemInfoGuid
140 extern EFI_GUID gEfiFileSystemVolumeLabelInfoIdGuid;
141 #define FileSystemVolumeLabelInfo gEfiFileSystemVolumeLabelInfoIdGuid
142 extern EFI_GUID gEfiPcAnsiGuid;
143 #define PcAnsiProtocol gEfiPcAnsiGuid
144 extern EFI_GUID gEfiVT100Guid;
145 #define Vt100Protocol gEfiVT100Guid
146 extern EFI_GUID gEfiVT100PlusGuid;
147 extern EFI_GUID gEfiVTUTF8Guid;
148 
149 extern EFI_GUID NullGuid;
150 extern EFI_GUID UnknownDevice;
151 
152 extern EFI_GUID EfiPartTypeSystemPartitionGuid;
153 extern EFI_GUID EfiPartTypeLegacyMbrGuid;
154 
155 extern EFI_GUID MpsTableGuid;
156 extern EFI_GUID AcpiTableGuid;
157 extern EFI_GUID SMBIOSTableGuid;
158 extern EFI_GUID SMBIOS3TableGuid;
159 extern EFI_GUID SalSystemTableGuid;
160 extern EFI_GUID EfiDtbTableGuid;
161 
162 extern EFI_GUID SimplePointerProtocol;
163 extern EFI_GUID AbsolutePointerProtocol;
164 
165 extern EFI_GUID gEfiDebugImageInfoTableGuid;
166 extern EFI_GUID gEfiDebugSupportProtocolGuid;
167 
168 extern EFI_GUID SimpleTextInputExProtocol;
169 
170 extern EFI_GUID ShellProtocolGuid;
171 extern EFI_GUID ShellParametersProtocolGuid;
172 extern EFI_GUID ShellDynamicCommandProtocolGuid;
173 
174 //
175 // EFI Variable strings
176 //
177 #define LOAD_OPTION_ACTIVE      0x00000001
178 
179 #define VarLanguageCodes       L"LangCodes"
180 #define VarLanguage            L"Lang"
181 #define VarTimeout             L"Timeout"
182 #define VarConsoleInp          L"ConIn"
183 #define VarConsoleOut          L"ConOut"
184 #define VarErrorOut            L"ErrOut"
185 #define VarBootOption          L"Boot%04x"
186 #define VarBootOrder           L"BootOrder"
187 #define VarBootNext            L"BootNext"
188 #define VarBootCurrent         L"BootCurrent"
189 #define VarDriverOption        L"Driver%04x"
190 #define VarDriverOrder         L"DriverOrder"
191 #define VarConsoleInpDev       L"ConInDev"
192 #define VarConsoleOutDev       L"ConOutDev"
193 #define VarErrorOutDev         L"ErrOutDev"
194 
195 #define LanguageCodeEnglish    "eng"
196 
197 extern EFI_DEVICE_PATH RootDevicePath[];
198 extern EFI_DEVICE_PATH EndDevicePath[];
199 extern EFI_DEVICE_PATH EndInstanceDevicePath[];
200 
201 //
202 // Other public data in the EFI library
203 //
204 
205 extern EFI_MEMORY_TYPE PoolAllocationType;
206 
207 //
208 // STATIC - Name is internal to the module
209 // INTERNAL - Name is internal to the component (i.e., directory)
210 // BOOTSERVCE - Name of a boot service function
211 //
212 
213 #define STATIC
214 #define INTERNAL
215 #define BOOTSERVICE
216 
217 //
218 // Prototypes
219 //
220 
221 VOID
222 InitializeLib (
223     IN EFI_HANDLE           ImageHandle,
224     IN EFI_SYSTEM_TABLE     *SystemTable
225     );
226 
227 VOID
228 InitializeUnicodeSupport (
229     CHAR8 *LangCode
230     );
231 
232 VOID
233 EFIDebugVariable (
234     VOID
235     );
236 
237 VOID
238 Exit(
239     IN EFI_STATUS   ExitStatus,
240     IN UINTN        ExitDataSize,
241     IN CHAR16       *ExitData OPTIONAL
242     );
243 
244 INTN
245 GetShellArgcArgv(
246     EFI_HANDLE ImageHandle,
247     CHAR16 **Argv[]  /* Statically allocated */
248     );
249 
250 VOID
251 SetCrc (
252     IN OUT EFI_TABLE_HEADER *Hdr
253     );
254 
255 VOID
256 SetCrcAltSize (
257     IN UINTN                 Size,
258     IN OUT EFI_TABLE_HEADER *Hdr
259     );
260 
261 BOOLEAN
262 CheckCrc (
263     IN UINTN                 MaxSize,
264     IN OUT EFI_TABLE_HEADER *Hdr
265     );
266 
267 BOOLEAN
268 CheckCrcAltSize (
269     IN UINTN                 MaxSize,
270     IN UINTN                 Size,
271     IN OUT EFI_TABLE_HEADER *Hdr
272     );
273 
274 UINT32
275 CalculateCrc (
276     UINT8 *pt,
277     UINTN Size
278     );
279 
280 VOID
281 ZeroMem (
282     IN VOID     *Buffer,
283     IN UINTN     Size
284     );
285 
286 VOID
287 SetMem (
288     IN VOID     *Buffer,
289     IN UINTN    Size,
290     IN UINT8    Value
291     );
292 
293 VOID
294 CopyMem (
295     IN VOID     *Dest,
296     IN CONST VOID     *Src,
297     IN UINTN    len
298     );
299 
300 INTN
301 CompareMem (
302     IN CONST VOID     *Dest,
303     IN CONST VOID     *Src,
304     IN UINTN    len
305     );
306 
307 INTN
308 StrCmp (
309     IN CONST CHAR16   *s1,
310     IN CONST CHAR16   *s2
311     );
312 
313 INTN
314 StrnCmp (
315     IN CONST CHAR16   *s1,
316     IN CONST CHAR16   *s2,
317     IN UINTN    len
318     );
319 
320 INTN
321 StriCmp (
322     IN CONST CHAR16   *s1,
323     IN CONST CHAR16   *s2
324     );
325 
326 VOID
327 StrLwr (
328     IN CHAR16   *Str
329     );
330 
331 VOID
332 StrUpr (
333     IN CHAR16   *Str
334     );
335 
336 VOID
337 StrCpy (
338     IN CHAR16   *Dest,
339     IN CONST CHAR16    *Src
340     );
341 
342 VOID
343 StrnCpy (
344     IN CHAR16   *Dest,
345     IN CONST CHAR16    *Src,
346     IN UINTN     Len
347     );
348 
349 CHAR16 *
350 StpCpy (
351     IN CHAR16   *Dest,
352     IN CONST CHAR16    *Src
353     );
354 
355 CHAR16 *
356 StpnCpy (
357     IN CHAR16   *Dest,
358     IN CONST CHAR16    *Src,
359     IN UINTN     Len
360     );
361 
362 VOID
363 StrCat (
364     IN CHAR16   *Dest,
365     IN CONST CHAR16   *Src
366     );
367 
368 VOID
369 StrnCat (
370     IN CHAR16   *Dest,
371     IN CONST CHAR16   *Src,
372     IN UINTN     Len
373     );
374 
375 UINTN
376 StrLen (
377     IN CONST CHAR16   *s1
378     );
379 
380 UINTN
381 StrnLen (
382     IN CONST CHAR16   *s1,
383     IN UINTN           Len
384     );
385 
386 UINTN
387 StrSize (
388     IN CONST CHAR16   *s1
389     );
390 
391 CHAR16 *
392 StrDuplicate (
393     IN CONST CHAR16   *Src
394     );
395 
396 UINTN
397 strlena (
398     IN CONST CHAR8    *s1
399     );
400 
401 UINTN
402 strcmpa (
403     IN CONST CHAR8    *s1,
404     IN CONST CHAR8    *s2
405     );
406 
407 UINTN
408 strncmpa (
409     IN CONST CHAR8    *s1,
410     IN CONST CHAR8    *s2,
411     IN UINTN    len
412     );
413 
414 UINTN
415 xtoi (
416     CONST CHAR16      *str
417     );
418 
419 UINTN
420 Atoi (
421     CONST CHAR16  *str
422     );
423 
424 BOOLEAN
425 MetaMatch (
426     IN CHAR16   *String,
427     IN CHAR16   *Pattern
428     );
429 
430 BOOLEAN
431 MetaiMatch (
432     IN CHAR16   *String,
433     IN CHAR16   *Pattern
434     );
435 
436 UINT64
437 LShiftU64 (
438     IN UINT64   Operand,
439     IN UINTN    Count
440     );
441 
442 UINT64
443 RShiftU64 (
444     IN UINT64   Operand,
445     IN UINTN    Count
446     );
447 
448 UINT64
449 MultU64x32 (
450     IN UINT64   Multiplicand,
451     IN UINTN    Multiplier
452     );
453 
454 UINT64
455 DivU64x32 (
456     IN UINT64   Dividend,
457     IN UINTN    Divisor,
458     OUT UINTN   *Remainder OPTIONAL
459     );
460 
461 VOID
462 InitializeLock (
463     IN OUT FLOCK    *Lock,
464     IN EFI_TPL  Priority
465     );
466 
467 VOID
468 AcquireLock (
469     IN FLOCK    *Lock
470     );
471 
472 VOID
473 ReleaseLock (
474     IN FLOCK    *Lock
475     );
476 
477 
478 INTN
479 CompareGuid(
480     IN EFI_GUID     *Guid1,
481     IN EFI_GUID     *Guid2
482     );
483 
484 VOID *
485 AllocatePool (
486     IN UINTN     Size
487     );
488 
489 VOID *
490 AllocateZeroPool (
491     IN UINTN     Size
492     );
493 
494 VOID *
495 ReallocatePool (
496     IN VOID                 *OldPool,
497     IN UINTN                OldSize,
498     IN UINTN                NewSize
499     );
500 
501 VOID
502 FreePool (
503     IN VOID     *p
504     );
505 
506 
507 VOID
508 Output (
509     IN CHAR16   *Str
510     );
511 
512 VOID
513 Input (
514     IN CHAR16   *Prompt OPTIONAL,
515     OUT CHAR16  *InStr,
516     IN UINTN    StrLen
517     );
518 
519 VOID
520 IInput (
521     IN SIMPLE_TEXT_OUTPUT_INTERFACE     *ConOut,
522     IN SIMPLE_INPUT_INTERFACE           *ConIn,
523     IN CHAR16                           *Prompt OPTIONAL,
524     OUT CHAR16                          *InStr,
525     IN UINTN                            StrLen
526     );
527 
528 UINTN
529 Print (
530     IN CONST CHAR16   *fmt,
531     ...
532     );
533 
534 UINTN
535 VPrint (
536     IN CONST CHAR16   *fmt,
537     va_list           args
538     );
539 
540 UINTN
541 UnicodeSPrint (
542     OUT CHAR16        *Str,
543     IN UINTN          StrSize,
544     IN CONST CHAR16   *fmt,
545     ...
546     );
547 
548 UINTN
549 UnicodeVSPrint (
550     OUT CHAR16        *Str,
551     IN UINTN          StrSize,
552     IN CONST CHAR16   *fmt,
553     va_list           args
554     );
555 
556 CHAR16 *
557 VPoolPrint (
558     IN CONST CHAR16     *fmt,
559     va_list             args
560     );
561 
562 CHAR16 *
563 PoolPrint (
564     IN CONST CHAR16     *fmt,
565     ...
566     );
567 
568 typedef struct {
569     CHAR16      *str;
570     UINTN       len;
571     UINTN       maxlen;
572 } POOL_PRINT;
573 
574 CHAR16 *
575 CatPrint (
576     IN OUT POOL_PRINT   *Str,
577     IN CONST CHAR16     *fmt,
578     ...
579     );
580 
581 UINTN
582 PrintAt (
583     IN UINTN         Column,
584     IN UINTN         Row,
585     IN CONST CHAR16  *fmt,
586     ...
587     );
588 
589 UINTN
590 IPrint (
591     IN SIMPLE_TEXT_OUTPUT_INTERFACE    *Out,
592     IN CONST CHAR16                    *fmt,
593     ...
594     );
595 
596 UINTN
597 IPrintAt (
598     IN SIMPLE_TEXT_OUTPUT_INTERFACE     *Out,
599     IN UINTN                            Column,
600     IN UINTN                            Row,
601     IN CONST CHAR16                     *fmt,
602     ...
603     );
604 
605 UINTN
606 AsciiPrint (
607     IN CONST CHAR8    *fmt,
608     ...
609     );
610 
611 UINTN
612 AsciiVSPrint(
613     OUT CHAR8         *Str,
614     IN  UINTN         StrSize,
615     IN  CONST CHAR8   *fmt,
616     va_list           args
617 );
618 
619 //
620 // For compatibility with previous gnu-efi versions
621 //
622 #define SPrint      UnicodeSPrint
623 #define VSPrint     UnicodeVSPrint
624 #define APrint      AsciiPrint
625 
626 VOID
627 ValueToHex (
628     IN CHAR16   *Buffer,
629     IN UINT64   v
630     );
631 
632 VOID
633 ValueToString (
634     IN CHAR16   *Buffer,
635     IN BOOLEAN  Comma,
636     IN INT64    v
637     );
638 
639 #ifndef __NetBSD__
640 VOID
641 FloatToString (
642     IN CHAR16   *Buffer,
643     IN BOOLEAN  Comma,
644     IN double    v
645     );
646 #endif
647 
648 VOID
649 TimeToString (
650     OUT CHAR16      *Buffer,
651     IN EFI_TIME     *Time
652     );
653 
654 VOID
655 GuidToString (
656     OUT CHAR16      *Buffer,
657     IN EFI_GUID     *Guid
658     );
659 
660 VOID
661 StatusToString (
662     OUT CHAR16      *Buffer,
663     EFI_STATUS      Status
664     );
665 
666 VOID
667 DumpHex (
668     IN UINTN        Indent,
669     IN UINTN        Offset,
670     IN UINTN        DataSize,
671     IN VOID         *UserData
672     );
673 
674 BOOLEAN
675 GrowBuffer(
676     IN OUT EFI_STATUS   *Status,
677     IN OUT VOID         **Buffer,
678     IN UINTN            BufferSize
679     );
680 
681 EFI_MEMORY_DESCRIPTOR *
682 LibMemoryMap (
683     OUT UINTN               *NoEntries,
684     OUT UINTN               *MapKey,
685     OUT UINTN               *DescriptorSize,
686     OUT UINT32              *DescriptorVersion
687     );
688 
689 VOID *
690 LibGetVariable (
691     IN CHAR16               *Name,
692     IN EFI_GUID             *VendorGuid
693     );
694 
695 VOID *
696 LibGetVariableAndSize (
697     IN CHAR16               *Name,
698     IN EFI_GUID             *VendorGuid,
699     OUT UINTN               *VarSize
700     );
701 
702 EFI_STATUS
703 LibDeleteVariable (
704     IN CHAR16   *VarName,
705     IN EFI_GUID *VarGuid
706     );
707 
708 EFI_STATUS
709 LibSetNVVariable (
710     IN CHAR16   *VarName,
711     IN EFI_GUID *VarGuid,
712     IN UINTN	 DataSize,
713     IN VOID     *Data
714     );
715 
716 EFI_STATUS
717 LibSetVariable (
718     IN CHAR16   *VarName,
719     IN EFI_GUID *VarGuid,
720     IN UINTN	 DataSize,
721     IN VOID     *Data
722     );
723 EFI_STATUS
724 LibInsertToTailOfBootOrder (
725     IN  UINT16  BootOption,
726     IN  BOOLEAN OnlyInsertIfEmpty
727     );
728 
729 EFI_STATUS
730 LibLocateProtocol (
731     IN  EFI_GUID    *ProtocolGuid,
732     OUT VOID        **Interface
733     );
734 
735 EFI_STATUS
736 LibLocateHandle (
737     IN EFI_LOCATE_SEARCH_TYPE   SearchType,
738     IN EFI_GUID                 *Protocol OPTIONAL,
739     IN VOID                     *SearchKey OPTIONAL,
740     IN OUT UINTN                *NoHandles,
741     OUT EFI_HANDLE              **Buffer
742     );
743 
744 EFI_STATUS
745 LibLocateHandleByDiskSignature (
746     IN UINT8                        MBRType,
747     IN UINT8                        SignatureType,
748     IN VOID                         *Signature,
749     IN OUT UINTN                    *NoHandles,
750     OUT EFI_HANDLE                  **Buffer
751     );
752 
753 EFI_STATUS
754 LibInstallProtocolInterfaces (
755     IN OUT EFI_HANDLE       *Handle,
756     ...
757     );
758 
759 VOID
760 LibUninstallProtocolInterfaces (
761     IN EFI_HANDLE           Handle,
762     ...
763     );
764 
765 EFI_STATUS
766 LibReinstallProtocolInterfaces (
767     IN OUT EFI_HANDLE           *Handle,
768     ...
769     );
770 
771 EFI_EVENT
772 LibCreateProtocolNotifyEvent (
773     IN EFI_GUID             *ProtocolGuid,
774     IN EFI_TPL              NotifyTpl,
775     IN EFI_EVENT_NOTIFY     NotifyFunction,
776     IN VOID                 *NotifyContext,
777     OUT VOID                *Registration
778     );
779 
780 EFI_STATUS
781 WaitForSingleEvent (
782     IN EFI_EVENT        Event,
783     IN UINT64           Timeout OPTIONAL
784     );
785 
786 VOID
787 WaitForEventWithTimeout (
788     IN  EFI_EVENT       Event,
789     IN  UINTN           Timeout,
790     IN  UINTN           Row,
791     IN  UINTN           Column,
792     IN  CHAR16          *String,
793     IN  EFI_INPUT_KEY   TimeoutKey,
794     OUT EFI_INPUT_KEY   *Key
795     );
796 
797 EFI_FILE_HANDLE
798 LibOpenRoot (
799     IN EFI_HANDLE           DeviceHandle
800     );
801 
802 EFI_FILE_INFO *
803 LibFileInfo (
804     IN EFI_FILE_HANDLE      FHand
805     );
806 
807 EFI_FILE_SYSTEM_INFO *
808 LibFileSystemInfo (
809     IN EFI_FILE_HANDLE      FHand
810     );
811 
812 EFI_FILE_SYSTEM_VOLUME_LABEL_INFO *
813 LibFileSystemVolumeLabelInfo (
814     IN EFI_FILE_HANDLE      FHand
815     );
816 
817 BOOLEAN
818 ValidMBR(
819     IN  MASTER_BOOT_RECORD  *Mbr,
820     IN  EFI_BLOCK_IO        *BlkIo
821     );
822 
823 BOOLEAN
824 LibMatchDevicePaths (
825     IN  EFI_DEVICE_PATH *Multi,
826     IN  EFI_DEVICE_PATH *Single
827     );
828 
829 EFI_DEVICE_PATH *
830 LibDuplicateDevicePathInstance (
831     IN EFI_DEVICE_PATH  *DevPath
832     );
833 
834 EFI_DEVICE_PATH *
835 DevicePathFromHandle (
836     IN EFI_HANDLE           Handle
837     );
838 
839 EFI_DEVICE_PATH *
840 DevicePathInstance (
841     IN OUT EFI_DEVICE_PATH  **DevicePath,
842     OUT UINTN               *Size
843     );
844 
845 UINTN
846 DevicePathInstanceCount (
847     IN EFI_DEVICE_PATH      *DevicePath
848     );
849 
850 EFI_DEVICE_PATH *
851 AppendDevicePath (
852     IN EFI_DEVICE_PATH      *Src1,
853     IN EFI_DEVICE_PATH      *Src2
854     );
855 
856 EFI_DEVICE_PATH *
857 AppendDevicePathNode (
858     IN EFI_DEVICE_PATH      *Src1,
859     IN EFI_DEVICE_PATH      *Src2
860     );
861 
862 EFI_DEVICE_PATH*
863 AppendDevicePathInstance (
864     IN EFI_DEVICE_PATH  *Src,
865     IN EFI_DEVICE_PATH  *Instance
866     );
867 
868 EFI_DEVICE_PATH *
869 FileDevicePath (
870     IN EFI_HANDLE           Device  OPTIONAL,
871     IN CHAR16               *FileName
872     );
873 
874 UINTN
875 DevicePathSize (
876     IN EFI_DEVICE_PATH      *DevPath
877     );
878 
879 EFI_DEVICE_PATH *
880 DuplicateDevicePath (
881     IN EFI_DEVICE_PATH      *DevPath
882     );
883 
884 EFI_DEVICE_PATH *
885 UnpackDevicePath (
886     IN EFI_DEVICE_PATH      *DevPath
887     );
888 
889 EFI_STATUS
890 LibDevicePathToInterface (
891     IN EFI_GUID             *Protocol,
892     IN EFI_DEVICE_PATH      *FilePath,
893     OUT VOID                **Interface
894     );
895 
896 CHAR16 *
897 DevicePathToStr (
898     EFI_DEVICE_PATH         *DevPath
899     );
900 
901 //
902 // BugBug: I need my own include files
903 //
904 typedef struct {
905     UINT8   Register;
906     UINT8   Function;
907     UINT8   Device;
908     UINT8   Bus;
909     UINT32  Reserved;
910 } EFI_ADDRESS;
911 
912 typedef union {
913     UINT64          Address;
914     EFI_ADDRESS     EfiAddress;
915 } EFI_PCI_ADDRESS_UNION;
916 
917 
918 EFI_STATUS
919 PciFindDeviceClass (
920     IN  OUT EFI_PCI_ADDRESS_UNION   *Address,
921     IN      UINT8                   BaseClass,
922     IN      UINT8                   SubClass
923     );
924 
925 EFI_STATUS
926 PciFindDevice (
927     IN  OUT EFI_PCI_ADDRESS_UNION   *DeviceAddress,
928     IN      UINT16                  VendorId,
929     IN      UINT16                  DeviceId,
930     IN OUT  PCI_TYPE00              *Pci
931     );
932 
933 //
934 // SIMPLE_READ_FILE object used to access files
935 //
936 
937 typedef VOID        *SIMPLE_READ_FILE;
938 
939 EFI_STATUS
940 OpenSimpleReadFile (
941     IN BOOLEAN                  BootPolicy,
942     IN VOID                     *SourceBuffer   OPTIONAL,
943     IN UINTN                    SourceSize,
944     IN OUT EFI_DEVICE_PATH      **FilePath,
945     OUT EFI_HANDLE              *DeviceHandle,
946     OUT SIMPLE_READ_FILE        *SimpleReadHandle
947     );
948 
949 EFI_STATUS
950 ReadSimpleReadFile (
951     IN SIMPLE_READ_FILE     SimpleReadHandle,
952     IN UINTN                Offset,
953     IN OUT UINTN            *ReadSize,
954     OUT VOID                *Buffer
955     );
956 
957 
958 VOID
959 CloseSimpleReadFile (
960     IN SIMPLE_READ_FILE     SimpleReadHandle
961     );
962 
963 VOID
964 InitializeGuid (
965     VOID
966     );
967 
968 UINT8
969 DecimaltoBCD(
970     IN  UINT8 DecValue
971     );
972 
973 UINT8
974 BCDtoDecimal(
975     IN  UINT8 BcdValue
976     );
977 
978 EFI_STATUS
979 LibGetSystemConfigurationTable(
980     IN EFI_GUID *TableGuid,
981     IN OUT VOID **Table
982     );
983 
984 BOOLEAN
985 LibIsValidTextGraphics (
986     IN  CHAR16  Graphic,
987     OUT CHAR8   *PcAnsi,    OPTIONAL
988     OUT CHAR8   *Ascii      OPTIONAL
989     );
990 
991 BOOLEAN
992 IsValidAscii (
993     IN  CHAR16  Ascii
994     );
995 
996 BOOLEAN
997 IsValidEfiCntlChar (
998     IN  CHAR16  c
999     );
1000 
1001 CHAR16 *
1002 LibGetUiString (
1003     IN  EFI_HANDLE      Handle,
1004     IN  UI_STRING_TYPE  StringType,
1005     IN  ISO_639_2       *LangCode,
1006     IN  BOOLEAN         ReturnDevicePathStrOnMismatch
1007     );
1008 
1009 CHAR8*
1010 LibGetSmbiosString (
1011     IN  SMBIOS_STRUCTURE_POINTER    *Smbios,
1012     IN  UINT16                      StringNumber
1013     );
1014 
1015 EFI_STATUS
1016 LibGetSmbiosSystemGuidAndSerialNumber (
1017     IN  EFI_GUID    *SystemGuid,
1018     OUT CHAR8       **SystemSerialNumber
1019     );
1020 
1021 
1022 EFI_STATUS
1023 InitializeGlobalIoDevice (
1024         IN  EFI_DEVICE_PATH             *DevicePath,
1025         IN  EFI_GUID                    *Protocol,
1026         IN  CHAR8                       *ErrorStr,
1027         OUT EFI_DEVICE_IO_INTERFACE     **GlobalIoFncs
1028         );
1029 
1030 UINT32
1031 ReadPort (
1032         IN  EFI_DEVICE_IO_INTERFACE     *GlobalIoFncs,
1033         IN  EFI_IO_WIDTH                Width,
1034         IN  UINTN                       Port
1035         );
1036 
1037 UINT32
1038 WritePort (
1039         IN  EFI_DEVICE_IO_INTERFACE     *GlobalIoFncs,
1040         IN  EFI_IO_WIDTH                Width,
1041         IN  UINTN                       Port,
1042         IN  UINTN                       Data
1043         );
1044 
1045 UINT32
1046 ReadPciConfig (
1047         IN  EFI_DEVICE_IO_INTERFACE     *GlobalIoFncs,
1048         IN  EFI_IO_WIDTH                Width,
1049         IN  UINTN                       Port
1050         );
1051 
1052 UINT32
1053 WritePciConfig (
1054         IN  EFI_DEVICE_IO_INTERFACE     *GlobalIoFncs,
1055         IN  EFI_IO_WIDTH                Width,
1056         IN  UINTN                       Port,
1057         IN  UINTN                       Data
1058         );
1059 
1060 VOID
1061 Pause (
1062     VOID
1063 );
1064 
1065 extern EFI_DEVICE_IO_INTERFACE  *GlobalIoFncs;
1066 
1067 #define outp(_Port, _DataByte)  (UINT8)WritePort(GlobalIoFncs,  IO_UINT8,  (UINTN)_Port, (UINTN)_DataByte)
1068 #define inp(_Port)              (UINT8)ReadPort(GlobalIoFncs,   IO_UINT8,  (UINTN)_Port)
1069 #define outpw(_Port, _DataByte) (UINT16)WritePort(GlobalIoFncs, IO_UINT16, (UINTN)_Port, (UINTN)_DataByte)
1070 #define inpw(_Port)             (UINT16)ReadPort(GlobalIoFncs,  IO_UINT16, (UINTN)_Port)
1071 #define outpd(_Port, _DataByte) (UINT32)WritePort(GlobalIoFncs, IO_UINT32, (UINTN)_Port, (UINTN)_DataByte)
1072 #define inpd(_Port)             (UINT32)ReadPort(GlobalIoFncs,  IO_UINT32, (UINTN)_Port)
1073 
1074 #define writepci8(_Addr, _DataByte)  (UINT8)WritePciConfig(GlobalIoFncs,  IO_UINT8,  (UINTN)_Addr, (UINTN)_DataByte)
1075 #define readpci8(_Addr)              (UINT8)ReadPciConfig(GlobalIoFncs,   IO_UINT8,  (UINTN)_Addr)
1076 #define writepci16(_Addr, _DataByte) (UINT16)WritePciConfig(GlobalIoFncs, IO_UINT16, (UINTN)_Addr, (UINTN)_DataByte)
1077 #define readpci16(_Addr)             (UINT16)ReadPciConfig(GlobalIoFncs,  IO_UINT16, (UINTN)_Addr)
1078 #define writepci32(_Addr, _DataByte) (UINT32)WritePciConfig(GlobalIoFncs, IO_UINT32, (UINTN)_Addr, (UINTN)_DataByte)
1079 #define readpci32(_Addr)             (UINT32)ReadPciConfig(GlobalIoFncs,  IO_UINT32, (UINTN)_Addr)
1080 
1081 #define Port80(_PostCode)   GlobalIoFncs->Io.Write (GlobalIoFncs, IO_UINT16, (UINT64)0x80, 1, &(_PostCode))
1082 
1083 #endif
1084