]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/PlatformPei/MemoryCallback.c
Upload BSD-licensed Vlv2TbltDevicePkg and Vlv2DeviceRefCodePkg to
[mirror_edk2.git] / Vlv2TbltDevicePkg / PlatformPei / MemoryCallback.c
1 /** @file
2
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
4
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 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 This file includes a memory call back function notified when MRC is done,
16 following action is performed in this file,
17 1. ICH initialization after MRC.
18 2. SIO initialization.
19 3. Install ResetSystem and FinvFv PPI.
20 4. Set MTRR for PEI
21 5. Create FV HOB and Flash HOB
22
23
24 **/
25
26
27 #include "CommonHeader.h"
28 #include "Platform.h"
29 #include <Ppi/Cache.h>
30 #include <Library/BaseCryptLib.h>
31 #include <Library/PciLib.h>
32 #include "VlvAccess.h"
33
34
35 EFI_PEI_PPI_DESCRIPTOR mPpiListRecoveryBootMode[] = {
36 { (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
37 &gEfiPeiBootInRecoveryModePpiGuid,
38 NULL
39 }
40 };
41
42 #if 0
43 STATIC
44 EFI_STATUS
45 GetMemorySize (
46 IN CONST EFI_PEI_SERVICES **PeiServices,
47 OUT UINT64 *LowMemoryLength,
48 OUT UINT64 *HighMemoryLength
49 )
50 {
51 EFI_STATUS Status;
52 EFI_PEI_HOB_POINTERS Hob;
53
54 *HighMemoryLength = 0;
55 *LowMemoryLength = 0x100000;
56 //
57 // Get the HOB list for processing
58 //
59 Status = (*PeiServices)->GetHobList (PeiServices, (void **)&Hob.Raw);
60 if (EFI_ERROR(Status)) {
61 return Status;
62 }
63
64 //
65 // Collect memory ranges
66 //
67 while (!END_OF_HOB_LIST (Hob)) {
68 if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
69 if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {
70 //
71 // Need memory above 1MB to be collected here
72 //
73 if (Hob.ResourceDescriptor->PhysicalStart >= 0x100000 &&
74 Hob.ResourceDescriptor->PhysicalStart < (EFI_PHYSICAL_ADDRESS) 0x100000000) {
75 *LowMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);
76 } else if (Hob.ResourceDescriptor->PhysicalStart >= (EFI_PHYSICAL_ADDRESS) 0x100000000) {
77 *HighMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);
78 }
79 }
80 }
81 Hob.Raw = GET_NEXT_HOB (Hob);
82 }
83
84 return EFI_SUCCESS;
85 }
86
87 #endif
88 /**
89 This function will be called when MRC is done.
90
91 @param PeiServices General purpose services available to every PEIM.
92 @param NotifyDescriptor Information about the notify event..
93 @param Ppi The notify context.
94
95 @retval EFI_SUCCESS If the function completed successfully.
96 **/
97 EFI_STATUS
98 EFIAPI
99 MemoryDiscoveredPpiNotifyCallback (
100 IN EFI_PEI_SERVICES **PeiServices,
101 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
102 IN VOID *Ppi
103 )
104 {
105
106 EFI_STATUS Status;
107 EFI_BOOT_MODE BootMode;
108 UINT32 Pages;
109 VOID* Memory;
110 UINTN Size;
111
112 //
113 // Allocate LM memory and configure PDM if enabled by user.
114 // ConfigureLM(PeiServices);
115 //
116 Status = (*PeiServices)->GetBootMode (
117 (const EFI_PEI_SERVICES **)PeiServices,
118 &BootMode
119 );
120
121 if (BootMode != BOOT_ON_S3_RESUME) {
122 Size = (PcdGet32 (PcdFlashFvRecovery2Base) - PcdGet32 (PcdFlashFvMainBase)) + FixedPcdGet32(PcdFlashFvRecovery2Size);
123 Pages= Size/0x1000;
124
125 Memory = AllocatePages ( Pages );
126 CopyMem(Memory , (VOID *) FixedPcdGet32(PcdFlashFvMainBase) , Size);
127
128 //
129 // We don't verify just load
130 //
131 PeiServicesInstallFvInfoPpi (
132 NULL,
133 (VOID *) ((UINTN) Memory + (PcdGet32 (PcdFlashFvRecovery2Base) - PcdGet32 (PcdFlashFvMainBase))),
134 PcdGet32 (PcdFlashFvRecovery2Size),
135 NULL,
136 NULL
137 );
138
139 PeiServicesInstallFvInfoPpi (
140 NULL,
141 (VOID *) Memory,
142 PcdGet32 (PcdFlashFvMainSize),
143 NULL,
144 NULL
145 );
146
147 }
148
149 if (BootMode == BOOT_ON_S3_RESUME) {
150 PeiServicesInstallFvInfoPpi (
151 NULL,
152 (VOID *) (UINTN) (PcdGet32 (PcdFlashFvRecovery2Base)),
153 PcdGet32 (PcdFlashFvRecovery2Size),
154 NULL,
155 NULL
156 );
157 }
158
159 return EFI_SUCCESS;
160 }