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