Initial import.
[mirror_edk2.git] / Tools / Source / TianoTools / Common / PeiLib / PeiLib.h
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2004, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 PeiLib.h\r
15\r
16Abstract:\r
17\r
18 PEI Library Functions\r
19 \r
20--*/\r
21\r
22#ifndef _PEI_LIB_H_\r
23#define _PEI_LIB_H_\r
24\r
25#include "Tiano.h"\r
26#include "Pei.h"\r
27#include "peiHobLib.h"\r
28#include EFI_PROTOCOL_DEFINITION (Decompress)\r
29#include EFI_PROTOCOL_DEFINITION (TianoDecompress)\r
30#include EFI_GUID_DEFINITION (PeiPeCoffLoader)\r
31\r
32VOID\r
33PeiCopyMem (\r
34 IN VOID *Destination,\r
35 IN VOID *Source,\r
36 IN UINTN Length\r
37 )\r
38/*++\r
39\r
40Routine Description:\r
41\r
42 Copy Length bytes from Source to Destination.\r
43\r
44Arguments:\r
45\r
46 Destination - Target of copy\r
47\r
48 Source - Place to copy from\r
49\r
50 Length - Number of bytes to copy\r
51\r
52Returns:\r
53\r
54 None\r
55\r
56--*/\r
57;\r
58\r
59VOID\r
60ZeroMem (\r
61 IN VOID *Buffer,\r
62 IN UINTN Size\r
63 )\r
64/*++\r
65\r
66Routine Description:\r
67\r
68 Set Buffer to zero for Size bytes.\r
69\r
70Arguments:\r
71\r
72 Buffer - Memory to set.\r
73\r
74 Size - Number of bytes to set\r
75\r
76Returns:\r
77\r
78 None\r
79\r
80--*/\r
81;\r
82\r
83VOID\r
84CopyMem (\r
85 IN VOID *Destination,\r
86 IN VOID *Source,\r
87 IN UINTN Length\r
88 )\r
89/*++\r
90\r
91Routine Description:\r
92\r
93 Copy Length bytes from Source to Destination.\r
94\r
95Arguments:\r
96\r
97 Destination - Target of copy\r
98\r
99 Source - Place to copy from\r
100\r
101 Length - Number of bytes to copy\r
102\r
103Returns:\r
104\r
105 None\r
106\r
107--*/\r
108;\r
109\r
110BOOLEAN\r
111CompareGuid (\r
112 IN EFI_GUID *Guid1,\r
113 IN EFI_GUID *Guid2\r
114 )\r
115/*++\r
116\r
117Routine Description:\r
118\r
119 Compares two GUIDs\r
120\r
121Arguments:\r
122\r
123 Guid1 - guid to compare\r
124 Guid2 - guid to compare\r
125\r
126Returns:\r
127 = TRUE if Guid1 == Guid2\r
128 = FALSE if Guid1 != Guid2 \r
129\r
130--*/\r
131;\r
132\r
133EFI_STATUS\r
134InstallEfiPeiPeCoffLoader (\r
135 IN EFI_PEI_SERVICES **PeiServices,\r
136 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL **This,\r
137 IN EFI_PEI_PPI_DESCRIPTOR *ThisPpi\r
138 )\r
139/*++\r
140\r
141Routine Description:\r
142\r
143 Install EFI Pei PE coff loader protocol.\r
144 \r
145Arguments:\r
146\r
147 PeiServices - The PEI core services table.\r
148 \r
149 This - Pointer to get Pei PE coff loader protocol as output\r
150 \r
151 ThisPpi - Passed in as EFI_NT_LOAD_AS_DLL_PPI on NT_EMULATOR platform\r
152\r
153Returns:\r
154\r
155 EFI_SUCCESS\r
156\r
157--*/\r
158;\r
159\r
160EFI_STATUS\r
161InstallEfiDecompress (\r
162 EFI_DECOMPRESS_PROTOCOL **This\r
163 )\r
164/*++\r
165\r
166Routine Description:\r
167\r
168 Install EFI decompress protocol.\r
169\r
170Arguments:\r
171\r
172 This - Pointer to get decompress protocol as output\r
173\r
174Returns:\r
175\r
176 EFI_SUCCESS - EFI decompress protocol successfully installed.\r
177\r
178--*/\r
179;\r
180\r
181EFI_STATUS\r
182InstallTianoDecompress (\r
183 EFI_TIANO_DECOMPRESS_PROTOCOL **This\r
184 )\r
185/*++\r
186\r
187Routine Description:\r
188\r
189 Install Tiano decompress protocol.\r
190\r
191Arguments:\r
192\r
193 This - Pointer to get decompress protocol as output\r
194\r
195Returns:\r
196\r
197 EFI_SUCCESS - Tiano decompress protocol successfully installed.\r
198\r
199--*/\r
200;\r
201\r
202VOID\r
203PeiPerfMeasure (\r
204 EFI_PEI_SERVICES **PeiServices,\r
205 IN UINT16 *Token,\r
206 IN EFI_FFS_FILE_HEADER *FileHeader,\r
207 IN BOOLEAN EntryExit,\r
208 IN UINT64 Value\r
209 )\r
210/*++\r
211\r
212Routine Description:\r
213\r
214 Log a timestamp count.\r
215\r
216Arguments:\r
217\r
218 PeiServices - Pointer to the PEI Core Services table\r
219 \r
220 Token - Pointer to Token Name\r
221 \r
222 FileHeader - Pointer to the file header\r
223\r
224 EntryExit - Indicates start or stop measurement\r
225\r
226 Value - The start time or the stop time\r
227\r
228Returns:\r
229\r
230--*/\r
231;\r
232\r
233EFI_STATUS\r
234GetTimerValue (\r
235 OUT UINT64 *TimerValue\r
236 )\r
237/*++\r
238\r
239Routine Description:\r
240\r
241 Get timer value.\r
242\r
243Arguments:\r
244\r
245 TimerValue - Pointer to the returned timer value\r
246\r
247Returns:\r
248\r
249 EFI_SUCCESS - Successfully got timer value\r
250\r
251--*/\r
252;\r
253\r
254#ifdef EFI_PEI_PERFORMANCE\r
255#define PEI_PERF_START(Ps, Token, FileHeader, Value) PeiPerfMeasure (Ps, Token, FileHeader, FALSE, Value)\r
256#define PEI_PERF_END(Ps, Token, FileHeader, Value) PeiPerfMeasure (Ps, Token, FileHeader, TRUE, Value)\r
257#else\r
258#define PEI_PERF_START(Ps, Token, FileHeader, Value)\r
259#define PEI_PERF_END(Ps, Token, FileHeader, Value)\r
260#endif\r
261\r
262#ifdef EFI_NT_EMULATOR\r
263EFI_STATUS\r
264PeCoffLoaderWinNtLoadAsDll (\r
265 IN CHAR8 *PdbFileName,\r
266 IN VOID **ImageEntryPoint,\r
267 OUT VOID **ModHandle\r
268 )\r
269/*++\r
270\r
271Routine Description:\r
272\r
273 Loads the .DLL file is present when a PE/COFF file is loaded. This provides source level\r
274 debugging for drivers that have cooresponding .DLL files on the local system.\r
275\r
276Arguments:\r
277\r
278 PdbFileName - The name of the .PDB file. This was found from the PE/COFF\r
279 file's debug directory entry.\r
280\r
281 ImageEntryPoint - A pointer to the DLL entry point of the .DLL file was loaded.\r
282\r
283 ModHandle - Pointer to loaded library.\r
284\r
285Returns:\r
286\r
287 EFI_SUCCESS - The .DLL file was loaded, and the DLL entry point is returned in ImageEntryPoint\r
288\r
289 EFI_NOT_FOUND - The .DLL file could not be found\r
290\r
291 EFI_UNSUPPORTED - The .DLL file was loaded, but the entry point to the .DLL file could not\r
292 determined.\r
293\r
294--*/\r
295;\r
296\r
297#endif\r
298//\r
299// hob.c\r
300//\r
301EFI_STATUS\r
302PeiBuildHobModule (\r
303 IN EFI_PEI_SERVICES **PeiServices,\r
304 IN EFI_GUID *ModuleName,\r
305 IN EFI_PHYSICAL_ADDRESS Module,\r
306 IN UINT64 ModuleLength,\r
307 IN EFI_PHYSICAL_ADDRESS EntryPoint\r
308 )\r
309/*++\r
310\r
311Routine Description:\r
312\r
313 Builds a HOB for a loaded PE32 module\r
314\r
315Arguments:\r
316\r
317 PeiServices - The PEI core services table.\r
318 ModuleName - The GUID File Name of the module\r
319 Memory - The 64 bit physical address of the module\r
320 ModuleLength - The length of the module in bytes\r
321 EntryPoint - The 64 bit physical address of the entry point\r
322 to the module\r
323\r
324Returns:\r
325\r
326 EFI_SUCCESS - Hob is successfully built.\r
327 Others - Errors occur while creating new Hob\r
328\r
329--*/\r
330;\r
331\r
332EFI_STATUS\r
333PeiBuildHobResourceDescriptor (\r
334 IN EFI_PEI_SERVICES **PeiServices,\r
335 IN EFI_RESOURCE_TYPE ResourceType,\r
336 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
337 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
338 IN UINT64 NumberOfBytes\r
339 )\r
340/*++\r
341\r
342Routine Description:\r
343\r
344 Builds a HOB that describes a chunck of system memory\r
345\r
346Arguments:\r
347\r
348 PeiServices - The PEI core services table.\r
349 \r
350 ResourceType - The type of resource described by this HOB\r
351\r
352 ResourceAttribute - The resource attributes of the memory described by this HOB\r
353\r
354 PhysicalStart - The 64 bit physical address of memory described by this HOB\r
355\r
356 NumberOfBytes - The length of the memoty described by this HOB in bytes\r
357\r
358Returns:\r
359\r
360 EFI_SUCCESS - Hob is successfully built.\r
361 Others - Errors occur while creating new Hob\r
362\r
363--*/\r
364;\r
365\r
366EFI_STATUS\r
367PeiBuildHobGuid (\r
368 IN EFI_PEI_SERVICES **PeiServices,\r
369 IN EFI_GUID *Guid,\r
370 IN UINTN DataLength,\r
371 IN OUT VOID **Hob\r
372 )\r
373/*++\r
374\r
375Routine Description:\r
376\r
377 Builds a custom HOB that is tagged with a GUID for identification\r
378\r
379Arguments:\r
380\r
381 PeiServices - The PEI core services table.\r
382\r
383 Guid - The GUID of the custome HOB type\r
384\r
385 DataLength - The size of the data payload for the GUIDed HOB\r
386\r
387 Hob - Pointer to the Hob\r
388\r
389Returns:\r
390\r
391 EFI_SUCCESS - Hob is successfully built.\r
392 Others - Errors occur while creating new Hob\r
393\r
394--*/\r
395;\r
396\r
397EFI_STATUS\r
398PeiBuildHobGuidData (\r
399 IN EFI_PEI_SERVICES **PeiServices,\r
400 IN EFI_GUID *Guid,\r
401 IN VOID *Data,\r
402 IN UINTN DataLength\r
403 )\r
404/*++\r
405\r
406Routine Description:\r
407\r
408 Builds a custom HOB that is tagged with a GUID for identification\r
409\r
410Arguments:\r
411\r
412 PeiServices - The PEI core services table.\r
413\r
414 Guid - The GUID of the custome HOB type\r
415\r
416 Data - The data to be copied into the GUIDed HOB data field.\r
417\r
418 DataLength - The data field length.\r
419\r
420Returns:\r
421\r
422 EFI_SUCCESS - Hob is successfully built.\r
423 Others - Errors occur while creating new Hob\r
424\r
425--*/\r
426;\r
427\r
428EFI_STATUS\r
429PeiBuildHobFv (\r
430 IN EFI_PEI_SERVICES **PeiServices,\r
431 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
432 IN UINT64 Length\r
433 )\r
434/*++\r
435\r
436Routine Description:\r
437\r
438 Builds a Firmware Volume HOB\r
439\r
440Arguments:\r
441\r
442 PeiServices - The PEI core services table.\r
443\r
444 BaseAddress - The base address of the Firmware Volume\r
445\r
446 Length - The size of the Firmware Volume in bytes\r
447\r
448Returns:\r
449\r
450 EFI_SUCCESS - Hob is successfully built.\r
451 Others - Errors occur while creating new Hob\r
452\r
453--*/\r
454;\r
455\r
456EFI_STATUS\r
457PeiBuildHobCpu (\r
458 IN EFI_PEI_SERVICES **PeiServices,\r
459 IN UINT8 SizeOfMemorySpace,\r
460 IN UINT8 SizeOfIoSpace\r
461 )\r
462/*++\r
463\r
464Routine Description:\r
465\r
466 Builds a HOB for the CPU\r
467\r
468Arguments:\r
469\r
470 PeiServices - The PEI core services table.\r
471\r
472 SizeOfMemorySpace - Identifies the maximum \r
473 physical memory addressibility of the processor.\r
474\r
475 SizeOfIoSpace - Identifies the maximum physical I/O addressibility \r
476 of the processor.\r
477\r
478Returns:\r
479\r
480 EFI_SUCCESS - Hob is successfully built.\r
481 Others - Errors occur while creating new Hob\r
482\r
483--*/\r
484;\r
485\r
486EFI_STATUS\r
487PeiBuildHobStack (\r
488 IN EFI_PEI_SERVICES **PeiServices,\r
489 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
490 IN UINT64 Length\r
491 )\r
492/*++\r
493\r
494Routine Description:\r
495\r
496 Builds a HOB for the Stack\r
497\r
498Arguments:\r
499\r
500 PeiServices - The PEI core services table.\r
501\r
502 BaseAddress - The 64 bit physical address of the Stack\r
503\r
504 Length - The length of the stack in bytes\r
505\r
506Returns:\r
507\r
508 EFI_SUCCESS - Hob is successfully built.\r
509 Others - Errors occur while creating new Hob\r
510\r
511--*/\r
512;\r
513\r
514EFI_STATUS\r
515PeiBuildHobBspStore (\r
516 IN EFI_PEI_SERVICES **PeiServices,\r
517 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
518 IN UINT64 Length,\r
519 IN EFI_MEMORY_TYPE MemoryType\r
520 )\r
521/*++\r
522\r
523Routine Description:\r
524\r
525 Builds a HOB for the bsp store\r
526\r
527Arguments:\r
528\r
529 PeiServices - The PEI core services table.\r
530\r
531 BaseAddress - The 64 bit physical address of the bsp store\r
532\r
533 Length - The length of the bsp store in bytes\r
534\r
535 MemoryType - Memory type\r
536\r
537Returns:\r
538\r
539 EFI_SUCCESS - Hob is successfully built.\r
540 Others - Errors occur while creating new Hob\r
541\r
542--*/\r
543;\r
544\r
545EFI_STATUS\r
546PeiBuildHobMemoryAllocation (\r
547 IN EFI_PEI_SERVICES **PeiServices,\r
548 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
549 IN UINT64 Length,\r
550 IN EFI_GUID *Name,\r
551 IN EFI_MEMORY_TYPE MemoryType\r
552 )\r
553/*++\r
554\r
555Routine Description:\r
556\r
557 Builds a HOB for the memory allocation\r
558\r
559Arguments:\r
560\r
561 PeiServices - The PEI core services table.\r
562\r
563 BaseAddress - The 64 bit physical address of the memory\r
564\r
565 Length - The length of the memory allocation in bytes\r
566\r
567 Name - Name for Hob\r
568\r
569 MemoryType - Memory type\r
570\r
571Returns:\r
572\r
573 EFI_SUCCESS - Hob is successfully built.\r
574 Others - Errors occur while creating new Hob\r
575\r
576--*/\r
577;\r
578\r
579//\r
580// print.c\r
581//\r
582UINTN\r
583AvSPrint (\r
584 OUT CHAR8 *StartOfBuffer,\r
585 IN UINTN StrSize,\r
586 IN CONST CHAR8 *Format,\r
587 IN VA_LIST Marker\r
588 )\r
589/*++\r
590\r
591Routine Description:\r
592\r
593 AvSPrint function to process format and place the results in Buffer. Since a \r
594 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus \r
595 this is the main print working routine\r
596\r
597Arguments:\r
598\r
599 StartOfBuffer - Ascii buffer to print the results of the parsing of Format into.\r
600\r
601 StrSize - Maximum number of characters to put into buffer. Zero means \r
602 no limit.\r
603\r
604 FormatString - Ascii format string see file header for more details.\r
605\r
606 Marker - Vararg list consumed by processing Format.\r
607\r
608Returns: \r
609\r
610 Number of characters printed.\r
611\r
612--*/\r
613;\r
614\r
615UINTN\r
616ASPrint (\r
617 OUT CHAR8 *Buffer,\r
618 IN UINTN BufferSize,\r
619 IN CONST CHAR8 *Format,\r
620 ...\r
621 )\r
622/*++\r
623\r
624Routine Description:\r
625\r
626 ASPrint function to process format and place the results in Buffer.\r
627\r
628Arguments:\r
629\r
630 Buffer - Ascii buffer to print the results of the parsing of Format into.\r
631\r
632 BufferSize - Maximum number of characters to put into buffer. Zero means no \r
633 limit.\r
634\r
635 Format - Ascii format string see file header for more details.\r
636\r
637 ... - Vararg list consumed by processing Format.\r
638\r
639Returns: \r
640\r
641 Number of characters printed.\r
642\r
643--*/\r
644;\r
645\r
646//\r
647// math.c\r
648//\r
649UINT64\r
650MultU64x32 (\r
651 IN UINT64 Multiplicand,\r
652 IN UINTN Multiplier\r
653 )\r
654/*++ \r
655 \r
656Routine Description:\r
657\r
658 This routine allows a 64 bit value to be multiplied with a 32 bit \r
659 value returns 64bit result.\r
660 No checking if the result is greater than 64bits\r
661\r
662Arguments:\r
663\r
664 Multiplicand - multiplicand\r
665 Multiplier - multiplier\r
666\r
667Returns:\r
668\r
669 Multiplicand * Multiplier\r
670 \r
671--*/\r
672;\r
673\r
674UINT64\r
675DivU64x32 (\r
676 IN UINT64 Dividend,\r
677 IN UINTN Divisor,\r
678 OUT UINTN *Remainder OPTIONAL\r
679 )\r
680/*++\r
681\r
682Routine Description:\r
683\r
684 This routine allows a 64 bit value to be divided with a 32 bit value returns \r
685 64bit result and the Remainder.\r
686 N.B. only works for 31bit divisors!!\r
687\r
688Arguments:\r
689\r
690 Dividend - dividend\r
691 Divisor - divisor\r
692 Remainder - buffer for remainder\r
693 \r
694Returns:\r
695\r
696 Dividend / Divisor\r
697 Remainder = Dividend mod Divisor\r
698\r
699--*/\r
700;\r
701\r
702UINT64\r
703RShiftU64 (\r
704 IN UINT64 Operand,\r
705 IN UINTN Count\r
706 )\r
707/*++\r
708\r
709Routine Description:\r
710\r
711 This routine allows a 64 bit value to be right shifted by 32 bits and returns the \r
712 shifted value.\r
713 Count is valid up 63. (Only Bits 0-5 is valid for Count)\r
714\r
715Arguments:\r
716\r
717 Operand - Value to be shifted\r
718 Count - Number of times to shift right.\r
719 \r
720Returns:\r
721\r
722 Value shifted right identified by the Count.\r
723\r
724--*/\r
725;\r
726\r
727UINT64\r
728LShiftU64 (\r
729 IN UINT64 Operand,\r
730 IN UINTN Count\r
731 )\r
732/*++\r
733\r
734Routine Description:\r
735\r
736 This routine allows a 64 bit value to be left shifted by 32 bits and \r
737 returns the shifted value.\r
738 Count is valid up 63. (Only Bits 0-5 is valid for Count)\r
739\r
740Arguments:\r
741\r
742 Operand - Value to be shifted\r
743 Count - Number of times to shift left.\r
744\r
745Returns:\r
746\r
747 Value shifted left identified by the Count.\r
748\r
749--*/\r
750;\r
751\r
752VOID\r
753RegisterNativeCpuIo (\r
754 IN EFI_PEI_SERVICES **PeiServices,\r
755 IN VOID *CpuIo\r
756 )\r
757/*++\r
758\r
759Routine Description:\r
760\r
761 Register a native Cpu IO\r
762\r
763Arguments:\r
764\r
765 PeiServices - Calling context\r
766 CpuIo - CpuIo instance to register\r
767\r
768Returns:\r
769\r
770 None\r
771\r
772--*/\r
773;\r
774\r
775VOID\r
776GetNativeCpuIo (\r
777 IN EFI_PEI_SERVICES **PeiServices,\r
778 OUT VOID **CpuIo\r
779 )\r
780/*++\r
781\r
782Routine Description:\r
783\r
784 Get registered Cpu IO.\r
785\r
786Arguments:\r
787\r
788 PeiServices - Calling context\r
789 CpuIo - CpuIo instance registered before\r
790\r
791Returns:\r
792\r
793 None\r
794\r
795--*/\r
796;\r
797\r
798#endif\r