xref: /aosp_15_r20/external/coreboot/src/drivers/efi/option.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <option.h>
4 #include <smmstore.h>
5 
6 #include <Uefi/UefiBaseType.h>
7 
8 #include "efivars.h"
9 
10 static const EFI_GUID EficorebootNvDataGuid = {
11 	0xceae4c1d, 0x335b, 0x4685, { 0xa4, 0xa0, 0xfc, 0x4a, 0x94, 0xee, 0xa0, 0x85 } };
12 
get_uint_option(const char * name,const unsigned int fallback)13 unsigned int get_uint_option(const char *name, const unsigned int fallback)
14 {
15 	struct region_device rdev;
16 	enum cb_err ret;
17 	uint32_t var;
18 	uint32_t size;
19 
20 	if (smmstore_lookup_region(&rdev))
21 		return fallback;
22 
23 	var = 0;
24 	size = sizeof(var);
25 	ret = efi_fv_get_option(&rdev, &EficorebootNvDataGuid, name, &var, &size);
26 	if (ret != CB_SUCCESS)
27 		return fallback;
28 
29 	return var;
30 }
31 
set_uint_option(const char * name,unsigned int value)32 enum cb_err set_uint_option(const char *name, unsigned int value)
33 {
34 	struct region_device rdev;
35 	uint32_t var = value;
36 
37 	if (smmstore_lookup_region(&rdev))
38 		return CB_CMOS_OTABLE_DISABLED;
39 
40 	return efi_fv_set_option(&rdev, &EficorebootNvDataGuid, name, &var, sizeof(var));
41 }
42