1 /** @file
2   The library implements the Extended SAL Library Class for boot service only modules.
3 
4   Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
5   This program and the accompanying materials
6   are licensed and made available under the terms and conditions of the BSD License
7   which accompanies this distribution.  The full text of the license may be found at
8   http://opensource.org/licenses/bsd-license.php.
9 
10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #include <PiDxe.h>
16 
17 #include <Protocol/ExtendedSalBootService.h>
18 #include <Protocol/ExtendedSalServiceClasses.h>
19 
20 #include <Library/ExtendedSalLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Library/DebugLib.h>
23 
24 /**
25   Stores the physical plabel of ESAL entrypoint.
26 
27   This assembly function stores the physical plabel of ESAL entrypoint
28   where GetEsalEntryPoint() can easily retrieve.
29 
30   @param  EntryPoint  Physical address of ESAL entrypoint
31   @param  Gp          Physical GP of ESAL entrypoint
32 
33   @return r8 = EFI_SAL_SUCCESS
34 
35 **/
36 SAL_RETURN_REGS
37 EFIAPI
38 SetEsalPhysicalEntryPoint (
39   IN  UINT64  EntryPoint,
40   IN  UINT64  Gp
41   );
42 
43 /**
44   Retrieves plabel of ESAL entrypoint.
45 
46   This function retrives plabel of ESAL entrypoint stored by
47   SetEsalPhysicalEntryPoint().
48 
49   @return r8  = EFI_SAL_SUCCESS
50           r9  = Physical Plabel
51           r10 = Virtual Plabel
52           r11 = PSR
53 
54 **/
55 SAL_RETURN_REGS
56 EFIAPI
57 GetEsalEntryPoint (
58   VOID
59   );
60 
61 EXTENDED_SAL_BOOT_SERVICE_PROTOCOL  *mEsalBootService = NULL;
62 EFI_PLABEL                          mPlabel;
63 
64 /**
65   Constructor function to get Extended SAL Boot Service Protocol, and initializes
66   physical plabel of ESAL entrypoint.
67 
68   This function first locates Extended SAL Boot Service Protocol and caches it in global variable.
69   Then it initializes the physical plable of ESAL entrypoint, and stores
70   it where GetEsalEntryPoint() can easily retrieve.
71 
72   @param  ImageHandle   The firmware allocated handle for the EFI image.
73   @param  SystemTable   A pointer to the EFI System Table.
74 
75   @retval  EFI_SUCCESS  Plable of ESAL entrypoint successfully stored.
76 
77 **/
78 EFI_STATUS
79 EFIAPI
DxeExtendedSalLibConstruct(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)80 DxeExtendedSalLibConstruct (
81   IN EFI_HANDLE           ImageHandle,
82   IN EFI_SYSTEM_TABLE     *SystemTable
83   )
84 {
85   EFI_PLABEL  *Plabel;
86   EFI_STATUS  Status;
87 
88   //
89   // The protocol contains a function pointer, which is an indirect procedure call.
90   // An indirect procedure call goes through a plabel, and pointer to a function is
91   // a pointer to a plabel. To implement indirect procedure calls that can work in
92   // both physical and virtual mode, two plabels are required (one physical and one
93   // virtual). So lets grap the physical PLABEL for the EsalEntryPoint and store it
94   // away. We cache it in a module global, so we can register the vitrual version.
95   //
96   Status = gBS->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid, NULL, (VOID **) &mEsalBootService);
97   ASSERT_EFI_ERROR (Status);
98 
99   Plabel              = (EFI_PLABEL *) (UINTN) mEsalBootService->ExtendedSalProc;
100   mPlabel.EntryPoint  = Plabel->EntryPoint;
101   mPlabel.GP          = Plabel->GP;
102   //
103   // Stores the physical plabel of ESAL entrypoint where GetEsalEntryPoint() can easily retrieve.
104   //
105   SetEsalPhysicalEntryPoint (mPlabel.EntryPoint, mPlabel.GP);
106 
107   return EFI_SUCCESS;
108 }
109 
110 /**
111   Registers function of ESAL class and it's associated global.
112 
113   This function registers function of ESAL class, together with its associated global.
114   It is worker function for RegisterEsalClass().
115   It is only for boot time.
116 
117   @param  FunctionId     ID of function to register
118   @param  ClassGuidLo    GUID of ESAL class, lower 64-bits
119   @param  ClassGuidHi    GUID of ESAL class, upper 64-bits
120   @param  Function       Function to register with ClassGuid/FunctionId pair
121   @param  ModuleGlobal   Module global for the function.
122 
123   @return Status returned by RegisterExtendedSalProc() of Extended SAL Boot Service Protocol
124 
125 **/
126 EFI_STATUS
RegisterEsalFunction(IN UINT64 FunctionId,IN UINT64 ClassGuidLo,IN UINT64 ClassGuidHi,IN SAL_INTERNAL_EXTENDED_SAL_PROC Function,IN VOID * ModuleGlobal)127 RegisterEsalFunction (
128   IN  UINT64                                    FunctionId,
129   IN  UINT64                                    ClassGuidLo,
130   IN  UINT64                                    ClassGuidHi,
131   IN  SAL_INTERNAL_EXTENDED_SAL_PROC            Function,
132   IN  VOID                                      *ModuleGlobal
133   )
134 {
135   return mEsalBootService->RegisterExtendedSalProc (
136                              mEsalBootService,
137                              ClassGuidLo,
138                              ClassGuidHi,
139                              FunctionId,
140                              Function,
141                              ModuleGlobal
142                              );
143 }
144 
145 /**
146   Registers ESAL Class and it's associated global.
147 
148   This function registers one or more Extended SAL services in a given
149   class along with the associated global context.
150   This function is only available prior to ExitBootServices().
151 
152   @param  ClassGuidLo          GUID of function class, lower 64-bits
153   @param  ClassGuidHi          GUID of function class, upper 64-bits
154   @param  ModuleGlobal         Module global for the class.
155   @param  ...                  List of Function/FunctionId pairs, ended by NULL
156 
157   @retval EFI_SUCCESS          The Extended SAL services were registered.
158   @retval EFI_UNSUPPORTED      This function was called after ExitBootServices().
159   @retval EFI_OUT_OF_RESOURCES There are not enough resources available to register one or more of the specified services.
160   @retval Other                ClassGuid could not be installed onto a new handle.
161 
162 **/
163 EFI_STATUS
164 EFIAPI
RegisterEsalClass(IN CONST UINT64 ClassGuidLo,IN CONST UINT64 ClassGuidHi,IN VOID * ModuleGlobal,OPTIONAL...)165 RegisterEsalClass (
166   IN  CONST UINT64    ClassGuidLo,
167   IN  CONST UINT64    ClassGuidHi,
168   IN  VOID            *ModuleGlobal,  OPTIONAL
169   ...
170   )
171 {
172   VA_LIST                         Args;
173   EFI_STATUS                      Status;
174   SAL_INTERNAL_EXTENDED_SAL_PROC  Function;
175   UINT64                          FunctionId;
176   EFI_HANDLE                      NewHandle;
177   EFI_GUID                        ClassGuid;
178 
179   VA_START (Args, ModuleGlobal);
180 
181   //
182   // Register all functions of the class to register.
183   //
184   Status = EFI_SUCCESS;
185   while (!EFI_ERROR (Status)) {
186     Function = (SAL_INTERNAL_EXTENDED_SAL_PROC) VA_ARG (Args, SAL_INTERNAL_EXTENDED_SAL_PROC);
187     //
188     // NULL serves as the end mark of function list
189     //
190     if (Function == NULL) {
191       break;
192     }
193 
194     FunctionId = VA_ARG (Args, UINT64);
195 
196     Status = RegisterEsalFunction (FunctionId, ClassGuidLo, ClassGuidHi, Function, ModuleGlobal);
197   }
198 
199   VA_END (Args);
200 
201   if (EFI_ERROR (Status)) {
202     return Status;
203   }
204 
205   NewHandle = NULL;
206   *((UINT64 *)(&ClassGuid) + 0) = ClassGuidLo;
207   *((UINT64 *)(&ClassGuid) + 1) = ClassGuidHi;
208   return gBS->InstallProtocolInterface (
209                 &NewHandle,
210                 &ClassGuid,
211                 EFI_NATIVE_INTERFACE,
212                 NULL
213                 );
214 }
215 
216 /**
217   Calls an Extended SAL Class service that was previously registered with RegisterEsalClass().
218 
219   This function gets the entrypoint of Extended SAL, and calls an Extended SAL Class service
220   that was previously registered with RegisterEsalClass() through this entrypoint.
221 
222   @param  ClassGuidLo     GUID of function, lower 64-bits
223   @param  ClassGuidHi     GUID of function, upper 64-bits
224   @param  FunctionId      Function in ClassGuid to call
225   @param  Arg2            Argument 2 ClassGuid/FunctionId defined
226   @param  Arg3            Argument 3 ClassGuid/FunctionId defined
227   @param  Arg4            Argument 4 ClassGuid/FunctionId defined
228   @param  Arg5            Argument 5 ClassGuid/FunctionId defined
229   @param  Arg6            Argument 6 ClassGuid/FunctionId defined
230   @param  Arg7            Argument 7 ClassGuid/FunctionId defined
231   @param  Arg8            Argument 8 ClassGuid/FunctionId defined
232 
233   @retval EFI_SAL_SUCCESS ESAL procedure successfully called.
234   @retval EFI_SAL_ERROR   The address of ExtendedSalProc() can not be correctly
235                           initialized.
236   @retval Other           Status returned from ExtendedSalProc() service of
237                           EXTENDED_SAL_BOOT_SERVICE_PROTOCOL.
238 
239 **/
240 SAL_RETURN_REGS
241 EFIAPI
EsalCall(IN UINT64 ClassGuidLo,IN UINT64 ClassGuidHi,IN UINT64 FunctionId,IN UINT64 Arg2,IN UINT64 Arg3,IN UINT64 Arg4,IN UINT64 Arg5,IN UINT64 Arg6,IN UINT64 Arg7,IN UINT64 Arg8)242 EsalCall (
243   IN UINT64  ClassGuidLo,
244   IN UINT64  ClassGuidHi,
245   IN UINT64  FunctionId,
246   IN UINT64  Arg2,
247   IN UINT64  Arg3,
248   IN UINT64  Arg4,
249   IN UINT64  Arg5,
250   IN UINT64  Arg6,
251   IN UINT64  Arg7,
252   IN UINT64  Arg8
253   )
254 {
255   SAL_RETURN_REGS       ReturnReg;
256   EXTENDED_SAL_PROC     EsalProc;
257 
258   //
259   // Get the entrypoint of Extended SAL
260   //
261   ReturnReg = GetEsalEntryPoint ();
262   if (*(UINT64 *)ReturnReg.r9 == 0 && *(UINT64 *)(ReturnReg.r9 + 8) == 0) {
263     //
264     // The ESAL Entry Point could not be initialized
265     //
266     ReturnReg.Status = EFI_SAL_ERROR;
267     return ReturnReg;
268   }
269 
270   //
271   // Test PSR.it which is BIT36
272   //
273   if ((ReturnReg.r11 & BIT36) != 0) {
274     //
275     // Virtual mode plabel to entry point
276     //
277     EsalProc = (EXTENDED_SAL_PROC) ReturnReg.r10;
278   } else {
279     //
280     // Physical mode plabel to entry point
281     //
282     EsalProc = (EXTENDED_SAL_PROC) ReturnReg.r9;
283   }
284 
285   return EsalProc (
286            ClassGuidLo,
287            ClassGuidHi,
288            FunctionId,
289            Arg2,
290            Arg3,
291            Arg4,
292            Arg5,
293            Arg6,
294            Arg7,
295            Arg8
296            );
297 }
298 
299 /**
300   Wrapper for the EsalStallFunctionId service of Extended SAL Stall Services Class.
301 
302   This function is a wrapper for the EsalStallFunctionId service of Extended SAL
303   Stall Services Class. See EsalStallFunctionId of Extended SAL Specification.
304 
305   @param  Microseconds                  The number of microseconds to delay.
306 
307   @retval EFI_SAL_SUCCESS               Call completed without error.
308   @retval EFI_SAL_INVALID_ARGUMENT      Invalid argument.
309   @retval EFI_SAL_VIRTUAL_ADDRESS_ERROR Virtual address not registered
310 
311 **/
312 SAL_RETURN_REGS
313 EFIAPI
EsalStall(IN UINTN Microseconds)314 EsalStall (
315   IN UINTN  Microseconds
316   )
317 {
318   return EsalCall (
319            EFI_EXTENDED_SAL_STALL_SERVICES_PROTOCOL_GUID_LO,
320            EFI_EXTENDED_SAL_STALL_SERVICES_PROTOCOL_GUID_HI,
321            StallFunctionId,
322            Microseconds,
323            0,
324            0,
325            0,
326            0,
327            0,
328            0
329            );
330 }
331 
332 /**
333   Wrapper for the EsalSetNewPalEntryFunctionId service of Extended SAL PAL Services Services Class.
334 
335   This function is a wrapper for the EsalSetNewPalEntryFunctionId service of Extended SAL
336   PAL Services Services Class. See EsalSetNewPalEntryFunctionId of Extended SAL Specification.
337 
338   @param  PhysicalAddress                If TRUE, then PalEntryPoint is a physical address.
339                                          If FALSE, then PalEntryPoint is a virtual address.
340   @param  PalEntryPoint                  The PAL Entry Point being set.
341 
342   @retval EFI_SAL_SUCCESS                The PAL Entry Point was set.
343   @retval EFI_SAL_VIRTUAL_ADDRESS_ERROR  This function was called in virtual mode before
344                                          virtual mappings for the specified Extended SAL
345                                          Procedure are available.
346 
347 **/
348 SAL_RETURN_REGS
349 EFIAPI
EsalSetNewPalEntry(IN BOOLEAN PhysicalAddress,IN UINT64 PalEntryPoint)350 EsalSetNewPalEntry (
351   IN BOOLEAN  PhysicalAddress,
352   IN UINT64   PalEntryPoint
353   )
354 {
355   return EsalCall (
356            EFI_EXTENDED_SAL_PAL_SERVICES_PROTOCOL_GUID_LO,
357            EFI_EXTENDED_SAL_PAL_SERVICES_PROTOCOL_GUID_HI,
358            SetNewPalEntryFunctionId,
359            PhysicalAddress,
360            PalEntryPoint,
361            0,
362            0,
363            0,
364            0,
365            0
366            );
367 }
368 
369 /**
370   Wrapper for the EsalGetNewPalEntryFunctionId service of Extended SAL PAL Services Services Class.
371 
372   This function is a wrapper for the EsalGetNewPalEntryFunctionId service of Extended SAL
373   PAL Services Services Class. See EsalGetNewPalEntryFunctionId of Extended SAL Specification.
374 
375   @param  PhysicalAddress                If TRUE, then PalEntryPoint is a physical address.
376                                          If FALSE, then PalEntryPoint is a virtual address.
377 
378   @retval EFI_SAL_SUCCESS                The PAL Entry Point was retrieved and returned in
379                                          SAL_RETURN_REGS.r9.
380   @retval EFI_SAL_VIRTUAL_ADDRESS_ERROR  This function was called in virtual mode before
381                                          virtual mappings for the specified Extended SAL
382                                          Procedure are available.
383   @return r9                             PAL entry point retrieved.
384 
385 **/
386 SAL_RETURN_REGS
387 EFIAPI
EsalGetNewPalEntry(IN BOOLEAN PhysicalAddress)388 EsalGetNewPalEntry (
389   IN BOOLEAN  PhysicalAddress
390   )
391 {
392   return EsalCall (
393            EFI_EXTENDED_SAL_PAL_SERVICES_PROTOCOL_GUID_LO,
394            EFI_EXTENDED_SAL_PAL_SERVICES_PROTOCOL_GUID_HI,
395            GetNewPalEntryFunctionId,
396            PhysicalAddress,
397            0,
398            0,
399            0,
400            0,
401            0,
402            0
403            );
404 }
405 
406 /**
407   Wrapper for the EsalGetStateBufferFunctionId service of Extended SAL MCA Log Services Class.
408 
409   This function is a wrapper for the EsalGetStateBufferFunctionId service of Extended SAL
410   MCA Log Services Class. See EsalGetStateBufferFunctionId of Extended SAL Specification.
411 
412   @param  McaType               See type parameter of SAL Procedure SAL_GET_STATE_INFO.
413   @param  McaBuffer             A pointer to the base address of the returned buffer.
414                                 Copied from SAL_RETURN_REGS.r9.
415   @param  BufferSize            A pointer to the size, in bytes, of the returned buffer.
416                                 Copied from SAL_RETURN_REGS.r10.
417 
418   @retval EFI_SAL_SUCCESS       The memory buffer to store error records was returned in r9 and r10.
419   @retval EFI_OUT_OF_RESOURCES  A memory buffer for string error records in not available
420   @return r9                    Base address of the returned buffer
421   @return r10                   Size of the returned buffer in bytes
422 
423 **/
424 SAL_RETURN_REGS
425 EFIAPI
EsalGetStateBuffer(IN UINT64 McaType,OUT UINT8 ** McaBuffer,OUT UINTN * BufferSize)426 EsalGetStateBuffer (
427   IN  UINT64  McaType,
428   OUT UINT8   **McaBuffer,
429   OUT UINTN   *BufferSize
430   )
431 {
432   SAL_RETURN_REGS Regs;
433 
434   Regs = EsalCall (
435            EFI_EXTENDED_SAL_MCA_LOG_SERVICES_PROTOCOL_GUID_LO,
436            EFI_EXTENDED_SAL_MCA_LOG_SERVICES_PROTOCOL_GUID_HI,
437            EsalGetStateBufferFunctionId,
438            McaType,
439            0,
440            0,
441            0,
442            0,
443            0,
444            0
445            );
446 
447   *McaBuffer  = (UINT8 *) Regs.r9;
448   *BufferSize = Regs.r10;
449 
450   return Regs;
451 }
452 
453 /**
454   Wrapper for the EsalSaveStateBufferFunctionId service of Extended SAL MCA Log Services Class.
455 
456   This function is a wrapper for the EsalSaveStateBufferFunctionId service of Extended SAL
457   MCA Log Services Class. See EsalSaveStateBufferFunctionId of Extended SAL Specification.
458 
459   @param  McaType      See type parameter of SAL Procedure SAL_GET_STATE_INFO.
460 
461   @retval EFI_SUCCESS  The memory buffer containing the error record was written to nonvolatile storage.
462 
463 **/
464 SAL_RETURN_REGS
465 EFIAPI
EsalSaveStateBuffer(IN UINT64 McaType)466 EsalSaveStateBuffer (
467   IN  UINT64  McaType
468   )
469 {
470   return EsalCall (
471            EFI_EXTENDED_SAL_MCA_LOG_SERVICES_PROTOCOL_GUID_LO,
472            EFI_EXTENDED_SAL_MCA_LOG_SERVICES_PROTOCOL_GUID_HI,
473            EsalSaveStateBufferFunctionId,
474            McaType,
475            0,
476            0,
477            0,
478            0,
479            0,
480            0
481            );
482 }
483 
484 /**
485   Wrapper for the EsalGetVectorsFunctionId service of Extended SAL Base Services Class.
486 
487   This function is a wrapper for the EsalGetVectorsFunctionId service of Extended SAL
488   Base Services Class. See EsalGetVectorsFunctionId of Extended SAL Specification.
489 
490   @param  VectorType               The vector type to retrieve.
491                                    0 - MCA, 1 - BSP INIT, 2 - BOOT_RENDEZ, 3 - AP INIT.
492 
493   @retval EFI_SAL_SUCCESS          Call completed without error.
494   @retval EFI_SAL_INVALID_ARGUMENT Invalid argument.
495   @retval EFI_SAL_NO_INFORMATION   The requested vector has not been registered
496                                    with the SAL Procedure SAL_SET_VECTORS.
497 
498 **/
499 SAL_RETURN_REGS
500 EFIAPI
EsalGetVectors(IN UINT64 VectorType)501 EsalGetVectors (
502   IN  UINT64  VectorType
503   )
504 {
505   return EsalCall (
506            EFI_EXTENDED_SAL_BASE_SERVICES_PROTOCOL_GUID_LO,
507            EFI_EXTENDED_SAL_BASE_SERVICES_PROTOCOL_GUID_HI,
508            EsalGetVectorsFunctionId,
509            VectorType,
510            0,
511            0,
512            0,
513            0,
514            0,
515            0
516            );
517 }
518 
519 /**
520   Wrapper for the EsalMcGetParamsFunctionId service of Extended SAL Base Services Class.
521 
522   This function is a wrapper for the EsalMcGetParamsFunctionId service of Extended SAL
523   Base Services Class. See EsalMcGetParamsFunctionId of Extended SAL Specification.
524 
525   @param  ParamInfoType            The parameter type to retrieve.
526                                    1 - rendezvous interrupt
527                                    2 - wake up
528                                    3 - Corrected Platform Error Vector.
529 
530   @retval EFI_SAL_SUCCESS          Call completed without error.
531   @retval EFI_SAL_INVALID_ARGUMENT Invalid argument.
532   @retval EFI_SAL_NO_INFORMATION   The requested vector has not been registered
533                                    with the SAL Procedure SAL_MC_SET_PARAMS.
534 
535 **/
536 SAL_RETURN_REGS
537 EFIAPI
EsalMcGetParams(IN UINT64 ParamInfoType)538 EsalMcGetParams (
539   IN  UINT64  ParamInfoType
540   )
541 {
542   return EsalCall (
543            EFI_EXTENDED_SAL_BASE_SERVICES_PROTOCOL_GUID_LO,
544            EFI_EXTENDED_SAL_BASE_SERVICES_PROTOCOL_GUID_HI,
545            EsalMcGetParamsFunctionId,
546            ParamInfoType,
547            0,
548            0,
549            0,
550            0,
551            0,
552            0
553            );
554 }
555 
556 /**
557   Wrapper for the EsalMcGetParamsFunctionId service of Extended SAL Base Services Class.
558 
559   This function is a wrapper for the EsalMcGetParamsFunctionId service of Extended SAL
560   Base Services Class. See EsalMcGetParamsFunctionId of Extended SAL Specification.
561 
562   @retval EFI_SAL_SUCCESS          Call completed without error.
563   @retval EFI_SAL_NO_INFORMATION   The requested vector has not been registered
564                                    with the SAL Procedure SAL_MC_SET_PARAMS.
565 
566 **/
567 SAL_RETURN_REGS
568 EFIAPI
EsalMcGetMcParams(VOID)569 EsalMcGetMcParams (
570   VOID
571   )
572 {
573   return EsalCall (
574            EFI_EXTENDED_SAL_BASE_SERVICES_PROTOCOL_GUID_LO,
575            EFI_EXTENDED_SAL_BASE_SERVICES_PROTOCOL_GUID_HI,
576            EsalMcGetMcParamsFunctionId,
577            0,
578            0,
579            0,
580            0,
581            0,
582            0,
583            0
584            );
585 }
586 
587 /**
588   Wrapper for the EsalGetMcCheckinFlagsFunctionId service of Extended SAL Base Services Class.
589 
590   This function is a wrapper for the EsalGetMcCheckinFlagsFunctionId service of Extended SAL
591   Base Services Class. See EsalGetMcCheckinFlagsFunctionId of Extended SAL Specification.
592 
593   @param  CpuIndex         The index of the CPU of set of enabled CPUs to check.
594 
595   @retval EFI_SAL_SUCCESS  The checkin status of the requested CPU was returned.
596 
597 **/
598 SAL_RETURN_REGS
599 EFIAPI
EsalGetMcCheckinFlags(IN UINT64 CpuIndex)600 EsalGetMcCheckinFlags (
601   IN  UINT64  CpuIndex
602   )
603 {
604   return EsalCall (
605            EFI_EXTENDED_SAL_BASE_SERVICES_PROTOCOL_GUID_LO,
606            EFI_EXTENDED_SAL_BASE_SERVICES_PROTOCOL_GUID_HI,
607            EsalGetMcCheckinFlagsFunctionId,
608            CpuIndex,
609            0,
610            0,
611            0,
612            0,
613            0,
614            0
615            );
616 }
617 
618 /**
619   Wrapper for the EsalAddCpuDataFunctionId service of Extended SAL MP Services Class.
620 
621   This function is a wrapper for the EsalAddCpuDataFunctionId service of Extended SAL
622   MP Services Class. See EsalAddCpuDataFunctionId of Extended SAL Specification.
623 
624   @param  CpuGlobalId                 The Global ID for the CPU being added.
625   @param  Enabled                     The enable flag for the CPU being added.
626                                       TRUE means the CPU is enabled.
627                                       FALSE means the CPU is disabled.
628   @param  PalCompatibility            The PAL Compatibility value for the CPU being added.
629 
630   @retval EFI_SAL_SUCCESS             The CPU was added to the database.
631   @retval EFI_SAL_NOT_ENOUGH_SCRATCH  There are not enough resource available to add the CPU.
632 
633 **/
634 SAL_RETURN_REGS
635 EFIAPI
EsalAddCpuData(IN UINT64 CpuGlobalId,IN BOOLEAN Enabled,IN UINT64 PalCompatibility)636 EsalAddCpuData (
637   IN UINT64   CpuGlobalId,
638   IN BOOLEAN  Enabled,
639   IN UINT64   PalCompatibility
640   )
641 {
642   return EsalCall (
643            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_LO,
644            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_HI,
645            AddCpuDataFunctionId,
646            CpuGlobalId,
647            Enabled,
648            PalCompatibility,
649            0,
650            0,
651            0,
652            0
653            );
654 }
655 
656 /**
657   Wrapper for the EsalRemoveCpuDataFunctionId service of Extended SAL MP Services Class.
658 
659   This function is a wrapper for the EsalRemoveCpuDataFunctionId service of Extended SAL
660   MP Services Class. See EsalRemoveCpuDataFunctionId of Extended SAL Specification.
661 
662   @param  CpuGlobalId             The Global ID for the CPU being removed.
663 
664   @retval EFI_SAL_SUCCESS         The CPU was removed from the database.
665   @retval EFI_SAL_NO_INFORMATION  The specified CPU is not in the database.
666 
667 **/
668 SAL_RETURN_REGS
669 EFIAPI
EsalRemoveCpuData(IN UINT64 CpuGlobalId)670 EsalRemoveCpuData (
671   IN UINT64  CpuGlobalId
672   )
673 {
674   return EsalCall (
675            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_LO,
676            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_HI,
677            RemoveCpuDataFunctionId,
678            CpuGlobalId,
679            0,
680            0,
681            0,
682            0,
683            0,
684            0
685            );
686 }
687 
688 /**
689   Wrapper for the EsalModifyCpuDataFunctionId service of Extended SAL MP Services Class.
690 
691   This function is a wrapper for the EsalModifyCpuDataFunctionId service of Extended SAL
692   MP Services Class. See EsalModifyCpuDataFunctionId of Extended SAL Specification.
693 
694   @param  CpuGlobalId             The Global ID for the CPU being modified.
695   @param  Enabled                 The enable flag for the CPU being modified.
696                                   TRUE means the CPU is enabled.
697                                   FALSE means the CPU is disabled.
698   @param  PalCompatibility        The PAL Compatibility value for the CPU being modified.
699 
700   @retval EFI_SAL_SUCCESS         The CPU database was updated.
701   @retval EFI_SAL_NO_INFORMATION  The specified CPU is not in the database.
702 
703 **/
704 SAL_RETURN_REGS
705 EFIAPI
EsalModifyCpuData(IN UINT64 CpuGlobalId,IN BOOLEAN Enabled,IN UINT64 PalCompatibility)706 EsalModifyCpuData (
707   IN UINT64   CpuGlobalId,
708   IN BOOLEAN  Enabled,
709   IN UINT64   PalCompatibility
710   )
711 {
712   return EsalCall (
713            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_LO,
714            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_HI,
715            ModifyCpuDataFunctionId,
716            CpuGlobalId,
717            Enabled,
718            PalCompatibility,
719            0,
720            0,
721            0,
722            0
723            );
724 }
725 
726 /**
727   Wrapper for the EsalGetCpuDataByIdFunctionId service of Extended SAL MP Services Class.
728 
729   This function is a wrapper for the EsalGetCpuDataByIdFunctionId service of Extended SAL
730   MP Services Class. See EsalGetCpuDataByIdFunctionId of Extended SAL Specification.
731 
732   @param  CpuGlobalId             The Global ID for the CPU being looked up.
733   @param  IndexByEnabledCpu       If TRUE, then the index of set of enabled CPUs of database is returned.
734                                   If FALSE, then the index of set of all CPUs of database is returned.
735 
736   @retval EFI_SAL_SUCCESS         The information on the specified CPU was returned.
737   @retval EFI_SAL_NO_INFORMATION  The specified CPU is not in the database.
738 
739 **/
740 SAL_RETURN_REGS
741 EFIAPI
EsalGetCpuDataById(IN UINT64 CpuGlobalId,IN BOOLEAN IndexByEnabledCpu)742 EsalGetCpuDataById (
743   IN UINT64   CpuGlobalId,
744   IN BOOLEAN  IndexByEnabledCpu
745   )
746 {
747   return EsalCall (
748            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_LO,
749            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_HI,
750            GetCpuDataByIDFunctionId,
751            CpuGlobalId,
752            IndexByEnabledCpu,
753            0,
754            0,
755            0,
756            0,
757            0
758            );
759 }
760 
761 /**
762   Wrapper for the EsalGetCpuDataByIndexFunctionId service of Extended SAL MP Services Class.
763 
764   This function is a wrapper for the EsalGetCpuDataByIndexFunctionId service of Extended SAL
765   MP Services Class. See EsalGetCpuDataByIndexFunctionId of Extended SAL Specification.
766 
767   @param  Index                   The Global ID for the CPU being modified.
768   @param  IndexByEnabledCpu       If TRUE, then the index of set of enabled CPUs of database is returned.
769                                   If FALSE, then the index of set of all CPUs of database is returned.
770 
771   @retval EFI_SAL_SUCCESS         The information on the specified CPU was returned.
772   @retval EFI_SAL_NO_INFORMATION  The specified CPU is not in the database.
773 
774 **/
775 SAL_RETURN_REGS
776 EFIAPI
EsalGetCpuDataByIndex(IN UINT64 Index,IN BOOLEAN IndexByEnabledCpu)777 EsalGetCpuDataByIndex (
778   IN UINT64   Index,
779   IN BOOLEAN  IndexByEnabledCpu
780   )
781 {
782   return EsalCall (
783            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_LO,
784            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_HI,
785            GetCpuDataByIndexFunctionId,
786            Index,
787            IndexByEnabledCpu,
788            0,
789            0,
790            0,
791            0,
792            0
793            );
794 }
795 
796 /**
797   Wrapper for the EsalWhoAmIFunctionId service of Extended SAL MP Services Class.
798 
799   This function is a wrapper for the EsalWhoAmIFunctionId service of Extended SAL
800   MP Services Class. See EsalWhoAmIFunctionId of Extended SAL Specification.
801 
802   @param  IndexByEnabledCpu       If TRUE, then the index of set of enabled CPUs of database is returned.
803                                   If FALSE, then the index of set of all CPUs of database is returned.
804 
805   @retval EFI_SAL_SUCCESS         The Global ID for the calling CPU was returned.
806   @retval EFI_SAL_NO_INFORMATION  The calling CPU is not in the database.
807 
808 **/
809 SAL_RETURN_REGS
810 EFIAPI
EsalWhoAmI(IN BOOLEAN IndexByEnabledCpu)811 EsalWhoAmI (
812   IN BOOLEAN  IndexByEnabledCpu
813   )
814 {
815   return EsalCall (
816            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_LO,
817            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_HI,
818            CurrentProcInfoFunctionId,
819            IndexByEnabledCpu,
820            0,
821            0,
822            0,
823            0,
824            0,
825            0
826            );
827 }
828 
829 /**
830   Wrapper for the EsalNumProcessors service of Extended SAL MP Services Class.
831 
832   This function is a wrapper for the EsalNumProcessors service of Extended SAL
833   MP Services Class. See EsalNumProcessors of Extended SAL Specification.
834 
835   @retval EFI_SAL_SUCCESS    The information on the number of CPUs in the platform
836                              was returned.
837 
838 **/
839 SAL_RETURN_REGS
840 EFIAPI
EsalNumProcessors(VOID)841 EsalNumProcessors (
842   VOID
843   )
844 {
845   return EsalCall (
846            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_LO,
847            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_HI,
848            NumProcessorsFunctionId,
849            0,
850            0,
851            0,
852            0,
853            0,
854            0,
855            0
856            );
857 }
858 
859 /**
860   Wrapper for the EsalSetMinStateFnctionId service of Extended SAL MP Services Class.
861 
862   This function is a wrapper for the EsalSetMinStateFnctionId service of Extended SAL
863   MP Services Class. See EsalSetMinStateFnctionId of Extended SAL Specification.
864 
865   @param  CpuGlobalId              The Global ID for the CPU whose MINSTATE pointer is being set.
866   @param  MinStatePointer          The physical address of the MINSTATE buffer for the CPU
867                                    specified by CpuGlobalId.
868 
869   @retval EFI_SAL_SUCCESS          The MINSTATE pointer was set for the specified CPU.
870   @retval EFI_SAL_NO_INFORMATION   The specified CPU is not in the database.
871 
872 **/
873 SAL_RETURN_REGS
874 EFIAPI
EsalSetMinState(IN UINT64 CpuGlobalId,IN EFI_PHYSICAL_ADDRESS MinStatePointer)875 EsalSetMinState (
876   IN UINT64                CpuGlobalId,
877   IN EFI_PHYSICAL_ADDRESS  MinStatePointer
878   )
879 {
880   return EsalCall (
881            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_LO,
882            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_HI,
883            SetMinStateFunctionId,
884            CpuGlobalId,
885            MinStatePointer,
886            0,
887            0,
888            0,
889            0,
890            0
891            );
892 }
893 
894 /**
895   Wrapper for the EsalGetMinStateFunctionId service of Extended SAL MP Services Class.
896 
897   This function is a wrapper for the EsalGetMinStateFunctionId service of Extended SAL
898   MP Services Class. See EsalGetMinStateFunctionId of Extended SAL Specification.
899 
900   @param  CpuGlobalId            The Global ID for the CPU whose MINSTATE pointer is being retrieved.
901 
902   @retval EFI_SAL_SUCCESS        The MINSTATE pointer for the specified CPU was retrieved.
903   @retval EFI_SAL_NO_INFORMATION The specified CPU is not in the database.
904 
905 **/
906 SAL_RETURN_REGS
907 EFIAPI
EsalGetMinState(IN UINT64 CpuGlobalId)908 EsalGetMinState (
909   IN UINT64  CpuGlobalId
910   )
911 {
912   return EsalCall (
913            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_LO,
914            EFI_EXTENDED_SAL_MP_SERVICES_PROTOCOL_GUID_HI,
915            GetMinStateFunctionId,
916            CpuGlobalId,
917            0,
918            0,
919            0,
920            0,
921            0,
922            0
923            );
924 }
925 
926 /**
927   Wrapper for the EsalMcsGetStateInfoFunctionId service of Extended SAL MCA Services Class.
928 
929   This function is a wrapper for the EsalMcsGetStateInfoFunctionId service of Extended SAL
930   MCA Services Class. See EsalMcsGetStateInfoFunctionId of Extended SAL Specification.
931 
932   @param  CpuGlobalId               The Global ID for the CPU whose MCA state buffer is being retrieved.
933   @param  StateBufferPointer        A pointer to the returned MCA state buffer.
934   @param  RequiredStateBufferSize   A pointer to the size, in bytes, of the returned MCA state buffer.
935 
936   @retval EFI_SUCCESS               MINSTATE successfully got and size calculated.
937   @retval EFI_SAL_NO_INFORMATION    Fail to get MINSTATE.
938 
939 **/
940 SAL_RETURN_REGS
941 EFIAPI
EsalMcaGetStateInfo(IN UINT64 CpuGlobalId,OUT EFI_PHYSICAL_ADDRESS * StateBufferPointer,OUT UINT64 * RequiredStateBufferSize)942 EsalMcaGetStateInfo (
943   IN  UINT64                CpuGlobalId,
944   OUT EFI_PHYSICAL_ADDRESS  *StateBufferPointer,
945   OUT UINT64                *RequiredStateBufferSize
946   )
947 {
948   SAL_RETURN_REGS  Regs;
949 
950   Regs = EsalCall (
951            EFI_EXTENDED_SAL_MCA_SERVICES_PROTOCOL_GUID_LO,
952            EFI_EXTENDED_SAL_MCA_SERVICES_PROTOCOL_GUID_HI,
953            McaGetStateInfoFunctionId,
954            CpuGlobalId,
955            0,
956            0,
957            0,
958            0,
959            0,
960            0
961            );
962 
963   *StateBufferPointer      = (EFI_PHYSICAL_ADDRESS) Regs.r9;
964   *RequiredStateBufferSize = (UINT64) Regs.r10;
965 
966   return Regs;
967 }
968 
969 /**
970   Wrapper for the EsalMcaRegisterCpuFunctionId service of Extended SAL MCA Services Class.
971 
972   This function is a wrapper for the EsalMcaRegisterCpuFunctionId service of Extended SAL
973   MCA Services Class. See EsalMcaRegisterCpuFunctionId of Extended SAL Specification.
974 
975   @param  CpuGlobalId              The Global ID for the CPU whose MCA state buffer is being set.
976   @param  StateBufferPointer       A pointer to the MCA state buffer.
977 
978   @retval EFI_SAL_NO_INFORMATION   Cannot get the processor info with the CpuId
979   @retval EFI_SUCCESS              Save the processor's state info successfully
980 
981 **/
982 SAL_RETURN_REGS
983 EFIAPI
EsalMcaRegisterCpu(IN UINT64 CpuGlobalId,IN EFI_PHYSICAL_ADDRESS StateBufferPointer)984 EsalMcaRegisterCpu (
985   IN UINT64                CpuGlobalId,
986   IN EFI_PHYSICAL_ADDRESS  StateBufferPointer
987   )
988 {
989   return EsalCall (
990            EFI_EXTENDED_SAL_MCA_SERVICES_PROTOCOL_GUID_LO,
991            EFI_EXTENDED_SAL_MCA_SERVICES_PROTOCOL_GUID_HI,
992            McaRegisterCpuFunctionId,
993            CpuGlobalId,
994            StateBufferPointer,
995            0,
996            0,
997            0,
998            0,
999            0
1000            );
1001 }
1002