]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbInfo.c
OvmfPkg: Add section of memory to use for PEI on S3 resume
[mirror_edk2.git] / OvmfPkg / QemuFlashFvbServicesRuntimeDxe / FvbInfo.c
CommitLineData
a4ce9ffd
JJ
1/**@file\r
2\r
3Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 FvbInfo.c\r
15\r
16Abstract:\r
17\r
18 Defines data structure that is the volume header found.These data is intent\r
19 to decouple FVB driver with FV header.\r
20\r
21**/\r
22\r
23//\r
24// The package level header files this module uses\r
25//\r
26#include <PiDxe.h>\r
27//\r
28// The protocols, PPI and GUID defintions for this module\r
29//\r
30#include <Guid/EventGroup.h>\r
31#include <Guid/FirmwareFileSystem2.h>\r
32#include <Guid/SystemNvDataGuid.h>\r
33#include <Protocol/FirmwareVolumeBlock.h>\r
34#include <Protocol/DevicePath.h>\r
35//\r
36// The Library classes this module consumes\r
37//\r
38#include <Library/UefiLib.h>\r
39#include <Library/UefiDriverEntryPoint.h>\r
40#include <Library/BaseLib.h>\r
41#include <Library/DxeServicesTableLib.h>\r
42#include <Library/UefiRuntimeLib.h>\r
43#include <Library/DebugLib.h>\r
44#include <Library/HobLib.h>\r
45#include <Library/BaseMemoryLib.h>\r
46#include <Library/MemoryAllocationLib.h>\r
47#include <Library/UefiBootServicesTableLib.h>\r
48#include <Library/PcdLib.h>\r
49\r
50typedef struct {\r
51 UINT64 FvLength;\r
52 EFI_FIRMWARE_VOLUME_HEADER FvbInfo;\r
53 //\r
54 // EFI_FV_BLOCK_MAP_ENTRY ExtraBlockMap[n];//n=0\r
55 //\r
56 EFI_FV_BLOCK_MAP_ENTRY End[1];\r
57} EFI_FVB_MEDIA_INFO;\r
58\r
59EFI_FVB_MEDIA_INFO mPlatformFvbMediaInfo[] = {\r
60 //\r
61 // Systen NvStorage FVB\r
62 //\r
63 {\r
64 FixedPcdGet32 (PcdFlashNvStorageVariableSize) +\r
65 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +\r
66 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +\r
67 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize),\r
68 {\r
69 {\r
70 0,\r
71 }, // ZeroVector[16]\r
72 EFI_SYSTEM_NV_DATA_FV_GUID,\r
73 FixedPcdGet32 (PcdFlashNvStorageVariableSize) +\r
74 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +\r
75 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +\r
76 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize),\r
77 EFI_FVH_SIGNATURE,\r
78 EFI_FVB2_MEMORY_MAPPED | \r
79 EFI_FVB2_READ_ENABLED_CAP |\r
80 EFI_FVB2_READ_STATUS |\r
81 EFI_FVB2_WRITE_ENABLED_CAP |\r
82 EFI_FVB2_WRITE_STATUS |\r
83 EFI_FVB2_ERASE_POLARITY |\r
84 EFI_FVB2_ALIGNMENT_16,\r
85 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),\r
86 0, // CheckSum\r
87 0, // ExtHeaderOffset\r
88 {\r
89 0,\r
90 }, // Reserved[1]\r
91 2, // Revision\r
92 {\r
93 (FixedPcdGet32 (PcdFlashNvStorageVariableSize) +\r
94 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +\r
95 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +\r
96 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize)) / FixedPcdGet32 (PcdOvmfFirmwareBlockSize),\r
97 FixedPcdGet32 (PcdOvmfFirmwareBlockSize),\r
98 }\r
99 },\r
100 {\r
101 0,\r
102 0\r
103 }\r
104 }\r
105};\r
106\r
107EFI_STATUS\r
108GetFvbInfo (\r
109 IN UINT64 FvLength,\r
110 OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo\r
111 )\r
112{\r
113 STATIC BOOLEAN Checksummed = FALSE;\r
114 UINTN Index;\r
115\r
116 if (!Checksummed) {\r
117 for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO); Index += 1) {\r
118 UINT16 Checksum;\r
119 mPlatformFvbMediaInfo[Index].FvbInfo.Checksum = 0;\r
120 Checksum = CalculateCheckSum16 (\r
121 (UINT16*) &mPlatformFvbMediaInfo[Index].FvbInfo,\r
122 mPlatformFvbMediaInfo[Index].FvbInfo.HeaderLength\r
123 );\r
124 mPlatformFvbMediaInfo[Index].FvbInfo.Checksum = Checksum;\r
125 }\r
126 Checksummed = TRUE;\r
127 }\r
128\r
129 for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO); Index += 1) {\r
130 if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) {\r
131 *FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo;\r
132 return EFI_SUCCESS;\r
133 }\r
134 }\r
135\r
136 return EFI_NOT_FOUND;\r
137}\r