1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
/** @file
Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Uefi.h>
#include <Library/ArmLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/NVParamLib.h>
#include "NVParamLibCommon.h"
/**
Retrieve a non-volatile parameter.
NOTE: If you need a signed value, cast it. It is expected that the
caller will carry the correct permission over various call sequences.
@param[in] Param Parameter ID to retrieve
@param[in] ACLRd Permission for read operation.
@param[out] Val Pointer to an UINT32 to the return value.
@retval EFI_SUCCESS Operation succeeded.
@retval EFI_ACCESS_DENIED Permission not allowed.
@retval EFI_DEVICE_ERROR Service is unavailable.
@retval EFI_INVALID_PARAMETER Val is NULL or return status is invalid.
@retval EFI_NOT_FOUND NVParam entry is not set.
**/
EFI_STATUS
NVParamGet (
IN UINT32 Param,
IN UINT16 ACLRd,
OUT UINT32 *Val
)
{
EFI_MM_COMMUNICATE_NVPARAM_RESPONSE MmNVParamRes;
EFI_STATUS Status;
UINT64 MmData[5];
if (Val == NULL) {
return EFI_INVALID_PARAMETER;
}
MmData[0] = MM_NVPARAM_FUNC_READ;
MmData[1] = Param;
MmData[2] = (UINT64)ACLRd;
Status = NVParamMmCommunicate (
MmData,
sizeof (MmData),
&MmNVParamRes,
sizeof (MmNVParamRes)
);
if (EFI_ERROR (Status)) {
return Status;
}
switch (MmNVParamRes.Status) {
case MM_NVPARAM_RES_SUCCESS:
*Val = (UINT32)MmNVParamRes.Value;
return EFI_SUCCESS;
case MM_NVPARAM_RES_NOT_SET:
return EFI_NOT_FOUND;
case MM_NVPARAM_RES_NO_PERM:
return EFI_ACCESS_DENIED;
case MM_NVPARAM_RES_FAIL:
return EFI_DEVICE_ERROR;
default:
return EFI_INVALID_PARAMETER;
}
}
/**
Set a non-volatile parameter.
NOTE: If you have a signed value, cast to unsigned. If the parameter has
not being created before, the provied permission is used to create the
parameter. Otherwise, it is checked for access. It is expected that the
caller will carry the correct permission over various call sequences.
@param[in] Param Parameter ID to set
@param[in] ACLRd Permission for read operation.
@param[in] ACLWr Permission for write operation.
@param[in] Val Unsigned int value to set.
@retval EFI_SUCCESS Operation succeeded.
@retval EFI_ACCESS_DENIED Permission not allowed.
@retval EFI_DEVICE_ERROR Service is unavailable.
@retval EFI_INVALID_PARAMETER Return status is invalid.
**/
EFI_STATUS
NVParamSet (
IN UINT32 Param,
IN UINT16 ACLRd,
IN UINT16 ACLWr,
IN UINT32 Val
)
{
EFI_MM_COMMUNICATE_NVPARAM_RESPONSE MmNVParamRes;
EFI_STATUS Status;
UINT64 MmData[5];
MmData[0] = MM_NVPARAM_FUNC_WRITE;
MmData[1] = Param;
MmData[2] = (UINT64)ACLRd;
MmData[3] = (UINT64)ACLWr;
MmData[4] = (UINT64)Val;
Status = NVParamMmCommunicate (
MmData,
sizeof (MmData),
&MmNVParamRes,
sizeof (MmNVParamRes)
);
if (EFI_ERROR (Status)) {
return Status;
}
switch (MmNVParamRes.Status) {
case MM_NVPARAM_RES_SUCCESS:
return EFI_SUCCESS;
case MM_NVPARAM_RES_NO_PERM:
return EFI_ACCESS_DENIED;
case MM_NVPARAM_RES_FAIL:
return EFI_DEVICE_ERROR;
default:
return EFI_INVALID_PARAMETER;
}
}
/**
Clear a non-volatile parameter.
NOTE: It is expected that the caller will carry the correct permission
over various call sequences.
@param[in] Param Parameter ID to set
@param[in] ACLWr Permission for write operation.
@retval EFI_SUCCESS Operation succeeded.
@retval EFI_ACCESS_DENIED Permission not allowed.
@retval EFI_DEVICE_ERROR Service is unavailable.
@retval EFI_INVALID_PARAMETER Return status is invalid.
**/
EFI_STATUS
NVParamClr (
IN UINT32 Param,
IN UINT16 ACLWr
)
{
EFI_MM_COMMUNICATE_NVPARAM_RESPONSE MmNVParamRes;
EFI_STATUS Status;
UINT64 MmData[5];
MmData[0] = MM_NVPARAM_FUNC_CLEAR;
MmData[1] = Param;
MmData[2] = 0;
MmData[3] = (UINT64)ACLWr;
Status = NVParamMmCommunicate (
MmData,
sizeof (MmData),
&MmNVParamRes,
sizeof (MmNVParamRes)
);
if (EFI_ERROR (Status)) {
return Status;
}
switch (MmNVParamRes.Status) {
case MM_NVPARAM_RES_SUCCESS:
return EFI_SUCCESS;
case MM_NVPARAM_RES_NO_PERM:
return EFI_ACCESS_DENIED;
case MM_NVPARAM_RES_FAIL:
return EFI_DEVICE_ERROR;
default:
return EFI_INVALID_PARAMETER;
}
}
/**
Clear all non-volatile parameters
@retval EFI_SUCCESS Operation succeeded.
@retval EFI_DEVICE_ERROR Service is unavailable.
@retval EFI_INVALID_PARAMETER Return status is invalid.
**/
EFI_STATUS
NVParamClrAll (
VOID
)
{
EFI_MM_COMMUNICATE_NVPARAM_RESPONSE MmNVParamRes;
EFI_STATUS Status;
UINT64 MmData[5];
MmData[0] = MM_NVPARAM_FUNC_CLEAR_ALL;
Status = NVParamMmCommunicate (
MmData,
sizeof (MmData),
&MmNVParamRes,
sizeof (MmNVParamRes)
);
if (EFI_ERROR (Status)) {
return Status;
}
switch (MmNVParamRes.Status) {
case MM_NVPARAM_RES_SUCCESS:
return EFI_SUCCESS;
case MM_NVPARAM_RES_FAIL:
return EFI_DEVICE_ERROR;
default:
return EFI_INVALID_PARAMETER;
}
}
|