aboutsummaryrefslogtreecommitdiff
path: root/gnu-efi/gnu-efi-3.0/lib/ia64/salpal.c
blob: 3d808f3e859429337d23f43a7a9bfba28b530d64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*++

Copyright (c) 1999  Intel Corporation
    
Module Name:

    salpal.c

Abstract:

    Functions to make SAL and PAL proc calls

Revision History

--*/
#include "lib.h"
#include "palproc.h"
#include "salproc.h"
/*++

Copyright (c) 1999  Intel Corporation

Module Name:

    EfiRtLib.h

Abstract:

    EFI Runtime library functions



Revision History

--*/

#include "efi.h"
#include "efilib.h"

rArg
MakeStaticPALCall (
    IN UINT64   PALPROCPtr,
    IN UINT64   Arg1,
    IN UINT64   Arg2,
    IN UINT64   Arg3,
    IN UINT64   Arg4
    );

rArg
MakeStackedPALCall (
    IN UINT64   PALPROCPtr,
    IN UINT64   Arg1,
    IN UINT64   Arg2,
    IN UINT64   Arg3,
    IN UINT64   Arg4
    );


PLABEL   SalProcPlabel;
PLABEL   PalProcPlabel;
CALL_SAL_PROC   GlobalSalProc;
CALL_PAL_PROC   GlobalPalProc;

VOID
LibInitSalAndPalProc (
    OUT PLABEL  *SalPlabel,
    OUT UINT64  *PalEntry
    )
{
    SAL_SYSTEM_TABLE_ASCENDING_ORDER    *SalSystemTable;
    EFI_STATUS                          Status;

    GlobalSalProc = NULL;
    GlobalPalProc = NULL;

    Status = LibGetSystemConfigurationTable(&SalSystemTableGuid, (VOID **)&SalSystemTable);
    if (EFI_ERROR(Status)) {
        return; 
    }

    //
    // BugBug: Add code to test checksum on the Sal System Table
    //
    if (SalSystemTable->Entry0.Type != 0) {
        return;
    }

    SalProcPlabel.ProcEntryPoint = SalSystemTable->Entry0.SalProcEntry; 
    SalProcPlabel.GP             = SalSystemTable->Entry0.GlobalDataPointer;
    GlobalSalProc                = (CALL_SAL_PROC)&SalProcPlabel.ProcEntryPoint;

    //
    // Need to check the PAL spec to make sure I'm not responsible for
    //  storing more state.
    // We are passing in a Plabel that should be ignorred by the PAL. Call
    //  this way will cause use to retore our gp after the PAL returns.
    //
    PalProcPlabel.ProcEntryPoint = SalSystemTable->Entry0.PalProcEntry; 
    PalProcPlabel.GP             = SalSystemTable->Entry0.GlobalDataPointer;
    GlobalPalProc                = (CALL_PAL_PROC)PalProcPlabel.ProcEntryPoint;

    *PalEntry = PalProcPlabel.ProcEntryPoint;
    *SalPlabel = SalProcPlabel;
}

EFI_STATUS
LibGetSalIoPortMapping (
    OUT UINT64  *IoPortMapping
    )
/*++

  Get the IO Port Map from the SAL System Table.
  DO NOT USE THIS TO DO YOU OWN IO's!!!!!!!!!!!!
  Only use this for getting info, or initing the built in EFI IO abstraction.
  Always use the EFI Device IO protoocl to access IO space.
  
--*/
{
    SAL_SYSTEM_TABLE_ASCENDING_ORDER    *SalSystemTable;
    SAL_ST_MEMORY_DESCRIPTOR_ENTRY      *SalMemDesc;
    EFI_STATUS                          Status;

    Status = LibGetSystemConfigurationTable(&SalSystemTableGuid, (VOID **)&SalSystemTable);
    if (EFI_ERROR(Status)) {
        return EFI_UNSUPPORTED; 
    }

    //
    // BugBug: Add code to test checksum on the Sal System Table
    //
    if (SalSystemTable->Entry0.Type != 0) {
        return EFI_UNSUPPORTED;
    }

    //
    // The SalSystemTable pointer includes the Type 0 entry.
    //  The SalMemDesc is Type 1 so it comes next.
    //
    SalMemDesc = (SAL_ST_MEMORY_DESCRIPTOR_ENTRY *)(SalSystemTable + 1);
    while (SalMemDesc->Type == SAL_ST_MEMORY_DESCRIPTOR) {
        if (SalMemDesc->MemoryType == SAL_IO_PORT_MAPPING) {
            *IoPortMapping = SalMemDesc->PhysicalMemoryAddress;
            return EFI_SUCCESS;
        }
        SalMemDesc++;
   } 
    return EFI_UNSUPPORTED;
}

EFI_STATUS
LibGetSalIpiBlock (
    OUT UINT64  *IpiBlock
    )
