]> git.proxmox.com Git - mirror_edk2.git/blob - QuarkPlatformPkg/Platform/Dxe/SaveMemoryConfig/SaveMemoryConfig.c
e6455acd63f8208cfcf968a0fc32ffceab07bc51
[mirror_edk2.git] / QuarkPlatformPkg / Platform / Dxe / SaveMemoryConfig / SaveMemoryConfig.c
1 /** @file
2 This is the driver that locates the MemoryConfigurationData HOB, if it
3 exists, and saves the data to nvRAM.
4
5 Copyright (c) 2013-2015 Intel Corporation.
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include <Library/DebugLib.h>
12 #include <Library/HobLib.h>
13 #include <Library/MemoryAllocationLib.h>
14 #include <Library/UefiBootServicesTableLib.h>
15 #include <Library/UefiRuntimeServicesTableLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/UefiDriverEntryPoint.h>
18
19 #include <Guid/MemoryConfigData.h>
20 #include <Guid/DebugMask.h>
21
22 EFI_STATUS
23 EFIAPI
24 SaveMemoryConfigEntryPoint (
25 IN EFI_HANDLE ImageHandle,
26 IN EFI_SYSTEM_TABLE *SystemTable
27 )
28 /*++
29
30 Routine Description:
31 This is the standard EFI driver point that detects whether there is a
32 MemoryConfigurationData HOB and, if so, saves its data to nvRAM.
33
34 Arguments:
35 ImageHandle - Handle for the image of this driver
36 SystemTable - Pointer to the EFI System Table
37
38 Returns:
39 EFI_SUCCESS - if the data is successfully saved or there was no data
40 EFI_NOT_FOUND - if the HOB list could not be located.
41 EFI_UNLOAD_IMAGE - It is not success
42
43 --*/
44 {
45 EFI_STATUS Status;
46 VOID *HobList;
47 EFI_HOB_GUID_TYPE *GuidHob;
48 VOID *HobData;
49 VOID *VariableData;
50 UINTN DataSize;
51 UINTN BufferSize;
52
53 DataSize = 0;
54 VariableData = NULL;
55 GuidHob = NULL;
56 HobList = NULL;
57 HobData = NULL;
58 Status = EFI_UNSUPPORTED;
59
60 //
61 // Get the HOB list. If it is not present, then ASSERT.
62 //
63 HobList = GetHobList ();
64 ASSERT (HobList != NULL);
65
66 //
67 // Search for the Memory Configuration GUID HOB. If it is not present, then
68 // there's nothing we can do. It may not exist on the update path.
69 //
70 GuidHob = GetNextGuidHob (&gEfiMemoryConfigDataGuid, HobList);
71 if (GuidHob != NULL) {
72 HobData = GET_GUID_HOB_DATA (GuidHob);
73 DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob);
74 //
75 // Use the HOB to save Memory Configuration Data
76 //
77 BufferSize = DataSize;
78 VariableData = AllocatePool (BufferSize);
79 ASSERT (VariableData != NULL);
80 Status = gRT->GetVariable (
81 EFI_MEMORY_CONFIG_DATA_NAME,
82 &gEfiMemoryConfigDataGuid,
83 NULL,
84 &BufferSize,
85 VariableData
86 );
87 if (Status == EFI_BUFFER_TOO_SMALL) {
88 gBS->FreePool (VariableData);
89 VariableData = AllocatePool (BufferSize);
90 ASSERT (VariableData != NULL);
91 Status = gRT->GetVariable (
92 EFI_MEMORY_CONFIG_DATA_NAME,
93 &gEfiMemoryConfigDataGuid,
94 NULL,
95 &BufferSize,
96 VariableData
97 );
98 }
99
100 if (EFI_ERROR(Status) || BufferSize != DataSize || CompareMem (HobData, VariableData, DataSize) != 0) {
101 Status = gRT->SetVariable (
102 EFI_MEMORY_CONFIG_DATA_NAME,
103 &gEfiMemoryConfigDataGuid,
104 (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS),
105 DataSize,
106 HobData
107 );
108 ASSERT((Status == EFI_SUCCESS) || (Status == EFI_OUT_OF_RESOURCES));
109 }
110
111 gBS->FreePool (VariableData);
112 }
113
114 //
115 // This driver does not produce any protocol services, so always unload it.
116 //
117 return Status;
118 }