]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/TianoTools/Common/PeiLib/PeiLib.h
Removed #ifdef NT32 as we don't need them for tools
[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
878ddf1f 262//\r
263// hob.c\r
264//\r
265EFI_STATUS\r
266PeiBuildHobModule (\r
267 IN EFI_PEI_SERVICES **PeiServices,\r
268 IN EFI_GUID *ModuleName,\r
269 IN EFI_PHYSICAL_ADDRESS Module,\r
270 IN UINT64 ModuleLength,\r
271 IN EFI_PHYSICAL_ADDRESS EntryPoint\r
272 )\r
273/*++\r
274\r
275Routine Description:\r
276\r
277 Builds a HOB for a loaded PE32 module\r
278\r
279Arguments:\r
280\r
281 PeiServices - The PEI core services table.\r
282 ModuleName - The GUID File Name of the module\r
283 Memory - The 64 bit physical address of the module\r
284 ModuleLength - The length of the module in bytes\r
285 EntryPoint - The 64 bit physical address of the entry point\r
286 to the module\r
287\r
288Returns:\r
289\r
290 EFI_SUCCESS - Hob is successfully built.\r
291 Others - Errors occur while creating new Hob\r
292\r
293--*/\r
294;\r
295\r
296EFI_STATUS\r
297PeiBuildHobResourceDescriptor (\r
298 IN EFI_PEI_SERVICES **PeiServices,\r
299 IN EFI_RESOURCE_TYPE ResourceType,\r
300 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
301 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
302 IN UINT64 NumberOfBytes\r
303 )\r
304/*++\r
305\r
306Routine Description:\r
307\r
308 Builds a HOB that describes a chunck of system memory\r
309\r
310Arguments:\r
311\r
312 PeiServices - The PEI core services table.\r
313 \r
314 ResourceType - The type of resource described by this HOB\r
315\r
316 ResourceAttribute - The resource attributes of the memory described by this HOB\r
317\r
318 PhysicalStart - The 64 bit physical address of memory described by this HOB\r
319\r
320 NumberOfBytes - The length of the memoty described by this HOB in bytes\r
321\r
322Returns:\r
323\r
324 EFI_SUCCESS - Hob is successfully built.\r
325 Others - Errors occur while creating new Hob\r
326\r
327--*/\r
328;\r
329\r
330EFI_STATUS\r
331PeiBuildHobGuid (\r
332 IN EFI_PEI_SERVICES **PeiServices,\r
333 IN EFI_GUID *Guid,\r
334 IN UINTN DataLength,\r
335 IN OUT VOID **Hob\r
336 )\r
337/*++\r
338\r
339Routine Description:\r
340\r
341 Builds a custom HOB that is tagged with a GUID for identification\r
342\r
343Arguments:\r
344\r
345 PeiServices - The PEI core services table.\r
346\r
347 Guid - The GUID of the custome HOB type\r
348\r
349 DataLength - The size of the data payload for the GUIDed HOB\r
350\r
351 Hob - Pointer to the Hob\r
352\r
353Returns:\r
354\r
355 EFI_SUCCESS - Hob is successfully built.\r
356 Others - Errors occur while creating new Hob\r
357\r
358--*/\r
359;\r
360\r
361EFI_STATUS\r
362PeiBuildHobGuidData (\r
363 IN EFI_PEI_SERVICES **PeiServices,\r
364 IN EFI_GUID *Guid,\r
365 IN VOID *Data,\r
366 IN UINTN DataLength\r
367 )\r
368/*++\r
369\r
370Routine Description:\r
371\r
372 Builds a custom HOB that is tagged with a GUID for identification\r
373\r
374Arguments:\r
375\r
376 PeiServices - The PEI core services table.\r
377\r
378 Guid - The GUID of the custome HOB type\r
379\r
380 Data - The data to be copied into the GUIDed HOB data field.\r
381\r
382 DataLength - The data field length.\r
383\r
384Returns:\r
385\r
386 EFI_SUCCESS - Hob is successfully built.\r
387 Others - Errors occur while creating new Hob\r
388\r
389--*/\r
390;\r
391\r
392EFI_STATUS\r
393PeiBuildHobFv (\r
394 IN EFI_PEI_SERVICES **PeiServices,\r
395 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
396 IN UINT64 Length\r
397 )\r
398/*++\r
399\r
400Routine Description:\r
401\r
402 Builds a Firmware Volume HOB\r
403\r
404Arguments:\r
405\r
406 PeiServices - The PEI core services table.\r
407\r
408 BaseAddress - The base address of the Firmware Volume\r
409\r
410 Length - The size of the Firmware Volume in bytes\r
411\r
412Returns:\r
413\r
414 EFI_SUCCESS - Hob is successfully built.\r
415 Others - Errors occur while creating new Hob\r
416\r
417--*/\r
418;\r
419\r
420EFI_STATUS\r
421PeiBuildHobCpu (\r
422 IN EFI_PEI_SERVICES **PeiServices,\r
423 IN UINT8 SizeOfMemorySpace,\r
424 IN UINT8 SizeOfIoSpace\r
425 )\r
426/*++\r
427\r
428Routine Description:\r
429\r
430 Builds a HOB for the CPU\r
431\r
432Arguments:\r
433\r
434 PeiServices - The PEI core services table.\r
435\r
436 SizeOfMemorySpace - Identifies the maximum \r
437 physical memory addressibility of the processor.\r
438\r
439 SizeOfIoSpace - Identifies the maximum physical I/O addressibility \r
440 of the processor.\r
441\r
442Returns:\r
443\r
444 EFI_SUCCESS - Hob is successfully built.\r
445 Others - Errors occur while creating new Hob\r
446\r
447--*/\r
448;\r
449\r
450EFI_STATUS\r
451PeiBuildHobStack (\r
452 IN EFI_PEI_SERVICES **PeiServices,\r
453 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
454 IN UINT64 Length\r
455 )\r
456/*++\r
457\r
458Routine Description:\r
459\r
460 Builds a HOB for the Stack\r
461\r
462Arguments:\r
463\r
464 PeiServices - The PEI core services table.\r
465\r
466 BaseAddress - The 64 bit physical address of the Stack\r
467\r
468 Length - The length of the stack in bytes\r
469\r
470Returns:\r
471\r
472 EFI_SUCCESS - Hob is successfully built.\r
473 Others - Errors occur while creating new Hob\r
474\r
475--*/\r
476;\r
477\r
478EFI_STATUS\r
479PeiBuildHobBspStore (\r
480 IN EFI_PEI_SERVICES **PeiServices,\r
481 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
482 IN UINT64 Length,\r
483 IN EFI_MEMORY_TYPE MemoryType\r
484 )\r
485/*++\r
486\r
487Routine Description:\r
488\r
489 Builds a HOB for the bsp store\r
490\r
491Arguments:\r
492\r
493 PeiServices - The PEI core services table.\r
494\r
495 BaseAddress - The 64 bit physical address of the bsp store\r
496\r
497 Length - The length of the bsp store in bytes\r
498\r
499 MemoryType - Memory type\r
500\r
501Returns:\r
502\r
503 EFI_SUCCESS - Hob is successfully built.\r
504 Others - Errors occur while creating new Hob\r
505\r
506--*/\r
507;\r
508\r
509EFI_STATUS\r
510PeiBuildHobMemoryAllocation (\r
511 IN EFI_PEI_SERVICES **PeiServices,\r
512 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
513 IN UINT64 Length,\r
514 IN EFI_GUID *Name,\r
515 IN EFI_MEMORY_TYPE MemoryType\r
516 )\r
517/*++\r
518\r
519Routine Description:\r
520\r
521 Builds a HOB for the memory allocation\r
522\r
523Arguments:\r
524\r
525 PeiServices - The PEI core services table.\r
526\r
527 BaseAddress - The 64 bit physical address of the memory\r
528\r
529 Length - The length of the memory allocation in bytes\r
530\r
531 Name - Name for Hob\r
532\r
533 MemoryType - Memory type\r
534\r
535Returns:\r
536\r
537 EFI_SUCCESS - Hob is successfully built.\r
538 Others - Errors occur while creating new Hob\r
539\r
540--*/\r
541;\r
542\r
543//\r
544// print.c\r
545//\r
546UINTN\r
547AvSPrint (\r
548 OUT CHAR8 *StartOfBuffer,\r
549 IN UINTN StrSize,\r
550 IN CONST CHAR8 *Format,\r
551 IN VA_LIST Marker\r
552 )\r
553/*++\r
554\r
555Routine Description:\r
556\r
557 AvSPrint function to process format and place the results in Buffer. Since a \r
558 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus \r
559 this is the main print working routine\r
560\r
561Arguments:\r
562\r
563 StartOfBuffer - Ascii buffer to print the results of the parsing of Format into.\r
564\r
565 StrSize - Maximum number of characters to put into buffer. Zero means \r
566 no limit.\r
567\r
568 FormatString - Ascii format string see file header for more details.\r
569\r
570 Marker - Vararg list consumed by processing Format.\r
571\r
572Returns: \r
573\r
574 Number of characters printed.\r
575\r
576--*/\r
577;\r
578\r
579UINTN\r
580ASPrint (\r
581 OUT CHAR8 *Buffer,\r
582 IN UINTN BufferSize,\r
583 IN CONST CHAR8 *Format,\r
584 ...\r
585 )\r
586/*++\r
587\r
588Routine Description:\r
589\r
590 ASPrint function to process format and place the results in Buffer.\r
591\r
592Arguments:\r
593\r
594 Buffer - Ascii buffer to print the results of the parsing of Format into.\r
595\r
596 BufferSize - Maximum number of characters to put into buffer. Zero means no \r
597 limit.\r
598\r
599 Format - Ascii format string see file header for more details.\r
600\r
601 ... - Vararg list consumed by processing Format.\r
602\r
603Returns: \r
604\r
605 Number of characters printed.\r
606\r
607--*/\r
608;\r
609\r
610//\r
611// math.c\r
612//\r
613UINT64\r
614MultU64x32 (\r
615 IN UINT64 Multiplicand,\r
616 IN UINTN Multiplier\r
617 )\r
618/*++ \r
619 \r
620Routine Description:\r
621\r
622 This routine allows a 64 bit value to be multiplied with a 32 bit \r
623 value returns 64bit result.\r
624 No checking if the result is greater than 64bits\r
625\r
626Arguments:\r
627\r
628 Multiplicand - multiplicand\r
629 Multiplier - multiplier\r
630\r
631Returns:\r
632\r
633 Multiplicand * Multiplier\r
634 \r
635--*/\r
636;\r
637\r
638UINT64\r
639DivU64x32 (\r
640 IN UINT64 Dividend,\r
641 IN UINTN Divisor,\r
642 OUT UINTN *Remainder OPTIONAL\r
643 )\r
644/*++\r
645\r
646Routine Description:\r
647\r
648 This routine allows a 64 bit value to be divided with a 32 bit value returns \r
649 64bit result and the Remainder.\r
650 N.B. only works for 31bit divisors!!\r
651\r
652Arguments:\r
653\r
654 Dividend - dividend\r
655 Divisor - divisor\r
656 Remainder - buffer for remainder\r
657 \r
658Returns:\r
659\r
660 Dividend / Divisor\r
661 Remainder = Dividend mod Divisor\r
662\r
663--*/\r
664;\r
665\r
666UINT64\r
667RShiftU64 (\r
668 IN UINT64 Operand,\r
669 IN UINTN Count\r
670 )\r
671/*++\r
672\r
673Routine Description:\r
674\r
675 This routine allows a 64 bit value to be right shifted by 32 bits and returns the \r
676 shifted value.\r
677 Count is valid up 63. (Only Bits 0-5 is valid for Count)\r
678\r
679Arguments:\r
680\r
681 Operand - Value to be shifted\r
682 Count - Number of times to shift right.\r
683 \r
684Returns:\r
685\r
686 Value shifted right identified by the Count.\r
687\r
688--*/\r
689;\r
690\r
691UINT64\r
692LShiftU64 (\r
693 IN UINT64 Operand,\r
694 IN UINTN Count\r
695 )\r
696/*++\r
697\r
698Routine Description:\r
699\r
700 This routine allows a 64 bit value to be left shifted by 32 bits and \r
701 returns the shifted value.\r
702 Count is valid up 63. (Only Bits 0-5 is valid for Count)\r
703\r
704Arguments:\r
705\r
706 Operand - Value to be shifted\r
707 Count - Number of times to shift left.\r
708\r
709Returns:\r
710\r
711 Value shifted left identified by the Count.\r
712\r
713--*/\r
714;\r
715\r
716VOID\r
717RegisterNativeCpuIo (\r
718 IN EFI_PEI_SERVICES **PeiServices,\r
719 IN VOID *CpuIo\r
720 )\r
721/*++\r
722\r
723Routine Description:\r
724\r
725 Register a native Cpu IO\r
726\r
727Arguments:\r
728\r
729 PeiServices - Calling context\r
730 CpuIo - CpuIo instance to register\r
731\r
732Returns:\r
733\r
734 None\r
735\r
736--*/\r
737;\r
738\r
739VOID\r
740GetNativeCpuIo (\r
741 IN EFI_PEI_SERVICES **PeiServices,\r
742 OUT VOID **CpuIo\r
743 )\r
744/*++\r
745\r
746Routine Description:\r
747\r
748 Get registered Cpu IO.\r
749\r
750Arguments:\r
751\r
752 PeiServices - Calling context\r
753 CpuIo - CpuIo instance registered before\r
754\r
755Returns:\r
756\r
757 None\r
758\r
759--*/\r
760;\r
761\r
762#endif\r