summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2024-03-04 19:59:38 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-03-05 16:28:05 +0100
commita1c7c158eedf0c810b521d68e622428518224974 (patch)
tree6143ba0c002c43fb52e1535e3cf86ca2a548ca0d
parent05d94839c918231b2fa70fd4a28a90210b120046 (diff)
downloadbarebox-a1c7c158eedf.tar.gz
barebox-a1c7c158eedf.tar.xz
efi: make headers self-contained
With the loader support, efi.h will grow quite a bit. To avoid having to include it always, lets move the base definitions into a new <efi/types.h> and make the different <efi/*.h> headers self contained. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-54-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/hw_random/efi-rng.c2
-rw-r--r--efi/devicepath.c1
-rw-r--r--efi/errno.c1
-rw-r--r--efi/guid.c1
-rw-r--r--efi/payload/fdt.c1
-rw-r--r--include/efi.h72
-rw-r--r--include/efi/device-path.h2
-rw-r--r--include/efi/efi-device.h4
-rw-r--r--include/efi/efi-payload.h6
-rw-r--r--include/efi/efi-stdio.h7
-rw-r--r--include/efi/efi-util.h8
-rw-r--r--include/efi/types.h66
12 files changed, 97 insertions, 74 deletions
diff --git a/drivers/hw_random/efi-rng.c b/drivers/hw_random/efi-rng.c
index b74075e3a4..61cb01caf6 100644
--- a/drivers/hw_random/efi-rng.c
+++ b/drivers/hw_random/efi-rng.c
@@ -3,7 +3,7 @@
#include <driver.h>
#include <init.h>
#include <linux/hw_random.h>
-#include <efi/efi-util.h>
+#include <efi.h>
#include <efi/efi-device.h>
struct efi_rng_priv {
diff --git a/efi/devicepath.c b/efi/devicepath.c
index fad36c78a2..63b0ea61f0 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -2,6 +2,7 @@
#include <common.h>
#include <efi.h>
+#include <efi/efi-util.h>
#include <malloc.h>
#include <string.h>
#include <wchar.h>
diff --git a/efi/errno.c b/efi/errno.c
index 3bb68e7781..ed14b1a8a6 100644
--- a/efi/errno.c
+++ b/efi/errno.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <efi/efi-util.h>
+#include <efi.h>
#include <errno.h>
const char *efi_strerror(efi_status_t err)
diff --git a/efi/guid.c b/efi/guid.c
index ca16f4520f..8103b3d631 100644
--- a/efi/guid.c
+++ b/efi/guid.c
@@ -2,6 +2,7 @@
#include <common.h>
#include <efi.h>
+#include <efi/efi-util.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/payload/fdt.c b/efi/payload/fdt.c
index faa7a5ad8d..8dacaa8b52 100644
--- a/efi/payload/fdt.c
+++ b/efi/payload/fdt.c
@@ -5,6 +5,7 @@
#include <common.h>
#include <init.h>
#include <libfile.h>
+#include <efi.h>
#include <efi/efi-payload.h>
#include <efi/efi-device.h>
diff --git a/include/efi.h b/include/efi.h
index 10e22f1e9f..2b248a1701 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -14,15 +14,7 @@
*/
#include <linux/string.h>
#include <linux/types.h>
-#include <linux/uuid.h>
-
-#ifdef CONFIG_EFI_PAYLOAD
-#define EFIAPI __attribute__((ms_abi))
-#else
-#define EFIAPI
-#endif
-
-struct efi_device_path;
+#include <efi/types.h>
/* Bit mask for EFI status code with error */
#define EFI_ERROR_MASK (1UL << (BITS_PER_LONG-1))
@@ -62,33 +54,6 @@ struct efi_device_path;
#define EFI_ERROR(a) (((signed long) a) < 0)
-typedef unsigned long efi_status_t;
-typedef u16 efi_char16_t; /* UNICODE character */
-typedef u64 efi_physical_addr_t;
-typedef void *efi_handle_t;
-
-/*
- * The UEFI spec and EDK2 reference implementation both define EFI_GUID as
- * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment
- * is 32 bits not 8 bits like our guid_t. In some cases (i.e., on 32-bit ARM),
- * this means that firmware services invoked by the kernel may assume that
- * efi_guid_t* arguments are 32-bit aligned, and use memory accessors that
- * do not tolerate misalignment. So let's set the minimum alignment to 32 bits.
- *
- * Note that the UEFI spec as well as some comments in the EDK2 code base
- * suggest that EFI_GUID should be 64-bit aligned, but this appears to be
- * a mistake, given that no code seems to exist that actually enforces that
- * or relies on it.
- */
-typedef guid_t efi_guid_t __aligned(__alignof__(u32));
-
-#define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
-((efi_guid_t) \
-{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
- (b) & 0xff, ((b) >> 8) & 0xff, \
- (c) & 0xff, ((c) >> 8) & 0xff, \
- (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
-
/*
* Generic EFI table header
*/
@@ -605,12 +570,6 @@ struct efi_loaded_image {
unsigned long unload;
};
-static inline int
-efi_guidcmp (efi_guid_t left, efi_guid_t right)
-{
- return memcmp(&left, &right, sizeof (efi_guid_t));
-}
-
__attribute__((noreturn)) void efi_main(efi_handle_t, struct efi_system_table *);
/*
@@ -637,12 +596,6 @@ __attribute__((noreturn)) void efi_main(efi_handle_t, struct efi_system_table *)
*/
#define EFI_VARIABLE_GUID_LEN 36
-struct efi_device_path {
- u8 type;
- u8 sub_type;
- u16 length;
-} __attribute ((packed));
-
struct simple_text_output_mode {
s32 max_mode;
s32 mode;
@@ -670,10 +623,7 @@ struct efi_simple_text_output_protocol {
struct simple_text_output_mode *mode;
};
-struct efi_input_key {
- u16 scan_code;
- s16 unicode_char;
-};
+struct efi_input_key;
struct efi_simple_input_interface {
efi_status_t(EFIAPI *reset)(struct efi_simple_input_interface *this,
@@ -683,24 +633,6 @@ struct efi_simple_input_interface {
void *wait_for_key;
};
-struct efi_mac_address {
- uint8_t Addr[32];
-};
-
-struct efi_ipv4_address {
- uint8_t Addr[4];
-};
-
-struct efi_ipv6_address {
- uint8_t Addr[16];
-};
-
-union efi_ip_address {
- uint32_t Addr[4];
- struct efi_ipv4_address v4;
- struct efi_ipv6_address v6;
-};
-
struct efi_device_path *device_path_from_handle(efi_handle_t Handle);
char *device_path_to_str(struct efi_device_path *dev_path);
u8 device_path_to_type(struct efi_device_path *dev_path);
diff --git a/include/efi/device-path.h b/include/efi/device-path.h
index 2882b87d68..4b97cadde4 100644
--- a/include/efi/device-path.h
+++ b/include/efi/device-path.h
@@ -1,6 +1,8 @@
#ifndef __EFI_DEVICE_PATH_H
#define __EFI_DEVICE_PATH_H
+#include <efi/types.h>
+
/*
* Hardware Device Path (UEFI 2.4 specification, version 2.4 ยง 9.3.2.)
*/
diff --git a/include/efi/efi-device.h b/include/efi/efi-device.h
index cb665edf65..eaf89beb8e 100644
--- a/include/efi/efi-device.h
+++ b/include/efi/efi-device.h
@@ -2,6 +2,10 @@
#ifndef __EFI_EFI_DEVICE_H
#define __EFI_EFI_DEVICE_H
+#include <efi/types.h>
+#include <efi/efi-util.h>
+#include <driver.h>
+
struct efi_device {
struct device dev;
efi_guid_t *guids;
diff --git a/include/efi/efi-payload.h b/include/efi/efi-payload.h
index cddd8c8ddd..3713ef3592 100644
--- a/include/efi/efi-payload.h
+++ b/include/efi/efi-payload.h
@@ -2,9 +2,12 @@
#ifndef __EFI_PAYLOAD_H
#define __EFI_PAYLOAD_H
-#include <efi.h>
+#include <efi/types.h>
#include <efi/efi-util.h>
+struct efi_system_table;
+struct efi_loaded_image;
+
extern struct efi_system_table *efi_sys_table;
extern efi_handle_t efi_parent_image;
extern struct efi_device_path *efi_device_path;
@@ -14,6 +17,7 @@ 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);
}
diff --git a/include/efi/efi-stdio.h b/include/efi/efi-stdio.h
index e8af244bfc..623b42c10f 100644
--- a/include/efi/efi-stdio.h
+++ b/include/efi/efi-stdio.h
@@ -2,7 +2,7 @@
#ifndef EFI_STDIO_H_
#define EFI_STDIO_H_
-#include <efi.h>
+#include <efi/types.h>
struct efi_simple_text_input_ex_protocol;
@@ -16,6 +16,11 @@ struct efi_key_state {
u8 toggle_state;
};
+struct efi_input_key {
+ u16 scan_code;
+ s16 unicode_char;
+};
+
struct efi_key_data {
struct efi_input_key key;
struct efi_key_state state;
diff --git a/include/efi/efi-util.h b/include/efi/efi-util.h
index 78e352456a..c61f3a5b05 100644
--- a/include/efi/efi-util.h
+++ b/include/efi/efi-util.h
@@ -2,7 +2,7 @@
#ifndef __EFI_UTIL_H
#define __EFI_UTIL_H
-#include <efi.h>
+#include <efi/types.h>
const char *efi_strerror(efi_status_t err);
int efi_errno(efi_status_t err);
@@ -11,4 +11,10 @@ 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/types.h b/include/efi/types.h
new file mode 100644
index 0000000000..3d42948d2b
--- /dev/null
+++ b/include/efi/types.h
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _EFI_TYPES_H_
+#define _EFI_TYPES_H_
+
+#include <linux/types.h>
+#include <linux/compiler.h>
+#include <linux/uuid.h>
+
+typedef unsigned long efi_status_t;
+typedef u16 efi_char16_t; /* UNICODE character */
+typedef u64 efi_physical_addr_t;
+typedef void *efi_handle_t;
+
+/*
+ * The UEFI spec and EDK2 reference implementation both define EFI_GUID as
+ * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment
+ * is 32 bits not 8 bits like our guid_t. In some cases (i.e., on 32-bit ARM),
+ * this means that firmware services invoked by the kernel may assume that
+ * efi_guid_t* arguments are 32-bit aligned, and use memory accessors that
+ * do not tolerate misalignment. So let's set the minimum alignment to 32 bits.
+ *
+ * Note that the UEFI spec as well as some comments in the EDK2 code base
+ * suggest that EFI_GUID should be 64-bit aligned, but this appears to be
+ * a mistake, given that no code seems to exist that actually enforces that
+ * or relies on it.
+ */
+typedef guid_t efi_guid_t __aligned(__alignof__(u32));
+
+#define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
+((efi_guid_t) \
+{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
+ (b) & 0xff, ((b) >> 8) & 0xff, \
+ (c) & 0xff, ((c) >> 8) & 0xff, \
+ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
+
+#ifdef CONFIG_EFI_PAYLOAD
+#define EFIAPI __attribute__((ms_abi))
+#else
+#define EFIAPI
+#endif
+
+struct efi_device_path {
+ u8 type;
+ u8 sub_type;
+ u16 length;
+} __packed;
+
+struct efi_mac_address {
+ uint8_t Addr[32];
+};
+
+struct efi_ipv4_address {
+ uint8_t Addr[4];
+};
+
+struct efi_ipv6_address {
+ uint8_t Addr[16];
+};
+
+union efi_ip_address {
+ uint32_t Addr[4];
+ struct efi_ipv4_address v4;
+ struct efi_ipv6_address v6;
+};
+
+#endif