]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiPalLib/UefiPalLib.c
Add following library instances to MDE package:
[mirror_edk2.git] / MdePkg / Library / UefiPalLib / UefiPalLib.c
1 /** @file
2 PAL Library implementation built upon UEFI.
3
4 Copyright (c) 2007 - 2008, Intel Corporation All rights
5 reserved. This program and the accompanying materials are
6 licensed and made available under the terms and conditions of
7 the BSD License which accompanies this distribution. The full
8 text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include <PiDxe.h>
17
18 #include <IndustryStandard/Sal.h>
19 #include <Library/UefiLib.h>
20 #include <Library/BaseLib.h>
21 #include <Library/DebugLib.h>
22
23 #include <Guid/SalSystemTable.h>
24
25 UINT64 mPalProcEntry;
26
27 /**
28 Makes a PAL procedure call.
29
30 This is a wrapper function to make a PAL procedure call. Based on the Index value,
31 this API will make static or stacked PAL call. Architected procedures may be designated
32 as required or optional. If a PAL procedure is specified as optional, a unique return
33 code of 0xFFFFFFFFFFFFFFFF is returned in the Status field of the PAL_CALL_RETURN structure.
34 This indicates that the procedure is not present in this PAL implementation. It is the
35 caller's responsibility to check for this return code after calling any optional PAL
36 procedure. No parameter checking is performed on the 4 input parameters, but there are
37 some common rules that the caller should follow when making a PAL call. Any address
38 passed to PAL as buffers for return parameters must be 8-byte aligned. Unaligned addresses
39 may cause undefined results. For those parameters defined as reserved or some fields
40 defined as reserved must be zero filled or the invalid argument return value may be
41 returned or undefined result may occur during the execution of the procedure.
42 This function is only available on IPF.
43
44 @param Index - The PAL procedure Index number.
45 @param Arg2 - The 2nd parameter for PAL procedure calls.
46 @param Arg3 - The 3rd parameter for PAL procedure calls.
47 @param Arg4 - The 4th parameter for PAL procedure calls.
48
49 @return structure returned from the PAL Call procedure, including the status and return value.
50
51 **/
52 PAL_CALL_RETURN
53 EFIAPI
54 PalCall (
55 IN UINT64 Index,
56 IN UINT64 Arg2,
57 IN UINT64 Arg3,
58 IN UINT64 Arg4
59 )
60 {
61 //
62 // mPalProcEntry is initialized in library constructor as PAL entry.
63 //
64 return AsmPalCall (
65 mPalProcEntry,
66 Index,
67 Arg2,
68 Arg3,
69 Arg4
70 );
71
72 }
73
74 /**
75 The constructor function of UEFI Pal Lib.
76
77 The constructor function looks up the SAL System Table in the EFI System Configuration
78 Table. Once the SAL System Table is found, the PAL Entry Point in the SAL System Table
79 will be derived and stored inot a global variable for library usage.
80 It will ASSERT() if the SAL System Table cannot be found or the data in the SAL System
81 Table is not the valid data.
82
83 @param ImageHandle The firmware allocated handle for the EFI image.
84 @param SystemTable A pointer to the EFI System Table.
85
86 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
87
88 **/
89 EFI_STATUS
90 EFIAPI
91 UefiPalLibConstructor (
92 IN EFI_HANDLE ImageHandle,
93 IN EFI_SYSTEM_TABLE *SystemTable
94 )
95 {
96 EFI_STATUS Status;
97 SAL_ST_ENTRY_POINT_DESCRIPTOR *SalStEntryDes;
98 SAL_SYSTEM_TABLE_HEADER *SalSystemTable;
99
100 Status = EfiGetSystemConfigurationTable (
101 &gEfiSalSystemTableGuid,
102 (VOID **) &SalSystemTable
103 );
104
105 ASSERT_EFI_ERROR (Status);
106
107 //
108 // Move the SAL System Table point to the first Entry
109 // Due to the SAL Entry is in ascending order with the Entry type,
110 // the type 0 Entry should be the first if exist.
111 //
112 SalStEntryDes = (SAL_ST_ENTRY_POINT_DESCRIPTOR *)(SalSystemTable + 1);
113
114 //
115 // Assure the SAL ENTRY Type is 0
116 //
117 ASSERT (SalStEntryDes->Type == EFI_SAL_ST_ENTRY_POINT);
118
119 mPalProcEntry = SalStEntryDes->PalProcEntry;
120 //
121 // Make sure the PalCallAddress has the valid value
122 //
123 ASSERT (mPalProcEntry != 0);
124
125 return EFI_SUCCESS;
126 }