1 | /** @file
|
---|
2 | PEI Services Table Pointer Library For Reigseter Mechanism.
|
---|
3 |
|
---|
4 | This library is used for PEIM which does executed from flash device directly but
|
---|
5 | executed in memory.
|
---|
6 |
|
---|
7 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
---|
8 | Copyright (c) 2011 Hewlett-Packard Corporation. All rights reserved.<BR>
|
---|
9 | Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.<BR>
|
---|
10 |
|
---|
11 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
12 |
|
---|
13 | **/
|
---|
14 |
|
---|
15 | #include <PiPei.h>
|
---|
16 | #include <Library/DebugLib.h>
|
---|
17 | #include <Library/PeiServicesTablePointerLib.h>
|
---|
18 | #include <Register/LoongArch64/Csr.h>
|
---|
19 |
|
---|
20 | /**
|
---|
21 | Caches a pointer PEI Services Table.
|
---|
22 |
|
---|
23 | Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer
|
---|
24 | in a platform specific manner.
|
---|
25 |
|
---|
26 | If PeiServicesTablePointer is NULL, then ASSERT().
|
---|
27 |
|
---|
28 | @param PeiServicesTablePointer The address of PeiServices pointer.
|
---|
29 | **/
|
---|
30 | VOID
|
---|
31 | EFIAPI
|
---|
32 | SetPeiServicesTablePointer (
|
---|
33 | IN CONST EFI_PEI_SERVICES **PeiServicesTablePointer
|
---|
34 | )
|
---|
35 | {
|
---|
36 | ASSERT (PeiServicesTablePointer != NULL);
|
---|
37 | CsrWrite (LOONGARCH_CSR_KS0, (UINTN)PeiServicesTablePointer);
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | Retrieves the cached value of the PEI Services Table pointer.
|
---|
42 |
|
---|
43 | Returns the cached value of the PEI Services Table pointer in a CPU specific manner
|
---|
44 | as specified in the CPU binding section of the Platform Initialization Pre-EFI
|
---|
45 | Initialization Core Interface Specification.
|
---|
46 |
|
---|
47 | If the cached PEI Services Table pointer is NULL, then ASSERT().
|
---|
48 |
|
---|
49 | @return The pointer to PeiServices.
|
---|
50 |
|
---|
51 | **/
|
---|
52 | CONST EFI_PEI_SERVICES **
|
---|
53 | EFIAPI
|
---|
54 | GetPeiServicesTablePointer (
|
---|
55 | VOID
|
---|
56 | )
|
---|
57 | {
|
---|
58 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
59 |
|
---|
60 | PeiServices = (CONST EFI_PEI_SERVICES **)(CsrRead (LOONGARCH_CSR_KS0));
|
---|
61 | ASSERT (PeiServices != NULL);
|
---|
62 | return PeiServices;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | Perform CPU specific actions required to migrate the PEI Services Table
|
---|
67 | pointer from temporary RAM to permanent RAM.
|
---|
68 |
|
---|
69 | For IA32 CPUs, the PEI Services Table pointer is stored in the 4 bytes
|
---|
70 | immediately preceding the Interrupt Descriptor Table (IDT) in memory.
|
---|
71 | For X64 CPUs, the PEI Services Table pointer is stored in the 8 bytes
|
---|
72 | immediately preceding the Interrupt Descriptor Table (IDT) in memory.
|
---|
73 | For Itanium, ARM and LoongArch CPUs, a the PEI Services Table Pointer
|
---|
74 | is stored in a dedicated CPU register. This means that there is no
|
---|
75 | memory storage associated with storing the PEI Services Table pointer,
|
---|
76 | so no additional migration actions are required for Itanium, ARM and
|
---|
77 | LoongArch CPUs.
|
---|
78 |
|
---|
79 | **/
|
---|
80 | VOID
|
---|
81 | EFIAPI
|
---|
82 | MigratePeiServicesTablePointer (
|
---|
83 | VOID
|
---|
84 | )
|
---|
85 | {
|
---|
86 | return;
|
---|
87 | }
|
---|