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