/*++

  Get the IPI block from the SAL system table
  
--*/
{
    SAL_SYSTEM_TABLE_ASCENDING_ORDER    *SalSystemTable;
    SAL_ST_MEMORY_DESCRIPTOR_ENTRY      *SalMemDesc;
    EFI_STATUS                          Status;

    Status = LibGetSystemConfigurationTable(&SalSystemTableGuid, (VOID*)&SalSystemTable);
    if (EFI_ERROR(Status)) {
        return EFI_UNSUPPORTED; 
    }

    //
    // BugBug: Add code to test checksum on the Sal System Table
    //
    if (SalSystemTable->Entry0.Type != 0) {
        return EFI_UNSUPPORTED;
    }

    //
    // The SalSystemTable pointer includes the Type 0 entry.
    //  The SalMemDesc is Type 1 so it comes next.
    //
    SalMemDesc = (SAL_ST_MEMORY_DESCRIPTOR_ENTRY *)(SalSystemTable + 1);
    while (SalMemDesc->Type == SAL_ST_MEMORY_DESCRIPTOR) {
        if (SalMemDesc->MemoryType == SAL_SAPIC_IPI_BLOCK ) {
            *IpiBlock = SalMemDesc->PhysicalMemoryAddress;
            return EFI_SUCCESS;
        }
        SalMemDesc++;
    }
    return EFI_UNSUPPORTED;
}

EFI_STATUS
LibGetSalWakeupVector (
    OUT UINT64  *WakeVector
    )
/*++

Get the wakeup vector from the SAL system table
  
--*/
{
    SAL_ST_AP_WAKEUP_DECRIPTOR      *ApWakeUp;

    ApWakeUp = LibSearchSalSystemTable (SAL_ST_AP_WAKEUP);
    if (!ApWakeUp) {
        *WakeVector = -1;
        return EFI_UNSUPPORTED;
    }
    *WakeVector = ApWakeUp->ExternalInterruptVector;
    return EFI_SUCCESS;
}

VOID *
LibSearchSalSystemTable (
    IN  UINT8   EntryType  
    )
{
    EFI_STATUS                          Status;
    UINT8                               *SalTableHack;
    SAL_SYSTEM_TABLE_ASCENDING_ORDER    *SalSystemTable;
    UINT16                              EntryCount;
    UINT16                              Count;

    Status = LibGetSystemConfigurationTable(&SalSystemTableGuid, (VOID*)&SalSystemTable);
    if (EFI_ERROR(Status)) {
        return NULL; 
    }

    EntryCount = SalSystemTable->Header.EntryCount;
    if (EntryCount == 0) {
        return NULL;
    }
    //
    // BugBug: Add code to test checksum on the Sal System Table
    //

    SalTableHack = (UINT8 *)&SalSystemTable->Entry0;
    for (Count = 0; Count < EntryCount ;Count++) {
        if (*SalTableHack == EntryType) {
            return (VOID *)SalTableHack;
        }
        switch (*SalTableHack) {
        case SAL_ST_ENTRY_POINT:
            SalTableHack += 48;
            break;
        case SAL_ST_MEMORY_DESCRIPTOR:
            SalTableHack += 32;
            break;
        case SAL_ST_PLATFORM_FEATURES:
            SalTableHack += 16;
            break;
        case SAL_ST_TR_USAGE:
            SalTableHack += 32;
            break;
        case SAL_ST_PTC:
            SalTableHack += 16;
            break;
        case SAL_ST_AP_WAKEUP:
            SalTableHack += 16;
            break;
        default:
            ASSERT(FALSE);
            break;
        }
    }
    return NULL;
}

VOID
LibSalProc (
    IN  UINT64    Arg1,
    IN  UINT64    Arg2,
    IN  UINT64    Arg3,
    IN  UINT64    Arg4,
    IN  UINT64    Arg5,
    IN  UINT64    Arg6,
    IN  UINT64    Arg7,
    IN  UINT64    Arg8,
    OUT rArg      *Results  OPTIONAL
    )
{
    rArg    ReturnValue;

    ReturnValue.p0 = -3;    // SAL status return completed with error 
    if (GlobalSalProc) {
        ReturnValue = GlobalSalProc(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8);
    }

    if (Results) {
        CopyMem (Results, &ReturnValue, sizeof(rArg));
    }
}

VOID
LibPalProc (
    IN  UINT64    Arg1, // Pal Proc index
    IN  UINT64    Arg2,
    IN  UINT64    Arg3,
    IN  UINT64    Arg4,
    OUT rArg      *Results  OPTIONAL
    )
{
    
    rArg    ReturnValue;

    ReturnValue.p0 = -3;    // PAL status return completed with error 

    //
    // check for valid PalProc entry point
    //
    
    if (!GlobalPalProc) {
        if (Results) 
            CopyMem (Results, &ReturnValue, sizeof(rArg));
        return;
    }
        
    //
    // check if index falls within stacked or static register calling conventions
    // and call appropriate Pal stub call
    //

    if (((Arg1 >=255) && (Arg1 <=511)) ||
        ((Arg1 >=768) && (Arg1 <=1023))) {    
            ReturnValue = MakeStackedPALCall((UINT64)GlobalPalProc,Arg1,Arg2,Arg3,Arg4);
    }
    else {
        ReturnValue = MakeStaticPALCall((UINT64)GlobalPalProc,Arg1,Arg2,Arg3,Arg4);
    }
          
    if (Results) 
        CopyMem (Results, &ReturnValue, sizeof(rArg));
        
    return;
}