Ilias Apalodimas | 30d537e | 2024-04-25 08:18:20 +0300 | [diff] [blame] | 1 | // 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 | |
| 14 | int 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; |
Ilias Apalodimas | 9a039e0 | 2024-04-25 08:18:21 +0300 | [diff] [blame] | 26 | } else if (!max_storage || !rem_storage || !max_size) { |
| 27 | efi_st_error("QueryVariableInfo: wrong info\n"); |
| 28 | return EFI_ST_FAILURE; |
Ilias Apalodimas | 30d537e | 2024-04-25 08:18:20 +0300 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | ret = runtime->query_variable_info(EFI_VARIABLE_RUNTIME_ACCESS, |
| 32 | &max_storage, &rem_storage, |
| 33 | &max_size); |
| 34 | if (ret != EFI_INVALID_PARAMETER) { |
| 35 | efi_st_error("QueryVariableInfo failed\n"); |
| 36 | return EFI_ST_FAILURE; |
| 37 | } |
| 38 | |
| 39 | ret = runtime->query_variable_info(attributes, |
| 40 | NULL, &rem_storage, |
| 41 | &max_size); |
| 42 | if (ret != EFI_INVALID_PARAMETER) { |
| 43 | efi_st_error("QueryVariableInfo failed\n"); |
| 44 | return EFI_ST_FAILURE; |
| 45 | } |
| 46 | |
| 47 | ret = runtime->query_variable_info(attributes, |
| 48 | &max_storage, NULL, |
| 49 | &max_size); |
| 50 | if (ret != EFI_INVALID_PARAMETER) { |
| 51 | efi_st_error("QueryVariableInfo failed\n"); |
| 52 | return EFI_ST_FAILURE; |
| 53 | } |
| 54 | |
| 55 | ret = runtime->query_variable_info(attributes, |
| 56 | &max_storage, &rem_storage, |
| 57 | NULL); |
| 58 | if (ret != EFI_INVALID_PARAMETER) { |
| 59 | efi_st_error("QueryVariableInfo failed\n"); |
| 60 | return EFI_ST_FAILURE; |
| 61 | } |
| 62 | |
| 63 | ret = runtime->query_variable_info(0, &max_storage, &rem_storage, |
| 64 | &max_size); |
| 65 | if (ret != EFI_INVALID_PARAMETER) { |
| 66 | efi_st_error("QueryVariableInfo failed\n"); |
| 67 | return EFI_ST_FAILURE; |
| 68 | } |
| 69 | |
| 70 | ret = runtime->query_variable_info(attributes | |
| 71 | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | |
| 72 | EFI_VARIABLE_NON_VOLATILE, |
| 73 | &max_storage, &rem_storage, |
| 74 | &max_size); |
| 75 | if (ret != EFI_UNSUPPORTED) { |
| 76 | efi_st_error("QueryVariableInfo failed\n"); |
| 77 | return EFI_ST_FAILURE; |
| 78 | } |
| 79 | |
| 80 | ret = runtime->query_variable_info(EFI_VARIABLE_NON_VOLATILE, |
| 81 | &max_storage, &rem_storage, |
| 82 | &max_size); |
| 83 | if (ret != EFI_INVALID_PARAMETER) { |
| 84 | efi_st_error("QueryVariableInfo failed\n"); |
| 85 | return EFI_ST_FAILURE; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Use a mix existing/non-existing attribute bits from the |
| 90 | * UEFI spec |
| 91 | */ |
| 92 | ret = runtime->query_variable_info(attributes | EFI_INVALID_ATTR | |
| 93 | EFI_VARIABLE_NON_VOLATILE, |
| 94 | &max_storage, &rem_storage, |
| 95 | &max_size); |
| 96 | if (ret != EFI_INVALID_PARAMETER) { |
| 97 | efi_st_error("QueryVariableInfo failed\n"); |
| 98 | return EFI_ST_FAILURE; |
| 99 | } |
| 100 | |
| 101 | return EFI_ST_SUCCESS; |
| 102 | } |