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