git: ce1342883e03 - main - efi: Move edk2 compat defines to sys/efi-edk2.h

From: Warner Losh <imp_at_FreeBSD.org>
Date: Sun, 16 Nov 2025 18:29:02 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=ce1342883e03e6a021f03a49d13539a145d320e2

commit ce1342883e03e6a021f03a49d13539a145d320e2
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2025-11-16 17:32:26 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2025-11-16 18:29:02 +0000

    efi: Move edk2 compat defines to sys/efi-edk2.h
    
    Create efi-freebsd.h, which is safe to include from the FreeBSD context
    (all of userland, except the small bits we share with edk2 and the
    kernel). This defines anything that we need. At the moment, it just
    includes NULL definitions.
    
    Create efi-edk2.h, which is approximately ProcessorBind.h from edk2 that
    we can include in FreeBSD compontents that are re-using edk2 components
    (bits of the boot laoder, and libefi*). Update the efi_gid definitions
    to match edk2 better. Add this file to badfiles.inc, since we can't
    write it in a way that's compatible. This is copied from the old
    efi-osdep.h.
    
    This has to be done in one commit that's bigger than I like since we
    can't easily move things piecemeal around they are so inter-related.
    
    Sponsored by:           Netflix
    Differential Revision:  https://reviews.freebsd.org/D53651
---
 lib/libefivar/ProcessorBind.h                   |  2 +-
 lib/libefivar/efivar-dp-format.c                |  3 --
 lib/libefivar/efivar-dp-parse.c                 |  3 --
 lib/libefivar/efivar-dp-xlate.c                 |  3 --
 lib/libefivar/uefi-dplib.h                      |  1 +
 lib/libefivar/uefi-dputil.c                     |  3 --
 lib/libefivar/efi-osdep.h => sys/sys/efi-edk2.h | 49 +++++++++++--------------
 sys/sys/efi-freebsd.h                           | 15 ++++++++
 sys/sys/efi.h                                   |  2 +-
 tools/build/test-includes/badfiles.inc          |  1 +
 10 files changed, 40 insertions(+), 42 deletions(-)

diff --git a/lib/libefivar/ProcessorBind.h b/lib/libefivar/ProcessorBind.h
index 46abe715d38f..6985a193cff9 100644
--- a/lib/libefivar/ProcessorBind.h
+++ b/lib/libefivar/ProcessorBind.h
@@ -1,3 +1,3 @@
 /* File in public domain */
 /* Brings in the glue for UEFI/EDK2 Tianocore code to run on this OS */
-#include "efi-osdep.h"
+#include <sys/efi-edk2.h>
diff --git a/lib/libefivar/efivar-dp-format.c b/lib/libefivar/efivar-dp-format.c
index f2dcf1b91c01..2050b09951cb 100644
--- a/lib/libefivar/efivar-dp-format.c
+++ b/lib/libefivar/efivar-dp-format.c
@@ -33,10 +33,7 @@
 #include <string.h>
 
 #include "efichar.h"
-
-#include "efi-osdep.h"
 #include "efivar-dp.h"
-
 #include "uefi-dplib.h"
 
 /*
diff --git a/lib/libefivar/efivar-dp-parse.c b/lib/libefivar/efivar-dp-parse.c
index 51c134692f1e..c594e94580da 100644
--- a/lib/libefivar/efivar-dp-parse.c
+++ b/lib/libefivar/efivar-dp-parse.c
@@ -35,10 +35,7 @@
 #include <wchar.h>
 
 #include "efichar.h"
-
-#include "efi-osdep.h"
 #include "efivar-dp.h"
-
 #include "uefi-dplib.h"
 
 /* XXX STUBS -- this stuff doesn't work yet */
diff --git a/lib/libefivar/efivar-dp-xlate.c b/lib/libefivar/efivar-dp-xlate.c
index 1e816cecbb81..78d82ba4bce0 100644
--- a/lib/libefivar/efivar-dp-xlate.c
+++ b/lib/libefivar/efivar-dp-xlate.c
@@ -39,10 +39,7 @@
 #include <string.h>
 
 #include "efichar.h"
-
-#include "efi-osdep.h"
 #include "efivar-dp.h"
-
 #include "uefi-dplib.h"
 
 #define MAX_DP_SANITY	4096		/* Biggest device path in bytes */
diff --git a/lib/libefivar/uefi-dplib.h b/lib/libefivar/uefi-dplib.h
index 6f76a9763a34..4787088dac19 100644
--- a/lib/libefivar/uefi-dplib.h
+++ b/lib/libefivar/uefi-dplib.h
@@ -37,6 +37,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #ifndef _UEFI_DEVICE_PATH_LIB_H_
 #define _UEFI_DEVICE_PATH_LIB_H_
