]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointer.c
Add support for PI1.2.1 TempRam Done PPI.
[mirror_edk2.git] / MdePkg / Library / PeiServicesTablePointerLibIdt / PeiServicesTablePointer.c
CommitLineData
bf231ea6 1/** @file\r
030cd1a2 2 PEI Services Table Pointer Library for IA-32 and x64.\r
bf231ea6 3\r
ce02b0b9 4 According to PI specification, the peiservice pointer is stored prior at IDT\r
5 table in IA32 and x64 architecture.\r
6 \r
fcfd5fb0 7 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
19388d29 8 This program and the accompanying materials \r
bf231ea6
A
9 are licensed and made available under the terms and conditions of the BSD License \r
10 which accompanies this distribution. The full text of the license may be found at \r
2fc59a00 11 http://opensource.org/licenses/bsd-license.php. \r
bf231ea6
A
12\r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
15\r
16**/\r
c7d265a9 17\r
5dd39dc6 18#include <PiPei.h>\r
19\r
20#include <Library/BaseLib.h>\r
21#include <Library/PeiServicesTablePointerLib.h>\r
22#include <Library/DebugLib.h>\r
fcfd5fb0
LG
23#include <Library/BaseMemoryLib.h>\r
24#include <Ppi/TemporaryRamSupport.h>\r
c7d265a9 25\r
26/**\r
4b8157f9 27 Retrieves the cached value of the PEI Services Table pointer.\r
f38fdc74 28\r
4b8157f9 29 Returns the cached value of the PEI Services Table pointer in a CPU specific manner \r
30 as specified in the CPU binding section of the Platform Initialization Pre-EFI \r
31 Initialization Core Interface Specification.\r
32 \r
33 If the cached PEI Services Table pointer is NULL, then ASSERT().\r
f38fdc74 34\r
4b8157f9 35 @return The pointer to PeiServices.\r
c7d265a9 36\r
37**/\r
5240b97c 38CONST EFI_PEI_SERVICES **\r
c7d265a9 39EFIAPI\r
40GetPeiServicesTablePointer (\r
41 VOID\r
42 )\r
43{\r
5240b97c 44 CONST EFI_PEI_SERVICES **PeiServices;\r
81c7803c 45 IA32_DESCRIPTOR Idtr;\r
46 \r
47 AsmReadIdtr (&Idtr);\r
5240b97c 48 PeiServices = (CONST EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - sizeof (UINTN)));\r
c7d265a9 49 ASSERT (PeiServices != NULL);\r
50 return PeiServices;\r
51}\r
52\r
81c7803c 53/**\r
4b8157f9 54 Caches a pointer PEI Services Table. \r
55 \r
56 Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer \r
57 in a CPU specific manner as specified in the CPU binding section of the Platform Initialization \r
58 Pre-EFI Initialization Core Interface Specification. \r
f38fdc74 59 The function set the pointer of PEI services immediately preceding the IDT table\r
60 according to PI specification.\r
81c7803c 61 \r
4b8157f9 62 If PeiServicesTablePointer is NULL, then ASSERT().\r
63 \r
f38fdc74 64 @param PeiServicesTablePointer The address of PeiServices pointer.\r
81c7803c 65**/\r
66VOID\r
67EFIAPI\r
68SetPeiServicesTablePointer (\r
a86fda43 69 IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer\r
81c7803c 70 )\r
71{\r
fcfd5fb0
LG
72 IA32_DESCRIPTOR Idtr;\r
73 EFI_PHYSICAL_ADDRESS IdtBase;\r
74 EFI_STATUS Status;\r
75 EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI *TemporaryRamSupportPpi;\r
81c7803c 76 \r
4b8157f9 77 ASSERT (PeiServicesTablePointer != NULL);\r
81c7803c 78 AsmReadIdtr (&Idtr);\r
fcfd5fb0
LG
79 if ((*(UINTN*)(Idtr.Base - sizeof (UINTN))) != (UINTN)PeiServicesTablePointer) {\r
80 (*(UINTN*)(Idtr.Base - sizeof (UINTN))) = (UINTN)PeiServicesTablePointer;\r
81 Status = (*PeiServicesTablePointer)->LocatePpi (\r
82 PeiServicesTablePointer, \r
83 &gEfiTemporaryRamSupportPpiGuid, \r
84 0, \r
85 NULL, \r
86 (VOID**)&TemporaryRamSupportPpi\r
87 );\r
88 \r
89 if (EFI_ERROR (Status)) {\r
90 //\r
91 // If TemporaryRamSupportPpi is not found, Idt table needs to be migrated into memory.\r
92 //\r
93 Status = (*PeiServicesTablePointer)->AllocatePages (\r
94 PeiServicesTablePointer, \r
95 EfiBootServicesCode,\r
96 EFI_SIZE_TO_PAGES(Idtr.Limit + 1 + sizeof (UINTN)),\r
97 &IdtBase\r
98 );\r
99 if (!EFI_ERROR (Status)) {\r
100 //\r
101 // Migrate Idt table\r
102 //\r
103 CopyMem ((VOID *) (UINTN) IdtBase, (VOID *) (Idtr.Base - sizeof (UINTN)), Idtr.Limit + 1 + sizeof (UINTN));\r
104 Idtr.Base = (UINTN) IdtBase + sizeof (UINTN);\r
105 AsmWriteIdtr (&Idtr);\r
106 }\r
107 }\r
108 }\r
81c7803c 109}\r
110\r
81c7803c 111\r