aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/efi
diff options
context:
space:
mode:
authorPatrick Rudolph <patrick.rudolph@9elements.com>2022-03-03 10:16:35 +0100
committerLean Sheng Tan <sheng.tan@9elements.com>2023-04-03 21:14:53 +0000
commit4d66ab5e34b709e9033cc677f5e3a7de788727ee (patch)
treefc84440ded0b019c8e1b6a60cb2fc09ed2cef3ee /src/drivers/efi
parent1ab8ad66d450094a1e429a004fc10e1d4b32bbfb (diff)
option: Allow to use the EFI variable driver as option backend
Use the introduced EFI variable store driver on top of the SMMSTORE region in SPI flash to read/write options. Change-Id: I520eca96bcd573f825ed35a29bf8f750e313a02d Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/62562 Reviewed-by: Lean Sheng Tan <sheng.tan@9elements.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/drivers/efi')
-rw-r--r--src/drivers/efi/option.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/drivers/efi/option.c b/src/drivers/efi/option.c
new file mode 100644
index 0000000000..3960cfc76b
--- /dev/null
+++ b/src/drivers/efi/option.c
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <stdlib.h>
+#include <string.h>
+#include <option.h>
+#include <smmstore.h>
+
+#include <Uefi/UefiBaseType.h>
+
+#include "efivars.h"
+
+static const EFI_GUID EficorebootNvDataGuid = {
+ 0xceae4c1d, 0x335b, 0x4685, { 0xa4, 0xa0, 0xfc, 0x4a, 0x94, 0xee, 0xa0, 0x85 } };
+
+unsigned int get_uint_option(const char *name, const unsigned int fallback)
+{
+ struct region_device rdev;
+ enum cb_err ret;
+ uint32_t var;
+ uint32_t size;
+
+ if (smmstore_lookup_region(&rdev))
+ return fallback;
+
+ var = 0;
+ size = sizeof(var);
+ ret = efi_fv_get_option(&rdev, &EficorebootNvDataGuid, name, &var, &size);
+ if (ret != CB_SUCCESS)
+ return fallback;
+
+ return var;
+}
+
+enum cb_err set_uint_option(const char *name, unsigned int value)
+{
+ struct region_device rdev;
+ uint32_t var = value;
+
+ if (smmstore_lookup_region(&rdev))
+ return CB_CMOS_OTABLE_DISABLED;
+
+ return efi_fv_set_option(&rdev, &EficorebootNvDataGuid, name, &var, sizeof(var));
+}