Adding upstream version 6.03~pre1+dfsg.
[syslinux-debian/hramrach.git] / efi32 / include / efi / efilib.h
blobe0c6375898dacb4a4b342215fbb40a624633a2d0
1 #ifndef _EFILIB_INCLUDE_
2 #define _EFILIB_INCLUDE_
4 /*++
6 Copyright (c) 2000 Intel Corporation
8 Module Name:
10 efilib.h
12 Abstract:
14 EFI library functions
18 Revision History
20 --*/
22 #include "efidebug.h"
23 #include "efipart.h"
24 #include "efilibplat.h"
25 #include "efilink.h"
26 #include "efirtlib.h"
27 #include "pci22.h"
28 #include "libsmbios.h"
31 // Public read-only data in the EFI library
34 extern EFI_SYSTEM_TABLE *ST;
35 extern EFI_BOOT_SERVICES *BS;
36 extern EFI_RUNTIME_SERVICES *RT;
38 extern EFI_GUID DevicePathProtocol;
39 extern EFI_GUID LoadedImageProtocol;
40 extern EFI_GUID TextInProtocol;
41 extern EFI_GUID TextOutProtocol;
42 extern EFI_GUID BlockIoProtocol;
43 extern EFI_GUID DiskIoProtocol;
44 extern EFI_GUID FileSystemProtocol;
45 extern EFI_GUID LoadFileProtocol;
46 extern EFI_GUID DeviceIoProtocol;
47 extern EFI_GUID VariableStoreProtocol;
48 extern EFI_GUID LegacyBootProtocol;
49 extern EFI_GUID UnicodeCollationProtocol;
50 extern EFI_GUID SerialIoProtocol;
51 extern EFI_GUID VgaClassProtocol;
52 extern EFI_GUID TextOutSpliterProtocol;
53 extern EFI_GUID ErrorOutSpliterProtocol;
54 extern EFI_GUID TextInSpliterProtocol;
55 extern EFI_GUID SimpleNetworkProtocol;
56 extern EFI_GUID PxeBaseCodeProtocol;
57 extern EFI_GUID PxeCallbackProtocol;
58 extern EFI_GUID NetworkInterfaceIdentifierProtocol;
59 extern EFI_GUID UiProtocol;
60 extern EFI_GUID InternalShellProtocol;
61 extern EFI_GUID PciIoProtocol;
63 extern EFI_GUID EfiGlobalVariable;
64 extern EFI_GUID GenericFileInfo;
65 extern EFI_GUID FileSystemInfo;
66 extern EFI_GUID FileSystemVolumeLabelInfo;
67 extern EFI_GUID PcAnsiProtocol;
68 extern EFI_GUID Vt100Protocol;
69 extern EFI_GUID NullGuid;
70 extern EFI_GUID UnknownDevice;
72 extern EFI_GUID EfiPartTypeSystemPartitionGuid;
73 extern EFI_GUID EfiPartTypeLegacyMbrGuid;
75 extern EFI_GUID MpsTableGuid;
76 extern EFI_GUID AcpiTableGuid;
77 extern EFI_GUID SMBIOSTableGuid;
78 extern EFI_GUID SalSystemTableGuid;
81 // EFI Variable strings
83 #define LOAD_OPTION_ACTIVE 0x00000001
85 #define VarLanguageCodes L"LangCodes"
86 #define VarLanguage L"Lang"
87 #define VarTimeout L"Timeout"
88 #define VarConsoleInp L"ConIn"
89 #define VarConsoleOut L"ConOut"
90 #define VarErrorOut L"ErrOut"
91 #define VarBootOption L"Boot%04x"
92 #define VarBootOrder L"BootOrder"
93 #define VarBootNext L"BootNext"
94 #define VarBootCurrent L"BootCurrent"
95 #define VarDriverOption L"Driver%04x"
96 #define VarDriverOrder L"DriverOrder"
97 #define VarConsoleInpDev L"ConInDev"
98 #define VarConsoleOutDev L"ConOutDev"
99 #define VarErrorOutDev L"ErrOutDev"
101 #define LanguageCodeEnglish "eng"
103 extern EFI_DEVICE_PATH RootDevicePath[];
104 extern EFI_DEVICE_PATH EndDevicePath[];
105 extern EFI_DEVICE_PATH EndInstanceDevicePath[];
108 // Other public data in the EFI library
111 extern EFI_MEMORY_TYPE PoolAllocationType;
114 // STATIC - Name is internal to the module
115 // INTERNAL - Name is internal to the component (i.e., directory)
116 // BOOTSERVCE - Name of a boot service function
119 #define STATIC
120 #define INTERNAL
121 #define BOOTSERVICE
124 // Prototypes
127 VOID
128 InitializeLib (
129 IN EFI_HANDLE ImageHandle,
130 IN EFI_SYSTEM_TABLE *SystemTable
133 VOID
134 InitializeUnicodeSupport (
135 CHAR8 *LangCode
138 VOID
139 EFIDebugVariable (
140 VOID
143 VOID
144 SetCrc (
145 IN OUT EFI_TABLE_HEADER *Hdr
148 VOID
149 SetCrcAltSize (
150 IN UINTN Size,
151 IN OUT EFI_TABLE_HEADER *Hdr
154 BOOLEAN
155 CheckCrc (
156 IN UINTN MaxSize,
157 IN OUT EFI_TABLE_HEADER *Hdr
160 BOOLEAN
161 CheckCrcAltSize (
162 IN UINTN MaxSize,
163 IN UINTN Size,
164 IN OUT EFI_TABLE_HEADER *Hdr
167 UINT32
168 CalculateCrc (
169 UINT8 *pt,
170 UINTN Size
173 VOID
174 ZeroMem (
175 IN VOID *Buffer,
176 IN UINTN Size
179 VOID
180 SetMem (
181 IN VOID *Buffer,
182 IN UINTN Size,
183 IN UINT8 Value
186 VOID
187 CopyMem (
188 IN VOID *Dest,
189 IN CONST VOID *Src,
190 IN UINTN len
193 INTN
194 CompareMem (
195 IN CONST VOID *Dest,
196 IN CONST VOID *Src,
197 IN UINTN len
200 INTN
201 StrCmp (
202 IN CONST CHAR16 *s1,
203 IN CONST CHAR16 *s2
206 INTN
207 StrnCmp (
208 IN CONST CHAR16 *s1,
209 IN CONST CHAR16 *s2,
210 IN UINTN len
213 INTN
214 StriCmp (
215 IN CONST CHAR16 *s1,
216 IN CONST CHAR16 *s2
219 VOID
220 StrLwr (
221 IN CHAR16 *Str
224 VOID
225 StrUpr (
226 IN CHAR16 *Str
229 VOID
230 StrCpy (
231 IN CHAR16 *Dest,
232 IN CONST CHAR16 *Src
235 VOID
236 StrCat (
237 IN CHAR16 *Dest,
238 IN CONST CHAR16 *Src
241 UINTN
242 StrLen (
243 IN CONST CHAR16 *s1
246 UINTN
247 StrSize (
248 IN CONST CHAR16 *s1
251 CHAR16 *
252 StrDuplicate (
253 IN CONST CHAR16 *Src
256 UINTN
257 strlena (
258 IN CONST CHAR8 *s1
261 UINTN
262 strcmpa (
263 IN CONST CHAR8 *s1,
264 IN CONST CHAR8 *s2
267 UINTN
268 strncmpa (
269 IN CONST CHAR8 *s1,
270 IN CONST CHAR8 *s2,
271 IN UINTN len
274 UINTN
275 xtoi (
276 CONST CHAR16 *str
279 UINTN
280 Atoi (
281 CONST CHAR16 *str
284 BOOLEAN
285 MetaMatch (
286 IN CHAR16 *String,
287 IN CHAR16 *Pattern
290 BOOLEAN
291 MetaiMatch (
292 IN CHAR16 *String,
293 IN CHAR16 *Pattern
296 UINT64
297 LShiftU64 (
298 IN UINT64 Operand,
299 IN UINTN Count
302 UINT64
303 RShiftU64 (
304 IN UINT64 Operand,
305 IN UINTN Count
308 UINT64
309 MultU64x32 (
310 IN UINT64 Multiplicand,
311 IN UINTN Multiplier
314 UINT64
315 DivU64x32 (
316 IN UINT64 Dividend,
317 IN UINTN Divisor,
318 OUT UINTN *Remainder OPTIONAL
321 VOID
322 InitializeLock (
323 IN OUT FLOCK *Lock,
324 IN EFI_TPL Priority
327 VOID
328 AcquireLock (
329 IN FLOCK *Lock
332 VOID
333 ReleaseLock (
334 IN FLOCK *Lock
338 INTN
339 CompareGuid(
340 IN EFI_GUID *Guid1,
341 IN EFI_GUID *Guid2
344 VOID *
345 AllocatePool (
346 IN UINTN Size
349 VOID *
350 AllocateZeroPool (
351 IN UINTN Size
354 VOID *
355 ReallocatePool (
356 IN VOID *OldPool,
357 IN UINTN OldSize,
358 IN UINTN NewSize
361 VOID
362 FreePool (
363 IN VOID *p
367 VOID
368 Output (
369 IN CHAR16 *Str
372 VOID
373 Input (
374 IN CHAR16 *Prompt OPTIONAL,
375 OUT CHAR16 *InStr,
376 IN UINTN StrLen
379 VOID
380 IInput (
381 IN SIMPLE_TEXT_OUTPUT_INTERFACE *ConOut,
382 IN SIMPLE_INPUT_INTERFACE *ConIn,
383 IN CHAR16 *Prompt OPTIONAL,
384 OUT CHAR16 *InStr,
385 IN UINTN StrLen
388 UINTN
389 Print (
390 IN CHAR16 *fmt,
394 UINTN
395 SPrint (
396 OUT CHAR16 *Str,
397 IN UINTN StrSize,
398 IN CHAR16 *fmt,
402 CHAR16 *
403 PoolPrint (
404 IN CHAR16 *fmt,
408 typedef struct {
409 CHAR16 *str;
410 UINTN len;
411 UINTN maxlen;
412 } POOL_PRINT;
414 CHAR16 *
415 CatPrint (
416 IN OUT POOL_PRINT *Str,
417 IN CHAR16 *fmt,
421 UINTN
422 PrintAt (
423 IN UINTN Column,
424 IN UINTN Row,
425 IN CHAR16 *fmt,
429 UINTN
430 IPrint (
431 IN SIMPLE_TEXT_OUTPUT_INTERFACE *Out,
432 IN CHAR16 *fmt,
436 UINTN
437 IPrintAt (
438 IN SIMPLE_TEXT_OUTPUT_INTERFACE *Out,
439 IN UINTN Column,
440 IN UINTN Row,
441 IN CHAR16 *fmt,
445 UINTN
446 APrint (
447 IN CHAR8 *fmt,
451 VOID
452 ValueToHex (
453 IN CHAR16 *Buffer,
454 IN UINT64 v
457 VOID
458 ValueToString (
459 IN CHAR16 *Buffer,
460 IN BOOLEAN Comma,
461 IN INT64 v
464 VOID
465 TimeToString (
466 OUT CHAR16 *Buffer,
467 IN EFI_TIME *Time
470 VOID
471 GuidToString (
472 OUT CHAR16 *Buffer,
473 IN EFI_GUID *Guid
476 VOID
477 StatusToString (
478 OUT CHAR16 *Buffer,
479 EFI_STATUS Status
482 VOID
483 DumpHex (
484 IN UINTN Indent,
485 IN UINTN Offset,
486 IN UINTN DataSize,
487 IN VOID *UserData
490 BOOLEAN
491 GrowBuffer(
492 IN OUT EFI_STATUS *Status,
493 IN OUT VOID **Buffer,
494 IN UINTN BufferSize
497 EFI_MEMORY_DESCRIPTOR *
498 LibMemoryMap (
499 OUT UINTN *NoEntries,
500 OUT UINTN *MapKey,
501 OUT UINTN *DescriptorSize,
502 OUT UINT32 *DescriptorVersion
505 VOID *
506 LibGetVariable (
507 IN CHAR16 *Name,
508 IN EFI_GUID *VendorGuid
511 VOID *
512 LibGetVariableAndSize (
513 IN CHAR16 *Name,
514 IN EFI_GUID *VendorGuid,
515 OUT UINTN *VarSize
518 EFI_STATUS
519 LibDeleteVariable (
520 IN CHAR16 *VarName,
521 IN EFI_GUID *VarGuid
524 EFI_STATUS
525 LibSetNVVariable (
526 IN CHAR16 *VarName,
527 IN EFI_GUID *VarGuid,
528 IN UINTN DataSize,
529 IN VOID *Data
532 EFI_STATUS
533 LibSetVariable (
534 IN CHAR16 *VarName,
535 IN EFI_GUID *VarGuid,
536 IN UINTN DataSize,
537 IN VOID *Data
539 EFI_STATUS
540 LibInsertToTailOfBootOrder (
541 IN UINT16 BootOption,
542 IN BOOLEAN OnlyInsertIfEmpty
545 EFI_STATUS
546 LibLocateProtocol (
547 IN EFI_GUID *ProtocolGuid,
548 OUT VOID **Interface
551 EFI_STATUS
552 LibLocateHandle (
553 IN EFI_LOCATE_SEARCH_TYPE SearchType,
554 IN EFI_GUID *Protocol OPTIONAL,
555 IN VOID *SearchKey OPTIONAL,
556 IN OUT UINTN *NoHandles,
557 OUT EFI_HANDLE **Buffer
560 EFI_STATUS
561 LibLocateHandleByDiskSignature (
562 IN UINT8 MBRType,
563 IN UINT8 SignatureType,
564 IN VOID *Signature,
565 IN OUT UINTN *NoHandles,
566 OUT EFI_HANDLE **Buffer
569 EFI_STATUS
570 LibInstallProtocolInterfaces (
571 IN OUT EFI_HANDLE *Handle,
575 VOID
576 LibUninstallProtocolInterfaces (
577 IN EFI_HANDLE Handle,
581 EFI_STATUS
582 LibReinstallProtocolInterfaces (
583 IN OUT EFI_HANDLE *Handle,
587 EFI_EVENT
588 LibCreateProtocolNotifyEvent (
589 IN EFI_GUID *ProtocolGuid,
590 IN EFI_TPL NotifyTpl,
591 IN EFI_EVENT_NOTIFY NotifyFunction,
592 IN VOID *NotifyContext,
593 OUT VOID *Registration
596 EFI_STATUS
597 WaitForSingleEvent (
598 IN EFI_EVENT Event,
599 IN UINT64 Timeout OPTIONAL
602 VOID
603 WaitForEventWithTimeout (
604 IN EFI_EVENT Event,
605 IN UINTN Timeout,
606 IN UINTN Row,
607 IN UINTN Column,
608 IN CHAR16 *String,
609 IN EFI_INPUT_KEY TimeoutKey,
610 OUT EFI_INPUT_KEY *Key
613 EFI_FILE_HANDLE
614 LibOpenRoot (
615 IN EFI_HANDLE DeviceHandle
618 EFI_FILE_INFO *
619 LibFileInfo (
620 IN EFI_FILE_HANDLE FHand
623 EFI_FILE_SYSTEM_INFO *
624 LibFileSystemInfo (
625 IN EFI_FILE_HANDLE FHand
628 EFI_FILE_SYSTEM_VOLUME_LABEL_INFO *
629 LibFileSystemVolumeLabelInfo (
630 IN EFI_FILE_HANDLE FHand
633 BOOLEAN
634 ValidMBR(
635 IN MASTER_BOOT_RECORD *Mbr,
636 IN EFI_BLOCK_IO *BlkIo
639 BOOLEAN
640 LibMatchDevicePaths (
641 IN EFI_DEVICE_PATH *Multi,
642 IN EFI_DEVICE_PATH *Single
645 EFI_DEVICE_PATH *
646 LibDuplicateDevicePathInstance (
647 IN EFI_DEVICE_PATH *DevPath
650 EFI_DEVICE_PATH *
651 DevicePathFromHandle (
652 IN EFI_HANDLE Handle
655 EFI_DEVICE_PATH *
656 DevicePathInstance (
657 IN OUT EFI_DEVICE_PATH **DevicePath,
658 OUT UINTN *Size
661 UINTN
662 DevicePathInstanceCount (
663 IN EFI_DEVICE_PATH *DevicePath
666 EFI_DEVICE_PATH *
667 AppendDevicePath (
668 IN EFI_DEVICE_PATH *Src1,
669 IN EFI_DEVICE_PATH *Src2
672 EFI_DEVICE_PATH *
673 AppendDevicePathNode (
674 IN EFI_DEVICE_PATH *Src1,
675 IN EFI_DEVICE_PATH *Src2
678 EFI_DEVICE_PATH*
679 AppendDevicePathInstance (
680 IN EFI_DEVICE_PATH *Src,
681 IN EFI_DEVICE_PATH *Instance
684 EFI_DEVICE_PATH *
685 FileDevicePath (
686 IN EFI_HANDLE Device OPTIONAL,
687 IN CHAR16 *FileName
690 UINTN
691 DevicePathSize (
692 IN EFI_DEVICE_PATH *DevPath
695 EFI_DEVICE_PATH *
696 DuplicateDevicePath (
697 IN EFI_DEVICE_PATH *DevPath
700 EFI_DEVICE_PATH *
701 UnpackDevicePath (
702 IN EFI_DEVICE_PATH *DevPath
705 EFI_STATUS
706 LibDevicePathToInterface (
707 IN EFI_GUID *Protocol,
708 IN EFI_DEVICE_PATH *FilePath,
709 OUT VOID **Interface
712 CHAR16 *
713 DevicePathToStr (
714 EFI_DEVICE_PATH *DevPath
718 // BugBug: I need my own include files
720 typedef struct {
721 UINT8 Register;
722 UINT8 Function;
723 UINT8 Device;
724 UINT8 Bus;
725 UINT32 Reserved;
726 } EFI_ADDRESS;
728 typedef union {
729 UINT64 Address;
730 EFI_ADDRESS EfiAddress;
731 } EFI_PCI_ADDRESS_UNION;
734 EFI_STATUS
735 PciFindDeviceClass (
736 IN OUT EFI_PCI_ADDRESS_UNION *Address,
737 IN UINT8 BaseClass,
738 IN UINT8 SubClass
741 EFI_STATUS
742 PciFindDevice (
743 IN OUT EFI_PCI_ADDRESS_UNION *DeviceAddress,
744 IN UINT16 VendorId,
745 IN UINT16 DeviceId,
746 IN OUT PCI_TYPE00 *Pci
750 // SIMPLE_READ_FILE object used to access files
753 typedef VOID *SIMPLE_READ_FILE;
755 EFI_STATUS
756 OpenSimpleReadFile (
757 IN BOOLEAN BootPolicy,
758 IN VOID *SourceBuffer OPTIONAL,
759 IN UINTN SourceSize,
760 IN OUT EFI_DEVICE_PATH **FilePath,
761 OUT EFI_HANDLE *DeviceHandle,
762 OUT SIMPLE_READ_FILE *SimpleReadHandle
765 EFI_STATUS
766 ReadSimpleReadFile (
767 IN SIMPLE_READ_FILE SimpleReadHandle,
768 IN UINTN Offset,
769 IN OUT UINTN *ReadSize,
770 OUT VOID *Buffer
774 VOID
775 CloseSimpleReadFile (
776 IN SIMPLE_READ_FILE SimpleReadHandle
779 VOID
780 InitializeGuid (
781 VOID
784 UINT8
785 DecimaltoBCD(
786 IN UINT8 DecValue
789 UINT8
790 BCDtoDecimal(
791 IN UINT8 BcdValue
794 EFI_STATUS
795 LibGetSystemConfigurationTable(
796 IN EFI_GUID *TableGuid,
797 IN OUT VOID **Table
800 BOOLEAN
801 LibIsValidTextGraphics (
802 IN CHAR16 Graphic,
803 OUT CHAR8 *PcAnsi, OPTIONAL
804 OUT CHAR8 *Ascii OPTIONAL
807 BOOLEAN
808 IsValidAscii (
809 IN CHAR16 Ascii
812 BOOLEAN
813 IsValidEfiCntlChar (
814 IN CHAR16 c
817 CHAR16 *
818 LibGetUiString (
819 IN EFI_HANDLE Handle,
820 IN UI_STRING_TYPE StringType,
821 IN ISO_639_2 *LangCode,
822 IN BOOLEAN ReturnDevicePathStrOnMismatch
825 CHAR8*
826 LibGetSmbiosString (
827 IN SMBIOS_STRUCTURE_POINTER *Smbios,
828 IN UINT16 StringNumber
831 EFI_STATUS
832 LibGetSmbiosSystemGuidAndSerialNumber (
833 IN EFI_GUID *SystemGuid,
834 OUT CHAR8 **SystemSerialNumber
838 EFI_STATUS
839 InitializeGlobalIoDevice (
840 IN EFI_DEVICE_PATH *DevicePath,
841 IN EFI_GUID *Protocol,
842 IN CHAR8 *ErrorStr,
843 OUT EFI_DEVICE_IO_INTERFACE **GlobalIoFncs
846 UINT32
847 ReadPort (
848 IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs,
849 IN EFI_IO_WIDTH Width,
850 IN UINTN Port
853 UINT32
854 WritePort (
855 IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs,
856 IN EFI_IO_WIDTH Width,
857 IN UINTN Port,
858 IN UINTN Data
861 UINT32
862 ReadPciConfig (
863 IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs,
864 IN EFI_IO_WIDTH Width,
865 IN UINTN Port
868 UINT32
869 WritePciConfig (
870 IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs,
871 IN EFI_IO_WIDTH Width,
872 IN UINTN Port,
873 IN UINTN Data
876 extern EFI_DEVICE_IO_INTERFACE *GlobalIoFncs;
878 #define outp(_Port, _DataByte) (UINT8)WritePort(GlobalIoFncs, IO_UINT8, (UINTN)_Port, (UINTN)_DataByte)
879 #define inp(_Port) (UINT8)ReadPort(GlobalIoFncs, IO_UINT8, (UINTN)_Port)
880 #define outpw(_Port, _DataByte) (UINT16)WritePort(GlobalIoFncs, IO_UINT16, (UINTN)_Port, (UINTN)_DataByte)
881 #define inpw(_Port) (UINT16)ReadPort(GlobalIoFncs, IO_UINT16, (UINTN)_Port)
882 #define outpd(_Port, _DataByte) (UINT32)WritePort(GlobalIoFncs, IO_UINT32, (UINTN)_Port, (UINTN)_DataByte)
883 #define inpd(_Port) (UINT32)ReadPort(GlobalIoFncs, IO_UINT32, (UINTN)_Port)
885 #define writepci8(_Addr, _DataByte) (UINT8)WritePciConfig(GlobalIoFncs, IO_UINT8, (UINTN)_Addr, (UINTN)_DataByte)
886 #define readpci8(_Addr) (UINT8)ReadPciConfig(GlobalIoFncs, IO_UINT8, (UINTN)_Addr)
887 #define writepci16(_Addr, _DataByte) (UINT16)WritePciConfig(GlobalIoFncs, IO_UINT16, (UINTN)_Addr, (UINTN)_DataByte)
888 #define readpci16(_Addr) (UINT16)ReadPciConfig(GlobalIoFncs, IO_UINT16, (UINTN)_Addr)
889 #define writepci32(_Addr, _DataByte) (UINT32)WritePciConfig(GlobalIoFncs, IO_UINT32, (UINTN)_Addr, (UINTN)_DataByte)
890 #define readpci32(_Addr) (UINT32)ReadPciConfig(GlobalIoFncs, IO_UINT32, (UINTN)_Addr)
892 #define Pause() WaitForSingleEvent (ST->ConIn->WaitForKey, 0)
893 #define Port80(_PostCode) GlobalIoFncs->Io.Write (GlobalIoFncs, IO_UINT16, (UINT64)0x80, 1, &(_PostCode))
895 #endif