1 | /** @file
|
---|
2 | The header file for Firmware volume block driver.
|
---|
3 |
|
---|
4 | Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #ifndef FW_BLOCK_SERVICE_H_
|
---|
10 | #define FW_BLOCK_SERVICE_H_
|
---|
11 |
|
---|
12 | #include <Guid/EventGroup.h>
|
---|
13 | #include <Guid/FirmwareFileSystem2.h>
|
---|
14 | #include <Guid/SystemNvDataGuid.h>
|
---|
15 | #include <Guid/VariableFormat.h>
|
---|
16 | #include <Protocol/DevicePath.h>
|
---|
17 | #include <Protocol/FirmwareVolumeBlock.h>
|
---|
18 | #include <Library/UefiDriverEntryPoint.h>
|
---|
19 | #include <Library/UefiBootServicesTableLib.h>
|
---|
20 | #include <Library/UefiLib.h>
|
---|
21 | #include <Library/BaseLib.h>
|
---|
22 | #include <Library/DebugLib.h>
|
---|
23 | #include <Library/BaseMemoryLib.h>
|
---|
24 | #include <Library/IoLib.h>
|
---|
25 | #include <Library/CacheMaintenanceLib.h>
|
---|
26 | #include <Library/MemoryAllocationLib.h>
|
---|
27 | #include <Library/PcdLib.h>
|
---|
28 | #include <Library/FlashDeviceLib.h>
|
---|
29 | #include <Library/DevicePathLib.h>
|
---|
30 | #include <Library/HobLib.h>
|
---|
31 | #include <Library/DxeServicesLib.h>
|
---|
32 | #include <Guid/NvVariableInfoGuid.h>
|
---|
33 | #include <Register/ArchitecturalMsr.h>
|
---|
34 |
|
---|
35 | //
|
---|
36 | // Define two helper macro to extract the Capability field or Status field in FVB
|
---|
37 | // bit fields
|
---|
38 | //
|
---|
39 | #define EFI_FVB2_CAPABILITIES (EFI_FVB2_READ_DISABLED_CAP |\
|
---|
40 | EFI_FVB2_READ_ENABLED_CAP | \
|
---|
41 | EFI_FVB2_WRITE_DISABLED_CAP | \
|
---|
42 | EFI_FVB2_WRITE_ENABLED_CAP | \
|
---|
43 | EFI_FVB2_LOCK_CAP \
|
---|
44 | )
|
---|
45 |
|
---|
46 | #define EFI_FVB2_STATUS (EFI_FVB2_READ_STATUS | EFI_FVB2_WRITE_STATUS | EFI_FVB2_LOCK_STATUS)
|
---|
47 |
|
---|
48 | typedef struct {
|
---|
49 | UINTN FvBase;
|
---|
50 | UINTN NumOfBlocks;
|
---|
51 | //
|
---|
52 | // Note!!!: VolumeHeader must be the last element
|
---|
53 | // of the structure.
|
---|
54 | //
|
---|
55 | EFI_FIRMWARE_VOLUME_HEADER VolumeHeader;
|
---|
56 | } EFI_FW_VOL_INSTANCE;
|
---|
57 |
|
---|
58 | typedef struct {
|
---|
59 | EFI_FW_VOL_INSTANCE *FvInstance;
|
---|
60 | UINT32 NumFv;
|
---|
61 | UINT32 Flags;
|
---|
62 | } FWB_GLOBAL;
|
---|
63 |
|
---|
64 | //
|
---|
65 | // Fvb Protocol instance data
|
---|
66 | //
|
---|
67 | #define FVB_DEVICE_FROM_THIS(a) CR(a, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance, FVB_DEVICE_SIGNATURE)
|
---|
68 | #define FVB_EXTEND_DEVICE_FROM_THIS(a) CR(a, EFI_FW_VOL_BLOCK_DEVICE, FvbExtension, FVB_DEVICE_SIGNATURE)
|
---|
69 | #define FVB_DEVICE_SIGNATURE SIGNATURE_32('F','V','B','C')
|
---|
70 |
|
---|
71 | typedef struct {
|
---|
72 | MEDIA_FW_VOL_DEVICE_PATH FvDevPath;
|
---|
73 | EFI_DEVICE_PATH_PROTOCOL EndDevPath;
|
---|
74 | } FV_PIWG_DEVICE_PATH;
|
---|
75 |
|
---|
76 | typedef struct {
|
---|
77 | MEMMAP_DEVICE_PATH MemMapDevPath;
|
---|
78 | EFI_DEVICE_PATH_PROTOCOL EndDevPath;
|
---|
79 | } FV_MEMMAP_DEVICE_PATH;
|
---|
80 |
|
---|
81 | typedef struct {
|
---|
82 | UINT32 Signature;
|
---|
83 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
---|
84 | UINTN Instance;
|
---|
85 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL FwVolBlockInstance;
|
---|
86 | } EFI_FW_VOL_BLOCK_DEVICE;
|
---|
87 |
|
---|
88 | /**
|
---|
89 | Get a heathy FV header used for variable store recovery
|
---|
90 |
|
---|
91 | @retval The FV header.
|
---|
92 |
|
---|
93 | **/
|
---|
94 | EFI_FIRMWARE_VOLUME_HEADER *
|
---|
95 | GetFvHeaderTemplate (
|
---|
96 | VOID
|
---|
97 | );
|
---|
98 |
|
---|
99 | EFI_STATUS
|
---|
100 | InitVariableStore (
|
---|
101 | VOID
|
---|
102 | );
|
---|
103 |
|
---|
104 | //
|
---|
105 | // Protocol APIs
|
---|
106 | //
|
---|
107 | EFI_STATUS
|
---|
108 | EFIAPI
|
---|
109 | FvbProtocolGetAttributes (
|
---|
110 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
|
---|
111 | OUT EFI_FVB_ATTRIBUTES_2 *Attributes
|
---|
112 | );
|
---|
113 |
|
---|
114 | EFI_STATUS
|
---|
115 | EFIAPI
|
---|
116 | FvbProtocolSetAttributes (
|
---|
117 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
|
---|
118 | IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
|
---|
119 | );
|
---|
120 |
|
---|
121 | EFI_STATUS
|
---|
122 | EFIAPI
|
---|
123 | FvbProtocolGetPhysicalAddress (
|
---|
124 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
|
---|
125 | OUT EFI_PHYSICAL_ADDRESS *Address
|
---|
126 | );
|
---|
127 |
|
---|
128 | EFI_STATUS
|
---|
129 | EFIAPI
|
---|
130 | FvbProtocolGetBlockSize (
|
---|
131 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
|
---|
132 | IN EFI_LBA Lba,
|
---|
133 | OUT UINTN *BlockSize,
|
---|
134 | OUT UINTN *NumOfBlocks
|
---|
135 | );
|
---|
136 |
|
---|
137 | EFI_STATUS
|
---|
138 | EFIAPI
|
---|
139 | FvbProtocolRead (
|
---|
140 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
|
---|
141 | IN EFI_LBA Lba,
|
---|
142 | IN UINTN Offset,
|
---|
143 | IN OUT UINTN *NumBytes,
|
---|
144 | OUT UINT8 *Buffer
|
---|
145 | );
|
---|
146 |
|
---|
147 | EFI_STATUS
|
---|
148 | EFIAPI
|
---|
149 | FvbProtocolWrite (
|
---|
150 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
|
---|
151 | IN EFI_LBA Lba,
|
---|
152 | IN UINTN Offset,
|
---|
153 | IN OUT UINTN *NumBytes,
|
---|
154 | IN UINT8 *Buffer
|
---|
155 | );
|
---|
156 |
|
---|
157 | EFI_STATUS
|
---|
158 | EFIAPI
|
---|
159 | FvbProtocolEraseBlocks (
|
---|
160 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
|
---|
161 | ...
|
---|
162 | );
|
---|
163 |
|
---|
164 | EFI_FW_VOL_INSTANCE *
|
---|
165 | GetFvbInstance (
|
---|
166 | IN UINTN Instance
|
---|
167 | );
|
---|
168 |
|
---|
169 | EFI_STATUS
|
---|
170 | InstallFvbProtocol (
|
---|
171 | IN EFI_FW_VOL_INSTANCE *FwhInstance,
|
---|
172 | IN UINTN InstanceNum
|
---|
173 | );
|
---|
174 |
|
---|
175 | EFI_STATUS
|
---|
176 | FvbInitialize (
|
---|
177 | VOID
|
---|
178 | );
|
---|
179 |
|
---|
180 | extern FWB_GLOBAL mFvbModuleGlobal;
|
---|
181 | extern EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate;
|
---|
182 | extern FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate;
|
---|
183 | extern FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate;
|
---|
184 |
|
---|
185 | #endif
|
---|