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