+
 #include <Uefi.h>
 #include <Protocol/DevicePathUtilities.h>
 #include <Protocol/DebugPort.h>
diff --git a/lib/libefivar/uefi-dputil.c b/lib/libefivar/uefi-dputil.c
index 6e8f3aeca2ce..c31da14eed2d 100644
--- a/lib/libefivar/uefi-dputil.c
+++ b/lib/libefivar/uefi-dputil.c
@@ -33,9 +33,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <sys/endian.h>
-
-#include "efi-osdep.h"
-
 #include "uefi-dplib.h"
 
 /* XXX maybe I should include the entire DevicePathUtiltiies.c and ifdef out what we don't use */
diff --git a/lib/libefivar/efi-osdep.h b/sys/sys/efi-edk2.h
similarity index 57%
rename from lib/libefivar/efi-osdep.h
rename to sys/sys/efi-edk2.h
index e91d7405da97..513c56549803 100644
--- a/lib/libefivar/efi-osdep.h
+++ b/sys/sys/efi-edk2.h
@@ -1,30 +1,11 @@
-/*-
- * Copyright (c) 2017 Netflix, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
+/*
+ * Copyright (c) 2017-2025 Netflix, Inc.
  *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-2-Clause
  */
 
-#ifndef	_EFI_OSDEP_H_
-#define	_EFI_OSDEP_H_
+#ifndef	_SYS_EFI_EDK2_H_
+#define	_SYS_EFI_EDK2_H_
 
 /*
  * Defines to adjust the types that EDK2 uses for FreeBSD so we can
@@ -34,10 +15,8 @@
  * annoying dependencies that are difficult to satisfy.
  */
 
-#include <sys/cdefs.h>
 #include <stdlib.h>
 #include <stdint.h>
-#include <uuid.h>
 
 typedef int8_t INT8;
 typedef int16_t INT16;
@@ -61,7 +40,7 @@ typedef void VOID;
 //typedef uuid_t EFI_GUID;
 
 /* We can't actually call this stuff, so snip out API syntactic sugar */
-#define INTERFACE_DECL(x)
+#define INTERFACE_DECL(x) struct x
 #define EFIAPI
 #define IN
 #define OUT
@@ -107,4 +86,18 @@ typedef void VOID;
 #endif
 /* FreeBSD doesn't have/use MDE_CPU_EBC or MDE_CPU_IPF (ia64) */
 
-#endif /* _EFI_OSDEP_H_ */
+#if __SIZEOF_LONG__ == 4
+#define MAX_BIT      0x80000000
+#else
+#define MAX_BIT      0x8000000000000000
+#endif
+
+/*
+ * Sometimes EFI is included after sys/param.h, and that causes a collision. We
+ * get a collision the other way too, so when including both, you have to
+ * include sys/param.h first.
+ */
+#undef MAX
+#undef MIN
+
+#endif /* _SYS_EFI_EDK2_H_ */
diff --git a/sys/sys/efi-freebsd.h b/sys/sys/efi-freebsd.h
new file mode 100644
index 000000000000..f3fd04a2196c
--- /dev/null
+++ b/sys/sys/efi-freebsd.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2025 Netflix, Inc.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#ifndef	_SYS_EFI_FREEBSD_H_
+#define	_SYS_EFI_FREEBSD_H_
+
+/*
+ * Minimal defines to allow FreeBSD to use the same type names as EDK2,
+ * but without depending on all of EDK2's types.
+ */
+#include <sys/_null.h>
+
+#endif /* _SYS_EFI_FREEBSD_H_ */
diff --git a/sys/sys/efi.h b/sys/sys/efi.h
index f82c733898b4..830cca9c1832 100644
--- a/sys/sys/efi.h
+++ b/sys/sys/efi.h
@@ -27,8 +27,8 @@
 #ifndef _SYS_EFI_H_
 #define _SYS_EFI_H_
 
-#include <sys/uuid.h>
 #include <machine/efi.h>
+#include <sys/efi-freebsd.h>
 
 #define	EFI_PAGE_SHIFT		12
 #define	EFI_PAGE_SIZE		(1 << EFI_PAGE_SHIFT)
diff --git a/tools/build/test-includes/badfiles.inc b/tools/build/test-includes/badfiles.inc
index 9feb73edc5d0..3c7390b22a89 100644
--- a/tools/build/test-includes/badfiles.inc
+++ b/tools/build/test-includes/badfiles.inc
@@ -31,6 +31,7 @@ BADHDRS= \
 	sys/domainset.h \
 	sys/dtrace_bsd.h \
 	sys/dvdio.h \
+	sys/efitcg.h \
 	sys/elf32.h \
 	sys/elf64.h \
 	sys/elf_common.h \