mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/16] efi: restructure for reuse from loader code
@ 2025-12-11 20:29 Ahmad Fatoum
  2025-12-11 20:29 ` [PATCH 01/16] efi: payload: restructure Kconfig Ahmad Fatoum
                   ` (17 more replies)
  0 siblings, 18 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:29 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

This series mostly prepares existing definitions and code used for
payload so it can be reused from the new loader support as well.

Ahmad Fatoum (16):
  efi: payload: restructure Kconfig
  efi: payload: populate $global.efi.payload variable
  efi: mode: add efi_get_runtime_services helper
  efi: payload: make EFI variable helpers usable for loader as well
  fs: efivarfs: prepare for use with barebox as EFI loader
  efi: handle: build for both EFI payload and loader
  efi: provide populate $efi.payload_default_path depending on arch
  efi: tidy up header includes for reuse
  efi: types: add efi_intn_t/efi_uintn_t definition
  efi: devicepath: make fully usable for loader
  efi: guid: don't interleave protocol and event GUIDs
  efi: guid: add some more GUIDs
  efi: guid: move static GUIDs out of drivers
  efi: gop: flesh out efi_graphics_output_protocol::blt definition
  efi: payload: initrd: move into common efi code
  efi: add missing EFIAPI to functions

 arch/Kconfig                                  |   5 +
 arch/arm/cpu/cpu.c                            |   2 +-
 arch/arm/cpu/interrupts_64.c                  |   2 +-
 arch/arm/cpu/mmu-common.c                     |   2 +-
 arch/arm/include/asm/pci.h                    |   2 +-
 arch/arm/lib64/armlinux.c                     |   2 +-
 arch/x86/mach-efi/clocksource.c               |   2 +-
 arch/x86/mach-efi/reloc_ia32.c                |   2 +-
 arch/x86/mach-efi/reloc_x86_64.c              |   2 +-
 commands/bfetch.c                             |   4 +-
 commands/efi_handle_dump.c                    |   8 +-
 common/startup.c                              |   6 +-
 drivers/block/efi-block-io.c                  |   7 +-
 drivers/bus/acpi.c                            |   5 +-
 drivers/clocksource/efi.c                     |   7 +-
 drivers/clocksource/efi_x86.c                 |   3 +-
 drivers/efi/Makefile                          |   2 +-
 drivers/efi/efi-device.c                      |  16 +-
 drivers/hw_random/efi-rng.c                   |   6 +-
 drivers/i2c/busses/i2c-efi.c                  |  54 +-
 drivers/net/efi-snp.c                         | 115 +--
 drivers/pci/pci-efi.c                         |   9 +-
 drivers/serial/efi-stdio.c                    |  11 +-
 drivers/serial/serial_efi.c                   |  78 +-
 drivers/serial/serial_semihosting.c           |   2 +-
 drivers/video/efi_gop.c                       |  57 +-
 drivers/watchdog/efi_wdt.c                    |   4 +-
 drivers/watchdog/itco_wdt.c                   |   1 -
 efi/Kconfig                                   |  24 +-
 efi/Makefile                                  |   3 +-
 efi/devicepath.c                              |  11 +-
 efi/efivar-filename.c                         |   3 +-
 efi/efivar.c                                  | 130 +++
 efi/errno.c                                   |   3 +-
 efi/guid.c                                    |  44 +-
 drivers/efi/efi-handle.c => efi/handle.c      |   8 +-
 efi/{payload/efi-initrd.c => initrd.c}        |  28 +-
 efi/payload/Kconfig                           |  27 -
 efi/payload/Makefile                          |   1 -
 efi/payload/boarddata.c                       |   5 +-
 efi/payload/bootm.c                           |   7 +-
 efi/payload/early-mem.c                       |   4 +-
 efi/payload/entry-multi.c                     |   5 +-
 efi/payload/entry-single.c                    |   6 +-
 efi/payload/fdt.c                             |   6 +-
 efi/payload/handover.c                        |   7 +-
 efi/payload/image.c                           |   7 +-
 efi/payload/init.c                            | 109 +--
 efi/payload/iomem.c                           |   6 +-
 fs/Kconfig                                    |   2 +-
 fs/efi.c                                      |   7 +-
 fs/efivarfs.c                                 |  45 +-
 fs/ubootvarfs.c                               |   1 -
 include/acpi.h                                |   2 +-
 include/efi.h                                 | 886 ------------------
 include/efi/attributes.h                      |  21 +
 include/efi/debug_ll.h                        |   9 +-
 include/efi/{device-path.h => devicepath.h}   |   9 +
 include/efi/efi-payload.h                     |  40 -
 include/efi/efi-util.h                        |  20 -
 include/efi/error.h                           |  58 ++
 include/efi/guid.h                            | 361 +++++++
 include/efi/initrd.h                          |  11 +
 include/efi/{memtype.h => memory.h}           |  19 +-
 include/efi/{efi-mode.h => mode.h}            |  11 +
 include/efi/payload.h                         |  37 +
 .../efi/{efi-device.h => payload/driver.h}    |  19 +-
 include/efi/{efi-init.h => payload/init.h}    |   4 +-
 include/efi/protocol/block.h                  |  35 +
 include/efi/protocol/file.h                   | 111 +++
 include/efi/protocol/gop.h                    |  53 ++
 include/efi/protocol/i2c.h                    |  55 ++
 .../pci-efi.h => include/efi/protocol/pci.h   |  10 +-
 include/efi/protocol/rng.h                    |  17 +
 include/efi/protocol/serial.h                 |  79 ++
 include/efi/protocol/snp.h                    | 110 +++
 include/efi/{efi-stdio.h => protocol/text.h}  |  44 +-
 include/efi/services.h                        | 271 ++++++
 include/efi/types.h                           |  51 +-
 include/efi/variable.h                        |  51 +
 lib/vsprintf.c                                |   2 +-
 test/self/mmu.c                               |   2 +-
 82 files changed, 1787 insertions(+), 1526 deletions(-)
 create mode 100644 efi/efivar.c
 rename drivers/efi/efi-handle.c => efi/handle.c (87%)
 rename efi/{payload/efi-initrd.c => initrd.c} (84%)
 delete mode 100644 include/efi.h
 create mode 100644 include/efi/attributes.h
 rename include/efi/{device-path.h => devicepath.h} (95%)
 delete mode 100644 include/efi/efi-payload.h
 delete mode 100644 include/efi/efi-util.h
 create mode 100644 include/efi/error.h
 create mode 100644 include/efi/guid.h
 create mode 100644 include/efi/initrd.h
 rename include/efi/{memtype.h => memory.h} (90%)
 rename include/efi/{efi-mode.h => mode.h} (68%)
 create mode 100644 include/efi/payload.h
 rename include/efi/{efi-device.h => payload/driver.h} (78%)
 rename include/efi/{efi-init.h => payload/init.h} (96%)
 create mode 100644 include/efi/protocol/block.h
 create mode 100644 include/efi/protocol/file.h
 create mode 100644 include/efi/protocol/gop.h
 create mode 100644 include/efi/protocol/i2c.h
 rename drivers/pci/pci-efi.h => include/efi/protocol/pci.h (98%)
 create mode 100644 include/efi/protocol/rng.h
 create mode 100644 include/efi/protocol/serial.h
 create mode 100644 include/efi/protocol/snp.h
 rename include/efi/{efi-stdio.h => protocol/text.h} (67%)
 create mode 100644 include/efi/services.h
 create mode 100644 include/efi/variable.h

-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 01/16] efi: payload: restructure Kconfig
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
@ 2025-12-11 20:29 ` Ahmad Fatoum
  2025-12-11 20:29 ` [PATCH 02/16] efi: payload: populate $global.efi.payload variable Ahmad Fatoum
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:29 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We will keep efi/Kconfig as entry point for the top-level Kconfig
options and make everything in the individual folders dependent on the
top-level symbol. Adopt this scheme for efi/payload/ and while at it,
clarify the symbol name and add a help text.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/Kconfig        |  5 +++++
 efi/Kconfig         | 24 +++++++++++++++++++++---
 efi/payload/Kconfig | 27 ---------------------------
 3 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 55618bf896c2..5af114a6e9e5 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -101,6 +101,11 @@ config ARCH_HAS_SJLJ
 	help
 	  Architecture has support implemented for setjmp()/longjmp()/initjmp()
 
+config HAVE_EFI_PAYLOAD
+	bool
+
+config HAVE_EFI_STUB
+	bool
 
 config PHYS_ADDR_T_64BIT
 	bool
diff --git a/efi/Kconfig b/efi/Kconfig
index 35850b20ef50..23ac601af647 100644
--- a/efi/Kconfig
+++ b/efi/Kconfig
@@ -2,14 +2,32 @@
 
 menu "EFI (Extensible Firmware Interface) Support"
 
+config EFI_PAYLOAD
+	bool "barebox as EFI payload/app (consumer)"
+	depends on HAVE_EFI_PAYLOAD || COMPILE_TEST
+	select PBL_FULLY_PIC if ARM64
+	select EFI
+	select EFI_GUID
+	select EFI_DEVICEPATH
+	select PRINTF_UUID
+	select PRINTF_WCHAR
+	select BLOCK
+	select PARTITION_DISK
+	select HW_HAS_PCI
+	select MALLOC_TLSF
+	help
+	  Select this option if you want a barebox.efi image generated that
+	  can be loaded from existing UEFI firmware and that consumes services
+	  and protocols provided by that UEFI firmware instead of having to
+	  interact directly with the hardware.
+
+if EFI_PAYLOAD
 source "efi/payload/Kconfig"
+endif
 
 config EFI
 	bool
 
-config HAVE_EFI_STUB
-	bool
-
 if EFI
 
 config EFI_GUID
diff --git a/efi/payload/Kconfig b/efi/payload/Kconfig
index 275e053ca868..01f54ee7cf10 100644
--- a/efi/payload/Kconfig
+++ b/efi/payload/Kconfig
@@ -1,30 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-config HAVE_EFI_PAYLOAD
-	bool
-
-config EFI_PAYLOAD
-	bool "Build as EFI payload"
-	depends on HAVE_EFI_PAYLOAD || COMPILE_TEST
-	select PBL_FULLY_PIC if ARM64
-	select EFI
-	select EFI_GUID
-	select EFI_DEVICEPATH
-	select PRINTF_UUID
-	select PRINTF_WCHAR
-	select BLOCK
-	select PARTITION_DISK
-	select HW_HAS_PCI
-	select MALLOC_TLSF
-
-config HAVE_EFI_STUB
-	bool
-
-if EFI_PAYLOAD
-
-config EFI_STUB
-	def_bool HAVE_EFI_STUB
-
 config EFI_PAYLOAD_ESP_IMAGE
 	bool "Generate barebox.esp image from payload"
 	depends on EFI_STUB || !PBL_IMAGE
@@ -57,5 +32,3 @@ config EFI_HANDOVER_PROTOCOL
 config EFI_PAYLOAD_BOOTM
 	bool "EFI bootm protocol"
 	default !X86
-
-endif
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 02/16] efi: payload: populate $global.efi.payload variable
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
  2025-12-11 20:29 ` [PATCH 01/16] efi: payload: restructure Kconfig Ahmad Fatoum
@ 2025-12-11 20:29 ` Ahmad Fatoum
  2025-12-11 20:29 ` [PATCH 03/16] efi: mode: add efi_get_runtime_services helper Ahmad Fatoum
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:29 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

As the same barebox binary will be able to function without EFI,
as EFI loader or as EFI payload, it's useful to have a variable
to check this at runtime.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/efi/efi-device.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 4db3d751a300..78f42a463400 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -13,6 +13,7 @@
 #include <string.h>
 #include <linux/sizes.h>
 #include <wchar.h>
+#include <magicvar.h>
 #include <init.h>
 #include <efi.h>
 #include <efi/efi-payload.h>
@@ -429,6 +430,7 @@ static int efi_init_devices(void)
 	dev_add_param_bool_fixed(&efi_bus.dev, "secure_boot", secure_boot);
 	dev_add_param_bool_fixed(&efi_bus.dev, "secure_mode",
 				 secure_boot & setup_mode);
+	dev_add_param_bool_fixed(&efi_bus.dev, "payload", true);
 
 	devinfo_add(&efi_bus.dev, efi_businfo);
 
@@ -440,6 +442,8 @@ static int efi_init_devices(void)
 }
 core_efi_initcall(efi_init_devices);
 
+BAREBOX_MAGICVAR(efi.payload, "1 indicates that barebox was loaded as EFI payload");
+
 void efi_pause_devices(void)
 {
 	struct device *dev;
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 03/16] efi: mode: add efi_get_runtime_services helper
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
  2025-12-11 20:29 ` [PATCH 01/16] efi: payload: restructure Kconfig Ahmad Fatoum
  2025-12-11 20:29 ` [PATCH 02/16] efi: payload: populate $global.efi.payload variable Ahmad Fatoum
@ 2025-12-11 20:29 ` Ahmad Fatoum
  2025-12-11 20:29 ` [PATCH 04/16] efi: payload: make EFI variable helpers usable for loader as well Ahmad Fatoum
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:29 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Similarly to the existing efi_get_boot_services() helper that replaces
hardcoded BS use to allow code to be usable from both payload and
upcoming loader support, efi_get_runtime_services() can replace RT use.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/efi/efi-mode.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/efi/efi-mode.h b/include/efi/efi-mode.h
index a917c038a1b0..696ab78acd50 100644
--- a/include/efi/efi-mode.h
+++ b/include/efi/efi-mode.h
@@ -7,7 +7,9 @@
 #include <linux/types.h>
 
 struct efi_boot_services;
+struct efi_runtime_services;
 extern struct efi_boot_services *BS;
+extern struct efi_runtime_services *RT;
 
 static inline bool efi_is_payload(void)
 {
@@ -27,4 +29,12 @@ static inline struct efi_boot_services *efi_get_boot_services(void)
 	return NULL;
 }
 
+static inline struct efi_runtime_services *efi_get_runtime_services(void)
+{
+	if (efi_is_payload())
+		return RT;
+
+	return NULL;
+}
+
 #endif
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 04/16] efi: payload: make EFI variable helpers usable for loader as well
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2025-12-11 20:29 ` [PATCH 03/16] efi: mode: add efi_get_runtime_services helper Ahmad Fatoum
@ 2025-12-11 20:29 ` Ahmad Fatoum
  2025-12-11 20:29 ` [PATCH 05/16] fs: efivarfs: prepare for use with barebox as EFI loader Ahmad Fatoum
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:29 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

These functions have nothing specific to the payload apart from
hardcoding RT. Make use of the new efi_get_runtime_services(), so the
code is equally usable from the upcoming loader support.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/efi/efi-device.c  |   1 +
 efi/Makefile              |   2 +-
 efi/efivar.c              | 130 ++++++++++++++++++++++++++++++++++++++
 efi/payload/handover.c    |   1 +
 efi/payload/image.c       |   1 +
 efi/payload/init.c        | 102 +-----------------------------
 include/efi/efi-mode.h    |   1 +
 include/efi/efi-payload.h |  13 +---
 include/efi/variable.h    |  23 +++++++
 9 files changed, 160 insertions(+), 114 deletions(-)
 create mode 100644 efi/efivar.c
 create mode 100644 include/efi/variable.h

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 78f42a463400..1ddf01658ee9 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -18,6 +18,7 @@
 #include <efi.h>
 #include <efi/efi-payload.h>
 #include <efi/efi-device.h>
+#include <efi/variable.h>
 #include <efi/device-path.h>
 #include <linux/err.h>
 
diff --git a/efi/Makefile b/efi/Makefile
index 2b188bafa0a4..508c07c9b536 100644
--- a/efi/Makefile
+++ b/efi/Makefile
@@ -3,4 +3,4 @@
 obj-$(CONFIG_EFI_PAYLOAD)	+= payload/
 obj-$(CONFIG_EFI_GUID)		+= guid.o
 obj-$(CONFIG_EFI_DEVICEPATH)	+= devicepath.o
-obj-y				+= errno.o efivar-filename.o
+obj-y				+= errno.o efivar.o efivar-filename.o
diff --git a/efi/efivar.c b/efi/efivar.c
new file mode 100644
index 000000000000..a51f3b2d1d8e
--- /dev/null
+++ b/efi/efivar.c
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * init.c - barebox EFI payload support
+ *
+ * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ */
+
+#define pr_fmt(fmt) "efi-var: " fmt
+
+#include <efi/efi-mode.h>
+#include <efi/variable.h>
+#include <efi.h>
+#include <efi/efi-util.h>
+#include <efi/variable.h>
+#include <wchar.h>
+#include <xfuncs.h>
+#include <linux/sprintf.h>
+
+void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size)
+{
+	struct efi_runtime_services *rt = efi_get_runtime_services();
+	efi_status_t efiret;
+	void *buf;
+	size_t size = 0;
+	s16 *name16;
+
+	if (!rt)
+		return ERR_PTR(-ENODEV);
+
+	name16 = xstrdup_char_to_wchar(name);
+
+	efiret = rt->get_variable(name16, vendor, NULL, &size, NULL);
+
+	if (EFI_ERROR(efiret) && efiret != EFI_BUFFER_TOO_SMALL) {
+		buf = ERR_PTR(-efi_errno(efiret));
+		goto out;
+	}
+
+	buf = malloc(size);
+	if (!buf) {
+		buf = ERR_PTR(-ENOMEM);
+		goto out;
+	}
+
+	efiret = rt->get_variable(name16, vendor, NULL, &size, buf);
+	if (EFI_ERROR(efiret)) {
+		free(buf);
+		buf = ERR_PTR(-efi_errno(efiret));
+		goto out;
+	}
+
+	if (var_size)
+		*var_size = size;
+
+out:
+	free(name16);
+
+	return buf;
+}
+
+int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
+		     void *buf, size_t size)
+{
+	struct efi_runtime_services *rt = efi_get_runtime_services();
+	efi_status_t efiret = EFI_SUCCESS;
+	s16 *name16;
+
+	if (!rt)
+		return -ENODEV;
+
+	name16 = xstrdup_char_to_wchar(name);
+
+	efiret = rt->set_variable(name16, vendor, attributes, size, buf);
+
+	free(name16);
+
+	return -efi_errno(efiret);
+}
+
+int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec)
+{
+	char buf[20];
+	wchar_t buf16[40];
+
+	snprintf(buf, sizeof(buf), "%lld", usec);
+	strcpy_char_to_wchar(buf16, buf);
+
+	return efi_set_variable(name, vendor,
+				EFI_VARIABLE_BOOTSERVICE_ACCESS |
+				EFI_VARIABLE_RUNTIME_ACCESS, buf16,
+				(strlen(buf)+1) * sizeof(wchar_t));
+}
+
+int efi_set_variable_printf(char *name, efi_guid_t *vendor, const char *fmt, ...)
+{
+	va_list args;
+	char *buf;
+	wchar_t *buf16;
+
+	va_start(args, fmt);
+	buf = xvasprintf(fmt, args);
+	va_end(args);
+	buf16 = xstrdup_char_to_wchar(buf);
+
+	return efi_set_variable(name, vendor,
+				EFI_VARIABLE_BOOTSERVICE_ACCESS |
+				EFI_VARIABLE_RUNTIME_ACCESS, buf16,
+				(strlen(buf)+1) * sizeof(wchar_t));
+	free(buf);
+	free(buf16);
+}
+
+int efi_set_variable_uint64_le(char *name, efi_guid_t *vendor, uint64_t value)
+{
+	uint8_t buf[8];
+
+	buf[0] = (uint8_t)(value >> 0U & 0xFF);
+	buf[1] = (uint8_t)(value >> 8U & 0xFF);
+	buf[2] = (uint8_t)(value >> 16U & 0xFF);
+	buf[3] = (uint8_t)(value >> 24U & 0xFF);
+	buf[4] = (uint8_t)(value >> 32U & 0xFF);
+	buf[5] = (uint8_t)(value >> 40U & 0xFF);
+	buf[6] = (uint8_t)(value >> 48U & 0xFF);
+	buf[7] = (uint8_t)(value >> 56U & 0xFF);
+
+	return efi_set_variable(name, vendor,
+				EFI_VARIABLE_BOOTSERVICE_ACCESS |
+				EFI_VARIABLE_RUNTIME_ACCESS, buf,
+				sizeof(buf));
+}
diff --git a/efi/payload/handover.c b/efi/payload/handover.c
index 68180d820e53..0bbac598542d 100644
--- a/efi/payload/handover.c
+++ b/efi/payload/handover.c
@@ -29,6 +29,7 @@
 #include <wchar.h>
 #include <efi/efi-payload.h>
 #include <efi/efi-device.h>
+#include <efi/variable.h>
 
 #include "image.h"
 
diff --git a/efi/payload/image.c b/efi/payload/image.c
index ed4307aab909..2dd545fc0d79 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -27,6 +27,7 @@
 #include <wchar.h>
 #include <efi/efi-payload.h>
 #include <efi/efi-device.h>
+#include <efi/variable.h>
 
 #include "image.h"
 
diff --git a/efi/payload/init.c b/efi/payload/init.c
index 5b827c57ed1f..7e407991b4a0 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -36,6 +36,7 @@
 #include <envfs.h>
 #include <efi/efi-payload.h>
 #include <efi/efi-device.h>
+#include <efi/variable.h>
 #include <libfile.h>
 #include <state.h>
 #include <bbu.h>
@@ -48,107 +49,6 @@ efi_handle_t efi_parent_image;
 struct efi_device_path *efi_device_path;
 struct efi_loaded_image *efi_loaded_image;
 
-void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size)
-{
-	efi_status_t efiret;
-	void *buf;
-	size_t size = 0;
-	s16 *name16 = xstrdup_char_to_wchar(name);
-
-	efiret = RT->get_variable(name16, vendor, NULL, &size, NULL);
-
-	if (EFI_ERROR(efiret) && efiret != EFI_BUFFER_TOO_SMALL) {
-		buf = ERR_PTR(-efi_errno(efiret));
-		goto out;
-	}
-
-	buf = malloc(size);
-	if (!buf) {
-		buf = ERR_PTR(-ENOMEM);
-		goto out;
-	}
-
-	efiret = RT->get_variable(name16, vendor, NULL, &size, buf);
-	if (EFI_ERROR(efiret)) {
-		free(buf);
-		buf = ERR_PTR(-efi_errno(efiret));
-		goto out;
-	}
-
-	if (var_size)
-		*var_size = size;
-
-out:
-	free(name16);
-
-	return buf;
-}
-
-int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
-		     void *buf, size_t size)
-{
-	efi_status_t efiret = EFI_SUCCESS;
-	s16 *name16 = xstrdup_char_to_wchar(name);
-
-	efiret = RT->set_variable(name16, vendor, attributes, size, buf);
-
-	free(name16);
-
-	return -efi_errno(efiret);
-}
-
-int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec)
-{
-	char buf[20];
-	wchar_t buf16[40];
-
-	snprintf(buf, sizeof(buf), "%lld", usec);
-	strcpy_char_to_wchar(buf16, buf);
-
-	return efi_set_variable(name, vendor,
-				EFI_VARIABLE_BOOTSERVICE_ACCESS |
-				EFI_VARIABLE_RUNTIME_ACCESS, buf16,
-				(strlen(buf)+1) * sizeof(wchar_t));
-}
-
-static int efi_set_variable_printf(char *name, efi_guid_t *vendor, const char *fmt, ...)
-{
-	va_list args;
-	char *buf;
-	wchar_t *buf16;
-
-	va_start(args, fmt);
-	buf = xvasprintf(fmt, args);
-	va_end(args);
-	buf16 = xstrdup_char_to_wchar(buf);
-
-	return efi_set_variable(name, vendor,
-				EFI_VARIABLE_BOOTSERVICE_ACCESS |
-				EFI_VARIABLE_RUNTIME_ACCESS, buf16,
-				(strlen(buf)+1) * sizeof(wchar_t));
-	free(buf);
-	free(buf16);
-}
-
-static int efi_set_variable_uint64_le(char *name, efi_guid_t *vendor, uint64_t value)
-{
-	uint8_t buf[8];
-
-	buf[0] = (uint8_t)(value >> 0U & 0xFF);
-	buf[1] = (uint8_t)(value >> 8U & 0xFF);
-	buf[2] = (uint8_t)(value >> 16U & 0xFF);
-	buf[3] = (uint8_t)(value >> 24U & 0xFF);
-	buf[4] = (uint8_t)(value >> 32U & 0xFF);
-	buf[5] = (uint8_t)(value >> 40U & 0xFF);
-	buf[6] = (uint8_t)(value >> 48U & 0xFF);
-	buf[7] = (uint8_t)(value >> 56U & 0xFF);
-
-	return efi_set_variable(name, vendor,
-				EFI_VARIABLE_BOOTSERVICE_ACCESS |
-				EFI_VARIABLE_RUNTIME_ACCESS, buf,
-				sizeof(buf));
-}
-
 struct efi_boot {
 	u32 attributes;
 	u16 file_path_len;
diff --git a/include/efi/efi-mode.h b/include/efi/efi-mode.h
index 696ab78acd50..f398d80d932f 100644
--- a/include/efi/efi-mode.h
+++ b/include/efi/efi-mode.h
@@ -5,6 +5,7 @@
 
 #include <linux/stddef.h>
 #include <linux/types.h>
+#include <efi/types.h>
 
 struct efi_boot_services;
 struct efi_runtime_services;
diff --git a/include/efi/efi-payload.h b/include/efi/efi-payload.h
index 337471117d5a..644620062aad 100644
--- a/include/efi/efi-payload.h
+++ b/include/efi/efi-payload.h
@@ -5,6 +5,7 @@
 #include <efi/types.h>
 #include <efi/efi-util.h>
 #include <efi/memtype.h>
+#include <efi/variable.h>
 
 struct efi_system_table;
 struct efi_loaded_image;
@@ -19,18 +20,6 @@ extern efi_handle_t efi_parent_image;
 extern struct efi_device_path *efi_device_path;
 extern struct efi_loaded_image *efi_loaded_image;
 
-void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size);
-
-static inline void *efi_get_global_var(char *name, int *var_size)
-{
-	extern efi_guid_t efi_global_variable_guid;
-	return efi_get_variable(name, &efi_global_variable_guid, var_size);
-}
-
-int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
-		     void *buf, size_t size);
-int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec);
-
 void *efi_earlymem_alloc(const struct efi_system_table *sys_table,
 			 size_t memsize, enum efi_memory_type mem_type);
 
