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
This commit is contained in:
Warner Losh
2025-11-16 10:32:26 -07:00
parent 87795c6e95
commit ce1342883e
10 changed files with 40 additions and 42 deletions
+1 -1
View File
@@ -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>
-110
View File
@@ -1,110 +0,0 @@
/*-
* 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.
*
* 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.
*/
#ifndef _EFI_OSDEP_H_
#define _EFI_OSDEP_H_
/*
* Defines to adjust the types that EDK2 uses for FreeBSD so we can
* use the code and headers mostly unchanged. The headers are imported
* all into one directory to avoid case issues with filenames and
* included. The actual code is heavily modified since it has too many
* 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;
typedef int32_t INT32;
typedef int64_t INT64;
typedef intptr_t INTN;
typedef uint8_t UINT8;
typedef uint16_t UINT16;
typedef uint32_t UINT32;
typedef uint64_t UINT64;
typedef uintptr_t UINTN;
//typedef uintptr_t EFI_PHYSICAL_ADDRESS;
//typedef uint32_t EFI_IPv4_ADDRESS;
//typedef uint8_t EFI_MAC_ADDRESS[6];
//typedef uint8_t EFI_IPv6_ADDRESS[16];
typedef uint8_t CHAR8;
typedef uint16_t CHAR16;
typedef UINT8 BOOLEAN;
typedef void VOID;
//typedef uuid_t GUID;
//typedef uuid_t EFI_GUID;
/* We can't actually call this stuff, so snip out API syntactic sugar */
#define INTERFACE_DECL(x)
#define EFIAPI
#define IN
#define OUT
#define CONST const
#define OPTIONAL
//#define TRUE 1
//#define FALSE 0
/*
* EDK2 has fine definitions for these, so let it define them.
*/
#undef NULL
#undef EFI_PAGE_SIZE
#undef EFI_PAGE_MASK
/*
* Note: the EDK2 code assumed #pragma packed works and PACKED is a
* workaround for some old toolchain issues for EDK2 that aren't
* relevent to FreeBSD.
*/
#define PACKED
/*
* Since we're not compiling for the UEFI boot time (which use ms abi
* conventions), tell EDK2 to define VA_START correctly. For the boot
* loader, this likely needs to be different.
*/
#define NO_MSABI_VA_FUNCS 1
/*
* Finally, we need to define the processor we are in EDK2 terms.
*/
#if defined(__i386__)
#define MDE_CPU_IA32
#elif defined(__amd64__)
#define MDE_CPU_X64
#elif defined(__arm__)
#define MDE_CPU_ARM
#elif defined(__aarch64__)
#define MDE_CPU_AARCH64
#elif defined(__riscv)
#define MDE_CPU_RISCV64
#endif
/* FreeBSD doesn't have/use MDE_CPU_EBC or MDE_CPU_IPF (ia64) */
#endif /* _EFI_OSDEP_H_ */
-3
View File
@@ -33,10 +33,7 @@
#include <string.h>
#include "efichar.h"
#include "efi-osdep.h"
#include "efivar-dp.h"
#include "uefi-dplib.h"
/*
-3
View File
@@ -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 */
-3
View File
@@ -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 */
+1
View File
@@ -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>
-3
View File
@@ -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 */