blob: 1e2be1135b94e9ac7b21cb1ef23f76e2adb1922a [file] [log] [blame]
Heinrich Schuchardt9827e842020-06-22 18:10:27 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * UEFI runtime variable services
4 *
5 * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
6 */
7
8#include <common.h>
9#include <efi_loader.h>
10#include <efi_variable.h>
11
12/**
13 * efi_efi_get_variable() - retrieve value of a UEFI variable
14 *
15 * This function implements the GetVariable runtime service.
16 *
17 * See the Unified Extensible Firmware Interface (UEFI) specification for
18 * details.
19 *
20 * @variable_name: name of the variable
21 * @vendor: vendor GUID
22 * @attributes: attributes of the variable
23 * @data_size: size of the buffer to which the variable value is copied
24 * @data: buffer to which the variable value is copied
25 * Return: status code
26 */
27efi_status_t EFIAPI efi_get_variable(u16 *variable_name,
28 const efi_guid_t *vendor, u32 *attributes,
29 efi_uintn_t *data_size, void *data)
30{
31 efi_status_t ret;
32
33 EFI_ENTRY("\"%ls\" %pUl %p %p %p", variable_name, vendor, attributes,
34 data_size, data);
35
36 ret = efi_get_variable_int(variable_name, vendor, attributes,
37 data_size, data, NULL);
38
39 /* Remove EFI_VARIABLE_READ_ONLY flag */
40 if (attributes)
41 *attributes &= EFI_VARIABLE_MASK;
42
43 return EFI_EXIT(ret);
44}
45
46/**
47 * efi_set_variable() - set value of a UEFI variable
48 *
49 * This function implements the SetVariable runtime service.
50 *
51 * See the Unified Extensible Firmware Interface (UEFI) specification for
52 * details.
53 *
54 * @variable_name: name of the variable
55 * @vendor: vendor GUID
56 * @attributes: attributes of the variable
57 * @data_size: size of the buffer with the variable value
58 * @data: buffer with the variable value
59 * Return: status code
60 */
61efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
62 const efi_guid_t *vendor, u32 attributes,
63 efi_uintn_t data_size, const void *data)
64{
65 efi_status_t ret;
66
67 EFI_ENTRY("\"%ls\" %pUl %x %zu %p", variable_name, vendor, attributes,
68 data_size, data);
69
70 /* Make sure that the EFI_VARIABLE_READ_ONLY flag is not set */
71 if (attributes & ~(u32)EFI_VARIABLE_MASK)
72 ret = EFI_INVALID_PARAMETER;
73 else
74 ret = efi_set_variable_int(variable_name, vendor, attributes,
75 data_size, data, true);
76
77 return EFI_EXIT(ret);
78}
Heinrich Schuchardt276c61d2020-06-26 17:57:48 +020079
80/**
81 * efi_get_next_variable_name() - enumerate the current variable names
82 *
83 * @variable_name_size: size of variable_name buffer in byte
84 * @variable_name: name of uefi variable's name in u16
85 * @vendor: vendor's guid
86 *
87 * See the Unified Extensible Firmware Interface (UEFI) specification for
88 * details.
89 *
90 * Return: status code
91 */
92efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size,
93 u16 *variable_name,
94 efi_guid_t *vendor)
95{
96 efi_status_t ret;
97
98 EFI_ENTRY("%p \"%ls\" %pUl", variable_name_size, variable_name, vendor);
99
100 ret = efi_get_next_variable_name_int(variable_name_size, variable_name,
101 vendor);
102
103 return EFI_EXIT(ret);
104}
105
106/**
107 * efi_query_variable_info() - get information about EFI variables
108 *
109 * This function implements the QueryVariableInfo() runtime service.
110 *
111 * See the Unified Extensible Firmware Interface (UEFI) specification for
112 * details.
113 *
114 * @attributes: bitmask to select variables to be
115 * queried
116 * @maximum_variable_storage_size: maximum size of storage area for the
117 * selected variable types
118 * @remaining_variable_storage_size: remaining size of storage are for the
119 * selected variable types
120 * @maximum_variable_size: maximum size of a variable of the
121 * selected type
122 * Returns: status code
123 */
124efi_status_t EFIAPI efi_query_variable_info(
125 u32 attributes, u64 *maximum_variable_storage_size,
126 u64 *remaining_variable_storage_size,
127 u64 *maximum_variable_size)
128{
129 efi_status_t ret;
130
131 EFI_ENTRY("%x %p %p %p", attributes, maximum_variable_storage_size,
132 remaining_variable_storage_size, maximum_variable_size);
133
134 ret = efi_query_variable_info_int(attributes,
135 maximum_variable_storage_size,
136 remaining_variable_storage_size,
137 maximum_variable_size);
138
139 return EFI_EXIT(ret);
140}