blob: e29a4be74a57aa174ce645748bcba95e3771ef08 [file] [log] [blame]
Ilias Apalodimas30d537e2024-04-25 08:18:20 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * efi_selftest_variables_runtime
4 *
5 * Copyright (c) 2024 Ilias Apalodimas <ilias.apalodimas@linaro.org>
6 *
7 * This unit test checks common service across boottime/runtime
8 */
9
10#include <efi_selftest.h>
11
12#define EFI_INVALID_ATTR BIT(30)
13
14int efi_st_query_variable_common(struct efi_runtime_services *runtime,
15 u32 attributes)
16{
17 efi_status_t ret;
18 u64 max_storage, rem_storage, max_size;
19
20 ret = runtime->query_variable_info(attributes,
21 &max_storage, &rem_storage,
22 &max_size);
23 if (ret != EFI_SUCCESS) {
24 efi_st_error("QueryVariableInfo failed\n");
25 return EFI_ST_FAILURE;
26 }
27
28 ret = runtime->query_variable_info(EFI_VARIABLE_RUNTIME_ACCESS,
29 &max_storage, &rem_storage,
30 &max_size);
31 if (ret != EFI_INVALID_PARAMETER) {
32 efi_st_error("QueryVariableInfo failed\n");
33 return EFI_ST_FAILURE;
34 }
35
36 ret = runtime->query_variable_info(attributes,
37 NULL, &rem_storage,
38 &max_size);
39 if (ret != EFI_INVALID_PARAMETER) {
40 efi_st_error("QueryVariableInfo failed\n");
41 return EFI_ST_FAILURE;
42 }
43
44 ret = runtime->query_variable_info(attributes,
45 &max_storage, NULL,
46 &max_size);
47 if (ret != EFI_INVALID_PARAMETER) {
48 efi_st_error("QueryVariableInfo failed\n");
49 return EFI_ST_FAILURE;
50 }
51
52 ret = runtime->query_variable_info(attributes,
53 &max_storage, &rem_storage,
54 NULL);
55 if (ret != EFI_INVALID_PARAMETER) {
56 efi_st_error("QueryVariableInfo failed\n");
57 return EFI_ST_FAILURE;
58 }
59
60 ret = runtime->query_variable_info(0, &max_storage, &rem_storage,
61 &max_size);
62 if (ret != EFI_INVALID_PARAMETER) {
63 efi_st_error("QueryVariableInfo failed\n");
64 return EFI_ST_FAILURE;
65 }
66
67 ret = runtime->query_variable_info(attributes |
68 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS |
69 EFI_VARIABLE_NON_VOLATILE,
70 &max_storage, &rem_storage,
71 &max_size);
72 if (ret != EFI_UNSUPPORTED) {
73 efi_st_error("QueryVariableInfo failed\n");
74 return EFI_ST_FAILURE;
75 }
76
77 ret = runtime->query_variable_info(EFI_VARIABLE_NON_VOLATILE,
78 &max_storage, &rem_storage,
79 &max_size);
80 if (ret != EFI_INVALID_PARAMETER) {
81 efi_st_error("QueryVariableInfo failed\n");
82 return EFI_ST_FAILURE;
83 }
84
85 /*
86 * Use a mix existing/non-existing attribute bits from the
87 * UEFI spec
88 */
89 ret = runtime->query_variable_info(attributes | EFI_INVALID_ATTR |
90 EFI_VARIABLE_NON_VOLATILE,
91 &max_storage, &rem_storage,
92 &max_size);
93 if (ret != EFI_INVALID_PARAMETER) {
94 efi_st_error("QueryVariableInfo failed\n");
95 return EFI_ST_FAILURE;
96 }
97
98 return EFI_ST_SUCCESS;
99}