diff --git a/include/efi/variable.h b/include/efi/variable.h
new file mode 100644
index 000000000000..c53b295eefe8
--- /dev/null
+++ b/include/efi/variable.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __EFI_VARIABLE_H
+#define __EFI_VARIABLE_H
+
+#include <efi/types.h>
+
+void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size);
+
+int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
+		     void *buf, size_t size);
+
+int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec);
+int efi_set_variable_printf(char *name, efi_guid_t *vendor, const char *fmt, ...);
+int efi_set_variable_uint64_le(char *name, efi_guid_t *vendor, uint64_t value);
+
+static inline void *efi_get_global_var(char *name, int *var_size)
+{
+	extern efi_guid_t efi_global_variable_guid;
+	return efi_get_variable(name, &efi_global_variable_guid, var_size);
+}
+
+#endif
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 05/16] fs: efivarfs: prepare for use with barebox as EFI loader
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (3 preceding siblings ...)
  2025-12-11 20:29 ` [PATCH 04/16] efi: payload: make EFI variable helpers usable for loader as well Ahmad Fatoum
@ 2025-12-11 20:29 ` Ahmad Fatoum
  2025-12-11 20:29 ` [PATCH 06/16] efi: handle: build for both EFI payload and loader Ahmad Fatoum
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:29 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The barebox efivarfs is currently only registered when barebox is an EFI
payload. It  hardcodes use of RT to access the runtime services and the
efivarfs is mounted on every startup.

Replace this with an automount and rework the file system slightly, so
the file system can be mounted later outside of payload once barebox
activates the upcoming EFI loader support.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/startup.c |  4 ++--
 efi/efivar.c     |  1 +
 fs/Kconfig       |  2 +-
 fs/efivarfs.c    | 38 ++++++++++++++++++++++++++++----------
 4 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/common/startup.c b/common/startup.c
index 602233345a25..c48adb42f953 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -62,9 +62,9 @@ static int mount_root(void)
 	mkdir("/mnt", 0);
 	devfs_init();
 
-	if (IS_ENABLED(CONFIG_FS_EFIVARFS) && efi_is_payload()) {
+	if (IS_ENABLED(CONFIG_FS_EFIVARFS)) {
 		mkdir("/efivars", 0);
-		mount("none", "efivarfs", "/efivars", NULL);
+		automount_add("/efivars", "mount -t efivarfs none /efivars");
 	}
 
 	if (IS_ENABLED(CONFIG_FS_PSTORE)) {
diff --git a/efi/efivar.c b/efi/efivar.c
index a51f3b2d1d8e..808693a7a746 100644
--- a/efi/efivar.c
+++ b/efi/efivar.c
@@ -14,6 +14,7 @@
 #include <efi/variable.h>
 #include <wchar.h>
 #include <xfuncs.h>
+#include <errno.h>
 #include <linux/sprintf.h>
 
 void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size)
diff --git a/fs/Kconfig b/fs/Kconfig
index e86420f9c259..c0c634bb419d 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -94,7 +94,7 @@ config FS_EFI
 	  by the EFI Firmware via the EFI Simple File System Protocol.
 
 config FS_EFIVARFS
-	depends on EFI_PAYLOAD
+	depends on EFI
 	select FS_LEGACY
 	select FS_WRITABLE
 	bool
diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index 7b80e703f2d9..3641dd92917d 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -25,6 +25,7 @@
 #include <xfuncs.h>
 #include <fcntl.h>
 #include <efi.h>
+#include <efi/efi-mode.h>
 #include <wchar.h>
 #include <linux/err.h>
 #include <linux/ctype.h>
@@ -45,12 +46,14 @@ struct efivarfs_dir {
 
 struct efivarfs_priv {
 	struct list_head inodes;
+	struct efi_runtime_services *rt;
 };
 
 static int efivars_create(struct device *dev, const char *pathname,
 			  mode_t mode)
 {
 	struct efivarfs_priv *priv = dev->priv;
+	struct efi_runtime_services *rt = priv->rt;
 	struct efivarfs_inode *inode;
 	efi_guid_t vendor;
 	efi_status_t efiret;
@@ -79,7 +82,7 @@ static int efivars_create(struct device *dev, const char *pathname,
 	inode->full_name = basprintf("%s-%pUl", name8, &inode->vendor);
 	free(name8);
 
-	efiret = RT->set_variable(inode->name, &inode->vendor,
+	efiret = rt->set_variable(inode->name, &inode->vendor,
 				  EFI_VARIABLE_NON_VOLATILE |
 				  EFI_VARIABLE_BOOTSERVICE_ACCESS |
 				  EFI_VARIABLE_RUNTIME_ACCESS,
@@ -97,6 +100,7 @@ static int efivars_create(struct device *dev, const char *pathname,
 static int efivars_unlink(struct device *dev, const char *pathname)
 {
 	struct efivarfs_priv *priv = dev->priv;
+	struct efi_runtime_services *rt = priv->rt;
 	struct efivarfs_inode *inode, *tmp;
 	efi_status_t efiret;
 
@@ -105,7 +109,7 @@ static int efivars_unlink(struct device *dev, const char *pathname)
 
 	list_for_each_entry_safe(inode, tmp, &priv->inodes, node) {
 		if (!strcmp(inode->full_name, pathname)) {
-			efiret = RT->set_variable(inode->name, &inode->vendor,
+			efiret = rt->set_variable(inode->name, &inode->vendor,
 						  0, 0, NULL);
 			if (EFI_ERROR(efiret))
 				return -efi_errno(efiret);
@@ -123,10 +127,13 @@ struct efivars_file {
 	efi_guid_t vendor;
 	s16 *name;
 	u32 attributes;
+	struct efivarfs_priv *priv;
 };
 
 static int efivarfs_open(struct device *dev, struct file *f, const char *filename)
 {
+	struct efivarfs_priv *priv = dev->priv;
+	struct efi_runtime_services *rt = priv->rt;
 	struct efivars_file *efile;
 	efi_status_t efiret;
 	int ret;
@@ -137,7 +144,7 @@ static int efivarfs_open(struct device *dev, struct file *f, const char *filenam
 	if (ret)
 		return -ENOENT;
 
-	efiret = RT->get_variable(efile->name, &efile->vendor,
+	efiret = rt->get_variable(efile->name, &efile->vendor,
 				  NULL, &efile->size, NULL);
 	if (EFI_ERROR(efiret) && efiret != EFI_BUFFER_TOO_SMALL) {
 		ret = -efi_errno(efiret);
@@ -150,7 +157,7 @@ static int efivarfs_open(struct device *dev, struct file *f, const char *filenam
 		goto out;
 	}
 
-	efiret = RT->get_variable(efile->name, &efile->vendor,
+	efiret = rt->get_variable(efile->name, &efile->vendor,
 				  &efile->attributes, &efile->size,
 				  efile->buf);
 	if (EFI_ERROR(efiret)) {
@@ -158,6 +165,8 @@ static int efivarfs_open(struct device *dev, struct file *f, const char *filenam
 		goto out;
 	}
 
+	efile->priv = priv;
+
 	f->f_size = efile->size;
 	f->private_data = efile;
 
@@ -192,6 +201,7 @@ static int efivarfs_read(struct file *f, void *buf, size_t insize)
 static int efivarfs_write(struct file *f, const void *buf, size_t insize)
 {
 	struct efivars_file *efile = f->private_data;
+	struct efi_runtime_services *rt = efile->priv->rt;
 	efi_status_t efiret;
 
 	if (efile->size < f->f_pos + insize) {
@@ -201,7 +211,7 @@ static int efivarfs_write(struct file *f, const void *buf, size_t insize)
 
 	memcpy(efile->buf + f->f_pos, buf, insize);
 
-	efiret = RT->set_variable(efile->name, &efile->vendor,
+	efiret = rt->set_variable(efile->name, &efile->vendor,
 				  efile->attributes,
 				  efile->size ? efile->size : 1, efile->buf);
 	if (EFI_ERROR(efiret))
@@ -213,12 +223,13 @@ static int efivarfs_write(struct file *f, const void *buf, size_t insize)
 static int efivarfs_truncate(struct file *f, loff_t size)
 {
 	struct efivars_file *efile = f->private_data;
+	struct efi_runtime_services *rt = efile->priv->rt;
 	efi_status_t efiret;
 
 	efile->size = size;
 	efile->buf = realloc(efile->buf, efile->size + sizeof(uint32_t));
 
-	efiret = RT->set_variable(efile->name, &efile->vendor,
+	efiret = rt->set_variable(efile->name, &efile->vendor,
 				  efile->attributes,
 				  efile->size ? efile->size : 1, efile->buf);
 	if (EFI_ERROR(efiret))
@@ -268,6 +279,8 @@ static int efivarfs_closedir(struct device *dev, DIR *dir)
 static int efivarfs_stat(struct device *dev, const char *filename,
 			 struct stat *s)
 {
+	struct efivarfs_priv *priv = dev->priv;
+	struct efi_runtime_services *rt = priv->rt;
 	efi_guid_t vendor;
 	s16 *name;
 	efi_status_t efiret;
@@ -278,7 +291,7 @@ static int efivarfs_stat(struct device *dev, const char *filename,
 	if (ret)
 		return -ENOENT;
 
-	efiret = RT->get_variable(name, &vendor, NULL, &size, NULL);
+	efiret = rt->get_variable(name, &vendor, NULL, &size, NULL);
 
 	free(name);
 
@@ -299,17 +312,23 @@ static int efivarfs_probe(struct device *dev)
 	char *name8;
 	size_t size;
 	struct efivarfs_priv *priv;
+	struct efi_runtime_services *rt;
+
+	rt = efi_get_runtime_services();
+	if (!rt)
+		return -ENODEV;
 
 	name[0] = 0;
 
 	priv = xzalloc(sizeof(*priv));
+	priv->rt = rt;
 	INIT_LIST_HEAD(&priv->inodes);
 
 	while (1) {
 		struct efivarfs_inode *inode;
 
 		size = sizeof(name);
-		efiret = RT->get_next_variable(&size, name, &vendor);
+		efiret = rt->get_next_variable(&size, name, &vendor);
 		if (EFI_ERROR(efiret))
 			break;
 
@@ -370,5 +389,4 @@ static int efivarfs_init(void)
 {
 	return register_fs_driver(&efivarfs_driver);
 }
-
-coredevice_efi_initcall(efivarfs_init);
+coredevice_initcall(efivarfs_init);
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 06/16] efi: handle: build for both EFI payload and loader
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (4 preceding siblings ...)
  2025-12-11 20:29 ` [PATCH 05/16] fs: efivarfs: prepare for use with barebox as EFI loader Ahmad Fatoum
