]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolAttrib.c
7af96142648fe15c5121f800586ede30b0e3d057
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / FirmwareVolume / FwVolDxe / FwVolAttrib.c
1 /** @file
2
3 Implements get/set firmware volume attributes.
4
5 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include "FwVolDriver.h"
12
13 /**
14 Retrieves attributes, insures positive polarity of attribute bits, returns
15 resulting attributes in output parameter.
16
17 @param This Calling context
18 @param Attributes output buffer which contains attributes
19
20 @retval EFI_SUCCESS Successfully got volume attributes
21
22 **/
23 EFI_STATUS
24 EFIAPI
25 FvGetVolumeAttributes (
26 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
27 OUT EFI_FV_ATTRIBUTES *Attributes
28 )
29 {
30 EFI_STATUS Status;
31 FV_DEVICE *FvDevice;
32 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
33 EFI_FVB_ATTRIBUTES_2 FvbAttributes;
34
35 FvDevice = FV_DEVICE_FROM_THIS (This);
36 Fvb = FvDevice->Fvb;
37
38 //
39 // First get the Firmware Volume Block Attributes
40 //
41 Status = Fvb->GetAttributes (Fvb, &FvbAttributes);
42 FvbAttributes &= 0xfffff0ff;
43
44 *Attributes = FvbAttributes;
45 *Attributes |= EFI_FV2_WRITE_POLICY_RELIABLE;
46 return Status;
47 }
48
49 /**
50 Sets current attributes for volume.
51
52 @param This Calling context
53 @param Attributes On input, FvAttributes is a pointer to
54 an EFI_FV_ATTRIBUTES containing the
55 desired firmware volume settings. On
56 successful return, it contains the new
57 settings of the firmware volume. On
58 unsuccessful return, FvAttributes is not
59 modified and the firmware volume
60 settings are not changed.
61
62 @retval EFI_SUCCESS The requested firmware volume attributes
63 were set and the resulting
64 EFI_FV_ATTRIBUTES is returned in
65 FvAttributes.
66 @retval EFI_ACCESS_DENIED Atrribute is locked down.
67 @retval EFI_INVALID_PARAMETER Atrribute is not valid.
68
69 **/
70 EFI_STATUS
71 EFIAPI
72 FvSetVolumeAttributes (
73 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
74 IN OUT EFI_FV_ATTRIBUTES *Attributes
75 )
76 {
77 EFI_STATUS Status;
78 FV_DEVICE *FvDevice;
79 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
80 EFI_FVB_ATTRIBUTES_2 OldFvbAttributes;
81 EFI_FVB_ATTRIBUTES_2 NewFvbAttributes;
82 UINT64 NewStatus;
83 UINT32 Capabilities;
84
85 FvDevice = FV_DEVICE_FROM_THIS (This);
86 Fvb = FvDevice->Fvb;
87
88 //
89 // First get the current Volume Attributes
90 //
91 Status = Fvb->GetAttributes (
92 Fvb,
93 &OldFvbAttributes
94 );
95
96 if ((OldFvbAttributes & EFI_FVB2_LOCK_STATUS) != 0) {
97 return EFI_ACCESS_DENIED;
98 }
99 //
100 // Only status attributes can be updated.
101 //
102 Capabilities = OldFvbAttributes & EFI_FVB2_CAPABILITIES;
103 NewStatus = (*Attributes) & EFI_FVB2_STATUS;
104
105 //
106 // Test read disable
107 //
108 if ((Capabilities & EFI_FVB2_READ_DISABLED_CAP) == 0) {
109 if ((NewStatus & EFI_FVB2_READ_STATUS) == 0) {
110 return EFI_INVALID_PARAMETER;
111 }
112 }
113 //
114 // Test read enable
115 //
116 if ((Capabilities & EFI_FVB2_READ_ENABLED_CAP) == 0) {
117 if ((NewStatus & EFI_FVB2_READ_STATUS) != 0) {
118 return EFI_INVALID_PARAMETER;
119 }
120 }
121 //
122 // Test write disable
123 //
124 if ((Capabilities & EFI_FVB2_WRITE_DISABLED_CAP) == 0) {
125 if ((NewStatus & EFI_FVB2_WRITE_STATUS) == 0) {
126 return EFI_INVALID_PARAMETER;
127 }
128 }
129 //
130 // Test write enable
131 //
132 if ((Capabilities & EFI_FVB2_WRITE_ENABLED_CAP) == 0) {
133 if ((NewStatus & EFI_FVB2_WRITE_STATUS) != 0) {
134 return EFI_INVALID_PARAMETER;
135 }
136 }
137 //
138 // Test lock
139 //
140 if ((Capabilities & EFI_FVB2_LOCK_CAP) == 0) {
141 if ((NewStatus & EFI_FVB2_LOCK_STATUS) != 0) {
142 return EFI_INVALID_PARAMETER;
143 }
144 }
145
146 NewFvbAttributes = OldFvbAttributes & (0xFFFFFFFF & (~EFI_FVB2_STATUS));
147 NewFvbAttributes |= NewStatus;
148 Status = Fvb->SetAttributes (
149 Fvb,
150 &NewFvbAttributes
151 );
152
153 if (EFI_ERROR (Status)) {
154 return Status;
155 }
156
157 *Attributes = 0;
158
159 This->GetVolumeAttributes (
160 This,
161 Attributes
162 );
163
164 return EFI_SUCCESS;
165 }
166
167 /**
168 Return information of type InformationType for the requested firmware
169 volume.
170
171 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.
172 @param InformationType InformationType for requested.
173 @param BufferSize On input, size of Buffer.On output, the amount of
174 data returned in Buffer.
175 @param Buffer A poniter to the data buffer to return.
176
177 @return EFI_UNSUPPORTED Could not get.
178
179 **/
180 EFI_STATUS
181 EFIAPI
182 FvGetVolumeInfo (
183 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
184 IN CONST EFI_GUID *InformationType,
185 IN OUT UINTN *BufferSize,
186 OUT VOID *Buffer
187 )
188 {
189 return EFI_UNSUPPORTED;
190 }
191
192 /**
193 Set information with InformationType into the requested firmware volume.
194
195 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.
196 @param InformationType InformationType for requested.
197 @param BufferSize Size of Buffer data.
198 @param Buffer A poniter to the data buffer to be set.
199
200 @retval EFI_UNSUPPORTED Could not set.
201
202 **/
203 EFI_STATUS
204 EFIAPI
205 FvSetVolumeInfo (
206 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
207 IN CONST EFI_GUID *InformationType,
208 IN UINTN BufferSize,
209 IN CONST VOID *Buffer
210 )
211 {
212 return EFI_UNSUPPORTED;
213 }