-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathefi_selftest_variables_common.c
102 lines (89 loc) · 2.67 KB
/
efi_selftest_variables_common.c
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
// SPDX-License-Identifier: GPL-2.0+
/*
* efi_selftest_variables_runtime
*
* Copyright (c) 2024 Ilias Apalodimas <ilias.apalodimas@linaro.org>
*
* This unit test checks common service across boottime/runtime
*/
#include <efi_selftest.h>
#define EFI_INVALID_ATTR BIT(30)
int efi_st_query_variable_common(struct efi_runtime_services *runtime,
u32 attributes)
{
efi_status_t ret;
u64 max_storage, rem_storage, max_size;
ret = runtime->query_variable_info(attributes,
&max_storage, &rem_storage,
&max_size);
if (ret != EFI_SUCCESS) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
} else if (!max_storage || !rem_storage || !max_size) {
efi_st_error("QueryVariableInfo: wrong info\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(EFI_VARIABLE_RUNTIME_ACCESS,
&max_storage, &rem_storage,
&max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(attributes,
NULL, &rem_storage,
&max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(attributes,
&max_storage, NULL,
&max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(attributes,
&max_storage, &rem_storage,
NULL);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(0, &max_storage, &rem_storage,
&max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(attributes |
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS |
EFI_VARIABLE_NON_VOLATILE,
&max_storage, &rem_storage,
&max_size);
if (ret != EFI_UNSUPPORTED) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(EFI_VARIABLE_NON_VOLATILE,
&max_storage, &rem_storage,
&max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
/*
* Use a mix existing/non-existing attribute bits from the
* UEFI spec
*/
ret = runtime->query_variable_info(attributes | EFI_INVALID_ATTR |
EFI_VARIABLE_NON_VOLATILE,
&max_storage, &rem_storage,
&max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
return EFI_ST_SUCCESS;
}