@ 2025-12-11 20:29 ` Ahmad Fatoum
  2025-12-11 20:29 ` [PATCH 07/16] efi: provide populate $efi.payload_default_path depending on arch Ahmad Fatoum
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:29 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Since commit 387d6f9ed9a1 ("commands: provide efi_handle_dump in both
payload and loader"), drivers/efi/efi-handle.c is usable outside payload
as well, so move it into the efi/ directory.

While at it, drop the common.h header as it's only included header you
actually needed.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/efi/Makefile                     | 2 +-
 efi/Makefile                             | 2 +-
 drivers/efi/efi-handle.c => efi/handle.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
 rename drivers/efi/efi-handle.c => efi/handle.c (97%)

diff --git a/drivers/efi/Makefile b/drivers/efi/Makefile
index 4e3c39e14486..8f0b43e70e45 100644
--- a/drivers/efi/Makefile
+++ b/drivers/efi/Makefile
@@ -1,3 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0-only
-obj-y += efi-handle.o
+
 obj-$(CONFIG_EFI_PAYLOAD) += efi-device.o
diff --git a/efi/Makefile b/efi/Makefile
index 508c07c9b536..6693564f7071 100644
--- a/efi/Makefile
+++ b/efi/Makefile
@@ -3,4 +3,4 @@
 obj-$(CONFIG_EFI_PAYLOAD)	+= payload/
 obj-$(CONFIG_EFI_GUID)		+= guid.o
 obj-$(CONFIG_EFI_DEVICEPATH)	+= devicepath.o
-obj-y				+= errno.o efivar.o efivar-filename.o
+obj-y				+= errno.o handle.o efivar.o efivar-filename.o
diff --git a/drivers/efi/efi-handle.c b/efi/handle.c
similarity index 97%
rename from drivers/efi/efi-handle.c
rename to efi/handle.c
index 6485e97ded3f..d091d9e16514 100644
--- a/drivers/efi/efi-handle.c
+++ b/efi/handle.c
@@ -3,11 +3,11 @@
  * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
  */
 
-#include <common.h>
 #include <efi.h>
 #include <efi/efi-util.h>
 #include <efi/efi-device.h>
 #include <efi/efi-mode.h>
+#include <malloc.h>
 
 int __efi_locate_handle(struct efi_boot_services *bs,
 			enum efi_locate_search_type search_type,
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 07/16] efi: provide populate $efi.payload_default_path depending on arch
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (5 preceding siblings ...)
  2025-12-11 20:29 ` [PATCH 06/16] efi: handle: build for both EFI payload and loader Ahmad Fatoum
@ 2025-12-11 20:29 ` Ahmad Fatoum
  2025-12-11 20:29 ` [PATCH 08/16] efi: tidy up header includes for reuse Ahmad Fatoum
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:29 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

To make it easily available to scripts, let's export the path as device
parameter.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/efi/efi-device.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 1ddf01658ee9..e700e2b2e89b 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -432,6 +432,8 @@ static int efi_init_devices(void)
 	dev_add_param_bool_fixed(&efi_bus.dev, "secure_mode",
 				 secure_boot & setup_mode);
 	dev_add_param_bool_fixed(&efi_bus.dev, "payload", true);
+	dev_add_param_fixed(&efi_bus.dev, "payload_default_path",
+			    CONFIG_EFI_PAYLOAD_DEFAULT_PATH);
 
 	devinfo_add(&efi_bus.dev, efi_businfo);
 
@@ -444,6 +446,7 @@ static int efi_init_devices(void)
 core_efi_initcall(efi_init_devices);
 
 BAREBOX_MAGICVAR(efi.payload, "1 indicates that barebox was loaded as EFI payload");
+BAREBOX_MAGICVAR(efi.payload_default_path, "The arch-specific removable media path");
 
 void efi_pause_devices(void)
 {
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 08/16] efi: tidy up header includes for reuse
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (6 preceding siblings ...)
  2025-12-11 20:29 ` [PATCH 07/16] efi: provide populate $efi.payload_default_path depending on arch Ahmad Fatoum
@ 2025-12-11 20:29 ` Ahmad Fatoum
  2025-12-11 20:30 ` [PATCH 09/16] efi: types: add efi_intn_t/efi_uintn_t definition Ahmad Fatoum
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:29 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We have a lot of EFI definitions, both inside efi.h and outside,
including some things that are only payload-specific.

Let's tidy that up and clearly split generic functionality and
definitions from the payload-specific pats.

While at it, we also remove the redundant efi- prefix in headers and
retire the efi.h header to avoid non-portable parts making it into
there.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/cpu/cpu.c                            |   2 +-
 arch/arm/cpu/interrupts_64.c                  |   2 +-
 arch/arm/cpu/mmu-common.c                     |   2 +-
 arch/arm/include/asm/pci.h                    |   2 +-
 arch/arm/lib64/armlinux.c                     |   2 +-
 arch/x86/mach-efi/clocksource.c               |   2 +-
 arch/x86/mach-efi/reloc_ia32.c                |   2 +-
 arch/x86/mach-efi/reloc_x86_64.c              |   2 +-
 commands/bfetch.c                             |   4 +-
 commands/efi_handle_dump.c                    |   8 +-
 common/startup.c                              |   2 +-
 drivers/block/efi-block-io.c                  |   7 +-
 drivers/bus/acpi.c                            |   5 +-
 drivers/clocksource/efi.c                     |   5 +-
 drivers/clocksource/efi_x86.c                 |   3 +-
 drivers/efi/efi-device.c                      |   8 +-
 drivers/hw_random/efi-rng.c                   |   6 +-
 drivers/i2c/busses/i2c-efi.c                  |  54 +-
 drivers/net/efi-snp.c                         | 109 +--
 drivers/pci/pci-efi.c                         |   9 +-
 drivers/serial/efi-stdio.c                    |   8 +-
 drivers/serial/serial_efi.c                   |  78 +-
 drivers/serial/serial_semihosting.c           |   2 +-
 drivers/video/efi_gop.c                       |  54 +-
 drivers/watchdog/efi_wdt.c                    |   4 +-
 drivers/watchdog/itco_wdt.c                   |   1 -
 efi/devicepath.c                              |   8 +-
 efi/efivar-filename.c                         |   3 +-
 efi/efivar.c                                  |   7 +-
 efi/errno.c                                   |   3 +-
 efi/guid.c                                    |   3 +-
 efi/handle.c                                  |   6 +-
 efi/payload/boarddata.c                       |   5 +-
 efi/payload/bootm.c                           |   7 +-
 efi/payload/early-mem.c                       |   4 +-
 efi/payload/efi-initrd.c                      |  12 +-
 efi/payload/entry-multi.c                     |   5 +-
 efi/payload/entry-single.c                    |   6 +-
 efi/payload/fdt.c                             |   6 +-
 efi/payload/handover.c                        |   6 +-
 efi/payload/image.c                           |   6 +-
 efi/payload/init.c                            |   7 +-
 efi/payload/iomem.c                           |   6 +-
 fs/efi.c                                      |   7 +-
 fs/efivarfs.c                                 |   9 +-
 fs/ubootvarfs.c                               |   1 -
 include/acpi.h                                |   2 +-
 include/efi.h                                 | 886 ------------------
 include/efi/attributes.h                      |  21 +
 include/efi/debug_ll.h                        |   9 +-
 include/efi/{device-path.h => devicepath.h}   |   9 +
 include/efi/efi-util.h                        |  20 -
 include/efi/error.h                           |  58 ++
 include/efi/guid.h                            | 303 ++++++
 include/efi/initrd.h                          |  11 +
 include/efi/{memtype.h => memory.h}           |  19 +-
 include/efi/{efi-mode.h => mode.h}            |   0
 include/efi/{efi-payload.h => payload.h}      |  18 +-
 .../efi/{efi-device.h => payload/driver.h}    |  19 +-
 include/efi/{efi-init.h => payload/init.h}    |   4 +-
 include/efi/protocol/block.h                  |  35 +
 include/efi/protocol/file.h                   | 111 +++
 include/efi/protocol/gop.h                    |  54 ++
 include/efi/protocol/i2c.h                    |  55 ++
 .../pci-efi.h => include/efi/protocol/pci.h   |  10 +-
 include/efi/protocol/rng.h                    |  17 +
 include/efi/protocol/serial.h                 |  79 ++
 include/efi/protocol/snp.h                    | 110 +++
 include/efi/{efi-stdio.h => protocol/text.h}  |  44 +-
 include/efi/services.h                        | 271 ++++++
 include/efi/types.h                           |  49 +-
 include/efi/variable.h                        |  28 +
 lib/vsprintf.c                                |   2 +-
 test/self/mmu.c                               |   2 +-
 74 files changed, 1419 insertions(+), 1327 deletions(-)
 delete mode 100644 include/efi.h
 create mode 100644 include/efi/attributes.h
 rename include/efi/{device-path.h => devicepath.h} (95%)
 delete mode 100644 include/efi/efi-util.h
 create mode 100644 include/efi/error.h
 create mode 100644 include/efi/guid.h
 create mode 100644 include/efi/initrd.h
 rename include/efi/{memtype.h => memory.h} (90%)
 rename include/efi/{efi-mode.h => mode.h} (100%)
 rename include/efi/{efi-payload.h => payload.h} (56%)
 rename include/efi/{efi-device.h => payload/driver.h} (78%)
 rename include/efi/{efi-init.h => payload/init.h} (96%)
 create mode 100644 include/efi/protocol/block.h
 create mode 100644 include/efi/protocol/file.h
 create mode 100644 include/efi/protocol/gop.h
 create mode 100644 include/efi/protocol/i2c.h
 rename drivers/pci/pci-efi.h => include/efi/protocol/pci.h (98%)
 create mode 100644 include/efi/protocol/rng.h
 create mode 100644 include/efi/protocol/serial.h
 create mode 100644 include/efi/protocol/snp.h
 rename include/efi/{efi-stdio.h => protocol/text.h} (67%)
 create mode 100644 include/efi/services.h

diff --git a/arch/arm/cpu/cpu.c b/arch/arm/cpu/cpu.c
index ab41da5cab50..0293181811b6 100644
--- a/arch/arm/cpu/cpu.c
+++ b/arch/arm/cpu/cpu.c
@@ -17,7 +17,7 @@
 #include <asm/cputype.h>
 #include <asm/cache.h>
 #include <asm/ptrace.h>
-#include <efi/efi-mode.h>
+#include <efi/mode.h>
 
 /**
  * Enable processor's instruction cache
diff --git a/arch/arm/cpu/interrupts_64.c b/arch/arm/cpu/interrupts_64.c
index 24eb1516ed6e..0b69359d67b1 100644
--- a/arch/arm/cpu/interrupts_64.c
+++ b/arch/arm/cpu/interrupts_64.c
@@ -11,7 +11,7 @@
 #include <init.h>
 #include <asm/system.h>
 #include <asm/esr.h>
-#include <efi/efi-mode.h>
+#include <efi/mode.h>
 
 /* Avoid missing prototype warning, called from assembly */
 void do_bad_sync (struct pt_regs *pt_regs);
diff --git a/arch/arm/cpu/mmu-common.c b/arch/arm/cpu/mmu-common.c
index d193956ad359..a1431c0ff461 100644
--- a/arch/arm/cpu/mmu-common.c
+++ b/arch/arm/cpu/mmu-common.c
@@ -14,7 +14,7 @@
 #include <zero_page.h>
 #include <range.h>
 #include "mmu-common.h"
-#include <efi/efi-mode.h>
+#include <efi/mode.h>
 
 const char *map_type_tostr(maptype_t map_type)
 {
diff --git a/arch/arm/include/asm/pci.h b/arch/arm/include/asm/pci.h
index 7c834f110111..d236e300b9f3 100644
--- a/arch/arm/include/asm/pci.h
+++ b/arch/arm/include/asm/pci.h
@@ -2,7 +2,7 @@
 #ifndef __ASM_PCI_H
 #define __ASM_PCI_H
 
-#include <efi/efi-mode.h>
+#include <efi/mode.h>
 
 #define pcibios_assign_all_busses()	(!efi_is_payload())
 
diff --git a/arch/arm/lib64/armlinux.c b/arch/arm/lib64/armlinux.c
index 74922cecd9ba..7803d5671719 100644
--- a/arch/arm/lib64/armlinux.c
+++ b/arch/arm/lib64/armlinux.c
@@ -6,7 +6,7 @@
 #include <init.h>
 #include <bootm.h>
 #include <asm/boot.h>
-#include <efi/efi-mode.h>
+#include <efi/mode.h>
 
 static int do_bootm_linux(struct image_data *data)
 {
diff --git a/arch/x86/mach-efi/clocksource.c b/arch/x86/mach-efi/clocksource.c
index daf3b3965851..2646bbe4a76e 100644
--- a/arch/x86/mach-efi/clocksource.c
+++ b/arch/x86/mach-efi/clocksource.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <common.h>
-#include <efi/efi-init.h>
+#include <efi/payload/init.h>
 #include <driver.h>
 
 static int efi_x86_pure_init(void)
diff --git a/arch/x86/mach-efi/reloc_ia32.c b/arch/x86/mach-efi/reloc_ia32.c
index c235421ce180..c9c1b380e46f 100644
--- a/arch/x86/mach-efi/reloc_ia32.c
+++ b/arch/x86/mach-efi/reloc_ia32.c
@@ -34,7 +34,7 @@
 */
 
 #include <common.h>
-#include <efi.h>
+#include <efi/error.h>
 
 #include <elf.h>
 
diff --git a/arch/x86/mach-efi/reloc_x86_64.c b/arch/x86/mach-efi/reloc_x86_64.c
index f015ae047dbf..a0c7012562c8 100644
--- a/arch/x86/mach-efi/reloc_x86_64.c
+++ b/arch/x86/mach-efi/reloc_x86_64.c
@@ -37,7 +37,7 @@
 
 #include <linux/linkage.h>
 #include <common.h>
-#include <efi.h>
+#include <efi/error.h>
 
 #include <elf.h>
 
diff --git a/commands/bfetch.c b/commands/bfetch.c
index 4de4692a6278..d9c615f65aca 100644
--- a/commands/bfetch.c
+++ b/commands/bfetch.c
@@ -25,8 +25,8 @@
 #include <unistd.h>
 #include <watchdog.h>
 
-#include <efi/efi-mode.h>
-#include <efi/efi-device.h>
+#include <efi/mode.h>
+#include <efi/payload/driver.h>
 
 #include <generated/utsrelease.h>
 #include <linux/clk.h>
diff --git a/commands/efi_handle_dump.c b/commands/efi_handle_dump.c
index 30abf9000387..c82f3e32469a 100644
--- a/commands/efi_handle_dump.c
+++ b/commands/efi_handle_dump.c
@@ -7,10 +7,12 @@
 
 #include <common.h>
 #include <command.h>
-#include <efi.h>
 #include <linux/uuid.h>
-#include <efi/efi-mode.h>
-#include <efi/efi-device.h>
+#include <efi/mode.h>
+#include <efi/payload.h>
+#include <efi/error.h>
+#include <efi/devicepath.h>
+#include <efi/payload/driver.h>
 
 static void efi_devpath(struct efi_boot_services *bs,
 			efi_handle_t handle,
diff --git a/common/startup.c b/common/startup.c
index c48adb42f953..53003b88bc1b 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -40,7 +40,7 @@
 #include <watchdog.h>
 #include <glob.h>
 #include <net.h>
-#include <efi/efi-mode.h>
+#include <efi/mode.h>
 #include <bselftest.h>
 #include <pbl/handoff-data.h>
 #include <libfile.h>
diff --git a/drivers/block/efi-block-io.c b/drivers/block/efi-block-io.c
index 1c2d801a42ef..8955a8c2b585 100644
--- a/drivers/block/efi-block-io.c
+++ b/drivers/block/efi-block-io.c
@@ -10,10 +10,11 @@
 #include <linux/stat.h>
 #include <xfuncs.h>
 #include <fcntl.h>
-#include <efi.h>
 #include <block.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
+#include <efi/payload.h>
+#include <efi/payload/driver.h>
+#include <efi/error.h>
+#include <efi/protocol/block.h>
 #include <bootsource.h>
 
 #define EFI_BLOCK_IO_PROTOCOL_REVISION2 0x00020001
diff --git a/drivers/bus/acpi.c b/drivers/bus/acpi.c
index f586b605d0d4..880bc6594d30 100644
--- a/drivers/bus/acpi.c
+++ b/drivers/bus/acpi.c
@@ -6,9 +6,8 @@
 #include <common.h>
 #include <driver.h>
 #include <init.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
+#include <efi/payload.h>
+#include <efi/payload/driver.h>
 #include <acpi.h>
 
 static struct sig_desc {
diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
index 2f8bfdec489a..534bea5525c4 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi.c
@@ -6,9 +6,8 @@
 #include <init.h>
 #include <driver.h>
 #include <clock.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
+#include <efi/payload.h>
+#include <efi/error.h>
 #include <linux/err.h>
 
 static uint64_t ticks = 1;
diff --git a/drivers/clocksource/efi_x86.c b/drivers/clocksource/efi_x86.c
index f5a822eef740..23ca3d1637c4 100644
--- a/drivers/clocksource/efi_x86.c
+++ b/drivers/clocksource/efi_x86.c
@@ -2,8 +2,7 @@
 #include <common.h>
 #include <init.h>
 #include <driver.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
+#include <efi/payload.h>
 #include <clock.h>
 
 #ifdef __x86_64__
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index e700e2b2e89b..f323455c90bd 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -15,11 +15,11 @@
 #include <wchar.h>
 #include <magicvar.h>
 #include <init.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
+#include <efi/payload.h>
+#include <efi/error.h>
+#include <efi/payload/driver.h>
+#include <efi/devicepath.h>
 #include <efi/variable.h>
-#include <efi/device-path.h>
 #include <linux/err.h>
 
 static int efi_locate_handle(enum efi_locate_search_type search_type,
diff --git a/drivers/hw_random/efi-rng.c b/drivers/hw_random/efi-rng.c
index 61cb01caf647..9256753ad806 100644
--- a/drivers/hw_random/efi-rng.c
+++ b/drivers/hw_random/efi-rng.c
@@ -3,8 +3,10 @@
 #include <driver.h>
 #include <init.h>
 #include <linux/hw_random.h>
-#include <efi.h>
-#include <efi/efi-device.h>
+#include <efi/error.h>
+#include <efi/payload/driver.h>
+#include <efi/protocol/rng.h>
+#include <efi/payload.h>
 
 struct efi_rng_priv {
 	struct efi_rng_protocol *protocol;
diff --git a/drivers/i2c/busses/i2c-efi.c b/drivers/i2c/busses/i2c-efi.c
index 4c58279e0398..dff10703fd9a 100644
--- a/drivers/i2c/busses/i2c-efi.c
+++ b/drivers/i2c/busses/i2c-efi.c
@@ -9,58 +9,12 @@
 #include <common.h>
 #include <i2c/i2c.h>
 #include <driver.h>
-#include <efi.h>
-#include <efi/efi-device.h>
-#include <efi/efi-util.h>
+#include <efi/protocol/i2c.h>
+#include <efi/payload/init.h>
+#include <efi/payload/driver.h>
+#include <efi/error.h>
 #include <linux/kernel.h>
 
-/* Define EFI I2C transfer control flags */
-#define EFI_I2C_FLAG_READ           0x00000001
-
-#define EFI_I2C_ADDRESSING_10_BIT   0x80000000
-
-/* The set_bus_frequency() EFI call doesn't work (doesn't alter SPI clock
- * frequency) if it's parameter is defined on the stack (observed with
- * American Megatrends EFI Revision 5.19) - let's define it globaly.
- */
-static unsigned int bus_clock;
-
-struct efi_i2c_capabilities {
-	u32 StructureSizeInBytes;
-	u32 MaximumReceiveBytes;
-	u32 MaximumTransmitBytes;
-	u32 MaximumTotalBytes;
-};
-
-struct efi_i2c_operation {
-	u32 Flags;
-	u32 LengthInBytes;
-	u8  *Buffer;
-};
-
-struct efi_i2c_request_packet {
-	unsigned int OperationCount;
-	struct efi_i2c_operation Operation[];
-};
-
-struct efi_i2c_master_protocol {
-	efi_status_t(EFIAPI * set_bus_frequency)(
-		struct efi_i2c_master_protocol *this,
-		unsigned int *bus_clock
-	);
-	efi_status_t(EFIAPI * reset)(
-		struct efi_i2c_master_protocol *this
-	);
-	efi_status_t(EFIAPI * start_request)(
-		struct efi_i2c_master_protocol *this,
-		unsigned int slave_address,
-		struct efi_i2c_request_packet *request_packet,
-		void *event,
-		efi_status_t *status
-	);
-	struct efi_i2c_capabilities *capabilities;
-};
-
 struct efi_i2c_priv {
 	struct efi_i2c_master_protocol *efi_protocol;
 	struct i2c_adapter adapter;
diff --git a/drivers/net/efi-snp.c b/drivers/net/efi-snp.c
index b4d2abfecf77..5dffe3793426 100644
--- a/drivers/net/efi-snp.c
+++ b/drivers/net/efi-snp.c
@@ -10,111 +10,10 @@
 #include <malloc.h>
 #include <net.h>
 #include <init.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
-
-struct efi_network_statistics {
-	uint64_t RxTotalFrames;
-	uint64_t RxGoodFrames;
-	uint64_t RxUndersizeFrames;
-	uint64_t RxOversizeFrames;
-	uint64_t RxDroppedFrames;
-	uint64_t RxUnicastFrames;
-	uint64_t RxBroadcastFrames;
-	uint64_t RxMulticastFrames;
-	uint64_t RxCrcErrorFrames;
-	uint64_t RxTotalBytes;
-	uint64_t TxTotalFrames;
-	uint64_t TxGoodFrames;
-	uint64_t TxUndersizeFrames;
-	uint64_t TxOversizeFrames;
-	uint64_t TxDroppedFrames;
-	uint64_t TxUnicastFrames;
-	uint64_t TxBroadcastFrames;
-	uint64_t TxMulticastFrames;
-	uint64_t TxCrcErrorFrames;
-	uint64_t TxTotalBytes;
-	uint64_t Collisions;
-	uint64_t UnsupportedProtocol;
-};
-
-enum efi_simple_network_state {
-	EfiSimpleNetworkStopped,
-	EfiSimpleNetworkStarted,
-	EfiSimpleNetworkInitialized,
-	EfiSimpleNetworkMaxState
-};
-
-#define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST               0x01
-#define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST             0x02
-#define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST             0x04
-#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS           0x08
-#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10
-
-#define EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT        0x01
-#define EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT       0x02
-#define EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT        0x04
-#define EFI_SIMPLE_NETWORK_SOFTWARE_INTERRUPT       0x08
-
-#define MAX_MCAST_FILTER_CNT    16
-struct efi_simple_network_mode {
-	uint32_t State;
-	uint32_t HwAddressSize;
-	uint32_t MediaHeaderSize;
-	uint32_t MaxPacketSize;
-	uint32_t NvRamSize;
-	uint32_t NvRamAccessSize;
-	uint32_t ReceiveFilterMask;
-	uint32_t ReceiveFilterSetting;
-	uint32_t MaxMCastFilterCount;
-	uint32_t MCastFilterCount;
-	struct efi_mac_address MCastFilter[MAX_MCAST_FILTER_CNT];
-	struct efi_mac_address CurrentAddress;
-	struct efi_mac_address BroadcastAddress;
-	struct efi_mac_address PermanentAddress;
-	uint8_t IfType;
-        bool MacAddressChangeable;
-	bool MultipleTxSupported;
-	bool MediaPresentSupported;
-	bool MediaPresent;
-};
-
-#define EFI_SIMPLE_NETWORK_INTERFACE_REVISION   0x00010000
-
-struct efi_simple_network {
-	uint64_t Revision;
-	efi_status_t (EFIAPI *start) (struct efi_simple_network *This);
-	efi_status_t (EFIAPI *stop) (struct efi_simple_network *This);
-	efi_status_t (EFIAPI *initialize) (struct efi_simple_network *This,
-			unsigned long ExtraRxBufferSize, unsigned long ExtraTxBufferSize);
-	efi_status_t (EFIAPI *reset) (struct efi_simple_network *This, bool ExtendedVerification);
-	efi_status_t (EFIAPI *shutdown) (struct efi_simple_network *This);
-	efi_status_t (EFIAPI *receive_filters) (struct efi_simple_network *This,
-			uint32_t Enable, uint32_t Disable, bool ResetMCastFilter,
-			unsigned long MCastFilterCnt, struct efi_mac_address *MCastFilter);
-	efi_status_t (EFIAPI *station_address) (struct efi_simple_network *This,
-			bool Reset, struct efi_mac_address *New);
-	efi_status_t (EFIAPI *statistics) (struct efi_simple_network *This,
-			bool Reset, unsigned long *StatisticsSize,
-			struct efi_network_statistics *StatisticsTable);
-	efi_status_t (EFIAPI *mcast_ip_to_mac) (struct efi_simple_network *This,
-			bool IPv6, union efi_ip_address *IP, struct efi_mac_address *MAC);
-	efi_status_t (EFIAPI *nvdata) (struct efi_simple_network *This,
-			bool ReadWrite, unsigned long Offset, unsigned long BufferSize,
-			void *Buffer);
-	efi_status_t (EFIAPI *get_status) (struct efi_simple_network *This,
-			uint32_t *InterruptStatus, void **TxBuf);
-	efi_status_t (EFIAPI *transmit) (struct efi_simple_network *This,
-			unsigned long HeaderSize, unsigned long BufferSize, void *Buffer,
-			struct efi_mac_address *SrcAddr, struct efi_mac_address *DestAddr,
-			uint16_t *Protocol);
-	efi_status_t (EFIAPI *receive) (struct efi_simple_network *This,
-			unsigned long *HeaderSize, unsigned long *BufferSize, void *Buffer,
-			struct efi_mac_address *SrcAddr, struct efi_mac_address *DestAddr, uint16_t *Protocol);
-	void *WaitForPacket;
-	struct efi_simple_network_mode *Mode;
-};
+#include <efi/error.h>
+#include <efi/payload.h>
+#include <efi/payload/driver.h>
+#include <efi/protocol/snp.h>
 
 struct efi_snp_priv {
 	struct device *dev;
diff --git a/drivers/pci/pci-efi.c b/drivers/pci/pci-efi.c
index 339a7ef673cd..7d4869db08df 100644
--- a/drivers/pci/pci-efi.c
+++ b/drivers/pci/pci-efi.c
@@ -8,13 +8,12 @@
 #include <driver.h>
 #include <init.h>
 #include <xfuncs.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
+#include <efi/payload.h>
+#include <efi/payload/driver.h>
+#include <efi/protocol/pci.h>
+#include <efi/error.h>
 #include <linux/pci.h>
 
-#include "pci-efi.h"
-
 struct efi_pci_priv {
 	struct efi_pci_root_bridge_io_protocol *protocol;
 	struct device *dev;
diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c
index 92133f837838..3390600be389 100644
--- a/drivers/serial/efi-stdio.c
+++ b/drivers/serial/efi-stdio.c
@@ -10,13 +10,13 @@
 #include <malloc.h>
 #include <console.h>
 #include <xfuncs.h>
-#include <efi.h>
 #include <readkey.h>
 #include <linux/ctype.h>
-#include <efi/efi-payload.h>
+#include <efi/payload.h>
 #include <kfifo.h>
-#include <efi/efi-device.h>
-#include <efi/efi-stdio.h>
+#include <efi/payload/driver.h>
+#include <efi/protocol/text.h>
+#include <efi/error.h>
 
 struct efi_console_priv {
 	struct efi_simple_text_output_protocol *out;
diff --git a/drivers/serial/serial_efi.c b/drivers/serial/serial_efi.c
index a0abbaf649d3..070abb142850 100644
--- a/drivers/serial/serial_efi.c
+++ b/drivers/serial/serial_efi.c
@@ -7,80 +7,10 @@
 #include <driver.h>
 #include <init.h>
 #include <malloc.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
-
-/*
- * define for Control bits, grouped by read only, write only, and read write
- *
- * Read Only
- */
-#define EFI_SERIAL_CLEAR_TO_SEND        0x00000010
-#define EFI_SERIAL_DATA_SET_READY       0x00000020
-#define EFI_SERIAL_RING_INDICATE        0x00000040
-#define EFI_SERIAL_CARRIER_DETECT       0x00000080
-#define EFI_SERIAL_INPUT_BUFFER_EMPTY   0x00000100
-#define EFI_SERIAL_OUTPUT_BUFFER_EMPTY  0x00000200
-
-/*
- * Write Only
- */
-#define EFI_SERIAL_REQUEST_TO_SEND      0x00000002
-#define EFI_SERIAL_DATA_TERMINAL_READY  0x00000001
-
-/*
- * Read Write
- */
-#define EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE     0x00001000
-#define EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE     0x00002000
-#define EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE 0x00004000
-
-typedef enum {
-	DefaultParity,
-	NoParity,
-	EvenParity,
-	OddParity,
-	MarkParity,
-	SpaceParity
-} efi_parity_type;
-
-typedef enum {
-	DefaultStopBits,
-	OneStopBit,
-	OneFiveStopBits,
-	TwoStopBits
-} efi_stop_bits_type;
-
-struct efi_serial_io_mode {
-	uint32_t controlmask;
-	uint32_t timeout;
-	uint64_t baudrate;
-	uint32_t receivefifodepth;
-	uint32_t databits;
-	uint32_t parity;
-	uint32_t stopbits;
-};
-
-struct efi_serial_io_protocol {
-	uint32_t revision;
-
-	efi_status_t (EFIAPI *reset) (struct efi_serial_io_protocol *This);
-	efi_status_t (EFIAPI *set_attributes) (struct efi_serial_io_protocol *This,
-			uint64_t baudrate, uint32_t receivefifodepth,
-			uint32_t timeout, efi_parity_type parity,
-			uint8_t databits, efi_stop_bits_type stopbits);
-	efi_status_t (EFIAPI *setcontrol) (struct efi_serial_io_protocol *This,
-			uint32_t control);
-	efi_status_t (EFIAPI *getcontrol) (struct efi_serial_io_protocol *This,
-			uint32_t *control);
-	efi_status_t (EFIAPI *write) (struct efi_serial_io_protocol *This,
-			size_t *buffersize, void *buffer);
-	efi_status_t (EFIAPI *read) (struct efi_serial_io_protocol *This,
-			size_t *buffersize, void *buffer);
-
-	struct efi_serial_io_mode *mode;
-};
+#include <efi/payload.h>
+#include <efi/error.h>
+#include <efi/payload/driver.h>
+#include <efi/protocol/serial.h>
 
 /*
  * We wrap our port structure around the generic console_device.
diff --git a/drivers/serial/serial_semihosting.c b/drivers/serial/serial_semihosting.c
index d495b07f11ca..02d2ade367d6 100644
--- a/drivers/serial/serial_semihosting.c
+++ b/drivers/serial/serial_semihosting.c
@@ -2,7 +2,7 @@
 
 #include <console.h>
 #include <asm/semihosting.h>
-#include <efi/efi-mode.h>
+#include <efi/mode.h>
 
 static void smh_serial_putc(struct console_device *cdev, char ch)
 {
diff --git a/drivers/video/efi_gop.c b/drivers/video/efi_gop.c
index cef8a6816cac..00ebd2fcbd55 100644
--- a/drivers/video/efi_gop.c
+++ b/drivers/video/efi_gop.c
@@ -11,56 +11,10 @@
 #include <fb.h>
 #include <errno.h>
 #include <gui/graphic_utils.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
-
-#define PIXEL_RGB_RESERVED_8BIT_PER_COLOR		0
-#define PIXEL_BGR_RESERVED_8BIT_PER_COLOR		1
-#define PIXEL_BIT_MASK					2
-#define PIXEL_BLT_ONLY					3
-#define PIXEL_FORMAT_MAX				4
-
-struct efi_pixel_bitmask {
-	u32 red_mask;
-	u32 green_mask;
-	u32 blue_mask;
-	u32 reserved_mask;
-};
-
-struct efi_graphics_output_mode_info {
-	u32 version;
-	u32 horizontal_resolution;
-	u32 vertical_resolution;
-	int pixel_format;
-	struct efi_pixel_bitmask pixel_information;
-	u32 pixels_per_scan_line;
-};
-
-struct efi_graphics_output_protocol_mode {
-	uint32_t max_mode;
-	uint32_t mode;
-	struct efi_graphics_output_mode_info *info;
-	size_t size_of_info;
-	void *frame_buffer_base;
-	size_t frame_buffer_size;
-};
-
-struct efi_graphics_output_protocol {
-	efi_status_t (EFIAPI *query_mode) (struct efi_graphics_output_protocol *This,
-			uint32_t mode_number, size_t *size_of_info,
-			struct efi_graphics_output_mode_info **info);
-	efi_status_t (EFIAPI *set_mode) (struct efi_graphics_output_protocol *This,
-			uint32_t mode_number);
-	efi_status_t (EFIAPI *blt)(struct efi_graphics_output_protocol *This,
-			void *buffer,
-			unsigned long operation,
-			unsigned long sourcex, unsigned long sourcey,
-			unsigned long destinationx, unsigned long destinationy,
-			unsigned long width, unsigned long height, unsigned
-			long delta);
-	struct efi_graphics_output_protocol_mode *mode;
-};
+#include <efi/payload.h>
+#include <efi/payload/driver.h>
+#include <efi/protocol/gop.h>
+#include <efi/error.h>
 
 struct efi_gop_priv {
 	struct device *dev;
diff --git a/drivers/watchdog/efi_wdt.c b/drivers/watchdog/efi_wdt.c
index 072240fcaf86..32b165fd0e66 100644
--- a/drivers/watchdog/efi_wdt.c
+++ b/drivers/watchdog/efi_wdt.c
@@ -6,8 +6,8 @@
 #include <common.h>
 #include <init.h>
 #include <driver.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
+#include <efi/payload.h>
+#include <efi/error.h>
 #include <watchdog.h>
 
 struct efi_wdt_priv {
diff --git a/drivers/watchdog/itco_wdt.c b/drivers/watchdog/itco_wdt.c
index ca012c92dc37..e55206b3498a 100644
--- a/drivers/watchdog/itco_wdt.c
+++ b/drivers/watchdog/itco_wdt.c
@@ -13,7 +13,6 @@
 
 #include <common.h>
 #include <init.h>
-#include <efi.h>
 #include <linux/pci.h>
 #include <watchdog.h>
 
diff --git a/efi/devicepath.c b/efi/devicepath.c
index 1c4a0d692c1e..1d49f450ec8e 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -2,13 +2,15 @@
 
 #include <common.h>
 #include <linux/compiler.h>
-#include <efi.h>
-#include <efi/efi-util.h>
 #include <malloc.h>
 #include <string.h>
 #include <wchar.h>
 #include <linux/overflow.h>
-#include <efi/device-path.h>
+#include <efi/devicepath.h>
+#include <efi/guid.h>
+#include <efi/mode.h>
+#include <efi/error.h>
+#include <efi/services.h>
 
 struct string {
 	char *str;
diff --git a/efi/efivar-filename.c b/efi/efivar-filename.c
index 51d0130fa774..984e40bc1c85 100644
--- a/efi/efivar-filename.c
+++ b/efi/efivar-filename.c
@@ -2,7 +2,8 @@
 
 #include <linux/ctype.h>
 #include <string.h>
-#include <efi/efi-util.h>
+#include <efi/guid.h>
+#include <efi/variable.h>
 
 static int char_to_nibble(char c)
 {
diff --git a/efi/efivar.c b/efi/efivar.c
index 808693a7a746..4fb28419d537 100644
--- a/efi/efivar.c
+++ b/efi/efivar.c
@@ -7,11 +7,10 @@
 
 #define pr_fmt(fmt) "efi-var: " fmt
 
-#include <efi/efi-mode.h>
-#include <efi/variable.h>
-#include <efi.h>
-#include <efi/efi-util.h>
+#include <efi/mode.h>
 #include <efi/variable.h>
+#include <efi/services.h>
+#include <efi/error.h>
 #include <wchar.h>
 #include <xfuncs.h>
 #include <errno.h>
diff --git a/efi/errno.c b/efi/errno.c
index ed14b1a8a6b0..79437be34712 100644
--- a/efi/errno.c
+++ b/efi/errno.c
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
-#include <efi/efi-util.h>
-#include <efi.h>
+#include <efi/error.h>
 #include <errno.h>
 
 const char *efi_strerror(efi_status_t err)
diff --git a/efi/guid.c b/efi/guid.c
index 46440c9f3328..6b8e50741ec1 100644
--- a/efi/guid.c
+++ b/efi/guid.c
@@ -1,8 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <common.h>
-#include <efi.h>
-#include <efi/efi-util.h>
+#include <efi/guid.h>
 
 efi_guid_t efi_file_info_id = EFI_FILE_INFO_GUID;
 efi_guid_t efi_simple_file_system_protocol_guid = EFI_SIMPLE_FILE_SYSTEM_GUID;
diff --git a/efi/handle.c b/efi/handle.c
index d091d9e16514..a330927d7be2 100644
--- a/efi/handle.c
+++ b/efi/handle.c
@@ -3,10 +3,8 @@
  * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
  */
 
-#include <efi.h>
-#include <efi/efi-util.h>
-#include <efi/efi-device.h>
-#include <efi/efi-mode.h>
+#include <efi/payload.h>
+#include <efi/error.h>
 #include <malloc.h>
 
 int __efi_locate_handle(struct efi_boot_services *bs,
diff --git a/efi/payload/boarddata.c b/efi/payload/boarddata.c
index d4e4b5ac1d49..a2f4b8d21b4a 100644
--- a/efi/payload/boarddata.c
+++ b/efi/payload/boarddata.c
@@ -6,8 +6,9 @@
 #define DEBUG
 #endif
 
-#include <efi/efi-payload.h>
-#include <efi.h>
+#include <efi/payload.h>
+#include <efi/error.h>
+#include <efi/guid.h>
 #include <memory.h>
 #include <linux/kernel.h>
 #include <linux/printk.h>
diff --git a/efi/payload/bootm.c b/efi/payload/bootm.c
index c81211d896ad..87bf1de709b4 100644
--- a/efi/payload/bootm.c
+++ b/efi/payload/bootm.c
@@ -18,7 +18,6 @@
 #include <init.h>
 #include <driver.h>
 #include <io.h>
-#include <efi.h>
 #include <malloc.h>
 #include <string.h>
 #include <linux/err.h>
@@ -29,8 +28,10 @@
 #include <binfmt.h>
 #include <wchar.h>
 #include <image-fit.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
+#include <efi/payload.h>
+#include <efi/payload/driver.h>
+#include <efi/error.h>
+#include <efi/initrd.h>
 
 #include "image.h"
 
diff --git a/efi/payload/early-mem.c b/efi/payload/early-mem.c
index c5e94b33a756..6cf48e543db4 100644
--- a/efi/payload/early-mem.c
+++ b/efi/payload/early-mem.c
@@ -2,8 +2,8 @@
 
 #include <linux/kernel.h>
 #include <linux/sizes.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
+#include <efi/error.h>
+#include <efi/payload.h>
 
 void *efi_earlymem_alloc(const struct efi_system_table *sys_table,
 			 size_t memsize, enum efi_memory_type mem_type)
diff --git a/efi/payload/efi-initrd.c b/efi/payload/efi-initrd.c
index 7a9317fa070e..708418da62b7 100644
--- a/efi/payload/efi-initrd.c
+++ b/efi/payload/efi-initrd.c
@@ -9,10 +9,12 @@
 #include <driver.h>
 #include <init.h>
 #include <linux/hw_random.h>
-#include <efi.h>
-#include <efi/efi-device.h>
-#include <efi/device-path.h>
-#include <efi/efi-payload.h>
+#include <efi/devicepath.h>
+#include <efi/protocol/file.h>
+#include <efi/protocol/initrd.h>
+#include <efi/guid.h>
+#include <efi/payload.h>
+#include <efi/error.h>
 
 static efi_status_t EFIAPI efi_initrd_load_file2(
 	struct efi_load_file_protocol *this, struct efi_device_path *file_path,
@@ -101,4 +103,4 @@ void efi_initrd_unregister(void)
 		&efi_load_file2_protocol_guid, &initrd.base, NULL);
 
 	initrd.base.load_file = NULL;
-}
\ No newline at end of file
+}
diff --git a/efi/payload/entry-multi.c b/efi/payload/entry-multi.c
index 82f3dfffe870..ef90ee077622 100644
--- a/efi/payload/entry-multi.c
+++ b/efi/payload/entry-multi.c
@@ -4,10 +4,9 @@
 #include <linux/linkage.h>
 #include <linux/sizes.h>
 #include <stdio.h>
-#include <efi.h>
 #include <asm/common.h>
-#include <efi/efi-util.h>
-#include <efi/efi-payload.h>
+#include <efi/protocol/text.h>
+#include <efi/payload.h>
 #include <pbl.h>
 #include <pbl/handoff-data.h>
 
diff --git a/efi/payload/entry-single.c b/efi/payload/entry-single.c
index f481d0942ba5..26930af0c314 100644
--- a/efi/payload/entry-single.c
+++ b/efi/payload/entry-single.c
@@ -6,8 +6,10 @@
 
 #include <linux/kernel.h>
 #include <linux/sizes.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
+#include <efi/payload.h>
+#include <efi/error.h>
+#include <efi/guid.h>
+#include <efi/protocol/text.h>
 #include <memory.h>
 #include <common.h>
 
diff --git a/efi/payload/fdt.c b/efi/payload/fdt.c
index b50c09691976..9cdb32370f22 100644
--- a/efi/payload/fdt.c
+++ b/efi/payload/fdt.c
@@ -5,9 +5,9 @@
 #include <common.h>
 #include <init.h>
 #include <libfile.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
+#include <efi/payload.h>
+#include <efi/payload/init.h>
+#include <efi/guid.h>
 
 static int efi_fdt_probe(void)
 {
diff --git a/efi/payload/handover.c b/efi/payload/handover.c
index 0bbac598542d..c7f1deabfffa 100644
--- a/efi/payload/handover.c
+++ b/efi/payload/handover.c
@@ -17,7 +17,6 @@
 #include <init.h>
 #include <driver.h>
 #include <io.h>
-#include <efi.h>
 #include <malloc.h>
 #include <string.h>
 #include <linux/err.h>
@@ -27,8 +26,9 @@
 #include <libfile.h>
 #include <binfmt.h>
 #include <wchar.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
+#include <efi/payload.h>
+#include <efi/payload/init.h>
+#include <efi/guid.h>
 #include <efi/variable.h>
 
 #include "image.h"
diff --git a/efi/payload/image.c b/efi/payload/image.c
index 2dd545fc0d79..976327e08842 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -15,7 +15,6 @@
 #include <init.h>
 #include <driver.h>
 #include <io.h>
-#include <efi.h>
 #include <malloc.h>
 #include <string.h>
 #include <linux/err.h>
@@ -25,8 +24,9 @@
 #include <libfile.h>
 #include <binfmt.h>
 #include <wchar.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
+#include <efi/error.h>
+#include <efi/payload.h>
+#include <efi/payload/driver.h>
 #include <efi/variable.h>
 
 #include "image.h"
diff --git a/efi/payload/init.c b/efi/payload/init.c
index 7e407991b4a0..7e361bab8ab3 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -25,7 +25,6 @@
 #include <driver.h>
 #include <platform_data/serial-ns16550.h>
 #include <io.h>
-#include <efi.h>
 #include <malloc.h>
 #include <string.h>
 #include <linux/err.h>
@@ -34,8 +33,10 @@
 #include <binfmt.h>
 #include <wchar.h>
 #include <envfs.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
+#include <efi/payload.h>
+#include <efi/payload/driver.h>
+#include <efi/devicepath.h>
+#include <efi/error.h>
 #include <efi/variable.h>
 #include <libfile.h>
 #include <state.h>
diff --git a/efi/payload/iomem.c b/efi/payload/iomem.c
index d58f95ca70a2..8b92dc47a7b9 100644
--- a/efi/payload/iomem.c
+++ b/efi/payload/iomem.c
@@ -5,9 +5,9 @@
 
 #include <common.h>
 #include <init.h>
-#include <efi.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-init.h>
+#include <efi/payload.h>
+#include <efi/error.h>
+#include <efi/payload/init.h>
 #include <memory.h>
 #include <linux/sizes.h>
 
diff --git a/fs/efi.c b/fs/efi.c
index 9cdae7efeeb4..76eb86a85eea 100644
--- a/fs/efi.c
+++ b/fs/efi.c
@@ -26,10 +26,11 @@
 #include <xfuncs.h>
 #include <fcntl.h>
 #include <wchar.h>
-#include <efi.h>
+#include <efi/protocol/file.h>
 #include <libfile.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
+#include <efi/payload.h>
+#include <efi/payload/driver.h>
+#include <efi/error.h>
 #include <linux/stddef.h>
 
 struct efifs_priv {
diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index 3641dd92917d..a4d8cc8d0268 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -24,13 +24,14 @@
 #include <linux/stat.h>
 #include <xfuncs.h>
 #include <fcntl.h>
-#include <efi.h>
-#include <efi/efi-mode.h>
 #include <wchar.h>
 #include <linux/err.h>
 #include <linux/ctype.h>
-#include <efi/efi-payload.h>
-#include <efi/efi-device.h>
+#include <efi/services.h>
+#include <efi/mode.h>
+#include <efi/variable.h>
+#include <efi/error.h>
+#include <efi/guid.h>
 
 struct efivarfs_inode {
 	s16 *name;
diff --git a/fs/ubootvarfs.c b/fs/ubootvarfs.c
index c725969b1ee3..c7fb97c8bded 100644
--- a/fs/ubootvarfs.c
+++ b/fs/ubootvarfs.c
@@ -15,7 +15,6 @@
 #include <linux/stat.h>
 #include <xfuncs.h>
 #include <fcntl.h>
-#include <efi.h>
 #include <wchar.h>
 #include <linux/err.h>
 #include <linux/ctype.h>
diff --git a/include/acpi.h b/include/acpi.h
index fa94d972e3fe..4bca3d421479 100644
--- a/include/acpi.h
+++ b/include/acpi.h
@@ -9,7 +9,7 @@
 #include <linux/string.h>
 #include <linux/types.h>
 #include <driver.h>
-#include <efi/efi-init.h>
+#include <efi/payload/init.h>
 
 /* Names within the namespace are 4 bytes long */
 
diff --git a/include/efi.h b/include/efi.h
deleted file mode 100644
index bd339ea097c3..000000000000
--- a/include/efi.h
+++ /dev/null
@@ -1,886 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-#ifndef _LINUX_EFI_H
-#define _LINUX_EFI_H
-
-/*
- * Extensible Firmware Interface
- * Based on 'Extensible Firmware Interface Specification' version 0.9, April 30, 1999
- *
- * Copyright (C) 1999 VA Linux Systems
- * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
- * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
- *	David Mosberger-Tang <davidm@hpl.hp.com>
- *	Stephane Eranian <eranian@hpl.hp.com>
- */
-#include <linux/string.h>
-#include <linux/types.h>
-#include <efi/types.h>
-#include <efi/memtype.h>
-
-/* Bit mask for EFI status code with error */
-#define EFI_ERROR_MASK (1UL << (BITS_PER_LONG-1))
-
-#define EFI_SUCCESS                       0
-#define EFI_LOAD_ERROR                  ( 1 | EFI_ERROR_MASK)
-#define EFI_INVALID_PARAMETER           ( 2 | EFI_ERROR_MASK)
-#define EFI_UNSUPPORTED                 ( 3 | EFI_ERROR_MASK)
-#define EFI_BAD_BUFFER_SIZE             ( 4 | EFI_ERROR_MASK)
-#define EFI_BUFFER_TOO_SMALL            ( 5 | EFI_ERROR_MASK)
-#define EFI_NOT_READY                   ( 6 | EFI_ERROR_MASK)
-#define EFI_DEVICE_ERROR                ( 7 | EFI_ERROR_MASK)
-#define EFI_WRITE_PROTECTED             ( 8 | EFI_ERROR_MASK)
-#define EFI_OUT_OF_RESOURCES            ( 9 | EFI_ERROR_MASK)
-#define EFI_VOLUME_CORRUPTED            (10 | EFI_ERROR_MASK)
-#define EFI_VOLUME_FULL                 (11 | EFI_ERROR_MASK)
-#define EFI_NO_MEDIA                    (12 | EFI_ERROR_MASK)
-#define EFI_MEDIA_CHANGED               (13 | EFI_ERROR_MASK)
-#define EFI_NOT_FOUND                   (14 | EFI_ERROR_MASK)
-#define EFI_ACCESS_DENIED               (15 | EFI_ERROR_MASK)
-#define EFI_NO_RESPONSE                 (16 | EFI_ERROR_MASK)
-#define EFI_NO_MAPPING                  (17 | EFI_ERROR_MASK)
-#define EFI_TIMEOUT                     (18 | EFI_ERROR_MASK)
-#define EFI_NOT_STARTED                 (19 | EFI_ERROR_MASK)
-#define EFI_ALREADY_STARTED             (20 | EFI_ERROR_MASK)
-#define EFI_ABORTED                     (21 | EFI_ERROR_MASK)
-#define EFI_ICMP_ERROR                  (22 | EFI_ERROR_MASK)
-#define EFI_TFTP_ERROR                  (23 | EFI_ERROR_MASK)
-#define EFI_PROTOCOL_ERROR              (24 | EFI_ERROR_MASK)
-#define EFI_INCOMPATIBLE_VERSION        (25 | EFI_ERROR_MASK)
-#define EFI_SECURITY_VIOLATION          (26 | EFI_ERROR_MASK)
-#define EFI_CRC_ERROR                   (27 | EFI_ERROR_MASK)
-#define EFI_END_OF_MEDIA                (28 | EFI_ERROR_MASK)
-#define EFI_END_OF_FILE                 (31 | EFI_ERROR_MASK)
-#define EFI_INVALID_LANGUAGE            (32 | EFI_ERROR_MASK)
-#define EFI_COMPROMISED_DATA            (33 | EFI_ERROR_MASK)
-
-#define EFI_WARN_UNKNOWN_GLYPH		1
-#define EFI_WARN_DELETE_FAILURE		2
-#define EFI_WARN_WRITE_FAILURE		3
-#define EFI_WARN_BUFFER_TOO_SMALL	4
-#define EFI_WARN_STALE_DATA		5
-#define EFI_WARN_FILE_SYSTEM		6
-#define EFI_WARN_RESET_REQUIRED		7
-
-#define EFI_ERROR(a)	(((signed long) a) < 0)
-
-/*
- * Generic EFI table header
- */
-struct efi_table_hdr {
-	u64 signature;
-	u32 revision;
-	u32 headersize;
-	u32 crc32;
-	u32 reserved;
-};
-
-/*
- * Memory map descriptor:
- */
-
-struct efi_memory_desc {
-    u32 type; /* enum efi_memory_type */
-    u32 _padding;
-    efi_physical_addr_t phys_start;
-    void *virt_start;
-    u64 npages;
-    u64 attrs;
-};
-
-#define EFI_PAGE_SHIFT		12
-#define EFI_PAGE_SIZE		(1ULL << EFI_PAGE_SHIFT)
-#define EFI_PAGE_MASK		(EFI_PAGE_SIZE - 1)
-
-/*
- * Allocation types for calls to boottime->allocate_pages.
- */
-enum efi_allocate_type {
-	EFI_ALLOCATE_ANY_PAGES,
-	EFI_ALLOCATE_MAX_ADDRESS,
-	EFI_ALLOCATE_ADDRESS,
-	EFI_MAX_ALLOCATE_TYPE
-};
-
-typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
-
-/*
- * Types and defines for Time Services
- */
-#define EFI_TIME_ADJUST_DAYLIGHT 0x1
-#define EFI_TIME_IN_DAYLIGHT     0x2
-#define EFI_UNSPECIFIED_TIMEZONE 0x07ff
-
-struct efi_time {
-	u16 year;
-	u8 month;
-	u8 day;
-	u8 hour;
-	u8 minute;
-	u8 second;
-	u8 pad1;
-	u32 nanosecond;
-	s16 timezone;
-	u8 daylight;
-	u8 pad2;
-};
-
-struct efi_time_cap {
-	u32 resolution;
-	u32 accuracy;
-	u8 sets_to_zero;
-};
-
-enum efi_locate_search_type {
-	ALL_HANDLES,
-	BY_REGISTER_NOTIFY,
-	BY_PROTOCOL
-};
-
-struct efi_open_protocol_information_entry {
-	efi_handle_t agent_handle;
-	efi_handle_t controller_handle;
-	u32 attributes;
-	u32 open_count;
-};
-
-enum efi_timer_delay {
-	EFI_TIMER_CANCEL = 0,
-	EFI_TIMER_PERIODIC = 1,
-	EFI_TIMER_RELATIVE = 2
-};
-
-struct efi_event;
-
-/*
- * EFI Boot Services table
- */
-struct efi_boot_services {
-	struct efi_table_hdr hdr;
-	efi_status_t (EFIAPI *raise_tpl)(unsigned long new_tpl);
-	void (EFIAPI *restore_tpl)(unsigned long old_tpl);
-	efi_status_t (EFIAPI *allocate_pages)(int, int, size_t,
-				       efi_physical_addr_t *);
-	efi_status_t (EFIAPI *free_pages)(efi_physical_addr_t, size_t);
-	efi_status_t (EFIAPI *get_memory_map)(size_t *, struct efi_memory_desc *,
-					      ulong *, size_t *, u32 *);
-	efi_status_t (EFIAPI *allocate_pool)(int, size_t, void **);
-	efi_status_t (EFIAPI *free_pool)(void *);
-#define EFI_EVT_TIMER				0x80000000
-#define EFI_EVT_RUNTIME				0x40000000
-#define EFI_EVT_NOTIFY_WAIT			0x00000100
-#define EFI_EVT_NOTIFY_SIGNAL			0x00000200
-#define EFI_EVT_SIGNAL_EXIT_BOOT_SERVICES	0x00000201
-#define EFI_EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE	0x60000202
-
-#define EFI_TPL_APPLICATION	4
-#define EFI_TPL_CALLBACK	8
-#define EFI_TPL_NOTIFY		16
-#define EFI_TPL_HIGH_LEVEL	31
-	efi_status_t(EFIAPI *create_event)(u32 type , unsigned long tpl,
-			void (*fn) (struct efi_event *event, void *ctx),
-			void *ctx, struct efi_event **event);
-	efi_status_t(EFIAPI *set_timer)(struct efi_event *event, enum efi_timer_delay type, uint64_t time);
-	efi_status_t(EFIAPI *wait_for_event)(size_t number_of_events, struct efi_event **event,
-			size_t *index);
-	efi_status_t (EFIAPI *signal_event)(struct efi_event *event);
-	efi_status_t(EFIAPI *close_event)(struct efi_event *event);
-#define EFI_NATIVE_INTERFACE	0x00000000
-	efi_status_t (EFIAPI *check_event)(struct efi_event *event);
-	efi_status_t (EFIAPI *install_protocol_interface)(efi_handle_t *handle, const efi_guid_t *protocol,
-			int protocol_interface_type, void *protocol_interface);
-	efi_status_t (EFIAPI *reinstall_protocol_interface)(efi_handle_t handle, const efi_guid_t *protocol,
-			void *old_interface, void *new_interface);
-	efi_status_t (EFIAPI *uninstall_protocol_interface)(efi_handle_t handle,
-			const efi_guid_t *protocol, void *protocol_interface);
-
-	efi_status_t (EFIAPI *handle_protocol)(efi_handle_t, const efi_guid_t *, void **);
-	void *__reserved;
-	efi_status_t (EFIAPI *register_protocol_notify)(const efi_guid_t *protocol, struct efi_event *event,
-			void **registration);
-	efi_status_t (EFIAPI *locate_handle) (enum efi_locate_search_type search_type,
-			const efi_guid_t *protocol, void *search_key,
-			size_t *buffer_size, efi_handle_t *buffer);
-	efi_status_t (EFIAPI *locate_device_path)(const efi_guid_t *protocol,
-			struct efi_device_path **device_path, efi_handle_t *device);
-	efi_status_t (EFIAPI *install_configuration_table)(const efi_guid_t *guid, void *table);
-	efi_status_t (EFIAPI *load_image)(bool boot_policiy, efi_handle_t parent_image,
-			struct efi_device_path *file_path, void *source_buffer,
-			size_t source_size, efi_handle_t *image);
-	efi_status_t (EFIAPI *start_image)(efi_handle_t handle,
-			size_t *exitdata_size, u16 **exitdata);
-	efi_status_t(EFIAPI *exit)(efi_handle_t handle,  efi_status_t exit_status,
-			size_t exitdata_size, u16 *exitdata);
-	efi_status_t (EFIAPI *unload_image)(efi_handle_t handle);
-	efi_status_t (EFIAPI *exit_boot_services)(efi_handle_t, unsigned long);
-	void *get_next_monotonic_count;
-	efi_status_t (EFIAPI *stall)(unsigned long usecs);
-	efi_status_t (EFIAPI *set_watchdog_timer)(unsigned long timeout,
-						  uint64_t watchdog_code,
-						  size_t data_size,
-						  u16 *watchdog_data);
-	efi_status_t(EFIAPI *connect_controller)(efi_handle_t controller_handle,
-			efi_handle_t *driver_image_handle,
-			struct efi_device_path *remaining_device_path,
-			bool Recursive);
-	efi_status_t (EFIAPI *disconnect_controller)(efi_handle_t controller_handle,
-			efi_handle_t driver_image_handle, efi_handle_t child_handle);
-#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL  0x00000001
-#define EFI_OPEN_PROTOCOL_GET_PROTOCOL        0x00000002
-#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL       0x00000004
-#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
-#define EFI_OPEN_PROTOCOL_BY_DRIVER           0x00000010
-#define EFI_OPEN_PROTOCOL_EXCLUSIVE           0x00000020
-	efi_status_t (EFIAPI *open_protocol)(efi_handle_t handle, const efi_guid_t *protocol,
-			void ** interface, efi_handle_t agent_handle,
-			efi_handle_t controller_handle, u32 attributes);
-	efi_status_t (EFIAPI *close_protocol)(efi_handle_t handle, const efi_guid_t *protocol,
-					      efi_handle_t agent, efi_handle_t controller);
-	efi_status_t(EFIAPI *open_protocol_information)(efi_handle_t handle, const efi_guid_t *Protocol,
-			struct efi_open_protocol_information_entry **entry_buffer,
-			size_t *entry_count);
-	efi_status_t (EFIAPI *protocols_per_handle)(efi_handle_t handle,
-			efi_guid_t ***protocol_buffer,
-			size_t *protocols_buffer_count);
-	efi_status_t (EFIAPI *locate_handle_buffer) (
-			enum efi_locate_search_type search_type,
-			const efi_guid_t *protocol, void *search_key,
-			size_t *no_handles, efi_handle_t **buffer);
-	efi_status_t (EFIAPI *locate_protocol)(const efi_guid_t *protocol,
-			void *registration, void **protocol_interface);
-	efi_status_t (EFIAPI *install_multiple_protocol_interfaces)(efi_handle_t *handle, ...);
-	efi_status_t (EFIAPI *uninstall_multiple_protocol_interfaces)(efi_handle_t handle, ...);
-	efi_status_t (EFIAPI *calculate_crc32)(const void *data,
-			size_t data_size, uint32_t *crc32);
-	void (EFIAPI *copy_mem)(void *destination, const void *source, size_t length);
-	void (EFIAPI *set_mem)(void *buffer, size_t size, uint8_t value);
-	void *create_event_ex;
-};
-
-extern struct efi_boot_services *BS;
-
-/*
- * Types and defines for EFI ResetSystem
- */
-enum efi_reset_type {
-	EFI_RESET_COLD = 0,
-	EFI_RESET_WARM = 1,
-	EFI_RESET_SHUTDOWN = 2,
-	EFI_RESET_PLATFORM_SPECIFIC = 3,
-};
-
-/*
- * EFI Runtime Services table
- */
-#define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
-#define EFI_RUNTIME_SERVICES_REVISION  0x00010000
-
-struct efi_capsule_header;
-
-struct efi_runtime_services {
-	struct efi_table_hdr hdr;
-	efi_status_t (EFIAPI *get_time)(struct efi_time *time,
-					struct efi_time_cap *capabilities);
-	efi_status_t (EFIAPI *set_time)(struct efi_time *time);
-	efi_status_t (EFIAPI *get_wakeup_time)(char *enabled, char *pending,
-				       struct efi_time *time);
-	efi_status_t (EFIAPI *set_wakeup_time)(char enabled, struct efi_time *time);
-	efi_status_t (EFIAPI *set_virtual_address_map)(size_t memory_map_size,
-				       size_t descriptor_size,
-				       uint32_t descriptor_version,
-				       struct efi_memory_desc *virtmap);
-	efi_status_t (*convert_pointer)(unsigned long dbg, void **address);
-	efi_status_t (EFIAPI *get_variable)(efi_char16_t *variable_name, const efi_guid_t *vendor,
-			u32 *Attributes, size_t *data_size, void *data);
-	efi_status_t (EFIAPI *get_next_variable)(size_t *variable_name_size,
-			efi_char16_t *variable_name, efi_guid_t *vendor);
-	efi_status_t (EFIAPI *set_variable)(efi_char16_t *variable_name, const efi_guid_t *vendor,
-			u32 Attributes, size_t data_size, const void *data);
-	efi_status_t (EFIAPI *get_next_high_mono_count)(uint32_t *high_count);
-	void (EFIAPI *reset_system)(enum efi_reset_type reset_type, efi_status_t reset_status,
-			size_t data_size, void *reset_data);
-	efi_status_t (EFIAPI *update_capsule)(struct efi_capsule_header **capsule_header_array,
-					      size_t capsule_count,
-					      u64 scatter_gather_list);
-	efi_status_t (EFIAPI *query_capsule_caps)(struct efi_capsule_header **capsule_header_array,
-						  size_t capsule_count,
-						  u64 *maximum_capsule_size,
-						  u32 *reset_type);
-	void *query_variable_info;
-};
-
-extern struct efi_runtime_services *RT;
-
-/* EFI event group GUID definitions */
-#define EFI_EVENT_GROUP_EXIT_BOOT_SERVICES \
-	EFI_GUID(0x27abf055, 0xb1b8, 0x4c26, 0x80, 0x48, \
-		 0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf)
-
-#define EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE \
-	EFI_GUID(0x13fa7698, 0xc831, 0x49c7, 0x87, 0xea, \
-		 0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96)
-
-#define EFI_EVENT_GROUP_MEMORY_MAP_CHANGE \
-	EFI_GUID(0x78bee926, 0x692f, 0x48fd, 0x9e, 0xdb, \
-		 0x01, 0x42, 0x2e, 0xf0, 0xd7, 0xab)
-
-#define EFI_EVENT_GROUP_READY_TO_BOOT \
-	EFI_GUID(0x7ce88fb3, 0x4bd7, 0x4679, 0x87, 0xa8, \
-		 0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b)
-
-#define EFI_EVENT_GROUP_RESET_SYSTEM \
-	EFI_GUID(0x62da6a56, 0x13fb, 0x485a, 0xa8, 0xda, \
-		 0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b)
-
-/*
- *  EFI Configuration Table and GUID definitions
- */
-#define EFI_NULL_GUID \
-    EFI_GUID(  0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 )
-
-#define EFI_MPS_TABLE_GUID    \
-    EFI_GUID(  0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
-
-#define EFI_ACPI_TABLE_GUID    \
-    EFI_GUID(  0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
-
-#define EFI_ACPI_20_TABLE_GUID    \
-    EFI_GUID(  0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 )
-
-#define EFI_SMBIOS_TABLE_GUID    \
-    EFI_GUID(  0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
-
-#define EFI_SAL_SYSTEM_TABLE_GUID    \
-    EFI_GUID(  0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
-
-#define EFI_HCDP_TABLE_GUID	\
-    EFI_GUID(  0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98 )
-
-#define EFI_UGA_IO_PROTOCOL_GUID \
-    EFI_GUID(  0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0xb, 0x7, 0xa2 )
-
-#define EFI_GLOBAL_VARIABLE_GUID \
-    EFI_GUID(  0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c )
-
-#define EFI_UV_SYSTEM_TABLE_GUID \
-    EFI_GUID(  0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93 )
-
-#define EFI_LINUX_EFI_CRASH_GUID \
-    EFI_GUID(  0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0 )
-
-#define EFI_LOADED_IMAGE_PROTOCOL_GUID \
-    EFI_GUID(  0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
-
-#define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \
-    EFI_GUID(0xbc62157e, 0x3e33, 0x4fec, 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf)
-
-#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
-    EFI_GUID(  0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a )
-
-#define EFI_UGA_PROTOCOL_GUID \
-    EFI_GUID(  0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39 )
-
-#define EFI_PCI_IO_PROTOCOL_GUID \
-    EFI_GUID(  0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x2, 0x9a )
-
-#define EFI_USB_IO_PROTOCOL_GUID \
-    EFI_GUID(0x2B2F68D6, 0x0CD2, 0x44cf, 0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75)
-
-#define EFI_FILE_INFO_GUID \
-    EFI_GUID(  0x9576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
-
-#define EFI_SIMPLE_FILE_SYSTEM_GUID \
-    EFI_GUID(  0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
-
-#define EFI_FILE_SYSTEM_INFO_GUID \
-    EFI_GUID(0x09576e93, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
-
-#define EFI_FILE_SYSTEM_VOLUME_LABEL_ID \
-    EFI_GUID(0xdb47d7d3, 0xfe81, 0x11d3, 0x9a, 0x35, 0x00, 0x90, 0x27, 0x3f, 0xC1, 0x4d)
-
-#define EFI_DEVICE_TREE_GUID \
-    EFI_GUID(  0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 )
-
-#define EFI_DEVICE_PATH_PROTOCOL_GUID \
-    EFI_GUID(  0x9576e91, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
-
-#define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
-    EFI_GUID( 0x8b843e20, 0x8132, 0x4852, 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c)
-
-#define EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID \
-    EFI_GUID(0x0379be4e, 0xd706, 0x437d, 0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4)
-
-#define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \
-    EFI_GUID( 0xA19832B9, 0xAC25, 0x11D3, 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D )
-
-#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
-    EFI_GUID(0x0964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
-
-#define EFI_UNKNOWN_DEVICE_GUID \
-    EFI_GUID(0xcf31fac5, 0xc24e, 0x11d2, 0x85, 0xf3, 0x0, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b)
-
-#define EFI_BLOCK_IO_PROTOCOL_GUID \
-    EFI_GUID(0x964e5b21, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
-
-/* additional GUID from EDK2 */
-#define EFI_FIRMWARE_VOLUME2_PROTOCOL_GUID \
-    EFI_GUID(0x220e73b6, 0x6bdb, 0x4413, 0x84, 0x5, 0xb9, 0x74, 0xb1, 0x8, 0x61, 0x9a)
-
-#define EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID \
-    EFI_GUID(0x8f644fa9, 0xe850, 0x4db1, 0x9c, 0xe2, 0xb, 0x44, 0x69, 0x8e, 0x8d, 0xa4)
-
-#define EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID \
-    EFI_GUID(0x2f707ebb, 0x4a1a, 0x11d4, 0x9a, 0x38, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
-
-#define EFI_ISA_ACPI_PROTOCOL_GUID \
-    EFI_GUID(0x64a892dc, 0x5561, 0x4536, 0x92, 0xc7, 0x79, 0x9b, 0xfc, 0x18, 0x33, 0x55)
-
-#define EFI_ISA_IO_PROTOCOL_GUID \
-    EFI_GUID(0x7ee2bd44, 0x3da0, 0x11d4, 0x9a, 0x38, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
-
-#define EFI_STANDARD_ERROR_DEVICE_GUID \
-    EFI_GUID(0xd3b36f2d, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
-
-#define EFI_CONSOLE_OUT_DEVICE_GUID \
-    EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
-
-#define EFI_CONSOLE_IN_DEVICE_GUID \
-    EFI_GUID(0xd3b36f2b, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
-
-#define EFI_SIMPLE_TEXT_OUT_PROTOCOL_GUID \
-    EFI_GUID(0x387477c2, 0x69c7, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
-
-#define EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID \
-    EFI_GUID(0xdd9e7534, 0x7762, 0x4698, 0x8c, 0x14, 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa)
-
-#define EFI_SIMPLE_TEXT_IN_PROTOCOL_GUID \
-    EFI_GUID(0x387477c1, 0x69c7, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
-
-#define EFI_CONSOLE_CONTROL_GUID \
-    EFI_GUID(0xf42f7782, 0x12e, 0x4c12, 0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21)
-
-#define EFI_DISK_IO_PROTOCOL_GUID \
-    EFI_GUID(0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
-
-#define EFI_IDE_CONTROLLER_INIT_PROTOCOL_GUID \
-    EFI_GUID(0xa1e37052, 0x80d9, 0x4e65, 0xa3, 0x17, 0x3e, 0x9a, 0x55, 0xc4, 0x3e, 0xc9)
-
-#define EFI_DISK_INFO_PROTOCOL_GUID \
-    EFI_GUID(0xd432a67f, 0x14dc, 0x484b, 0xb3, 0xbb, 0x3f, 0x2, 0x91, 0x84, 0x93, 0x27)
-
-#define EFI_SERIAL_IO_PROTOCOL_GUID \
-    EFI_GUID(0xbb25cf6f, 0xf1d4, 0x11d2, 0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0xfd)
-
-#define EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL_GUID \
-    EFI_GUID(0x3bc1b285, 0x8a15, 0x4a82, 0xaa, 0xbf, 0x4d, 0x7d, 0x13, 0xfb, 0x32, 0x65)
-
-#define EFI_LOAD_FILE2_PROTOCOL_GUID \
-    EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d)
-
-#define EFI_MTFTP4_SERVICE_BINDING_PROTOCOL_GUID \
-    EFI_GUID(0x2fe800be, 0x8f01, 0x4aa6, 0x94, 0x6b, 0xd7, 0x13, 0x88, 0xe1, 0x83, 0x3f)
-
-#define EFI_DHCP4_PROTOCOL_GUID \
-    EFI_GUID(0x9d9a39d8, 0xbd42, 0x4a73, 0xa4, 0xd5, 0x8e, 0xe9, 0x4b, 0xe1, 0x13, 0x80)
-
-#define EFI_UDP4_SERVICE_BINDING_PROTOCOL_GUID \
-    EFI_GUID(0x83f01464, 0x99bd, 0x45e5, 0xb3, 0x83, 0xaf, 0x63, 0x05, 0xd8, 0xe9, 0xe6)
-
-#define EFI_TCP4_SERVICE_BINDING_PROTOCOL_GUID \
-    EFI_GUID(0x00720665, 0x67EB, 0x4a99, 0xBA, 0xF7, 0xD3, 0xC3, 0x3A, 0x1C, 0x7C, 0xC9)
-
-#define EFI_IP4_SERVICE_BINDING_PROTOCOL_GUID \
-    EFI_GUID(0xc51711e7, 0xb4bf, 0x404a, 0xbf, 0xb8, 0x0a, 0x04, 0x8e, 0xf1, 0xff, 0xe4)
-
-#define EFI_IP4_CONFIG_PROTOCOL_GUID \
-    EFI_GUID(0x3b95aa31, 0x3793, 0x434b, 0x86, 0x67, 0xc8, 0x07, 0x08, 0x92, 0xe0, 0x5e)
-
-#define EFI_ARP_SERVICE_BINDING_PROTOCOL_GUID\
-    EFI_GUID(0xf44c00ee, 0x1f2c, 0x4a00, 0xaa, 0x9, 0x1c, 0x9f, 0x3e, 0x8, 0x0, 0xa3)
-
-#define EFI_MANAGED_NETWORK_SERVICE_BINDING_PROTOCOL_GUID \
-    EFI_GUID(0xf36ff770, 0xa7e1, 0x42cf, 0x9e, 0xd2, 0x56, 0xf0, 0xf2, 0x71, 0xf4, 0x4c)
-
-#define EFI_VLAN_CONFIG_PROTOCOL_GUID \
-    EFI_GUID(0x9e23d768, 0xd2f3, 0x4366, 0x9f, 0xc3, 0x3a, 0x7a, 0xba, 0x86, 0x43, 0x74)
-
-#define EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID \
-    EFI_GUID(0x330d4706, 0xf2a0, 0x4e4f, 0xa3, 0x69, 0xb6, 0x6f, 0xa8, 0xd5, 0x43, 0x85)
-
-#define EFI_LOAD_FILE_PROTOCOL_GUID \
-    EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
-
-#define EFI_COMPONENT_NAME2_PROTOCOL_GUID \
-    EFI_GUID(0x6a7a5cff, 0xe8d9, 0x4f70, 0xba, 0xda, 0x75, 0xab, 0x30, 0x25, 0xce, 0x14)
-
-#define EFI_IDEBUSDXE_INF_GUID \
-    EFI_GUID(0x69fd8e47, 0xa161, 0x4550, 0xb0, 0x1a, 0x55, 0x94, 0xce, 0xb2, 0xb2, 0xb2)
-
-#define EFI_TERMINALDXE_INF_GUID \
-    EFI_GUID(0x9e863906, 0xa40f, 0x4875, 0x97, 0x7f, 0x5b, 0x93, 0xff, 0x23, 0x7f, 0xc6)
-
-#define EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID_31 \
-    EFI_GUID(0x1aced566, 0x76ed, 0x4218, 0xbc, 0x81, 0x76, 0x7f, 0x1f, 0x97, 0x7a, 0x89)
-
-#define EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID \
-    EFI_GUID(0xe18541cd, 0xf755, 0x4f73, 0x92, 0x8d, 0x64, 0x3c, 0x8a, 0x79, 0xb2, 0x29)
-
-#define EFI_ISCSIDXE_INF_GUID \
-    EFI_GUID(0x4579b72d, 0x7ec4, 0x4dd4, 0x84, 0x86, 0x08, 0x3c, 0x86, 0xb1, 0x82, 0xa7)
-
-#define EFI_VLANCONFIGDXE_INF_GUID \
-    EFI_GUID(0xe4f61863, 0xfe2c, 0x4b56, 0xa8, 0xf4, 0x08, 0x51, 0x9b, 0xc4, 0x39, 0xdf)
-
-#define EFI_TIMESTAMP_PROTOCOL_GUID \
-    EFI_GUID(0xafbfde41, 0x2e6e, 0x4262, 0xba, 0x65, 0x62, 0xb9, 0x23, 0x6e, 0x54, 0x95)
-
-#define EFI_I2C_MASTER_PROTOCOL_GUID \
-	EFI_GUID(0xcd72881f, 0x45b5, 0x4feb, 0x98, 0xc8, 0x31, 0x3d, 0xa8, 0x11, 0x74, 0x62)
-
-/* barebox specific GUIDs */
-#define EFI_BAREBOX_VENDOR_GUID \
-    EFI_GUID(0x5b91f69c, 0x8b88, 0x4a2b, 0x92, 0x69, 0x5f, 0x1d, 0x80, 0x2b, 0x51, 0x75)
-
-/* for systemd */
-#define EFI_SYSTEMD_VENDOR_GUID \
-    EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
-
-/* for TPM 1.2 */
-#define EFI_TCG_PROTOCOL_GUID \
-    EFI_GUID(0xf541796d, 0xa62e, 0x4954, 0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd)
-
-/* for TPM 2.0 */
-#define EFI_TCG2_PROTOCOL_GUID \
-    EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
-
-#define EFI_DT_FIXUP_PROTOCOL_GUID \
-    EFI_GUID(0xe617d64c, 0xfe08, 0x46da, 0xf4, 0xdc, 0xbb, 0xd5, 0x87, 0x0c, 0x73, 0x00)
-
-#define EFI_DRIVER_BINDING_PROTOCOL_GUID \
-    EFI_GUID(0x18a031ab, 0xb443, 0x4d1a, 0xa5, 0xc0, 0x0c, 0x09, 0x26, 0x1e, 0x9f, 0x71)
-
-#define EFI_LINUX_INITRD_MEDIA_GUID \
-	EFI_GUID(0x5568e427, 0x68fc, 0x4f3d,  0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
-
-struct efi_driver_binding_protocol {
-	efi_status_t (EFIAPI * supported)(
-			struct efi_driver_binding_protocol *this,
-			efi_handle_t controller_handle,
-			struct efi_device_path *remaining_device_path);
-	efi_status_t (EFIAPI * start)(
-			struct efi_driver_binding_protocol *this,
-			efi_handle_t controller_handle,
-			struct efi_device_path *remaining_device_path);
-	efi_status_t (EFIAPI * stop)(
-			struct efi_driver_binding_protocol *this,
-			efi_handle_t controller_handle,
-			size_t number_of_children,
-			efi_handle_t *child_handle_buffer);
-	u32 version;
-	efi_handle_t image_handle;
-	efi_handle_t driver_binding_handle;
-};
-
-extern efi_guid_t efi_file_info_id;
-extern efi_guid_t efi_simple_file_system_protocol_guid;
-extern efi_guid_t efi_file_system_info_guid;
-extern efi_guid_t efi_system_volume_label_id;
-extern efi_guid_t efi_device_path_protocol_guid;
-extern efi_guid_t efi_loaded_image_protocol_guid;
-extern efi_guid_t efi_unknown_device_guid;
-extern efi_guid_t efi_null_guid;
-extern efi_guid_t efi_global_variable_guid;
-extern efi_guid_t efi_block_io_protocol_guid;
-extern efi_guid_t efi_rng_protocol_guid;
-extern efi_guid_t efi_barebox_vendor_guid;
-extern efi_guid_t efi_systemd_vendor_guid;
-extern efi_guid_t efi_fdt_guid;
-extern efi_guid_t efi_loaded_image_device_path_guid;
-extern const efi_guid_t efi_device_path_to_text_protocol_guid;
-extern const efi_guid_t efi_dt_fixup_protocol_guid;
-extern const efi_guid_t efi_driver_binding_protocol_guid;
-extern const efi_guid_t efi_guid_event_group_exit_boot_services;
-extern const efi_guid_t efi_guid_event_group_virtual_address_change;
-extern const efi_guid_t efi_guid_event_group_memory_map_change;
-extern const efi_guid_t efi_guid_event_group_ready_to_boot;
-extern const efi_guid_t efi_guid_event_group_reset_system;
-extern const efi_guid_t efi_load_file_protocol_guid;
-extern const efi_guid_t efi_load_file2_protocol_guid;
-extern const efi_guid_t efi_device_path_utilities_protocol_guid;
-extern const efi_guid_t efi_linux_initrd_media_guid;
-
-struct efi_config_table {
-	efi_guid_t guid;
-	void * table;
-};
-
-#define for_each_efi_config_table(t) \
-	for (t = efi_sys_table->tables; \
-	     t - efi_sys_table->tables < efi_sys_table->nr_tables; \
-	     t++)
-
-#define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
-
-#define EFI_2_30_SYSTEM_TABLE_REVISION  ((2 << 16) | (30))
-#define EFI_2_20_SYSTEM_TABLE_REVISION  ((2 << 16) | (20))
-#define EFI_2_10_SYSTEM_TABLE_REVISION  ((2 << 16) | (10))
-#define EFI_2_00_SYSTEM_TABLE_REVISION  ((2 << 16) | (00))
-#define EFI_1_10_SYSTEM_TABLE_REVISION  ((1 << 16) | (10))
-#define EFI_1_02_SYSTEM_TABLE_REVISION  ((1 << 16) | (02))
-
-struct efi_system_table {
-	struct efi_table_hdr hdr;
-	efi_char16_t *fw_vendor;	/* physical addr of CHAR16 vendor string */
-	u32 fw_revision;
-	efi_handle_t con_in_handle;
-	struct efi_simple_text_input_protocol *con_in;
-	efi_handle_t con_out_handle;
-	struct efi_simple_text_output_protocol *con_out;
-	efi_handle_t stderr_handle;
-	struct efi_simple_text_output_protocol *std_err;
-	struct efi_runtime_services *runtime;
-	struct efi_boot_services *boottime;
-	size_t nr_tables;
-	struct efi_config_table *tables;
-};
-
-struct efi_loaded_image {
-	u32 revision;
-	efi_handle_t parent_handle;
-	struct efi_system_table *system_table;
-	efi_handle_t device_handle;
-	void *file_path;
-	void *reserved;
-	u32 load_options_size;
-	void *load_options;
-	void *image_base;
-	__aligned_u64 image_size;
-	unsigned int image_code_type;
-	unsigned int image_data_type;
-	efi_status_t (EFIAPI *unload)(efi_handle_t image_handle);
-};
-
-/* Open modes */
-#define EFI_FILE_MODE_READ      0x0000000000000001
-#define EFI_FILE_MODE_WRITE     0x0000000000000002
-#define EFI_FILE_MODE_CREATE    0x8000000000000000
-
-/* File attributes */
-#define EFI_FILE_READ_ONLY      0x0000000000000001
-#define EFI_FILE_HIDDEN         0x0000000000000002
-#define EFI_FILE_SYSTEM         0x0000000000000004
-#define EFI_FILE_RESERVIED      0x0000000000000008
-#define EFI_FILE_DIRECTORY      0x0000000000000010
-#define EFI_FILE_ARCHIVE        0x0000000000000020
-#define EFI_FILE_VALID_ATTR     0x0000000000000037
-
-struct efi_file_io_token {
-	struct efi_event *event;
-	efi_status_t status;
-	size_t buffer_size;
-	void *buffer;
-};
-
-#define EFI_FILE_HANDLE_REVISION         0x00010000
-#define EFI_FILE_HANDLE_REVISION2        0x00020000
-#define EFI_FILE_HANDLE_LATEST_REVISION  EFI_FILE_PROTOCOL_REVISION2
-struct efi_file_handle {
-	uint64_t Revision;
-	efi_status_t(EFIAPI *open)(struct efi_file_handle *File,
-			struct efi_file_handle **NewHandle, efi_char16_t *FileName,
-			uint64_t OpenMode, uint64_t Attributes);
-	efi_status_t(EFIAPI *close)(struct efi_file_handle *File);
-	efi_status_t(EFIAPI *delete)(struct efi_file_handle *File);
-	efi_status_t(EFIAPI *read)(struct efi_file_handle *File, size_t *BufferSize,
-			void *Buffer);
-	efi_status_t(EFIAPI *write)(struct efi_file_handle *File,
-			size_t *BufferSize, void *Buffer);
-	efi_status_t(EFIAPI *get_position)(struct efi_file_handle *File,
-			uint64_t *Position);
-	efi_status_t(EFIAPI *set_position)(struct efi_file_handle *File,
-			uint64_t Position);
-	efi_status_t(EFIAPI *get_info)(struct efi_file_handle *File,
-			const efi_guid_t *InformationType, size_t *BufferSize,
-			void *Buffer);
-	efi_status_t(EFIAPI *set_info)(struct efi_file_handle *File,
-			const efi_guid_t *InformationType, size_t BufferSize,
-			void *Buffer);
-	efi_status_t(EFIAPI *flush)(struct efi_file_handle *File);
-	efi_status_t (EFIAPI *open_ex)(struct efi_file_handle *this,
-			struct efi_file_handle **new_handle,
-			u16 *file_name, u64 open_mode, u64 attributes,
-			struct efi_file_io_token *token);
-	efi_status_t (EFIAPI *read_ex)(struct efi_file_handle *this,
-			struct efi_file_io_token *token);
-	efi_status_t (EFIAPI *write_ex)(struct efi_file_handle *this,
-			struct efi_file_io_token *token);
-	efi_status_t (EFIAPI *flush_ex)(struct efi_file_handle *this,
-			struct efi_file_io_token *token);
-};
-
-#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION 0x00010000
-
-struct efi_load_file_protocol {
-	efi_status_t (EFIAPI *load_file)(struct efi_load_file_protocol *this,
-					 struct efi_device_path *file_path,
-					 bool boot_policy,
-					 size_t *buffer_size,
-					 void *buffer);
-};
-
-#define EFI_FILE_IO_INTERFACE_REVISION   0x00010000
-
-struct efi_file_io_interface {
-	uint64_t Revision;
-	efi_status_t(EFIAPI *open_volume)(
-			struct efi_file_io_interface *This,
-			struct efi_file_handle **Root);
-};
-
-struct efi_simple_file_system_protocol {
-	u64 Revision;
-	efi_status_t (EFIAPI *open_volume)(struct efi_simple_file_system_protocol *this,
-			struct efi_file_handle **root);
-};
-
-struct efi_file_info {
-	uint64_t Size;
-	uint64_t FileSize;
-	uint64_t PhysicalSize;
-	struct efi_time CreateTime;
-	struct efi_time LastAccessTime;
-	struct efi_time ModificationTime;
-	uint64_t Attribute;
-	efi_char16_t FileName[];
-};
-
-struct efi_file_system_info {
-	u64 size;
-	u8 read_only;
-	u64 volume_size;
-	u64 free_space;
-	u32 block_size;
-	efi_char16_t volume_label[];
-};
-
-__attribute__((noreturn)) void efi_main(efi_handle_t, struct efi_system_table *);
-
-/*
- * Variable Attributes
- */
-#define EFI_VARIABLE_NON_VOLATILE       0x0000000000000001
-#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
-#define EFI_VARIABLE_RUNTIME_ACCESS     0x0000000000000004
-#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
-#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
-#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
-#define EFI_VARIABLE_APPEND_WRITE	0x0000000000000040
-
-#define EFI_VARIABLE_MASK 	(EFI_VARIABLE_NON_VOLATILE | \
-				EFI_VARIABLE_BOOTSERVICE_ACCESS | \
-				EFI_VARIABLE_RUNTIME_ACCESS | \
-				EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
-				EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
-				EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
-				EFI_VARIABLE_APPEND_WRITE)
-/*
- * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
- * not including trailing NUL
- */
-#define EFI_VARIABLE_GUID_LEN 36
-
-struct efi_block_io_media{
-	u32 media_id;
-	bool removable_media;
-	bool media_present;
-	bool logical_partition;
-	bool read_only;
-	bool write_caching;
-	u32 block_size;
-	u32 io_align;
-	sector_t last_block;
-	u64 lowest_aligned_lba; /* added in Revision 2 */
-	u32 logical_blocks_per_physical_block; /* added in Revision 2 */
-	u32 optimal_transfer_length_granularity; /* added in Revision 3 */
-};
-
-struct efi_block_io_protocol {
-	u64 revision;
-	struct efi_block_io_media *media;
-	efi_status_t(EFIAPI *reset)(struct efi_block_io_protocol *this,
-			bool ExtendedVerification);
-	efi_status_t(EFIAPI *read)(struct efi_block_io_protocol *this, u32 media_id,
-			u64 lba, size_t buffer_size, void *buf);
-	efi_status_t(EFIAPI *write)(struct efi_block_io_protocol *this, u32 media_id,
-			u64 lba, size_t buffer_size, void *buf);
-	efi_status_t(EFIAPI *flush)(struct efi_block_io_protocol *this);
-};
-
-struct simple_text_output_mode {
-	s32 max_mode;
-	s32 mode;
-	s32 attribute;
-	s32 cursor_column;
-	s32 cursor_row;
-	bool cursor_visible;
-};
-
-struct efi_simple_text_output_protocol {
-	efi_status_t (EFIAPI *reset)(
-			struct efi_simple_text_output_protocol *this,
-			char extended_verification);
-	efi_status_t (EFIAPI *output_string)(struct efi_simple_text_output_protocol *this, const efi_char16_t *str);
-	efi_status_t (EFIAPI *test_string)(struct efi_simple_text_output_protocol *this,
-			const efi_char16_t *str);
-
-	efi_status_t(EFIAPI *query_mode)(struct efi_simple_text_output_protocol *this,
-			unsigned long mode_number, unsigned long *columns, unsigned long *rows);
-	efi_status_t(EFIAPI *set_mode)(struct efi_simple_text_output_protocol *this,
-			unsigned long mode_number);
-	efi_status_t(EFIAPI *set_attribute)(struct efi_simple_text_output_protocol *this,
-			unsigned long attribute);
-	efi_status_t(EFIAPI *clear_screen) (struct efi_simple_text_output_protocol *this);
-	efi_status_t(EFIAPI *set_cursor_position) (struct efi_simple_text_output_protocol *this,
-			unsigned long column, unsigned long row);
-	efi_status_t(EFIAPI *enable_cursor)(struct efi_simple_text_output_protocol *this,
-			bool enable);
-	struct simple_text_output_mode *mode;
-};
-
-struct efi_input_key;
-
-struct efi_simple_text_input_protocol {
-	efi_status_t(EFIAPI *reset)(struct efi_simple_text_input_protocol *this,
-			bool ExtendedVerification);
-	efi_status_t(EFIAPI *read_key_stroke)(struct efi_simple_text_input_protocol *this,
-			struct efi_input_key *key);
-	struct efi_event *wait_for_key;
-};
-
-const struct efi_device_path *device_path_from_handle(efi_handle_t handle);
-char *device_path_to_str(const struct efi_device_path *dev_path);
-size_t device_path_to_str_buf(const struct efi_device_path *dev_path, char buf[], size_t size);
-u8 device_path_to_type(const struct efi_device_path *dev_path);
-u8 device_path_to_subtype(const struct efi_device_path *dev_path);
-char *device_path_to_partuuid(const struct efi_device_path *dev_path);
-char *device_path_to_filepath(const struct efi_device_path *dev_path);
-
-const char *efi_guid_string(efi_guid_t *g);
-
-#define EFI_RNG_PROTOCOL_GUID \
-	EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, \
-		 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
-
-#define EFI_RNG_ALGORITHM_RAW \
-	EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, \
-		 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61)
-
-struct efi_rng_protocol {
-	efi_status_t (EFIAPI *get_info)(struct efi_rng_protocol *protocol,
-					size_t *rng_algorithm_list_size,
-					efi_guid_t *rng_algorithm_list);
-	efi_status_t (EFIAPI *get_rng)(struct efi_rng_protocol *protocol,
-				       efi_guid_t *rng_algorithm,
-				       size_t rng_value_length, uint8_t *rng_value);
-};
-
-#endif /* _LINUX_EFI_H */
diff --git a/include/efi/attributes.h b/include/efi/attributes.h
new file mode 100644
index 000000000000..49d401b8fab1
--- /dev/null
+++ b/include/efi/attributes.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _EFI_ATTRIBUTES_H_
+#define _EFI_ATTRIBUTES_H_
+
+#ifdef __x86_64__
+#define EFIAPI __attribute__((ms_abi))
+#define efi_va_list __builtin_ms_va_list
+#define efi_va_start __builtin_ms_va_start
+#define efi_va_arg __builtin_va_arg
+#define efi_va_copy __builtin_ms_va_copy
+#define efi_va_end __builtin_ms_va_end
+#else
+#define EFIAPI
+#define efi_va_list va_list
+#define efi_va_start va_start
+#define efi_va_arg va_arg
+#define efi_va_copy va_copy
+#define efi_va_end va_end
+#endif /* __x86_64__ */
+
+#endif
diff --git a/include/efi/debug_ll.h b/include/efi/debug_ll.h
index 279e8995f2b3..2cc75b83b104 100644
--- a/include/efi/debug_ll.h
+++ b/include/efi/debug_ll.h
@@ -1,12 +1,13 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
-#ifndef __MACH_DEBUG_LL_H__
-#define __MACH_DEBUG_LL_H__
+#ifndef __EFI_DEBUG_LL_H__
+#define __EFI_DEBUG_LL_H__
 
 #define EFI_DEBUG 0
 #define EFI_DEBUG_CLEAR_MEMORY 0
 
-#include <efi.h>
-#include <efi/efi-payload.h>
+#include <efi/services.h>
+#include <efi/payload.h>
+#include <efi/protocol/text.h>
 
 static inline void PUTC_LL(char c)
 {
diff --git a/include/efi/device-path.h b/include/efi/devicepath.h
similarity index 95%
rename from include/efi/device-path.h
rename to include/efi/devicepath.h
index f6f11672f5d6..405f4446310e 100644
--- a/include/efi/device-path.h
+++ b/include/efi/devicepath.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 #ifndef __EFI_DEVICE_PATH_H
 #define __EFI_DEVICE_PATH_H
 
@@ -395,4 +396,12 @@ struct efi_device_path_bbs_bbs {
 #define DEVICE_PATH_SUB_TYPE_INSTANCE_END	0x01
 #define DEVICE_PATH_END_LENGTH			(sizeof(struct efi_device_path))
 
+const struct efi_device_path *device_path_from_handle(efi_handle_t handle);
+char *device_path_to_str(const struct efi_device_path *dev_path);
+size_t device_path_to_str_buf(const struct efi_device_path *dev_path, char buf[], size_t size);
+u8 device_path_to_type(const struct efi_device_path *dev_path);
+u8 device_path_to_subtype(const struct efi_device_path *dev_path);
+char *device_path_to_partuuid(const struct efi_device_path *dev_path);
+char *device_path_to_filepath(const struct efi_device_path *dev_path);
+
 #endif /* __EFI_DEVICE_PATH_H */
diff --git a/include/efi/efi-util.h b/include/efi/efi-util.h
deleted file mode 100644
index c61f3a5b05d2..000000000000
--- a/include/efi/efi-util.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-#ifndef __EFI_UTIL_H
-#define __EFI_UTIL_H
-
-#include <efi/types.h>
-
-const char *efi_strerror(efi_status_t err);
-int efi_errno(efi_status_t err);
-
-int __efivarfs_parse_filename(const char *filename, efi_guid_t *vendor,
-			      s16 *name, size_t *namelen);
-int efivarfs_parse_filename(const char *filename, efi_guid_t *vendor, s16 **name);
-
-static inline int
-efi_guidcmp (efi_guid_t left, efi_guid_t right)
-{
-	return memcmp(&left, &right, sizeof (efi_guid_t));
-}
-
-#endif
diff --git a/include/efi/error.h b/include/efi/error.h
new file mode 100644
index 000000000000..2bff720670bd
--- /dev/null
+++ b/include/efi/error.h
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __EFI_ERROR_H_
+#define __EFI_ERROR_H_
+
+#include <asm/bitsperlong.h>
+#include <efi/types.h>
+
+/* Bit mask for EFI status code with error */
+#define EFI_ERROR_MASK (1UL << (BITS_PER_LONG-1))
+
+#define EFI_SUCCESS                       0
+#define EFI_LOAD_ERROR                  ( 1 | EFI_ERROR_MASK)
+#define EFI_INVALID_PARAMETER           ( 2 | EFI_ERROR_MASK)
+#define EFI_UNSUPPORTED                 ( 3 | EFI_ERROR_MASK)
+#define EFI_BAD_BUFFER_SIZE             ( 4 | EFI_ERROR_MASK)
+#define EFI_BUFFER_TOO_SMALL            ( 5 | EFI_ERROR_MASK)
+#define EFI_NOT_READY                   ( 6 | EFI_ERROR_MASK)
+#define EFI_DEVICE_ERROR                ( 7 | EFI_ERROR_MASK)
+#define EFI_WRITE_PROTECTED             ( 8 | EFI_ERROR_MASK)
+#define EFI_OUT_OF_RESOURCES            ( 9 | EFI_ERROR_MASK)
+#define EFI_VOLUME_CORRUPTED            (10 | EFI_ERROR_MASK)
+#define EFI_VOLUME_FULL                 (11 | EFI_ERROR_MASK)
+#define EFI_NO_MEDIA                    (12 | EFI_ERROR_MASK)
+#define EFI_MEDIA_CHANGED               (13 | EFI_ERROR_MASK)
+#define EFI_NOT_FOUND                   (14 | EFI_ERROR_MASK)
+#define EFI_ACCESS_DENIED               (15 | EFI_ERROR_MASK)
+#define EFI_NO_RESPONSE                 (16 | EFI_ERROR_MASK)
+#define EFI_NO_MAPPING                  (17 | EFI_ERROR_MASK)
+#define EFI_TIMEOUT                     (18 | EFI_ERROR_MASK)
+#define EFI_NOT_STARTED                 (19 | EFI_ERROR_MASK)
+#define EFI_ALREADY_STARTED             (20 | EFI_ERROR_MASK)
+#define EFI_ABORTED                     (21 | EFI_ERROR_MASK)
+#define EFI_ICMP_ERROR                  (22 | EFI_ERROR_MASK)
+#define EFI_TFTP_ERROR                  (23 | EFI_ERROR_MASK)
+#define EFI_PROTOCOL_ERROR              (24 | EFI_ERROR_MASK)
+#define EFI_INCOMPATIBLE_VERSION        (25 | EFI_ERROR_MASK)
+#define EFI_SECURITY_VIOLATION          (26 | EFI_ERROR_MASK)
+#define EFI_CRC_ERROR                   (27 | EFI_ERROR_MASK)
+#define EFI_END_OF_MEDIA                (28 | EFI_ERROR_MASK)
+#define EFI_END_OF_FILE                 (31 | EFI_ERROR_MASK)
+#define EFI_INVALID_LANGUAGE            (32 | EFI_ERROR_MASK)
+#define EFI_COMPROMISED_DATA            (33 | EFI_ERROR_MASK)
+
+#define EFI_WARN_UNKNOWN_GLYPH		1
+#define EFI_WARN_DELETE_FAILURE		2
+#define EFI_WARN_WRITE_FAILURE		3
+#define EFI_WARN_BUFFER_TOO_SMALL	4
+#define EFI_WARN_STALE_DATA		5
+#define EFI_WARN_FILE_SYSTEM		6
+#define EFI_WARN_RESET_REQUIRED		7
+
+#define EFI_ERROR(a)	(((signed long) a) < 0)
+
+const char *efi_strerror(efi_status_t err);
+int efi_errno(efi_status_t err);
+
+#endif
diff --git a/include/efi/guid.h b/include/efi/guid.h
new file mode 100644
index 000000000000..a5b26d420f05
--- /dev/null
+++ b/include/efi/guid.h
@@ -0,0 +1,303 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __EFI_GUID_H_
+#define __EFI_GUID_H_
+
+#include <efi/types.h>
+#include <linux/string.h>
+
+const char *efi_guid_string(efi_guid_t *g);
+
+static inline int
+efi_guidcmp (efi_guid_t left, efi_guid_t right)
+{
+	return memcmp(&left, &right, sizeof (efi_guid_t));
+}
+
+extern efi_guid_t efi_file_info_id;
+extern efi_guid_t efi_simple_file_system_protocol_guid;
+extern efi_guid_t efi_file_system_info_guid;
+extern efi_guid_t efi_system_volume_label_id;
+extern efi_guid_t efi_device_path_protocol_guid;
+extern efi_guid_t efi_loaded_image_protocol_guid;
+extern efi_guid_t efi_unknown_device_guid;
+extern efi_guid_t efi_null_guid;
+extern efi_guid_t efi_global_variable_guid;
+extern efi_guid_t efi_block_io_protocol_guid;
+extern efi_guid_t efi_rng_protocol_guid;
+extern efi_guid_t efi_barebox_vendor_guid;
+extern efi_guid_t efi_systemd_vendor_guid;
+extern efi_guid_t efi_fdt_guid;
+extern efi_guid_t efi_loaded_image_device_path_guid;
+extern const efi_guid_t efi_device_path_to_text_protocol_guid;
+extern const efi_guid_t efi_dt_fixup_protocol_guid;
+extern const efi_guid_t efi_driver_binding_protocol_guid;
+extern const efi_guid_t efi_guid_event_group_exit_boot_services;
+extern const efi_guid_t efi_guid_event_group_virtual_address_change;
+extern const efi_guid_t efi_guid_event_group_memory_map_change;
+extern const efi_guid_t efi_guid_event_group_ready_to_boot;
+extern const efi_guid_t efi_guid_event_group_reset_system;
+extern const efi_guid_t efi_load_file_protocol_guid;
+extern const efi_guid_t efi_load_file2_protocol_guid;
+extern const efi_guid_t efi_device_path_utilities_protocol_guid;
+extern const efi_guid_t efi_linux_initrd_media_guid;
+
+
+/* EFI event group GUID definitions */
+#define EFI_EVENT_GROUP_EXIT_BOOT_SERVICES \
+	EFI_GUID(0x27abf055, 0xb1b8, 0x4c26, 0x80, 0x48, \
+		 0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf)
+
+#define EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE \
+	EFI_GUID(0x13fa7698, 0xc831, 0x49c7, 0x87, 0xea, \
+		 0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96)
+
+#define EFI_EVENT_GROUP_MEMORY_MAP_CHANGE \
+	EFI_GUID(0x78bee926, 0x692f, 0x48fd, 0x9e, 0xdb, \
+		 0x01, 0x42, 0x2e, 0xf0, 0xd7, 0xab)
+
+#define EFI_EVENT_GROUP_READY_TO_BOOT \
+	EFI_GUID(0x7ce88fb3, 0x4bd7, 0x4679, 0x87, 0xa8, \
+		 0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b)
+
+#define EFI_EVENT_GROUP_RESET_SYSTEM \
+	EFI_GUID(0x62da6a56, 0x13fb, 0x485a, 0xa8, 0xda, \
+		 0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b)
+
+/*
+ *  EFI Configuration Table and GUID definitions
+ */
+#define EFI_NULL_GUID \
+    EFI_GUID(  0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 )
+
+#define EFI_MPS_TABLE_GUID    \
+    EFI_GUID(  0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
+
+#define EFI_ACPI_TABLE_GUID    \
+    EFI_GUID(  0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
+
+#define EFI_ACPI_20_TABLE_GUID    \
+    EFI_GUID(  0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 )
+
+#define EFI_SMBIOS_TABLE_GUID    \
+    EFI_GUID(  0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
+
+#define EFI_SAL_SYSTEM_TABLE_GUID    \
+    EFI_GUID(  0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
+
+#define EFI_HCDP_TABLE_GUID \
+    EFI_GUID(  0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98 )
+
+#define EFI_UGA_IO_PROTOCOL_GUID \
+    EFI_GUID(  0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0xb, 0x7, 0xa2 )
+
+#define EFI_GLOBAL_VARIABLE_GUID \
+    EFI_GUID(  0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c )
+
+#define EFI_UV_SYSTEM_TABLE_GUID \
+    EFI_GUID(  0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93 )
+
+#define EFI_LINUX_EFI_CRASH_GUID \
+    EFI_GUID(  0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0 )
+
+#define EFI_LOADED_IMAGE_PROTOCOL_GUID \
+    EFI_GUID(  0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
+
+#define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \
+    EFI_GUID(0xbc62157e, 0x3e33, 0x4fec, 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf)
+
+#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
+    EFI_GUID(  0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a )
+
+#define EFI_UGA_PROTOCOL_GUID \
+    EFI_GUID(  0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39 )
+
+#define EFI_PCI_IO_PROTOCOL_GUID \
+    EFI_GUID(  0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x2, 0x9a )
+
+#define EFI_USB_IO_PROTOCOL_GUID \
+    EFI_GUID(0x2B2F68D6, 0x0CD2, 0x44cf, 0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75)
+
+#define EFI_FILE_INFO_GUID \
+    EFI_GUID(  0x9576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
+
+#define EFI_SIMPLE_FILE_SYSTEM_GUID \
+    EFI_GUID(  0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
+
+#define EFI_FILE_SYSTEM_INFO_GUID \
+    EFI_GUID(0x09576e93, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+
+#define EFI_FILE_SYSTEM_VOLUME_LABEL_ID \
+    EFI_GUID(0xdb47d7d3, 0xfe81, 0x11d3, 0x9a, 0x35, 0x00, 0x90, 0x27, 0x3f, 0xC1, 0x4d)
+
+#define EFI_DEVICE_TREE_GUID \
+    EFI_GUID(  0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 )
+
+#define EFI_DEVICE_PATH_PROTOCOL_GUID \
+    EFI_GUID(  0x9576e91, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
+
+#define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
+    EFI_GUID( 0x8b843e20, 0x8132, 0x4852, 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c)
+
+#define EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID \
+    EFI_GUID(0x0379be4e, 0xd706, 0x437d, 0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4)
+
+#define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \
+    EFI_GUID( 0xA19832B9, 0xAC25, 0x11D3, 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D )
+
+#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
+    EFI_GUID(0x0964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+
+#define EFI_UNKNOWN_DEVICE_GUID \
+    EFI_GUID(0xcf31fac5, 0xc24e, 0x11d2, 0x85, 0xf3, 0x0, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b)
+
+#define EFI_BLOCK_IO_PROTOCOL_GUID \
+    EFI_GUID(0x964e5b21, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+
+/* additional GUID from EDK2 */
+#define EFI_FIRMWARE_VOLUME2_PROTOCOL_GUID \
+    EFI_GUID(0x220e73b6, 0x6bdb, 0x4413, 0x84, 0x5, 0xb9, 0x74, 0xb1, 0x8, 0x61, 0x9a)
+
+#define EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID \
+    EFI_GUID(0x8f644fa9, 0xe850, 0x4db1, 0x9c, 0xe2, 0xb, 0x44, 0x69, 0x8e, 0x8d, 0xa4)
+
+#define EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID \
+    EFI_GUID(0x2f707ebb, 0x4a1a, 0x11d4, 0x9a, 0x38, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+
+#define EFI_ISA_ACPI_PROTOCOL_GUID \
+    EFI_GUID(0x64a892dc, 0x5561, 0x4536, 0x92, 0xc7, 0x79, 0x9b, 0xfc, 0x18, 0x33, 0x55)
+
+#define EFI_ISA_IO_PROTOCOL_GUID \
+    EFI_GUID(0x7ee2bd44, 0x3da0, 0x11d4, 0x9a, 0x38, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+
+#define EFI_STANDARD_ERROR_DEVICE_GUID \
+    EFI_GUID(0xd3b36f2d, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+
+#define EFI_CONSOLE_OUT_DEVICE_GUID \
+    EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+
+#define EFI_CONSOLE_IN_DEVICE_GUID \
+    EFI_GUID(0xd3b36f2b, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+
+#define EFI_SIMPLE_TEXT_OUT_PROTOCOL_GUID \
+    EFI_GUID(0x387477c2, 0x69c7, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+
+#define EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID \
+    EFI_GUID(0xdd9e7534, 0x7762, 0x4698, 0x8c, 0x14, 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa)
+
+#define EFI_SIMPLE_TEXT_IN_PROTOCOL_GUID \
+    EFI_GUID(0x387477c1, 0x69c7, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+
+#define EFI_CONSOLE_CONTROL_GUID \
+    EFI_GUID(0xf42f7782, 0x12e, 0x4c12, 0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21)
+
+#define EFI_DISK_IO_PROTOCOL_GUID \
+    EFI_GUID(0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+
+#define EFI_IDE_CONTROLLER_INIT_PROTOCOL_GUID \
+    EFI_GUID(0xa1e37052, 0x80d9, 0x4e65, 0xa3, 0x17, 0x3e, 0x9a, 0x55, 0xc4, 0x3e, 0xc9)
+
+#define EFI_DISK_INFO_PROTOCOL_GUID \
+    EFI_GUID(0xd432a67f, 0x14dc, 0x484b, 0xb3, 0xbb, 0x3f, 0x2, 0x91, 0x84, 0x93, 0x27)
+
+#define EFI_SERIAL_IO_PROTOCOL_GUID \
+    EFI_GUID(0xbb25cf6f, 0xf1d4, 0x11d2, 0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0xfd)
+
+#define EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL_GUID \
+    EFI_GUID(0x3bc1b285, 0x8a15, 0x4a82, 0xaa, 0xbf, 0x4d, 0x7d, 0x13, 0xfb, 0x32, 0x65)
+
+#define EFI_LOAD_FILE2_PROTOCOL_GUID \
+    EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d)
+
+#define EFI_MTFTP4_SERVICE_BINDING_PROTOCOL_GUID \
+    EFI_GUID(0x2fe800be, 0x8f01, 0x4aa6, 0x94, 0x6b, 0xd7, 0x13, 0x88, 0xe1, 0x83, 0x3f)
+
+#define EFI_DHCP4_PROTOCOL_GUID \
+    EFI_GUID(0x9d9a39d8, 0xbd42, 0x4a73, 0xa4, 0xd5, 0x8e, 0xe9, 0x4b, 0xe1, 0x13, 0x80)
+
+#define EFI_UDP4_SERVICE_BINDING_PROTOCOL_GUID \
+    EFI_GUID(0x83f01464, 0x99bd, 0x45e5, 0xb3, 0x83, 0xaf, 0x63, 0x05, 0xd8, 0xe9, 0xe6)
+
+#define EFI_TCP4_SERVICE_BINDING_PROTOCOL_GUID \
+    EFI_GUID(0x00720665, 0x67EB, 0x4a99, 0xBA, 0xF7, 0xD3, 0xC3, 0x3A, 0x1C, 0x7C, 0xC9)
+
+#define EFI_IP4_SERVICE_BINDING_PROTOCOL_GUID \
+    EFI_GUID(0xc51711e7, 0xb4bf, 0x404a, 0xbf, 0xb8, 0x0a, 0x04, 0x8e, 0xf1, 0xff, 0xe4)
+
+#define EFI_IP4_CONFIG_PROTOCOL_GUID \
+    EFI_GUID(0x3b95aa31, 0x3793, 0x434b, 0x86, 0x67, 0xc8, 0x07, 0x08, 0x92, 0xe0, 0x5e)
+
+#define EFI_ARP_SERVICE_BINDING_PROTOCOL_GUID\
+    EFI_GUID(0xf44c00ee, 0x1f2c, 0x4a00, 0xaa, 0x9, 0x1c, 0x9f, 0x3e, 0x8, 0x0, 0xa3)
+
+#define EFI_MANAGED_NETWORK_SERVICE_BINDING_PROTOCOL_GUID \
+    EFI_GUID(0xf36ff770, 0xa7e1, 0x42cf, 0x9e, 0xd2, 0x56, 0xf0, 0xf2, 0x71, 0xf4, 0x4c)
+
+#define EFI_VLAN_CONFIG_PROTOCOL_GUID \
+    EFI_GUID(0x9e23d768, 0xd2f3, 0x4366, 0x9f, 0xc3, 0x3a, 0x7a, 0xba, 0x86, 0x43, 0x74)
+
+#define EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID \
+    EFI_GUID(0x330d4706, 0xf2a0, 0x4e4f, 0xa3, 0x69, 0xb6, 0x6f, 0xa8, 0xd5, 0x43, 0x85)
+
+#define EFI_LOAD_FILE_PROTOCOL_GUID \
+    EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+
+#define EFI_COMPONENT_NAME2_PROTOCOL_GUID \
+    EFI_GUID(0x6a7a5cff, 0xe8d9, 0x4f70, 0xba, 0xda, 0x75, 0xab, 0x30, 0x25, 0xce, 0x14)
+
+#define EFI_IDEBUSDXE_INF_GUID \
+    EFI_GUID(0x69fd8e47, 0xa161, 0x4550, 0xb0, 0x1a, 0x55, 0x94, 0xce, 0xb2, 0xb2, 0xb2)
+
+#define EFI_TERMINALDXE_INF_GUID \
+    EFI_GUID(0x9e863906, 0xa40f, 0x4875, 0x97, 0x7f, 0x5b, 0x93, 0xff, 0x23, 0x7f, 0xc6)
+
+#define EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID_31 \
+    EFI_GUID(0x1aced566, 0x76ed, 0x4218, 0xbc, 0x81, 0x76, 0x7f, 0x1f, 0x97, 0x7a, 0x89)
+
+#define EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID \
+    EFI_GUID(0xe18541cd, 0xf755, 0x4f73, 0x92, 0x8d, 0x64, 0x3c, 0x8a, 0x79, 0xb2, 0x29)
+
+#define EFI_ISCSIDXE_INF_GUID \
+    EFI_GUID(0x4579b72d, 0x7ec4, 0x4dd4, 0x84, 0x86, 0x08, 0x3c, 0x86, 0xb1, 0x82, 0xa7)
+
+#define EFI_VLANCONFIGDXE_INF_GUID \
+    EFI_GUID(0xe4f61863, 0xfe2c, 0x4b56, 0xa8, 0xf4, 0x08, 0x51, 0x9b, 0xc4, 0x39, 0xdf)
+
+#define EFI_TIMESTAMP_PROTOCOL_GUID \
+    EFI_GUID(0xafbfde41, 0x2e6e, 0x4262, 0xba, 0x65, 0x62, 0xb9, 0x23, 0x6e, 0x54, 0x95)
+
+#define EFI_I2C_MASTER_PROTOCOL_GUID \
+    EFI_GUID(0xcd72881f, 0x45b5, 0x4feb, 0x98, 0xc8, 0x31, 0x3d, 0xa8, 0x11, 0x74, 0x62)
+
+/* barebox specific GUIDs */
+#define EFI_BAREBOX_VENDOR_GUID \
+    EFI_GUID(0x5b91f69c, 0x8b88, 0x4a2b, 0x92, 0x69, 0x5f, 0x1d, 0x80, 0x2b, 0x51, 0x75)
+
+/* for systemd */
+#define EFI_SYSTEMD_VENDOR_GUID \
+    EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
+
+/* for TPM 1.2 */
+#define EFI_TCG_PROTOCOL_GUID \
+    EFI_GUID(0xf541796d, 0xa62e, 0x4954, 0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd)
+
+/* for TPM 2.0 */
+#define EFI_TCG2_PROTOCOL_GUID \
+    EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
+
+#define EFI_DT_FIXUP_PROTOCOL_GUID \
+    EFI_GUID(0xe617d64c, 0xfe08, 0x46da, 0xf4, 0xdc, 0xbb, 0xd5, 0x87, 0x0c, 0x73, 0x00)
+
+#define EFI_DRIVER_BINDING_PROTOCOL_GUID \
+    EFI_GUID(0x18a031ab, 0xb443, 0x4d1a, 0xa5, 0xc0, 0x0c, 0x09, 0x26, 0x1e, 0x9f, 0x71)
+
+#define EFI_LINUX_INITRD_MEDIA_GUID \
+    EFI_GUID(0x5568e427, 0x68fc, 0x4f3d,  0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
+
+#define EFI_RNG_PROTOCOL_GUID \
+    EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
+
+#define EFI_RNG_ALGORITHM_RAW \
+    EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61)
+
+#endif
diff --git a/include/efi/initrd.h b/include/efi/initrd.h
new file mode 100644
index 000000000000..08af2d299ad6
--- /dev/null
+++ b/include/efi/initrd.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __EFI_PAYLOAD_INITRD_H
+#define __EFI_PAYLOAD_INITRD_H
+
+#include <linux/types.h>
+
+int efi_initrd_register(void *initrd, size_t initrd_size);
+void efi_initrd_unregister(void);
+
+#endif
diff --git a/include/efi/memtype.h b/include/efi/memory.h
similarity index 90%
rename from include/efi/memtype.h
rename to include/efi/memory.h
index 3f33b911a545..df980a0f348f 100644
--- a/include/efi/memtype.h
+++ b/include/efi/memory.h
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
-#ifndef _EFI_MEMTYPE_H_
-#define _EFI_MEMTYPE_H_
+#ifndef _EFI_MEMORY_H_
+#define _EFI_MEMORY_H_
 
 #include <linux/ioport.h>
 #include <efi/types.h>
@@ -76,4 +76,19 @@ static inline void resource_set_efi_memory_type_attrs(struct resource *res,
 	res->flags |= IORESOURCE_TYPE_VALID;
 }
 
+/*
+ * Memory map descriptor:
+ */
+
+struct efi_memory_desc {
+    u32 type; /* enum efi_memory_type */
+    u32 _padding;
+    efi_physical_addr_t phys_start;
+    void *virt_start;
+    u64 npages;
+    u64 attrs;
+};
+
+#define EFI_MEMORY_DESCRIPTOR_VERSION	1
+
 #endif
diff --git a/include/efi/efi-mode.h b/include/efi/mode.h
similarity index 100%
rename from include/efi/efi-mode.h
rename to include/efi/mode.h
diff --git a/include/efi/efi-payload.h b/include/efi/payload.h
similarity index 56%
rename from include/efi/efi-payload.h
rename to include/efi/payload.h
index 644620062aad..381598ba59f2 100644
--- a/include/efi/efi-payload.h
+++ b/include/efi/payload.h
@@ -1,20 +1,24 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
+
 #ifndef __EFI_PAYLOAD_H
 #define __EFI_PAYLOAD_H
 
 #include <efi/types.h>
-#include <efi/efi-util.h>
-#include <efi/memtype.h>
-#include <efi/variable.h>
+#include <efi/memory.h>
+#include <efi/services.h>
 
 struct efi_system_table;
 struct efi_loaded_image;
+struct efi_boot_services;
+struct efi_runtime_services;
 
 struct barebox_efi_data {
 	void *image;
 	void *sys_table;
 };
 
+extern struct efi_boot_services *BS;
+extern struct efi_runtime_services *RT;
 extern struct efi_system_table *efi_sys_table;
 extern efi_handle_t efi_parent_image;
 extern struct efi_device_path *efi_device_path;
@@ -23,7 +27,11 @@ extern struct efi_loaded_image *efi_loaded_image;
 void *efi_earlymem_alloc(const struct efi_system_table *sys_table,
 			 size_t memsize, enum efi_memory_type mem_type);
 
-int efi_initrd_register(void *initrd, size_t initrd_size);
-void efi_initrd_unregister(void);
+__attribute__((noreturn)) void efi_main(efi_handle_t, struct efi_system_table *);
+
+#define for_each_efi_config_table(t) \
+	for (t = efi_sys_table->tables; \
+	     t - efi_sys_table->tables < efi_sys_table->nr_tables; \
+	     t++)
 
 #endif
diff --git a/include/efi/efi-device.h b/include/efi/payload/driver.h
similarity index 78%
rename from include/efi/efi-device.h
rename to include/efi/payload/driver.h
index 06903f48da64..e8da580133d4 100644
--- a/include/efi/efi-device.h
+++ b/include/efi/payload/driver.h
@@ -1,11 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
-#ifndef __EFI_EFI_DEVICE_H
-#define __EFI_EFI_DEVICE_H
+#ifndef __EFI_PAYLOAD_DRIVER_H
+#define __EFI_PAYLOAD_DRIVER_H
 
 #include <efi/types.h>
-#include <efi/efi-util.h>
+#include <efi/guid.h>
 #include <driver.h>
-#include <efi/efi-init.h>
+#include <efi/payload/init.h>
 
 struct efi_device {
 	struct device dev;
@@ -60,13 +60,4 @@ static inline bool efi_device_has_guid(struct efi_device *efidev, efi_guid_t gui
 	return false;
 }
 
-enum efi_locate_search_type;
-
-int __efi_locate_handle(struct efi_boot_services *bs,
-		enum efi_locate_search_type search_type,
-		efi_guid_t *protocol,
-		void *search_key,
-		size_t *no_handles,
-		efi_handle_t **buffer);
-
-#endif /* __EFI_EFI_DEVICE_H */
+#endif /* __EFI_PAYLOAD_DRIVER_H */
diff --git a/include/efi/efi-init.h b/include/efi/payload/init.h
similarity index 96%
rename from include/efi/efi-init.h
rename to include/efi/payload/init.h
index f524f3973e0e..f27151636bad 100644
--- a/include/efi/efi-init.h
+++ b/include/efi/payload/init.h
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 
-#ifndef EFI_INIT_H_
-#define EFI_INIT_H_
+#ifndef __EFI_PAYLOAD_INIT_H_
+#define __EFI_PAYLOAD_INIT_H_
 
 #include <init.h>
 #include <linux/compiler.h>
diff --git a/include/efi/protocol/block.h b/include/efi/protocol/block.h
new file mode 100644
index 000000000000..e3e99334eead
--- /dev/null
+++ b/include/efi/protocol/block.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __EFI_PROTOCOL_BLOCK_H_
+#define __EFI_PROTOCOL_BLOCK_H_
+
+#include <efi/types.h>
+
+struct efi_block_io_media{
+	u32 media_id;
+	bool removable_media;
+	bool media_present;
+	bool logical_partition;
+	bool read_only;
+	bool write_caching;
+	u32 block_size;
+	u32 io_align;
+	sector_t last_block;
+	u64 lowest_aligned_lba; /* added in Revision 2 */
+	u32 logical_blocks_per_physical_block; /* added in Revision 2 */
+	u32 optimal_transfer_length_granularity; /* added in Revision 3 */
+};
+
+struct efi_block_io_protocol {
+	u64 revision;
+	struct efi_block_io_media *media;
+	efi_status_t(EFIAPI *reset)(struct efi_block_io_protocol *this,
+			bool ExtendedVerification);
+	efi_status_t(EFIAPI *read)(struct efi_block_io_protocol *this, u32 media_id,
+			u64 lba, size_t buffer_size, void *buf);
+	efi_status_t(EFIAPI *write)(struct efi_block_io_protocol *this, u32 media_id,
+			u64 lba, size_t buffer_size, void *buf);
+	efi_status_t(EFIAPI *flush)(struct efi_block_io_protocol *this);
+};
+
+#endif
diff --git a/include/efi/protocol/file.h b/include/efi/protocol/file.h
new file mode 100644
index 000000000000..50dedc631303
--- /dev/null
+++ b/include/efi/protocol/file.h
@@ -0,0 +1,111 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __EFI_PROTOCOL_FILE_H_
+#define __EFI_PROTOCOL_FILE_H_
+
+#include <efi/types.h>
+
+/* Open modes */
+#define EFI_FILE_MODE_READ      0x0000000000000001
+#define EFI_FILE_MODE_WRITE     0x0000000000000002
+#define EFI_FILE_MODE_CREATE    0x8000000000000000
+
+/* File attributes */
+#define EFI_FILE_READ_ONLY      0x0000000000000001
+#define EFI_FILE_HIDDEN         0x0000000000000002
+#define EFI_FILE_SYSTEM         0x0000000000000004
+#define EFI_FILE_RESERVIED      0x0000000000000008
+#define EFI_FILE_DIRECTORY      0x0000000000000010
+#define EFI_FILE_ARCHIVE        0x0000000000000020
+#define EFI_FILE_VALID_ATTR     0x0000000000000037
+
+struct efi_file_io_token {
+	struct efi_event *event;
+	efi_status_t status;
+	size_t buffer_size;
+	void *buffer;
+};
+
+#define EFI_FILE_HANDLE_REVISION         0x00010000
+#define EFI_FILE_HANDLE_REVISION2        0x00020000
+#define EFI_FILE_HANDLE_LATEST_REVISION  EFI_FILE_PROTOCOL_REVISION2
+struct efi_file_handle {
+	uint64_t Revision;
+	efi_status_t(EFIAPI *open)(struct efi_file_handle *File,
+			struct efi_file_handle **NewHandle, efi_char16_t *FileName,
+			uint64_t OpenMode, uint64_t Attributes);
+	efi_status_t(EFIAPI *close)(struct efi_file_handle *File);
+	efi_status_t(EFIAPI *delete)(struct efi_file_handle *File);
+	efi_status_t(EFIAPI *read)(struct efi_file_handle *File, size_t *BufferSize,
+			void *Buffer);
+	efi_status_t(EFIAPI *write)(struct efi_file_handle *File,
+			size_t *BufferSize, void *Buffer);
+	efi_status_t(EFIAPI *get_position)(struct efi_file_handle *File,
+			uint64_t *Position);
+	efi_status_t(EFIAPI *set_position)(struct efi_file_handle *File,
+			uint64_t Position);
+	efi_status_t(EFIAPI *get_info)(struct efi_file_handle *File,
+			const efi_guid_t *InformationType, size_t *BufferSize,
+			void *Buffer);
+	efi_status_t(EFIAPI *set_info)(struct efi_file_handle *File,
+			const efi_guid_t *InformationType, size_t BufferSize,
+			void *Buffer);
+	efi_status_t(EFIAPI *flush)(struct efi_file_handle *File);
+	efi_status_t (EFIAPI *open_ex)(struct efi_file_handle *this,
+			struct efi_file_handle **new_handle,
+			u16 *file_name, u64 open_mode, u64 attributes,
+			struct efi_file_io_token *token);
+	efi_status_t (EFIAPI *read_ex)(struct efi_file_handle *this,
+			struct efi_file_io_token *token);
+	efi_status_t (EFIAPI *write_ex)(struct efi_file_handle *this,
+			struct efi_file_io_token *token);
+	efi_status_t (EFIAPI *flush_ex)(struct efi_file_handle *this,
+			struct efi_file_io_token *token);
+};
+
+#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION 0x00010000
+
+#define EFI_FILE_IO_INTERFACE_REVISION   0x00010000
+
+struct efi_file_io_interface {
+	uint64_t Revision;
+	efi_status_t(EFIAPI *open_volume)(
+			struct efi_file_io_interface *This,
+			struct efi_file_handle **Root);
+};
+
+struct efi_simple_file_system_protocol {
+	u64 Revision;
+	efi_status_t (EFIAPI *open_volume)(struct efi_simple_file_system_protocol *this,
+			struct efi_file_handle **root);
+};
+
+struct efi_file_info {
+	uint64_t Size;
+	uint64_t FileSize;
+	uint64_t PhysicalSize;
+	struct efi_time CreateTime;
+	struct efi_time LastAccessTime;
+	struct efi_time ModificationTime;
+	uint64_t Attribute;
+	efi_char16_t FileName[];
+};
+
+struct efi_file_system_info {
+	u64 size;
+	u8 read_only;
+	u64 volume_size;
+	u64 free_space;
+	u32 block_size;
+	efi_char16_t volume_label[];
+};
+
+struct efi_load_file_protocol {
+	efi_status_t (EFIAPI *load_file)(struct efi_load_file_protocol *this,
+					 struct efi_device_path *file_path,
+					 bool boot_policy,
+					 size_t *buffer_size,
+					 void *buffer);
+};
+
+#endif
diff --git a/include/efi/protocol/gop.h b/include/efi/protocol/gop.h
new file mode 100644
index 000000000000..bad9f64f0623
--- /dev/null
+++ b/include/efi/protocol/gop.h
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __EFI_PROTOCOL_GOP_H_
+#define __EFI_PROTOCOL_GOP_H_
+
+#include <efi/types.h>
+
+#define PIXEL_RGB_RESERVED_8BIT_PER_COLOR		0
+#define PIXEL_BGR_RESERVED_8BIT_PER_COLOR		1
+#define PIXEL_BIT_MASK					2
+#define PIXEL_BLT_ONLY					3
+#define PIXEL_FORMAT_MAX				4
+
+struct efi_pixel_bitmask {
+	u32 red_mask;
+	u32 green_mask;
+	u32 blue_mask;
+	u32 reserved_mask;
+};
+
+struct efi_graphics_output_mode_info {
+	u32 version;
+	u32 horizontal_resolution;
+	u32 vertical_resolution;
+	int pixel_format;
+	struct efi_pixel_bitmask pixel_information;
+	u32 pixels_per_scan_line;
+};
+
+struct efi_graphics_output_protocol_mode {
+	uint32_t max_mode;
+	uint32_t mode;
+	struct efi_graphics_output_mode_info *info;
+	size_t size_of_info;
+	void *frame_buffer_base;
+	size_t frame_buffer_size;
+};
+
+struct efi_graphics_output_protocol {
+	efi_status_t (EFIAPI *query_mode) (struct efi_graphics_output_protocol *This,
+			uint32_t mode_number, size_t *size_of_info,
+			struct efi_graphics_output_mode_info **info);
+	efi_status_t (EFIAPI *set_mode) (struct efi_graphics_output_protocol *This,
+			uint32_t mode_number);
+	efi_status_t (EFIAPI *blt)(struct efi_graphics_output_protocol *This,
+			void *buffer,
+			unsigned long operation,
+			unsigned long sourcex, unsigned long sourcey,
+			unsigned long destinationx, unsigned long destinationy,
+			unsigned long width, unsigned long height, unsigned
+			long delta);
+	struct efi_graphics_output_protocol_mode *mode;
+};
+
+#endif
diff --git a/include/efi/protocol/i2c.h b/include/efi/protocol/i2c.h
new file mode 100644
index 000000000000..f87846788f84
--- /dev/null
+++ b/include/efi/protocol/i2c.h
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __EFI_PROTOCOL_I2C_H_
+#define __EFI_PROTOCOL_I2C_H_
+
+#include <efi/types.h>
+
+/* Define EFI I2C transfer control flags */
+#define EFI_I2C_FLAG_READ           0x00000001
+
+#define EFI_I2C_ADDRESSING_10_BIT   0x80000000
+
+/* The set_bus_frequency() EFI call doesn't work (doesn't alter SPI clock
+ * frequency) if it's parameter is defined on the stack (observed with
+ * American Megatrends EFI Revision 5.19) - let's define it globaly.
+ */
+static unsigned int bus_clock;
+
+struct efi_i2c_capabilities {
+	u32 StructureSizeInBytes;
+	u32 MaximumReceiveBytes;
+	u32 MaximumTransmitBytes;
+	u32 MaximumTotalBytes;
+};
+
+struct efi_i2c_operation {
+	u32 Flags;
+	u32 LengthInBytes;
+	u8  *Buffer;
+};
+
+struct efi_i2c_request_packet {
+	unsigned int OperationCount;
+	struct efi_i2c_operation Operation[];
+};
+
+struct efi_i2c_master_protocol {
+	efi_status_t(EFIAPI * set_bus_frequency)(
+		struct efi_i2c_master_protocol *this,
+		unsigned int *bus_clock
+	);
+	efi_status_t(EFIAPI * reset)(
+		struct efi_i2c_master_protocol *this
+	);
+	efi_status_t(EFIAPI * start_request)(
+		struct efi_i2c_master_protocol *this,
+		unsigned int slave_address,
+		struct efi_i2c_request_packet *request_packet,
+		void *event,
+		efi_status_t *status
+	);
+	struct efi_i2c_capabilities *capabilities;
+};
+
+#endif
diff --git a/drivers/pci/pci-efi.h b/include/efi/protocol/pci.h
similarity index 98%
rename from drivers/pci/pci-efi.h
rename to include/efi/protocol/pci.h
index 1dba0b9906f9..41feab4fdb95 100644
--- a/drivers/pci/pci-efi.h
+++ b/include/efi/protocol/pci.h
@@ -1,8 +1,10 @@
-// SPDX-License-Identifier: GPL-2.0-only
-#ifndef __PCI_EFI_H_
-#define __PCI_EFI_H_
+/* SPDX-License-Identifier: GPL-2.0-only */
 
-#include <efi.h>
+#ifndef __EFI_PROTOCOL_PCI_H_
+#define __EFI_PROTOCOL_PCI_H_
+
+#include <efi/types.h>
+#include <efi/memory.h>
 
 struct efi_pci_root_bridge_io_protocol;
 struct efi_pci_io_protocol;
diff --git a/include/efi/protocol/rng.h b/include/efi/protocol/rng.h
new file mode 100644
index 000000000000..d8f29453dafe
--- /dev/null
+++ b/include/efi/protocol/rng.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __EFI_PROTOCOL_RNG_H_
+#define __EFI_PROTOCOL_RNG_H_
+
+#include <efi/types.h>
+
+struct efi_rng_protocol {
+	efi_status_t (EFIAPI *get_info)(struct efi_rng_protocol *protocol,
+					size_t *rng_algorithm_list_size,
+					efi_guid_t *rng_algorithm_list);
+	efi_status_t (EFIAPI *get_rng)(struct efi_rng_protocol *protocol,
+				       efi_guid_t *rng_algorithm,
+				       size_t rng_value_length, uint8_t *rng_value);
+};
+
+#endif
diff --git a/include/efi/protocol/serial.h b/include/efi/protocol/serial.h
new file mode 100644
index 000000000000..3d1e285a2f37
--- /dev/null
+++ b/include/efi/protocol/serial.h
@@ -0,0 +1,79 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __EFI_PROTOCOL_SERIAL_H_
+#define __EFI_PROTOCOL_SERIAL_H_
+
+#include <efi/types.h>
+
+/*
+ * define for Control bits, grouped by read only, write only, and read write
+ *
+ * Read Only
+ */
+#define EFI_SERIAL_CLEAR_TO_SEND        0x00000010
+#define EFI_SERIAL_DATA_SET_READY       0x00000020
+#define EFI_SERIAL_RING_INDICATE        0x00000040
+#define EFI_SERIAL_CARRIER_DETECT       0x00000080
+#define EFI_SERIAL_INPUT_BUFFER_EMPTY   0x00000100
+#define EFI_SERIAL_OUTPUT_BUFFER_EMPTY  0x00000200
+
+/*
+ * Write Only
+ */
+#define EFI_SERIAL_REQUEST_TO_SEND      0x00000002
+#define EFI_SERIAL_DATA_TERMINAL_READY  0x00000001
+
+/*
+ * Read Write
+ */
+#define EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE     0x00001000
+#define EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE     0x00002000
+#define EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE 0x00004000
+
+typedef enum {
+	DefaultParity,
+	NoParity,
+	EvenParity,
+	OddParity,
+	MarkParity,
+	SpaceParity
+} efi_parity_type;
+
+typedef enum {
+	DefaultStopBits,
+	OneStopBit,
+	OneFiveStopBits,
+	TwoStopBits
+} efi_stop_bits_type;
+
+struct efi_serial_io_mode {
+	uint32_t controlmask;
+	uint32_t timeout;
+	uint64_t baudrate;
+	uint32_t receivefifodepth;
+	uint32_t databits;
+	uint32_t parity;
+	uint32_t stopbits;
+};
+
+struct efi_serial_io_protocol {
+	uint32_t revision;
+
+	efi_status_t (EFIAPI *reset) (struct efi_serial_io_protocol *This);
+	efi_status_t (EFIAPI *set_attributes) (struct efi_serial_io_protocol *This,
+			uint64_t baudrate, uint32_t receivefifodepth,
+			uint32_t timeout, efi_parity_type parity,
+			uint8_t databits, efi_stop_bits_type stopbits);
+	efi_status_t (EFIAPI *setcontrol) (struct efi_serial_io_protocol *This,
+			uint32_t control);
+	efi_status_t (EFIAPI *getcontrol) (struct efi_serial_io_protocol *This,
+			uint32_t *control);
+	efi_status_t (EFIAPI *write) (struct efi_serial_io_protocol *This,
+			size_t *buffersize, void *buffer);
+	efi_status_t (EFIAPI *read) (struct efi_serial_io_protocol *This,
+			size_t *buffersize, void *buffer);
+
+	struct efi_serial_io_mode *mode;
+};
+
+#endif
diff --git a/include/efi/protocol/snp.h b/include/efi/protocol/snp.h
new file mode 100644
index 000000000000..afd9f508c3fd
--- /dev/null
+++ b/include/efi/protocol/snp.h
@@ -0,0 +1,110 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __EFI_PROTOCOL_SNP_H_
+#define __EFI_PROTOCOL_SNP_H_
+
+#include <efi/types.h>
+
+struct efi_network_statistics {
+	uint64_t RxTotalFrames;
+	uint64_t RxGoodFrames;
+	uint64_t RxUndersizeFrames;
+	uint64_t RxOversizeFrames;
+	uint64_t RxDroppedFrames;
+	uint64_t RxUnicastFrames;
+	uint64_t RxBroadcastFrames;
+	uint64_t RxMulticastFrames;
+	uint64_t RxCrcErrorFrames;
+	uint64_t RxTotalBytes;
+	uint64_t TxTotalFrames;
+	uint64_t TxGoodFrames;
+	uint64_t TxUndersizeFrames;
+	uint64_t TxOversizeFrames;
+	uint64_t TxDroppedFrames;
+	uint64_t TxUnicastFrames;
+	uint64_t TxBroadcastFrames;
+	uint64_t TxMulticastFrames;
+	uint64_t TxCrcErrorFrames;
+	uint64_t TxTotalBytes;
+	uint64_t Collisions;
+	uint64_t UnsupportedProtocol;
+};
+
+enum efi_simple_network_state {
+	EfiSimpleNetworkStopped,
+	EfiSimpleNetworkStarted,
+	EfiSimpleNetworkInitialized,
+	EfiSimpleNetworkMaxState
+};
+
+#define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST               0x01
+#define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST             0x02
+#define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST             0x04
+#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS           0x08
+#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10
+
+#define EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT        0x01
+#define EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT       0x02
+#define EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT        0x04
+#define EFI_SIMPLE_NETWORK_SOFTWARE_INTERRUPT       0x08
+
+#define MAX_MCAST_FILTER_CNT    16
+struct efi_simple_network_mode {
+	uint32_t State;
+	uint32_t HwAddressSize;
+	uint32_t MediaHeaderSize;
+	uint32_t MaxPacketSize;
+	uint32_t NvRamSize;
+	uint32_t NvRamAccessSize;
+	uint32_t ReceiveFilterMask;
+	uint32_t ReceiveFilterSetting;
+	uint32_t MaxMCastFilterCount;
+	uint32_t MCastFilterCount;
+	struct efi_mac_address MCastFilter[MAX_MCAST_FILTER_CNT];
+	struct efi_mac_address CurrentAddress;
+	struct efi_mac_address BroadcastAddress;
+	struct efi_mac_address PermanentAddress;
+	uint8_t IfType;
+        bool MacAddressChangeable;
+	bool MultipleTxSupported;
+	bool MediaPresentSupported;
+	bool MediaPresent;
+};
+
+#define EFI_SIMPLE_NETWORK_INTERFACE_REVISION   0x00010000
+
+struct efi_simple_network {
+	uint64_t Revision;
+	efi_status_t (EFIAPI *start) (struct efi_simple_network *This);
+	efi_status_t (EFIAPI *stop) (struct efi_simple_network *This);
+	efi_status_t (EFIAPI *initialize) (struct efi_simple_network *This,
+			unsigned long ExtraRxBufferSize, unsigned long ExtraTxBufferSize);
+	efi_status_t (EFIAPI *reset) (struct efi_simple_network *This, bool ExtendedVerification);
+	efi_status_t (EFIAPI *shutdown) (struct efi_simple_network *This);
+	efi_status_t (EFIAPI *receive_filters) (struct efi_simple_network *This,
+			uint32_t Enable, uint32_t Disable, bool ResetMCastFilter,
+			unsigned long MCastFilterCnt, struct efi_mac_address *MCastFilter);
+	efi_status_t (EFIAPI *station_address) (struct efi_simple_network *This,
+			bool Reset, struct efi_mac_address *New);
+	efi_status_t (EFIAPI *statistics) (struct efi_simple_network *This,
+			bool Reset, unsigned long *StatisticsSize,
+			struct efi_network_statistics *StatisticsTable);
+	efi_status_t (EFIAPI *mcast_ip_to_mac) (struct efi_simple_network *This,
+			bool IPv6, union efi_ip_address *IP, struct efi_mac_address *MAC);
+	efi_status_t (EFIAPI *nvdata) (struct efi_simple_network *This,
+			bool ReadWrite, unsigned long Offset, unsigned long BufferSize,
+			void *Buffer);
+	efi_status_t (EFIAPI *get_status) (struct efi_simple_network *This,
+			uint32_t *InterruptStatus, void **TxBuf);
+	efi_status_t (EFIAPI *transmit) (struct efi_simple_network *This,
+			unsigned long HeaderSize, unsigned long BufferSize, void *Buffer,
+			struct efi_mac_address *SrcAddr, struct efi_mac_address *DestAddr,
+			uint16_t *Protocol);
+	efi_status_t (EFIAPI *receive) (struct efi_simple_network *This,
+			unsigned long *HeaderSize, unsigned long *BufferSize, void *Buffer,
+			struct efi_mac_address *SrcAddr, struct efi_mac_address *DestAddr, uint16_t *Protocol);
+	void *WaitForPacket;
+	struct efi_simple_network_mode *Mode;
+};
+
+#endif
diff --git a/include/efi/efi-stdio.h b/include/efi/protocol/text.h
similarity index 67%
rename from include/efi/efi-stdio.h
rename to include/efi/protocol/text.h
index 55ceb47d1b79..7a1fe8e4875a 100644
--- a/include/efi/efi-stdio.h
+++ b/include/efi/protocol/text.h
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
-#ifndef EFI_STDIO_H_
-#define EFI_STDIO_H_
+
+#ifndef __EFI_PROTOCOL_TEXT_H_
+#define __EFI_PROTOCOL_TEXT_H_
 
 #include <efi/types.h>
 
@@ -61,6 +62,45 @@ struct efi_simple_text_input_ex_protocol {
 	efi_unregister_keystroke_notify unregister_key_notify;
 };
 
+struct simple_text_output_mode {
+	s32 max_mode;
+	s32 mode;
+	s32 attribute;
+	s32 cursor_column;
+	s32 cursor_row;
+	bool cursor_visible;
+};
+
+struct efi_simple_text_output_protocol {
+	efi_status_t (EFIAPI *reset)(
+			struct efi_simple_text_output_protocol *this,
+			char extended_verification);
+	efi_status_t (EFIAPI *output_string)(struct efi_simple_text_output_protocol *this, const efi_char16_t *str);
+	efi_status_t (EFIAPI *test_string)(struct efi_simple_text_output_protocol *this,
+			const efi_char16_t *str);
+
+	efi_status_t(EFIAPI *query_mode)(struct efi_simple_text_output_protocol *this,
+			unsigned long mode_number, unsigned long *columns, unsigned long *rows);
+	efi_status_t(EFIAPI *set_mode)(struct efi_simple_text_output_protocol *this,
+			unsigned long mode_number);
+	efi_status_t(EFIAPI *set_attribute)(struct efi_simple_text_output_protocol *this,
+			unsigned long attribute);
+	efi_status_t(EFIAPI *clear_screen) (struct efi_simple_text_output_protocol *this);
+	efi_status_t(EFIAPI *set_cursor_position) (struct efi_simple_text_output_protocol *this,
+			unsigned long column, unsigned long row);
+	efi_status_t(EFIAPI *enable_cursor)(struct efi_simple_text_output_protocol *this,
+			bool enable);
+	struct simple_text_output_mode *mode;
+};
+
+struct efi_simple_text_input_protocol {
+	efi_status_t(EFIAPI *reset)(struct efi_simple_text_input_protocol *this,
+			bool ExtendedVerification);
+	efi_status_t(EFIAPI *read_key_stroke)(struct efi_simple_text_input_protocol *this,
+			struct efi_input_key *key);
+	struct efi_event *wait_for_key;
+};
+
 #define EFI_SHIFT_STATE_VALID           0x80000000
 #define EFI_RIGHT_CONTROL_PRESSED       0x00000004
 #define EFI_LEFT_CONTROL_PRESSED        0x00000008
diff --git a/include/efi/services.h b/include/efi/services.h
new file mode 100644
index 000000000000..9fc6a066a917
--- /dev/null
+++ b/include/efi/services.h
@@ -0,0 +1,271 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _EFI_SERVICES_H_
+#define _EFI_SERVICES_H_
+
+#include <efi/types.h>
+
+/*
+ * Generic EFI table header
+ */
+struct efi_table_hdr {
+	u64 signature;
+	u32 revision;
+	u32 headersize;
+	u32 crc32;
+	u32 reserved;
+};
+
+typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
+
+enum efi_locate_search_type {
+	ALL_HANDLES,
+	BY_REGISTER_NOTIFY,
+	BY_PROTOCOL
+};
+
+struct efi_open_protocol_information_entry {
+	efi_handle_t agent_handle;
+	efi_handle_t controller_handle;
+	u32 attributes;
+	u32 open_count;
+};
+
+enum efi_timer_delay {
+	EFI_TIMER_CANCEL = 0,
+	EFI_TIMER_PERIODIC = 1,
+	EFI_TIMER_RELATIVE = 2
+};
+
+struct efi_event;
+struct efi_memory_desc;
+
+/*
+ * EFI Boot Services table
+ */
+struct efi_boot_services {
+	struct efi_table_hdr hdr;
+	efi_status_t (EFIAPI *raise_tpl)(unsigned long new_tpl);
+	void (EFIAPI *restore_tpl)(unsigned long old_tpl);
+	efi_status_t (EFIAPI *allocate_pages)(int, int, size_t,
+				       efi_physical_addr_t *);
+	efi_status_t (EFIAPI *free_pages)(efi_physical_addr_t, size_t);
+	efi_status_t (EFIAPI *get_memory_map)(size_t *, struct efi_memory_desc *,
+					      ulong *, size_t *, u32 *);
+	efi_status_t (EFIAPI *allocate_pool)(int, size_t, void **);
+	efi_status_t (EFIAPI *free_pool)(void *);
+#define EFI_EVT_TIMER				0x80000000
+#define EFI_EVT_RUNTIME				0x40000000
+#define EFI_EVT_NOTIFY_WAIT			0x00000100
+#define EFI_EVT_NOTIFY_SIGNAL			0x00000200
+#define EFI_EVT_SIGNAL_EXIT_BOOT_SERVICES	0x00000201
+#define EFI_EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE	0x60000202
+
+#define EFI_TPL_APPLICATION	4
+#define EFI_TPL_CALLBACK	8
+#define EFI_TPL_NOTIFY		16
+#define EFI_TPL_HIGH_LEVEL	31
+	efi_status_t(EFIAPI *create_event)(u32 type , unsigned long tpl,
+			void (*fn) (struct efi_event *event, void *ctx),
+			void *ctx, struct efi_event **event);
+	efi_status_t(EFIAPI *set_timer)(struct efi_event *event, enum efi_timer_delay type, uint64_t time);
+	efi_status_t(EFIAPI *wait_for_event)(size_t number_of_events, struct efi_event **event,
+			size_t *index);
+	efi_status_t (EFIAPI *signal_event)(struct efi_event *event);
+	efi_status_t(EFIAPI *close_event)(struct efi_event *event);
+#define EFI_NATIVE_INTERFACE	0x00000000
+	efi_status_t (EFIAPI *check_event)(struct efi_event *event);
+	efi_status_t (EFIAPI *install_protocol_interface)(efi_handle_t *handle, const efi_guid_t *protocol,
+			int protocol_interface_type, void *protocol_interface);
+	efi_status_t (EFIAPI *reinstall_protocol_interface)(efi_handle_t handle, const efi_guid_t *protocol,
+			void *old_interface, void *new_interface);
+	efi_status_t (EFIAPI *uninstall_protocol_interface)(efi_handle_t handle,
+			const efi_guid_t *protocol, void *protocol_interface);
+
+	efi_status_t (EFIAPI *handle_protocol)(efi_handle_t, const efi_guid_t *, void **);
+	void *__reserved;
+	efi_status_t (EFIAPI *register_protocol_notify)(const efi_guid_t *protocol, struct efi_event *event,
+			void **registration);
+	efi_status_t (EFIAPI *locate_handle) (enum efi_locate_search_type search_type,
+			const efi_guid_t *protocol, void *search_key,
+			size_t *buffer_size, efi_handle_t *buffer);
+	efi_status_t (EFIAPI *locate_device_path)(const efi_guid_t *protocol,
+			struct efi_device_path **device_path, efi_handle_t *device);
+	efi_status_t (EFIAPI *install_configuration_table)(const efi_guid_t *guid, void *table);
+	efi_status_t (EFIAPI *load_image)(bool boot_policiy, efi_handle_t parent_image,
+			struct efi_device_path *file_path, void *source_buffer,
+			size_t source_size, efi_handle_t *image);
+	efi_status_t (EFIAPI *start_image)(efi_handle_t handle,
+			size_t *exitdata_size, u16 **exitdata);
+	efi_status_t(EFIAPI *exit)(efi_handle_t handle,  efi_status_t exit_status,
+			size_t exitdata_size, u16 *exitdata);
+	efi_status_t (EFIAPI *unload_image)(efi_handle_t handle);
+	efi_status_t (EFIAPI *exit_boot_services)(efi_handle_t, unsigned long);
+	void *get_next_monotonic_count;
+	efi_status_t (EFIAPI *stall)(unsigned long usecs);
+	efi_status_t (EFIAPI *set_watchdog_timer)(unsigned long timeout,
+						  uint64_t watchdog_code,
+						  size_t data_size,
+						  u16 *watchdog_data);
+	efi_status_t(EFIAPI *connect_controller)(efi_handle_t controller_handle,
+			efi_handle_t *driver_image_handle,
+			struct efi_device_path *remaining_device_path,
+			bool Recursive);
+	efi_status_t (EFIAPI *disconnect_controller)(efi_handle_t controller_handle,
+			efi_handle_t driver_image_handle, efi_handle_t child_handle);
+#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL  0x00000001
+#define EFI_OPEN_PROTOCOL_GET_PROTOCOL        0x00000002
+#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL       0x00000004
+#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
+#define EFI_OPEN_PROTOCOL_BY_DRIVER           0x00000010
+#define EFI_OPEN_PROTOCOL_EXCLUSIVE           0x00000020
+	efi_status_t (EFIAPI *open_protocol)(efi_handle_t handle, const efi_guid_t *protocol,
+			void ** interface, efi_handle_t agent_handle,
+			efi_handle_t controller_handle, u32 attributes);
+	efi_status_t (EFIAPI *close_protocol)(efi_handle_t handle, const efi_guid_t *protocol,
+					      efi_handle_t agent, efi_handle_t controller);
+	efi_status_t(EFIAPI *open_protocol_information)(efi_handle_t handle, const efi_guid_t *Protocol,
+			struct efi_open_protocol_information_entry **entry_buffer,
+			size_t *entry_count);
+	efi_status_t (EFIAPI *protocols_per_handle)(efi_handle_t handle,
+			efi_guid_t ***protocol_buffer,
+			size_t *protocols_buffer_count);
+	efi_status_t (EFIAPI *locate_handle_buffer) (
+			enum efi_locate_search_type search_type,
+			const efi_guid_t *protocol, void *search_key,
+			size_t *no_handles, efi_handle_t **buffer);
+	efi_status_t (EFIAPI *locate_protocol)(const efi_guid_t *protocol,
+			void *registration, void **protocol_interface);
+	efi_status_t (EFIAPI *install_multiple_protocol_interfaces)(efi_handle_t *handle, ...);
+	efi_status_t (EFIAPI *uninstall_multiple_protocol_interfaces)(efi_handle_t handle, ...);
+	efi_status_t (EFIAPI *calculate_crc32)(const void *data,
+			size_t data_size, uint32_t *crc32);
+	void (EFIAPI *copy_mem)(void *destination, const void *source, size_t length);
+	void (EFIAPI *set_mem)(void *buffer, size_t size, uint8_t value);
+	void *create_event_ex;
+};
+
+/*
+ * Types and defines for EFI ResetSystem
+ */
+enum efi_reset_type {
+	EFI_RESET_COLD = 0,
+	EFI_RESET_WARM = 1,
+	EFI_RESET_SHUTDOWN = 2,
+	EFI_RESET_PLATFORM_SPECIFIC = 3,
+};
+
+/*
+ * EFI Runtime Services table
+ */
+#define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
+#define EFI_RUNTIME_SERVICES_REVISION  0x00010000
+
+struct efi_capsule_header;
+
+struct efi_runtime_services {
+	struct efi_table_hdr hdr;
+	efi_status_t (EFIAPI *get_time)(struct efi_time *time,
+					struct efi_time_cap *capabilities);
+	efi_status_t (EFIAPI *set_time)(struct efi_time *time);
+	efi_status_t (EFIAPI *get_wakeup_time)(char *enabled, char *pending,
+				       struct efi_time *time);
+	efi_status_t (EFIAPI *set_wakeup_time)(char enabled, struct efi_time *time);
+	efi_status_t (EFIAPI *set_virtual_address_map)(size_t memory_map_size,
+				       size_t descriptor_size,
+				       uint32_t descriptor_version,
+				       struct efi_memory_desc *virtmap);
+	efi_status_t (*convert_pointer)(unsigned long dbg, void **address);
+	efi_status_t (EFIAPI *get_variable)(efi_char16_t *variable_name, const efi_guid_t *vendor,
+			u32 *Attributes, size_t *data_size, void *data);
+	efi_status_t (EFIAPI *get_next_variable)(size_t *variable_name_size,
+			efi_char16_t *variable_name, efi_guid_t *vendor);
+	efi_status_t (EFIAPI *set_variable)(efi_char16_t *variable_name, const efi_guid_t *vendor,
+			u32 Attributes, size_t data_size, const void *data);
+	efi_status_t (EFIAPI *get_next_high_mono_count)(uint32_t *high_count);
+	void (EFIAPI *reset_system)(enum efi_reset_type reset_type, efi_status_t reset_status,
+			size_t data_size, void *reset_data);
+	efi_status_t (EFIAPI *update_capsule)(struct efi_capsule_header **capsule_header_array,
+					      size_t capsule_count,
+					      u64 scatter_gather_list);
+	efi_status_t (EFIAPI *query_capsule_caps)(struct efi_capsule_header **capsule_header_array,
+						  size_t capsule_count,
+						  u64 *maximum_capsule_size,
+						  u32 *reset_type);
+	void *query_variable_info;
+};
+
+struct efi_driver_binding_protocol {
+	efi_status_t (EFIAPI * supported)(
+			struct efi_driver_binding_protocol *this,
+			efi_handle_t controller_handle,
+			struct efi_device_path *remaining_device_path);
+	efi_status_t (EFIAPI * start)(
+			struct efi_driver_binding_protocol *this,
+			efi_handle_t controller_handle,
+			struct efi_device_path *remaining_device_path);
+	efi_status_t (EFIAPI * stop)(
+			struct efi_driver_binding_protocol *this,
+			efi_handle_t controller_handle,
+			size_t number_of_children,
+			efi_handle_t *child_handle_buffer);
+	u32 version;
+	efi_handle_t image_handle;
+	efi_handle_t driver_binding_handle;
+};
+
+struct efi_config_table {
+	efi_guid_t guid;
+	void * table;
+};
+
+#define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
+
+#define EFI_2_30_SYSTEM_TABLE_REVISION  ((2 << 16) | (30))
+#define EFI_2_20_SYSTEM_TABLE_REVISION  ((2 << 16) | (20))
+#define EFI_2_10_SYSTEM_TABLE_REVISION  ((2 << 16) | (10))
+#define EFI_2_00_SYSTEM_TABLE_REVISION  ((2 << 16) | (00))
+#define EFI_1_10_SYSTEM_TABLE_REVISION  ((1 << 16) | (10))
+#define EFI_1_02_SYSTEM_TABLE_REVISION  ((1 << 16) | (02))
+
+struct efi_system_table {
+	struct efi_table_hdr hdr;
+	efi_char16_t *fw_vendor;	/* physical addr of CHAR16 vendor string */
+	u32 fw_revision;
+	efi_handle_t con_in_handle;
+	struct efi_simple_text_input_protocol *con_in;
+	efi_handle_t con_out_handle;
+	struct efi_simple_text_output_protocol *con_out;
+	efi_handle_t stderr_handle;
+	struct efi_simple_text_output_protocol *std_err;
+	struct efi_runtime_services *runtime;
+	struct efi_boot_services *boottime;
+	size_t nr_tables;
+	struct efi_config_table *tables;
+};
+
+struct efi_loaded_image {
+	u32 revision;
+	efi_handle_t parent_handle;
+	struct efi_system_table *system_table;
+	efi_handle_t device_handle;
+	void *file_path;
+	void *reserved;
+	u32 load_options_size;
+	void *load_options;
+	void *image_base;
+	__aligned_u64 image_size;
+	unsigned int image_code_type;
+	unsigned int image_data_type;
+	efi_status_t (EFIAPI *unload)(efi_handle_t image_handle);
+};
+
+enum efi_locate_search_type;
+
+int __efi_locate_handle(struct efi_boot_services *bs,
+		enum efi_locate_search_type search_type,
+		efi_guid_t *protocol,
+		void *search_key,
+		size_t *no_handles,
+		efi_handle_t **buffer);
+
+#endif
diff --git a/include/efi/types.h b/include/efi/types.h
index 4b2276038de2..0d6d6c8b05b9 100644
--- a/include/efi/types.h
+++ b/include/efi/types.h
@@ -2,6 +2,8 @@
 #ifndef _EFI_TYPES_H_
 #define _EFI_TYPES_H_
 
+#include <efi/attributes.h>
+
 #ifndef __ASSEMBLY__
 
 #include <linux/types.h>
@@ -39,12 +41,6 @@ typedef guid_t efi_guid_t __aligned(__alignof__(u32));
   (c) & 0xff, ((c) >> 8) & 0xff, \
   (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
 
-#ifdef __x86_64__
-#define EFIAPI __attribute__((ms_abi))
-#else
-#define EFIAPI
-#endif
-
 struct efi_device_path {
 	u8 type;
 	u8 sub_type;
@@ -82,6 +78,47 @@ static inline efi_physical_addr_t efi_virt_to_phys(const void *addr)
 	return (uintptr_t)addr;
 }
 
+/*
+ * Types and defines for Time Services
+ */
+#define EFI_TIME_ADJUST_DAYLIGHT 0x1
+#define EFI_TIME_IN_DAYLIGHT     0x2
+#define EFI_UNSPECIFIED_TIMEZONE 0x07ff
+
+struct efi_time {
+	u16 year;
+	u8 month;
+	u8 day;
+	u8 hour;
+	u8 minute;
+	u8 second;
+	u8 pad1;
+	u32 nanosecond;
+	s16 timezone;
+	u8 daylight;
+	u8 pad2;
+};
+
+struct efi_time_cap {
+	u32 resolution;
+	u32 accuracy;
+	u8 sets_to_zero;
+};
+
+/*
+ * Allocation types for calls to boottime->allocate_pages.
+ */
+enum efi_allocate_type {
+	EFI_ALLOCATE_ANY_PAGES,
+	EFI_ALLOCATE_MAX_ADDRESS,
+	EFI_ALLOCATE_ADDRESS,
+	EFI_MAX_ALLOCATE_TYPE
+};
+
+#define EFI_PAGE_SHIFT			12
+#define EFI_PAGE_SIZE			(1ULL << EFI_PAGE_SHIFT)
+#define EFI_PAGE_MASK			(EFI_PAGE_SIZE - 1)
+
 #endif
 
 #endif
diff --git a/include/efi/variable.h b/include/efi/variable.h
index c53b295eefe8..53f465117cd5 100644
--- a/include/efi/variable.h
+++ b/include/efi/variable.h
@@ -5,6 +5,34 @@
 
 #include <efi/types.h>
 
+/*
+ * Variable Attributes
+ */
+#define EFI_VARIABLE_NON_VOLATILE       0x0000000000000001
+#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
+#define EFI_VARIABLE_RUNTIME_ACCESS     0x0000000000000004
+#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
+#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
+#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
+#define EFI_VARIABLE_APPEND_WRITE	0x0000000000000040
+
+#define EFI_VARIABLE_MASK 	(EFI_VARIABLE_NON_VOLATILE | \
+				EFI_VARIABLE_BOOTSERVICE_ACCESS | \
+				EFI_VARIABLE_RUNTIME_ACCESS | \
+				EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
+				EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
+				EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
+				EFI_VARIABLE_APPEND_WRITE)
+/*
+ * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
+ * not including trailing NUL
+ */
+#define EFI_VARIABLE_GUID_LEN 36
+
+int __efivarfs_parse_filename(const char *filename, efi_guid_t *vendor,
+			      s16 *name, size_t *namelen);
+int efivarfs_parse_filename(const char *filename, efi_guid_t *vendor, s16 **name);
+
 void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size);
 
 int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index c7295c1067e0..622b40ac69e9 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -21,7 +21,7 @@
 #include <kallsyms.h>
 #include <wchar.h>
 #include <of.h>
-#include <efi.h>
+#include <efi/devicepath.h>
 
 #include <common.h>
 #include <pbl.h>
diff --git a/test/self/mmu.c b/test/self/mmu.c
index 60bc9b38e84a..f5a09d76131e 100644
--- a/test/self/mmu.c
+++ b/test/self/mmu.c
@@ -9,7 +9,7 @@
 #include <abort.h>
 #include <zero_page.h>
 #include <linux/sizes.h>
-#include <efi/efi-mode.h>
+#include <efi/mode.h>
 #include <memory.h>
 
 #define TEST_BUFFER_SIZE		SZ_1M
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 09/16] efi: types: add efi_intn_t/efi_uintn_t definition
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (7 preceding siblings ...)
  2025-12-11 20:29 ` [PATCH 08/16] efi: tidy up header includes for reuse Ahmad Fatoum
@ 2025-12-11 20:30 ` Ahmad Fatoum
  2025-12-11 20:30 ` [PATCH 10/16] efi: devicepath: make fully usable for loader Ahmad Fatoum
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:30 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

To make porting code from U-Boot easier, let's define these types
instead of having to change all incoming code to use size_t/ssize_t.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/efi/types.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/efi/types.h b/include/efi/types.h
index 0d6d6c8b05b9..f157f7ffe106 100644
--- a/include/efi/types.h
+++ b/include/efi/types.h
@@ -13,6 +13,8 @@
 #include <linux/uuid.h>
 
 typedef unsigned long efi_status_t;
+typedef size_t efi_uintn_t;
+typedef ssize_t efi_intn_t;
 typedef wchar_t efi_char16_t;		/* UNICODE character */
 typedef u64 efi_physical_addr_t;	/* always, even on 32-bit systems */
 
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 10/16] efi: devicepath: make fully usable for loader
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (8 preceding siblings ...)
  2025-12-11 20:30 ` [PATCH 09/16] efi: types: add efi_intn_t/efi_uintn_t definition Ahmad Fatoum
@ 2025-12-11 20:30 ` Ahmad Fatoum
  2025-12-11 20:30 ` [PATCH 11/16] efi: guid: don't interleave protocol and event GUIDs Ahmad Fatoum
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:30 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

While in a common location, the file still makes use of BS, which is
only available for the EFI payload case. Switch to
efi_get_boot_services() for reusability.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/devicepath.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/efi/devicepath.c b/efi/devicepath.c
index 1d49f450ec8e..e4170d701e47 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -67,6 +67,7 @@ const struct efi_device_path end_instance_device_path = {
 const struct efi_device_path *
 device_path_from_handle(efi_handle_t Handle)
 {
+	struct efi_boot_services *bs = efi_get_boot_services();
 	const efi_guid_t *const protocols[] = {
 		&efi_loaded_image_device_path_guid,
 		&efi_device_path_protocol_guid,
@@ -78,7 +79,7 @@ device_path_from_handle(efi_handle_t Handle)
 	for (proto = protocols; *proto; proto++) {
 		const struct efi_device_path *device_path;
 
-		Status = BS->handle_protocol(Handle, *proto, (void *) &device_path);
+		Status = bs->handle_protocol(Handle, *proto, (void *) &device_path);
 		if (!EFI_ERROR(Status) && device_path)
 			return device_path;
 	}
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 11/16] efi: guid: don't interleave protocol and event GUIDs
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (9 preceding siblings ...)
  2025-12-11 20:30 ` [PATCH 10/16] efi: devicepath: make fully usable for loader Ahmad Fatoum
@ 2025-12-11 20:30 ` Ahmad Fatoum
  2025-12-11 20:30 ` [PATCH 12/16] efi: guid: add some more GUIDs Ahmad Fatoum
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:30 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Before adding even more GUIDs, let's tidy the existing ones up by
not mixing GUIDs for protocols and events.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/guid.c         | 17 +++++++++-----
 include/efi/guid.h | 55 +++++++++++++++++++++++-----------------------
 2 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/efi/guid.c b/efi/guid.c
index 6b8e50741ec1..44f03c8046d9 100644
--- a/efi/guid.c
+++ b/efi/guid.c
@@ -3,6 +3,7 @@
 #include <common.h>
 #include <efi/guid.h>
 
+/* ---------- Protocol GUIDs ---------- */
 efi_guid_t efi_file_info_id = EFI_FILE_INFO_GUID;
 efi_guid_t efi_simple_file_system_protocol_guid = EFI_SIMPLE_FILE_SYSTEM_GUID;
 efi_guid_t efi_file_system_info_guid = EFI_FILE_SYSTEM_INFO_GUID;
@@ -25,6 +26,15 @@ const efi_guid_t efi_dt_fixup_protocol_guid = EFI_DT_FIXUP_PROTOCOL_GUID;
 /* GUID of the EFI_DRIVER_BINDING_PROTOCOL */
 const efi_guid_t efi_driver_binding_protocol_guid = EFI_DRIVER_BINDING_PROTOCOL_GUID;
 
+/* GUIDs of the Load File and Load File2 protocols */
+const efi_guid_t efi_load_file_protocol_guid = EFI_LOAD_FILE_PROTOCOL_GUID;
+const efi_guid_t efi_load_file2_protocol_guid = EFI_LOAD_FILE2_PROTOCOL_GUID;
+const efi_guid_t efi_device_path_utilities_protocol_guid =
+	EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID;
+const efi_guid_t efi_linux_initrd_media_guid = EFI_LINUX_INITRD_MEDIA_GUID;
+
+
+/* ---------- Event  GUIDs ---------- */
 /* event group ExitBootServices() invoked */
 const efi_guid_t efi_guid_event_group_exit_boot_services =
 			EFI_EVENT_GROUP_EXIT_BOOT_SERVICES;
@@ -38,12 +48,7 @@ const efi_guid_t efi_guid_event_group_memory_map_change =
 const efi_guid_t efi_guid_event_group_ready_to_boot = EFI_EVENT_GROUP_READY_TO_BOOT;
 /* event group ResetSystem() invoked (before ExitBootServices) */
 const efi_guid_t efi_guid_event_group_reset_system = EFI_EVENT_GROUP_RESET_SYSTEM;
-/* GUIDs of the Load File and Load File2 protocols */
-const efi_guid_t efi_load_file_protocol_guid = EFI_LOAD_FILE_PROTOCOL_GUID;
-const efi_guid_t efi_load_file2_protocol_guid = EFI_LOAD_FILE2_PROTOCOL_GUID;
-const efi_guid_t efi_device_path_utilities_protocol_guid =
-	EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID;
-const efi_guid_t efi_linux_initrd_media_guid = EFI_LINUX_INITRD_MEDIA_GUID;
+
 
 #define EFI_GUID_STRING(guid, short, long) do {	\
 	if (!efi_guidcmp(guid, *g))		\
diff --git a/include/efi/guid.h b/include/efi/guid.h
index a5b26d420f05..a2bf8638c2e2 100644
--- a/include/efi/guid.h
+++ b/include/efi/guid.h
@@ -14,6 +14,8 @@ efi_guidcmp (efi_guid_t left, efi_guid_t right)
 	return memcmp(&left, &right, sizeof (efi_guid_t));
 }
 
+
+/* ---------- Protocol GUIDs ---------- */
 extern efi_guid_t efi_file_info_id;
 extern efi_guid_t efi_simple_file_system_protocol_guid;
 extern efi_guid_t efi_file_system_info_guid;
@@ -32,38 +34,11 @@ extern efi_guid_t efi_loaded_image_device_path_guid;
 extern const efi_guid_t efi_device_path_to_text_protocol_guid;
 extern const efi_guid_t efi_dt_fixup_protocol_guid;
 extern const efi_guid_t efi_driver_binding_protocol_guid;
-extern const efi_guid_t efi_guid_event_group_exit_boot_services;
-extern const efi_guid_t efi_guid_event_group_virtual_address_change;
-extern const efi_guid_t efi_guid_event_group_memory_map_change;
-extern const efi_guid_t efi_guid_event_group_ready_to_boot;
-extern const efi_guid_t efi_guid_event_group_reset_system;
 extern const efi_guid_t efi_load_file_protocol_guid;
 extern const efi_guid_t efi_load_file2_protocol_guid;
 extern const efi_guid_t efi_device_path_utilities_protocol_guid;
 extern const efi_guid_t efi_linux_initrd_media_guid;
 
-
-/* EFI event group GUID definitions */
-#define EFI_EVENT_GROUP_EXIT_BOOT_SERVICES \
-	EFI_GUID(0x27abf055, 0xb1b8, 0x4c26, 0x80, 0x48, \
-		 0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf)
-
-#define EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE \
-	EFI_GUID(0x13fa7698, 0xc831, 0x49c7, 0x87, 0xea, \
-		 0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96)
-
-#define EFI_EVENT_GROUP_MEMORY_MAP_CHANGE \
-	EFI_GUID(0x78bee926, 0x692f, 0x48fd, 0x9e, 0xdb, \
-		 0x01, 0x42, 0x2e, 0xf0, 0xd7, 0xab)
-
-#define EFI_EVENT_GROUP_READY_TO_BOOT \
-	EFI_GUID(0x7ce88fb3, 0x4bd7, 0x4679, 0x87, 0xa8, \
-		 0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b)
-
-#define EFI_EVENT_GROUP_RESET_SYSTEM \
-	EFI_GUID(0x62da6a56, 0x13fb, 0x485a, 0xa8, 0xda, \
-		 0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b)
-
 /*
  *  EFI Configuration Table and GUID definitions
  */
@@ -300,4 +275,30 @@ extern const efi_guid_t efi_linux_initrd_media_guid;
 #define EFI_RNG_ALGORITHM_RAW \
     EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61)
 
+
+/* ---------- Event  GUIDs ---------- */
+extern const efi_guid_t efi_guid_event_group_exit_boot_services;
+extern const efi_guid_t efi_guid_event_group_virtual_address_change;
+extern const efi_guid_t efi_guid_event_group_memory_map_change;
+extern const efi_guid_t efi_guid_event_group_ready_to_boot;
+extern const efi_guid_t efi_guid_event_group_reset_system;
+
+
+/* EFI event group GUID definitions */
+#define EFI_EVENT_GROUP_EXIT_BOOT_SERVICES \
+    EFI_GUID(0x27abf055, 0xb1b8, 0x4c26, 0x80, 0x48, 0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf)
+
+#define EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE \
+    EFI_GUID(0x13fa7698, 0xc831, 0x49c7, 0x87, 0xea, 0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96)
+
+#define EFI_EVENT_GROUP_MEMORY_MAP_CHANGE \
+    EFI_GUID(0x78bee926, 0x692f, 0x48fd, 0x9e, 0xdb, 0x01, 0x42, 0x2e, 0xf0, 0xd7, 0xab)
+
+#define EFI_EVENT_GROUP_READY_TO_BOOT \
+    EFI_GUID(0x7ce88fb3, 0x4bd7, 0x4679, 0x87, 0xa8, 0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b)
+
+#define EFI_EVENT_GROUP_RESET_SYSTEM \
+    EFI_GUID(0x62da6a56, 0x13fb, 0x485a, 0xa8, 0xda, 0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b)
+
+
 #endif
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 12/16] efi: guid: add some more GUIDs
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (10 preceding siblings ...)
  2025-12-11 20:30 ` [PATCH 11/16] efi: guid: don't interleave protocol and event GUIDs Ahmad Fatoum
@ 2025-12-11 20:30 ` Ahmad Fatoum
  2025-12-15  8:30   ` [PATCH] fixup! " Ahmad Fatoum
  2025-12-11 20:30 ` [PATCH 13/16] efi: guid: move static GUIDs out of drivers Ahmad Fatoum
                   ` (5 subsequent siblings)
  17 siblings, 1 reply; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:30 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

These GUIDs will be used by the upcoming barebox EFI loader support, so
add them all at once to avoid the churn.

They don't do harm if they are unreferenced.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/guid.c         | 21 ++++++++++++++++++
 include/efi/guid.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/efi/guid.c b/efi/guid.c
index 44f03c8046d9..8d4618df5730 100644
--- a/efi/guid.c
+++ b/efi/guid.c
@@ -13,9 +13,11 @@ efi_guid_t efi_loaded_image_protocol_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
 efi_guid_t efi_unknown_device_guid = EFI_UNKNOWN_DEVICE_GUID;
 efi_guid_t efi_null_guid = EFI_NULL_GUID;
 efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
+const efi_guid_t efi_guid_image_security_database = EFI_IMAGE_SECURITY_DATABASE_GUID;
 efi_guid_t efi_block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
 efi_guid_t efi_rng_protocol_guid = EFI_RNG_PROTOCOL_GUID;
 efi_guid_t efi_barebox_vendor_guid = EFI_BAREBOX_VENDOR_GUID;
+efi_guid_t efi_file_store_vars_guid = EFI_FILE_STORE_VARS_GUID;
 efi_guid_t efi_systemd_vendor_guid = EFI_SYSTEMD_VENDOR_GUID;
 efi_guid_t efi_fdt_guid = EFI_DEVICE_TREE_GUID;
 efi_guid_t efi_loaded_image_device_path_guid =
@@ -32,6 +34,19 @@ const efi_guid_t efi_load_file2_protocol_guid = EFI_LOAD_FILE2_PROTOCOL_GUID;
 const efi_guid_t efi_device_path_utilities_protocol_guid =
 	EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID;
 const efi_guid_t efi_linux_initrd_media_guid = EFI_LINUX_INITRD_MEDIA_GUID;
+const efi_guid_t efi_smbios_guid = EFI_SMBIOS_TABLE_GUID;
+const efi_guid_t efi_guid_hii_database_protocol = EFI_HII_DATABASE_PROTOCOL_GUID;
+const efi_guid_t efi_guid_hii_string_protocol = EFI_HII_STRING_PROTOCOL_GUID;
+const efi_guid_t efi_guid_hii_config_routing_protocol = EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID;
+const efi_guid_t efi_guid_hii_config_access_protocol = EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID;
+const efi_guid_t efi_guid_unicode_collation_protocol2 = EFI_UNICODE_COLLATION_PROTOCOL2_GUID;
+const efi_guid_t shim_lock_guid = SHIM_LOCK_GUID;
+/* GUID of the runtime properties table */
+const efi_guid_t efi_rt_properties_table_guid = EFI_RT_PROPERTIES_TABLE_GUID;
+const efi_guid_t efi_guid_firmware_management_protocol = EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID;
+const efi_guid_t efi_debug_image_info_table_guid = EFI_DEBUG_IMAGE_INFO_TABLE_GUID;
+const efi_guid_t efi_text_input_guid = EFI_SIMPLE_TEXT_IN_PROTOCOL_GUID;
+const efi_guid_t efi_text_output_guid = EFI_SIMPLE_TEXT_OUT_PROTOCOL_GUID;
 
 
 /* ---------- Event  GUIDs ---------- */
@@ -48,6 +63,12 @@ const efi_guid_t efi_guid_event_group_memory_map_change =
 const efi_guid_t efi_guid_event_group_ready_to_boot = EFI_EVENT_GROUP_READY_TO_BOOT;
 /* event group ResetSystem() invoked (before ExitBootServices) */
 const efi_guid_t efi_guid_event_group_reset_system = EFI_EVENT_GROUP_RESET_SYSTEM;
+/* event group before ExitBootServices() invoked */
+const efi_guid_t efi_guid_event_group_before_exit_boot_services =
+			EFI_EVENT_GROUP_BEFORE_EXIT_BOOT_SERVICES;
+/* event group return to efibootmgr */
+const efi_guid_t efi_guid_event_group_return_to_efibootmgr =
+			EFI_EVENT_GROUP_RETURN_TO_EFIBOOTMGR;
 
 
 #define EFI_GUID_STRING(guid, short, long) do {	\
diff --git a/include/efi/guid.h b/include/efi/guid.h
index a2bf8638c2e2..44fbe9f428ae 100644
--- a/include/efi/guid.h
+++ b/include/efi/guid.h
@@ -25,9 +25,11 @@ extern efi_guid_t efi_loaded_image_protocol_guid;
 extern efi_guid_t efi_unknown_device_guid;
 extern efi_guid_t efi_null_guid;
 extern efi_guid_t efi_global_variable_guid;
+extern const efi_guid_t efi_guid_image_security_database;
 extern efi_guid_t efi_block_io_protocol_guid;
 extern efi_guid_t efi_rng_protocol_guid;
 extern efi_guid_t efi_barebox_vendor_guid;
+extern efi_guid_t efi_file_store_vars_guid;
 extern efi_guid_t efi_systemd_vendor_guid;
 extern efi_guid_t efi_fdt_guid;
 extern efi_guid_t efi_loaded_image_device_path_guid;
@@ -38,6 +40,18 @@ extern const efi_guid_t efi_load_file_protocol_guid;
 extern const efi_guid_t efi_load_file2_protocol_guid;
 extern const efi_guid_t efi_device_path_utilities_protocol_guid;
 extern const efi_guid_t efi_linux_initrd_media_guid;
+extern const efi_guid_t efi_smbios_guid;
+extern const efi_guid_t efi_text_input_guid;
+extern const efi_guid_t efi_text_output_guid;
+extern const efi_guid_t efi_guid_unicode_collation_protocol2;
+extern const efi_guid_t efi_guid_hii_config_routing_protocol;
+extern const efi_guid_t efi_guid_hii_config_access_protocol;
+extern const efi_guid_t efi_guid_hii_database_protocol;
+extern const efi_guid_t efi_guid_hii_string_protocol;
+extern const efi_guid_t shim_lock_guid;
+extern const efi_guid_t efi_rt_properties_table_guid;
+extern const efi_guid_t efi_guid_firmware_management_protocol;
+extern const efi_guid_t efi_debug_image_info_table_guid;
 
 /*
  *  EFI Configuration Table and GUID definitions
@@ -69,9 +83,15 @@ extern const efi_guid_t efi_linux_initrd_media_guid;
 #define EFI_GLOBAL_VARIABLE_GUID \
     EFI_GUID(  0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c )
 
+#define EFI_IMAGE_SECURITY_DATABASE_GUID \
+    EFI_GUID(  0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f )
+
 #define EFI_UV_SYSTEM_TABLE_GUID \
     EFI_GUID(  0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93 )
 
+#define EFI_RT_PROPERTIES_TABLE_GUID \
+    EFI_GUID(  0xeb66918a, 0x7eef, 0x402a, 0x84, 0x2e, 0x93, 0x1d, 0x21, 0xc3, 0x8a, 0xe9 )
+
 #define EFI_LINUX_EFI_CRASH_GUID \
     EFI_GUID(  0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0 )
 
@@ -248,6 +268,9 @@ extern const efi_guid_t efi_linux_initrd_media_guid;
 #define EFI_BAREBOX_VENDOR_GUID \
     EFI_GUID(0x5b91f69c, 0x8b88, 0x4a2b, 0x92, 0x69, 0x5f, 0x1d, 0x80, 0x2b, 0x51, 0x75)
 
+#define EFI_FILE_STORE_VARS_GUID \
+    EFI_GUID(0xb2ac5fc9, 0x92b7, 0x4acd, 0xae, 0xac, 0x11, 0xe8, 0x18, 0xc3, 0x13, 0x0c)
+
 /* for systemd */
 #define EFI_SYSTEMD_VENDOR_GUID \
     EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
@@ -275,6 +298,30 @@ extern const efi_guid_t efi_linux_initrd_media_guid;
 #define EFI_RNG_ALGORITHM_RAW \
     EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61)
 
+#define EFI_HII_STRING_PROTOCOL_GUID \
+    EFI_GUID(0x0fd96974, 0x23aa, 0x4cdc, 0xb9, 0xcb, 0x98, 0xd1, 0x77, 0x50, 0x32, 0x2a)
+
+#define EFI_HII_DATABASE_PROTOCOL_GUID \
+    EFI_GUID(0xef9fc172, 0xa1b2, 0x4693, 0xb3, 0x27, 0x6d, 0x32, 0xfc, 0x41, 0x60, 0x42)
+
+#define EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID \
+    EFI_GUID(0x587e72d7, 0xcc50, 0x4f79, 0x82, 0x09, 0xca, 0x29, 0x1f, 0xc1, 0xa1, 0x0f)
+
+#define EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID \
+    EFI_GUID(0x330d4706, 0xf2a0, 0x4e4f, 0xa3, 0x69, 0xb6, 0x6f, 0xa8, 0xd5, 0x43, 0x85)
+
+#define EFI_UNICODE_COLLATION_PROTOCOL2_GUID \
+    EFI_GUID(0xa4c751fc, 0x23ae, 0x4c3e, 0x92, 0xe9, 0x49, 0x64, 0xcf, 0x63, 0xf3, 0x49)
+
+/* GUID used by Shim to store the MOK database */
+#define SHIM_LOCK_GUID \
+    EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23)
+
+#define EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID \
+    EFI_GUID(0x86c77a67, 0x0b97, 0x4633, 0xa1, 0x87, 0x49, 0x10, 0x4d, 0x06, 0x85, 0xc7)
+
+#define EFI_DEBUG_IMAGE_INFO_TABLE_GUID \
+   EFI_GUID(0x49152e77, 0x1ada, 0x4764, 0xb7, 0xa2, 0x7a, 0xfe, 0xfe, 0xd9, 0x5e, 0x8b)
 
 /* ---------- Event  GUIDs ---------- */
 extern const efi_guid_t efi_guid_event_group_exit_boot_services;
@@ -282,12 +329,17 @@ extern const efi_guid_t efi_guid_event_group_virtual_address_change;
 extern const efi_guid_t efi_guid_event_group_memory_map_change;
 extern const efi_guid_t efi_guid_event_group_ready_to_boot;
 extern const efi_guid_t efi_guid_event_group_reset_system;
+extern const efi_guid_t efi_guid_event_group_before_exit_boot_services;
+extern const efi_guid_t efi_guid_event_group_return_to_efibootmgr;
 
 
 /* EFI event group GUID definitions */
 #define EFI_EVENT_GROUP_EXIT_BOOT_SERVICES \
     EFI_GUID(0x27abf055, 0xb1b8, 0x4c26, 0x80, 0x48, 0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf)
 
+#define EFI_EVENT_GROUP_BEFORE_EXIT_BOOT_SERVICES \
+    EFI_GUID(0x8be0e274, 0x3970, 0x4b44, 0x80, 0xc5, 0x1a, 0xb9, 0x50, 0x2f, 0x3b, 0xfc)
+
 #define EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE \
     EFI_GUID(0x13fa7698, 0xc831, 0x49c7, 0x87, 0xea, 0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96)
 
@@ -300,5 +352,7 @@ extern const efi_guid_t efi_guid_event_group_reset_system;
 #define EFI_EVENT_GROUP_RESET_SYSTEM \
     EFI_GUID(0x62da6a56, 0x13fb, 0x485a, 0xa8, 0xda, 0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b)
 
+#define EFI_EVENT_GROUP_RETURN_TO_EFIBOOTMGR \
+    EFI_GUID(0xb4a40fe6, 0x9149, 0x4f29, 0x94, 0x47, 0x49, 0x38, 0x7a, 0x7f, 0xab, 0x87)
 
 #endif
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 13/16] efi: guid: move static GUIDs out of drivers
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (11 preceding siblings ...)
  2025-12-11 20:30 ` [PATCH 12/16] efi: guid: add some more GUIDs Ahmad Fatoum
@ 2025-12-11 20:30 ` Ahmad Fatoum
  2025-12-11 20:30 ` [PATCH 14/16] efi: gop: flesh out efi_graphics_output_protocol::blt definition Ahmad Fatoum
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:30 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The GUIDs for SNP, STDIO and GOP drivers are compiled statically into
the drivers using them. The same GUIDs will be used for barebox acting
as EFI loader as well, so move them to the common efi/guid.c to allow
reuse.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/net/efi-snp.c      | 6 ++----
 drivers/serial/efi-stdio.c | 3 +--
 drivers/video/efi_gop.c    | 3 +--
 efi/guid.c                 | 3 +++
 include/efi/guid.h         | 3 +++
 5 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/net/efi-snp.c b/drivers/net/efi-snp.c
index 5dffe3793426..3927ebbb8be9 100644
--- a/drivers/net/efi-snp.c
+++ b/drivers/net/efi-snp.c
@@ -75,8 +75,6 @@ static void efi_snp_eth_rx(struct eth_device *edev)
 	net_receive(edev, priv->rx_buf, bufsize);
 }
 
-static efi_guid_t snp_guid = EFI_SIMPLE_NETWORK_PROTOCOL_GUID;
-
 static int efi_snp_open_exclusive(struct efi_device *efidev)
 {
 	void *interface;
@@ -86,7 +84,7 @@ static int efi_snp_open_exclusive(struct efi_device *efidev)
 	 * Try to re-open SNP exlusively to close any active MNP protocol instance
 	 * that may compete for packet polling
 	 */
-	efiret = BS->open_protocol(efidev->handle, &snp_guid,
+	efiret = BS->open_protocol(efidev->handle, &efi_snp_guid,
 			&interface, efi_parent_image, NULL, EFI_OPEN_PROTOCOL_EXCLUSIVE);
 	if (EFI_ERROR(efiret)) {
 		dev_err(&efidev->dev, "failed to open exclusively: %s\n", efi_strerror(efiret));
@@ -98,7 +96,7 @@ static int efi_snp_open_exclusive(struct efi_device *efidev)
 
 static void efi_snp_close_exclusive(struct efi_device *efidev)
 {
-	BS->close_protocol(efidev->handle, &snp_guid, efi_parent_image, NULL);
+	BS->close_protocol(efidev->handle, &efi_snp_guid, efi_parent_image, NULL);
 }
 
 static int efi_snp_eth_open(struct eth_device *edev)
diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c
index 3390600be389..cbeda6f3bb8b 100644
--- a/drivers/serial/efi-stdio.c
+++ b/drivers/serial/efi-stdio.c
@@ -423,7 +423,6 @@ static void efi_set_mode(struct efi_console_priv *priv)
 
 static int efi_console_probe(struct device *dev)
 {
-	efi_guid_t inex_guid = EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID;
 	struct efi_simple_text_input_ex_protocol *inex;
 	struct console_device *cdev;
 	struct efi_console_priv *priv;
@@ -440,7 +439,7 @@ static int efi_console_probe(struct device *dev)
 		return -ENOMEM;
 
 	efiret = BS->open_protocol(efi_sys_table->con_in_handle,
-			     &inex_guid,
+			     &efi_text_input_ex_guid,
 			     (void **)&inex,
 			     efi_parent_image,
 			     0,
diff --git a/drivers/video/efi_gop.c b/drivers/video/efi_gop.c
index 00ebd2fcbd55..aff1e45b28a2 100644
--- a/drivers/video/efi_gop.c
+++ b/drivers/video/efi_gop.c
@@ -163,10 +163,9 @@ static int efi_gop_probe(struct efi_device *efidev)
 	struct efi_gop_priv *priv;
 	int ret = 0;
 	efi_status_t efiret;
-	efi_guid_t got_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
 	void *protocol;
 
-	efiret = BS->handle_protocol(efidev->handle, &got_guid, &protocol);
+	efiret = BS->handle_protocol(efidev->handle, &efi_gop_guid, &protocol);
 	if (EFI_ERROR(efiret))
 		return  -efi_errno(efiret);
 
diff --git a/efi/guid.c b/efi/guid.c
index 8d4618df5730..8b29ba52fbe6 100644
--- a/efi/guid.c
+++ b/efi/guid.c
@@ -45,6 +45,9 @@ const efi_guid_t shim_lock_guid = SHIM_LOCK_GUID;
 const efi_guid_t efi_rt_properties_table_guid = EFI_RT_PROPERTIES_TABLE_GUID;
 const efi_guid_t efi_guid_firmware_management_protocol = EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID;
 const efi_guid_t efi_debug_image_info_table_guid = EFI_DEBUG_IMAGE_INFO_TABLE_GUID;
+const efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
+const efi_guid_t efi_snp_guid = EFI_SIMPLE_NETWORK_PROTOCOL_GUID;
+const efi_guid_t efi_text_input_ex_guid = EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID;
 const efi_guid_t efi_text_input_guid = EFI_SIMPLE_TEXT_IN_PROTOCOL_GUID;
 const efi_guid_t efi_text_output_guid = EFI_SIMPLE_TEXT_OUT_PROTOCOL_GUID;
 
diff --git a/include/efi/guid.h b/include/efi/guid.h
index 44fbe9f428ae..c36faaf72350 100644
--- a/include/efi/guid.h
+++ b/include/efi/guid.h
@@ -41,6 +41,9 @@ extern const efi_guid_t efi_load_file2_protocol_guid;
 extern const efi_guid_t efi_device_path_utilities_protocol_guid;
 extern const efi_guid_t efi_linux_initrd_media_guid;
 extern const efi_guid_t efi_smbios_guid;
+extern const efi_guid_t efi_gop_guid;
+extern const efi_guid_t efi_snp_guid;
+extern const efi_guid_t efi_text_input_ex_guid;
 extern const efi_guid_t efi_text_input_guid;
 extern const efi_guid_t efi_text_output_guid;
 extern const efi_guid_t efi_guid_unicode_collation_protocol2;
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 14/16] efi: gop: flesh out efi_graphics_output_protocol::blt definition
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (12 preceding siblings ...)
  2025-12-11 20:30 ` [PATCH 13/16] efi: guid: move static GUIDs out of drivers Ahmad Fatoum
@ 2025-12-11 20:30 ` Ahmad Fatoum
  2025-12-11 20:30 ` [PATCH 15/16] efi: payload: initrd: move into common efi code Ahmad Fatoum
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:30 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We don't use this callback, but the GOP implementation in barebox as EFI
loader will, so set the stage for that.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/efi/protocol/gop.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/include/efi/protocol/gop.h b/include/efi/protocol/gop.h
index bad9f64f0623..04d139ffcb3f 100644
--- a/include/efi/protocol/gop.h
+++ b/include/efi/protocol/gop.h
@@ -42,12 +42,11 @@ struct efi_graphics_output_protocol {
 	efi_status_t (EFIAPI *set_mode) (struct efi_graphics_output_protocol *This,
 			uint32_t mode_number);
 	efi_status_t (EFIAPI *blt)(struct efi_graphics_output_protocol *This,
-			void *buffer,
-			unsigned long operation,
-			unsigned long sourcex, unsigned long sourcey,
-			unsigned long destinationx, unsigned long destinationy,
-			unsigned long width, unsigned long height, unsigned
-			long delta);
+			struct efi_pixel_bitmask *buffer,
+			u32 operation,
+			size_t sourcex, size_t sourcey,
+			size_t destinationx, size_t destinationy,
+			size_t width, size_t height, size_t delta);
 	struct efi_graphics_output_protocol_mode *mode;
 };
 
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 15/16] efi: payload: initrd: move into common efi code
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (13 preceding siblings ...)
  2025-12-11 20:30 ` [PATCH 14/16] efi: gop: flesh out efi_graphics_output_protocol::blt definition Ahmad Fatoum
@ 2025-12-11 20:30 ` Ahmad Fatoum
  2025-12-11 20:30 ` [PATCH 16/16] efi: add missing EFIAPI to functions Ahmad Fatoum
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:30 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

This code will be equally useful for barebox running as EFI loader, so
move it to a common location and touch it up to be reusable.

While at it, drop unneeded headers.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/Makefile                           |  1 +
 efi/{payload/efi-initrd.c => initrd.c} | 20 +++++++++++++-------
 efi/payload/Makefile                   |  1 -
 3 files changed, 14 insertions(+), 8 deletions(-)
 rename efi/{payload/efi-initrd.c => initrd.c} (87%)

diff --git a/efi/Makefile b/efi/Makefile
index 6693564f7071..4c35917475c0 100644
--- a/efi/Makefile
+++ b/efi/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_EFI_PAYLOAD)	+= payload/
 obj-$(CONFIG_EFI_GUID)		+= guid.o
 obj-$(CONFIG_EFI_DEVICEPATH)	+= devicepath.o
 obj-y				+= errno.o handle.o efivar.o efivar-filename.o
+obj-y				+= initrd.o
diff --git a/efi/payload/efi-initrd.c b/efi/initrd.c
similarity index 87%
rename from efi/payload/efi-initrd.c
rename to efi/initrd.c
index 708418da62b7..7fd8e021f353 100644
--- a/efi/payload/efi-initrd.c
+++ b/efi/initrd.c
@@ -5,15 +5,14 @@
  * Copyright (c) 2025 Anis Chali <chalianis1@gmail.com>
  * Copyright (C) 2025 Ahmad Fatoum <a.fatoum@pengutronix.de>
  */
-#include <common.h>
-#include <driver.h>
 #include <init.h>
 #include <linux/hw_random.h>
 #include <efi/devicepath.h>
+#include <efi/mode.h>
+#include <efi/services.h>
 #include <efi/protocol/file.h>
-#include <efi/protocol/initrd.h>
+#include <efi/initrd.h>
 #include <efi/guid.h>
-#include <efi/payload.h>
 #include <efi/error.h>
 
 static efi_status_t EFIAPI efi_initrd_load_file2(
@@ -73,6 +72,7 @@ static efi_status_t EFIAPI efi_initrd_load_file2(
 
 int efi_initrd_register(void *initrd_base, size_t initrd_sz)
 {
+	struct efi_boot_services *bs;
 	efi_status_t efiret;
 	int ret;
 
@@ -80,7 +80,11 @@ int efi_initrd_register(void *initrd_base, size_t initrd_sz)
 	initrd.start = initrd_base;
 	initrd.size = initrd_sz;
 
-	efiret = BS->install_multiple_protocol_interfaces(
+	bs = efi_get_boot_services();
+	if (!bs)
+		return -EOPNOTSUPP;
+
+	efiret = bs->install_multiple_protocol_interfaces(
 		&initrd.lf2_handle, &efi_load_file2_protocol_guid, &initrd.base,
 		&efi_device_path_protocol_guid, &initrd_dev_path, NULL);
 	if (EFI_ERROR(efiret)) {
@@ -95,10 +99,12 @@ int efi_initrd_register(void *initrd_base, size_t initrd_sz)
 
 void efi_initrd_unregister(void)
 {
-	if (!initrd.base.load_file)
+	struct efi_boot_services *bs = efi_get_boot_services();
+
+	if (!bs || !initrd.base.load_file)
 		return;
 
-	BS->uninstall_multiple_protocol_interfaces(
+	bs->uninstall_multiple_protocol_interfaces(
 		initrd.lf2_handle, &efi_device_path_protocol_guid, &initrd_dev_path,
 		&efi_load_file2_protocol_guid, &initrd.base, NULL);
 
diff --git a/efi/payload/Makefile b/efi/payload/Makefile
index 34efe6105d22..6306540ab595 100644
--- a/efi/payload/Makefile
+++ b/efi/payload/Makefile
@@ -4,7 +4,6 @@ obj-y += init.o
 obj-y += image.o
 obj-$(CONFIG_EFI_HANDOVER_PROTOCOL) += handover.o
 obj-y += bootm.o
-obj-y += efi-initrd.o
 obj-$(CONFIG_OFTREE) += fdt.o
 bbenv-y += env-efi
 obj-$(CONFIG_CMD_IOMEM) += iomem.o
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 16/16] efi: add missing EFIAPI to functions
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (14 preceding siblings ...)
  2025-12-11 20:30 ` [PATCH 15/16] efi: payload: initrd: move into common efi code Ahmad Fatoum
@ 2025-12-11 20:30 ` Ahmad Fatoum
  2025-12-13 10:42 ` [PATCH] fixup! efi: payload: restructure Kconfig Ahmad Fatoum
  2025-12-15  9:03 ` [PATCH 00/16] efi: restructure for reuse from loader code Sascha Hauer
  17 siblings, 0 replies; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:30 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

EFI functions have a different calling convention on x86, but this was
missed for a few functions and function pointers.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/clocksource/efi.c | 2 +-
 include/efi/services.h    | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
index 534bea5525c4..7a07db0af83d 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi.c
@@ -18,7 +18,7 @@ static uint64_t efi_cs_read(void)
 	return ticks;
 }
 
-static void efi_cs_inc(struct efi_event *event, void *ctx)
+static void EFIAPI efi_cs_inc(struct efi_event *event, void *ctx)
 {
 	ticks++;
 }
diff --git a/include/efi/services.h b/include/efi/services.h
index 9fc6a066a917..eaeaf1a55ee8 100644
--- a/include/efi/services.h
+++ b/include/efi/services.h
@@ -65,7 +65,7 @@ struct efi_boot_services {
 #define EFI_TPL_NOTIFY		16
 #define EFI_TPL_HIGH_LEVEL	31
 	efi_status_t(EFIAPI *create_event)(u32 type , unsigned long tpl,
-			void (*fn) (struct efi_event *event, void *ctx),
+			void (EFIAPI *fn) (struct efi_event *event, void *ctx),
 			void *ctx, struct efi_event **event);
 	efi_status_t(EFIAPI *set_timer)(struct efi_event *event, enum efi_timer_delay type, uint64_t time);
 	efi_status_t(EFIAPI *wait_for_event)(size_t number_of_events, struct efi_event **event,
@@ -174,7 +174,7 @@ struct efi_runtime_services {
 				       size_t descriptor_size,
 				       uint32_t descriptor_version,
 				       struct efi_memory_desc *virtmap);
-	efi_status_t (*convert_pointer)(unsigned long dbg, void **address);
+	efi_status_t (EFIAPI *convert_pointer)(unsigned long dbg, void **address);
 	efi_status_t (EFIAPI *get_variable)(efi_char16_t *variable_name, const efi_guid_t *vendor,
 			u32 *Attributes, size_t *data_size, void *data);
 	efi_status_t (EFIAPI *get_next_variable)(size_t *variable_name_size,
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH] fixup! efi: payload: restructure Kconfig
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (15 preceding siblings ...)
  2025-12-11 20:30 ` [PATCH 16/16] efi: add missing EFIAPI to functions Ahmad Fatoum
@ 2025-12-13 10:42 ` Ahmad Fatoum
  2025-12-15  9:03   ` (subset) " Sascha Hauer
  2025-12-15  9:03 ` [PATCH 00/16] efi: restructure for reuse from loader code Sascha Hauer
  17 siblings, 1 reply; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-13 10:42 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

efi: payload: reinstate lost EFI_STUB option

This one was lost while moving stuff across files.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/payload/Kconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/efi/payload/Kconfig b/efi/payload/Kconfig
index 01f54ee7cf10..a5496ab766ad 100644
--- a/efi/payload/Kconfig
+++ b/efi/payload/Kconfig
@@ -32,3 +32,6 @@ config EFI_HANDOVER_PROTOCOL
 config EFI_PAYLOAD_BOOTM
 	bool "EFI bootm protocol"
 	default !X86
+
+config EFI_STUB
+       def_bool HAVE_EFI_STUB
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH] fixup! efi: guid: add some more GUIDs
  2025-12-11 20:30 ` [PATCH 12/16] efi: guid: add some more GUIDs Ahmad Fatoum
@ 2025-12-15  8:30   ` Ahmad Fatoum
  2025-12-15  9:03     ` Sascha Hauer
  0 siblings, 1 reply; 22+ messages in thread
From: Ahmad Fatoum @ 2025-12-15  8:30 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

efi: guid: add SMBIOS3 GUID as well

The EFI loader will install a table with a SMBIOS3 table, so let's
squeeze its GUID in for preparation.

Having all GUIDs added in a single commit gives some more flexibility
with ordering the protocols and tables for which support is going to be
added.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/guid.c         | 1 +
 include/efi/guid.h | 8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/efi/guid.c b/efi/guid.c
index cbea412c1c42..8853829d216b 100644
--- a/efi/guid.c
+++ b/efi/guid.c
@@ -35,6 +35,7 @@ const efi_guid_t efi_device_path_utilities_protocol_guid =
 	EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID;
 const efi_guid_t efi_linux_initrd_media_guid = EFI_LINUX_INITRD_MEDIA_GUID;
 const efi_guid_t efi_smbios_guid = EFI_SMBIOS_TABLE_GUID;
+const efi_guid_t efi_smbios3_guid = EFI_SMBIOS3_TABLE_GUID;
 const efi_guid_t efi_guid_hii_database_protocol = EFI_HII_DATABASE_PROTOCOL_GUID;
 const efi_guid_t efi_guid_hii_string_protocol = EFI_HII_STRING_PROTOCOL_GUID;
 const efi_guid_t efi_guid_hii_config_routing_protocol = EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID;
diff --git a/include/efi/guid.h b/include/efi/guid.h
index eafd80b25ccd..202300c74aaa 100644
--- a/include/efi/guid.h
+++ b/include/efi/guid.h
@@ -41,6 +41,7 @@ extern const efi_guid_t efi_load_file2_protocol_guid;
 extern const efi_guid_t efi_device_path_utilities_protocol_guid;
 extern const efi_guid_t efi_linux_initrd_media_guid;
 extern const efi_guid_t efi_smbios_guid;
+extern const efi_guid_t efi_smbios3_guid;
 extern const efi_guid_t efi_gop_guid;
 extern const efi_guid_t efi_snp_guid;
 extern const efi_guid_t efi_text_input_ex_guid;
@@ -71,8 +72,11 @@ extern const efi_guid_t efi_debug_image_info_table_guid;
 #define EFI_ACPI_20_TABLE_GUID    \
     EFI_GUID(  0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 )
 
-#define EFI_SMBIOS_TABLE_GUID    \
-    EFI_GUID(  0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
+#define EFI_SMBIOS_TABLE_GUID \
+    EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
+
+#define EFI_SMBIOS3_TABLE_GUID \
+    EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 )
 
 #define EFI_SAL_SYSTEM_TABLE_GUID    \
     EFI_GUID(  0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
-- 
2.47.3




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: (subset) [PATCH] fixup! efi: payload: restructure Kconfig
  2025-12-13 10:42 ` [PATCH] fixup! efi: payload: restructure Kconfig Ahmad Fatoum
@ 2025-12-15  9:03   ` Sascha Hauer
  0 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-12-15  9:03 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Sat, 13 Dec 2025 11:42:09 +0100, Ahmad Fatoum wrote:
> efi: payload: reinstate lost EFI_STUB option
> 
> This one was lost while moving stuff across files.
> 
> 

Applied, thanks!

[1/1] fixup! efi: payload: restructure Kconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=04420713a696 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 00/16] efi: restructure for reuse from loader code
  2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
                   ` (16 preceding siblings ...)
  2025-12-13 10:42 ` [PATCH] fixup! efi: payload: restructure Kconfig Ahmad Fatoum
@ 2025-12-15  9:03 ` Sascha Hauer
  17 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-12-15  9:03 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Thu, 11 Dec 2025 21:29:51 +0100, Ahmad Fatoum wrote:
> This series mostly prepares existing definitions and code used for
> payload so it can be reused from the new loader support as well.
> 
> Ahmad Fatoum (16):
>   efi: payload: restructure Kconfig
>   efi: payload: populate $global.efi.payload variable
>   efi: mode: add efi_get_runtime_services helper
>   efi: payload: make EFI variable helpers usable for loader as well
>   fs: efivarfs: prepare for use with barebox as EFI loader
>   efi: handle: build for both EFI payload and loader
>   efi: provide populate $efi.payload_default_path depending on arch
>   efi: tidy up header includes for reuse
>   efi: types: add efi_intn_t/efi_uintn_t definition
>   efi: devicepath: make fully usable for loader
>   efi: guid: don't interleave protocol and event GUIDs
>   efi: guid: add some more GUIDs
>   efi: guid: move static GUIDs out of drivers
>   efi: gop: flesh out efi_graphics_output_protocol::blt definition
>   efi: payload: initrd: move into common efi code
>   efi: add missing EFIAPI to functions
> 
> [...]

Applied, thanks!

[01/1] fixup! efi: guid: add some more GUIDs
       https://git.pengutronix.de/cgit/barebox/commit/?id=9c5619f9019a (link may not be stable)
[01/16] efi: payload: restructure Kconfig
        https://git.pengutronix.de/cgit/barebox/commit/?id=ed21fe7e6efd (link may not be stable)
[03/16] efi: mode: add efi_get_runtime_services helper
        https://git.pengutronix.de/cgit/barebox/commit/?id=dcabd235966d (link may not be stable)
[04/16] efi: payload: make EFI variable helpers usable for loader as well
        https://git.pengutronix.de/cgit/barebox/commit/?id=b0f46a7df454 (link may not be stable)
[05/16] fs: efivarfs: prepare for use with barebox as EFI loader
        https://git.pengutronix.de/cgit/barebox/commit/?id=a3ebd37e7fb9 (link may not be stable)
[06/16] efi: handle: build for both EFI payload and loader
        https://git.pengutronix.de/cgit/barebox/commit/?id=63d6011df954 (link may not be stable)
[07/16] efi: provide populate $efi.payload_default_path depending on arch
        https://git.pengutronix.de/cgit/barebox/commit/?id=eb4971313129 (link may not be stable)
[08/16] efi: tidy up header includes for reuse
        https://git.pengutronix.de/cgit/barebox/commit/?id=df0789c9d8f7 (link may not be stable)
[09/16] efi: types: add efi_intn_t/efi_uintn_t definition
        https://git.pengutronix.de/cgit/barebox/commit/?id=f5c433fd496c (link may not be stable)
[10/16] efi: devicepath: make fully usable for loader
        https://git.pengutronix.de/cgit/barebox/commit/?id=ee9e080b46de (link may not be stable)
[11/16] efi: guid: don't interleave protocol and event GUIDs
        https://git.pengutronix.de/cgit/barebox/commit/?id=1d5d1afd83f9 (link may not be stable)
[12/16] efi: guid: add some more GUIDs
        https://git.pengutronix.de/cgit/barebox/commit/?id=4f3ff37a63ab (link may not be stable)
[13/16] efi: guid: move static GUIDs out of drivers
        https://git.pengutronix.de/cgit/barebox/commit/?id=8a860f8eea13 (link may not be stable)
[14/16] efi: gop: flesh out efi_graphics_output_protocol::blt definition
        https://git.pengutronix.de/cgit/barebox/commit/?id=e014bb52f015 (link may not be stable)
[15/16] efi: payload: initrd: move into common efi code
        https://git.pengutronix.de/cgit/barebox/commit/?id=919f43c39c50 (link may not be stable)
[16/16] efi: add missing EFIAPI to functions
        https://git.pengutronix.de/cgit/barebox/commit/?id=488b96b307a2 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH] fixup! efi: guid: add some more GUIDs
  2025-12-15  8:30   ` [PATCH] fixup! " Ahmad Fatoum
@ 2025-12-15  9:03     ` Sascha Hauer
  0 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-12-15  9:03 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 15 Dec 2025 09:30:22 +0100, Ahmad Fatoum wrote:
> efi: guid: add SMBIOS3 GUID as well
> 
> The EFI loader will install a table with a SMBIOS3 table, so let's
> squeeze its GUID in for preparation.
> 
> Having all GUIDs added in a single commit gives some more flexibility
> with ordering the protocols and tables for which support is going to be
> added.
> 
> [...]

Applied, thanks!

[1/1] fixup! efi: guid: add some more GUIDs
      https://git.pengutronix.de/cgit/barebox/commit/?id=9c5619f9019a (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2025-12-15  9:04 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 01/16] efi: payload: restructure Kconfig Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 02/16] efi: payload: populate $global.efi.payload variable Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 03/16] efi: mode: add efi_get_runtime_services helper Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 04/16] efi: payload: make EFI variable helpers usable for loader as well Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 05/16] fs: efivarfs: prepare for use with barebox as EFI loader Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 06/16] efi: handle: build for both EFI payload and loader Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 07/16] efi: provide populate $efi.payload_default_path depending on arch Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 08/16] efi: tidy up header includes for reuse Ahmad Fatoum
2025-12-11 20:30 ` [PATCH 09/16] efi: types: add efi_intn_t/efi_uintn_t definition Ahmad Fatoum
2025-12-11 20:30 ` [PATCH 10/16] efi: devicepath: make fully usable for loader Ahmad Fatoum
2025-12-11 20:30 ` [PATCH 11/16] efi: guid: don't interleave protocol and event GUIDs Ahmad Fatoum
2025-12-11 20:30 ` [PATCH 12/16] efi: guid: add some more GUIDs Ahmad Fatoum
2025-12-15  8:30   ` [PATCH] fixup! " Ahmad Fatoum
2025-12-15  9:03     ` Sascha Hauer
2025-12-11 20:30 ` [PATCH 13/16] efi: guid: move static GUIDs out of drivers Ahmad Fatoum
2025-12-11 20:30 ` [PATCH 14/16] efi: gop: flesh out efi_graphics_output_protocol::blt definition Ahmad Fatoum
2025-12-11 20:30 ` [PATCH 15/16] efi: payload: initrd: move into common efi code Ahmad Fatoum
2025-12-11 20:30 ` [PATCH 16/16] efi: add missing EFIAPI to functions Ahmad Fatoum
2025-12-13 10:42 ` [PATCH] fixup! efi: payload: restructure Kconfig Ahmad Fatoum
2025-12-15  9:03   ` (subset) " Sascha Hauer
2025-12-15  9:03 ` [PATCH 00/16] efi: restructure for reuse from loader code Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox