Skip to content

[libc] Add UEFI headers #127126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2025
Merged

Conversation

RossComputerGuy
Copy link
Member

Originated from #120687

This PR simply adds the necessary headers for UEFI which defines all the necessary types. This PR unlocks the ability to work on other PR's for UEFI support.

@llvmbot llvmbot added the libc label Feb 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 13, 2025

@llvm/pr-subscribers-libc

Author: Tristan Ross (RossComputerGuy)

Changes

Originated from #120687

This PR simply adds the necessary headers for UEFI which defines all the necessary types. This PR unlocks the ability to work on other PR's for UEFI support.


Patch is 48.80 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/127126.diff

30 Files Affected:

  • (modified) libc/include/CMakeLists.txt (+13)
  • (added) libc/include/Uefi.h.def (+16)
  • (added) libc/include/Uefi.yaml (+15)
  • (modified) libc/include/llvm-libc-macros/CMakeLists.txt (+6)
  • (added) libc/include/llvm-libc-macros/EFIAPI-macros.h (+18)
  • (modified) libc/include/llvm-libc-types/CMakeLists.txt (+124)
  • (added) libc/include/llvm-libc-types/EFI_ALLOCATE_TYPE.h (+19)
  • (added) libc/include/llvm-libc-types/EFI_BOOT_SERVICES.h (+250)
  • (added) libc/include/llvm-libc-types/EFI_CAPSULE.h (+26)
  • (added) libc/include/llvm-libc-types/EFI_CONFIGURATION_TABLE.h (+19)
  • (added) libc/include/llvm-libc-types/EFI_DEVICE_PATH_PROTOCOL.h (+23)
  • (added) libc/include/llvm-libc-types/EFI_EVENT.h (+21)
  • (added) libc/include/llvm-libc-types/EFI_GUID.h (+21)
  • (added) libc/include/llvm-libc-types/EFI_HANDLE.h (+14)
  • (added) libc/include/llvm-libc-types/EFI_INTERFACE_TYPE.h (+16)
  • (added) libc/include/llvm-libc-types/EFI_LOCATE_SEARCH_TYPE.h (+18)
  • (added) libc/include/llvm-libc-types/EFI_MEMORY_DESCRIPTOR.h (+43)
  • (added) libc/include/llvm-libc-types/EFI_MEMORY_TYPE.h (+32)
  • (added) libc/include/llvm-libc-types/EFI_OPEN_PROTOCOL_INFORMATION_ENTRY.h (+22)
  • (added) libc/include/llvm-libc-types/EFI_PHYSICAL_ADDRESS.h (+16)
  • (added) libc/include/llvm-libc-types/EFI_RUNTIME_SERVICES.h (+134)
  • (added) libc/include/llvm-libc-types/EFI_SIMPLE_TEXT_INPUT_PROTOCOL.h (+39)
  • (added) libc/include/llvm-libc-types/EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.h (+64)
  • (added) libc/include/llvm-libc-types/EFI_STATUS.h (+16)
  • (added) libc/include/llvm-libc-types/EFI_SYSTEM_TABLE.h (+63)
  • (added) libc/include/llvm-libc-types/EFI_TABLE_HEADER.h (+22)
  • (added) libc/include/llvm-libc-types/EFI_TIME.h (+37)
  • (added) libc/include/llvm-libc-types/EFI_TIMER_DELAY.h (+18)
  • (added) libc/include/llvm-libc-types/EFI_TPL.h (+21)
  • (added) libc/include/llvm-libc-types/EFI_VIRTUAL_ADDRESS.h (+16)
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 867bd1e5ee20f..41f6d3b67c95b 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -724,6 +724,19 @@ add_header_macro(
     .llvm-libc-macros.poll-macros
   )
 
+# UEFI spec references "Uefi.h" so we use that name for compatibility
+add_header_macro(
+  uefi
+  ../libc/include/Uefi.yaml
+  Uefi.h.def
+  Uefi.h
+  DEPENDS
+    .llvm_libc_common_h
+    .llvm-libc-types.EFI_GUID
+    .llvm-libc-types.EFI_STATUS
+    .llvm-libc-types.EFI_SYSTEM_TABLE
+)
+
 if(NOT LLVM_LIBC_FULL_BUILD)
   # We don't install headers in non-fullbuild mode.
   return()
diff --git a/libc/include/Uefi.h.def b/libc/include/Uefi.h.def
new file mode 100644
index 0000000000000..6655e13579cd8
--- /dev/null
+++ b/libc/include/Uefi.h.def
@@ -0,0 +1,16 @@
+//===-- UEFI header uefi.h --------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_UEFI_H
+#define LLVM_LIBC_UEFI_H
+
+#include "__llvm-libc-common.h"
+
+%%public_api()
+
+#endif // LLVM_LIBC_UEFI_H
diff --git a/libc/include/Uefi.yaml b/libc/include/Uefi.yaml
new file mode 100644
index 0000000000000..28582eb2524b1
--- /dev/null
+++ b/libc/include/Uefi.yaml
@@ -0,0 +1,15 @@
+header: Uefi.h
+standards: UEFI
+macros: []
+types:
+  - type_name: EFI_BOOT_SERVICES
+  - type_name: EFI_GUID
+  - type_name: EFI_STATUS
+  - type_name: EFI_SYSTEM_TABLE
+enums: []
+functions: []
+objects:
+  - object_name: efi_system_table
+    object_type: EFI_SYSTEM_TABLE *
+  - object_name: efi_image_handle
+    object_type: EFI_HANDLE
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 8c1f7387f3b4d..7f10e773479a3 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -337,3 +337,9 @@ add_macro_header(
   HDR
     poll-macros.h
 )
+
+add_macro_header(
+  EFIAPI_macros
+  HDR
+    EFIAPI-macros.h
+)
diff --git a/libc/include/llvm-libc-macros/EFIAPI-macros.h b/libc/include/llvm-libc-macros/EFIAPI-macros.h
new file mode 100644
index 0000000000000..cb854928d0ab7
--- /dev/null
+++ b/libc/include/llvm-libc-macros/EFIAPI-macros.h
@@ -0,0 +1,18 @@
+//===-- Definition of EFIAPI macro ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_MACROS_EFIAPI_MACROS_H
+#define LLVM_LIBC_MACROS_EFIAPI_MACROS_H
+
+#if defined(__x86_64__) && !defined(__ILP32__)
+#define EFIAPI __attribute__((ms_abi))
+#else
+#define EFIAPI
+#endif
+
+#endif // LLVM_LIBC_MACROS_EFIAPI_MACROS_H
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 7ed69ab1af6d9..58761ac97d7cf 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -157,3 +157,127 @@ DEPENDS
 add_header(locale_t HDR locale_t.h)
 add_header(struct_lconv HDR struct_lconv.h)
 add_header(stdfix-types HDR stdfix-types.h)
+
+# UEFI
+add_header(EFI_GUID HDR EFI_GUID.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
+add_header(EFI_CONFIGURATION_TABLE HDR EFI_CONFIGURATION_TABLE.h DEPENDS .EFI_GUID)
+
+add_header(EFI_PHYSICAL_ADDRESS HDR EFI_PHYSICAL_ADDRESS.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
+add_header(EFI_VIRTUAL_ADDRESS HDR EFI_VIRTUAL_ADDRESS.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
+
+add_header(EFI_MEMORY_DESCRIPTOR
+  HDR
+    EFI_MEMORY_DESCRIPTOR.h
+  DEPENDS
+    libc.include.llvm-libc-macros.stdint_macros
+    .EFI_PHYSICAL_ADDRESS
+    .EFI_VIRTUAL_ADDRESS
+)
+
+add_header(EFI_ALLOCATE_TYPE HDR EFI_ALLOCATE_TYPE.h)
+add_header(EFI_EVENT HDR EFI_EVENT.h)
+add_header(EFI_INTERFACE_TYPE HDR EFI_INTERFACE_TYPE.h)
+add_header(EFI_LOCATE_SEARCH_TYPE HDR EFI_LOCATE_SEARCH_TYPE.h)
+add_header(EFI_MEMORY_TYPE HDR EFI_MEMORY_TYPE.h)
+add_header(EFI_HANDLE HDR EFI_HANDLE.h)
+add_header(EFI_TIME HDR EFI_TIME.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
+add_header(EFI_TIMER_DELAY HDR EFI_TIMER_DELAY.h)
+add_header(EFI_TPL HDR EFI_TPL.h DEPENDS .size_t)
+add_header(EFI_STATUS HDR EFI_STATUS.h DEPENDS .size_t)
+
+add_header(EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
+  HDR
+    EFI_OPEN_PROTOCOL_INFORMATION_ENTRY.h
+  DEPENDS
+    libc.include.llvm-libc-macros.stdint_macros
+    .EFI_HANDLE
+)
+
+add_header(EFI_CAPSULE
+  HDR
+    EFI_CAPSULE.h
+  DEPENDS
+    libc.include.llvm-libc-macros.stdint_macros
+    .EFI_GUID
+)
+
+add_header(EFI_TABLE_HEADER
+  HDR
+    EFI_TABLE_HEADER.h
+  DEPENDS
+    libc.include.llvm-libc-macros.stdint_macros
+)
+
+add_header(EFI_DEVICE_PATH_PROTOCOL
+  HDR
+    EFI_DEVICE_PATH_PROTOCOL.h
+  DEPENDS
+    libc.include.llvm-libc-macros.stdint_macros
+)
+
+add_header(EFI_SIMPLE_TEXT_INPUT_PROTOCOL
+  HDR
+    EFI_SIMPLE_TEXT_INPUT_PROTOCOL.h
+  DEPENDS
+    libc.include.llvm-libc-macros.EFIAPI_macros
+    libc.include.llvm-libc-macros.stdint_macros
+    .EFI_EVENT
+    .EFI_STATUS
+    .char16_t
+)
+
+add_header(EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
+  HDR
+    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.h
+  DEPENDS
+    libc.include.llvm-libc-macros.stdint_macros
+    .EFI_STATUS
+    .size_t
+)
+
+add_header(EFI_BOOT_SERVICES
+  HDR
+    EFI_BOOT_SERVICES.h
+  DEPENDS
+    libc.include.llvm-libc-macros.EFIAPI_macros
+    .EFI_ALLOCATE_TYPE
+    .EFI_DEVICE_PATH_PROTOCOL
+    .EFI_EVENT
+    .EFI_INTERFACE_TYPE
+    .EFI_LOCATE_SEARCH_TYPE
+    .EFI_MEMORY_DESCRIPTOR
+    .EFI_MEMORY_TYPE
+    .EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
+    .EFI_PHYSICAL_ADDRESS
+    .EFI_STATUS
+    .EFI_TABLE_HEADER
+    .EFI_TIMER_DELAY
+    .EFI_TPL
+    .char16_t
+)
+
+add_header(EFI_RUNTIME_SERVICES
+  HDR
+    EFI_RUNTIME_SERVICES.h
+  DEPENDS
+    .EFI_CAPSULE
+    .EFI_STATUS
+    .EFI_TABLE_HEADER
+    .EFI_TIME
+    .char16_t
+)
+
+add_header(EFI_SYSTEM_TABLE
+  HDR
+    EFI_SYSTEM_TABLE.h
+  DEPENDS
+    .EFI_BOOT_SERVICES
+    .EFI_CONFIGURATION_TABLE
+    .EFI_HANDLE
+    .EFI_RUNTIME_SERVICES
+    .EFI_SIMPLE_TEXT_INPUT_PROTOCOL
+    .EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
+    .EFI_STATUS
+    .EFI_TABLE_HEADER
+    .char16_t
+)
diff --git a/libc/include/llvm-libc-types/EFI_ALLOCATE_TYPE.h b/libc/include/llvm-libc-types/EFI_ALLOCATE_TYPE.h
new file mode 100644
index 0000000000000..90f23969678f4
--- /dev/null
+++ b/libc/include/llvm-libc-types/EFI_ALLOCATE_TYPE.h
@@ -0,0 +1,19 @@
+//===-- Definition of EFI_ALLOCATE_TYPE type ------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_EFI_ALLOCATE_TYPE_H
+#define LLVM_LIBC_TYPES_EFI_ALLOCATE_TYPE_H
+
+typedef enum {
+  AllocateAnyPages,
+  AllocateMaxAddress,
+  AllocateAddress,
+  MaxAllocateType
+} EFI_ALLOCATE_TYPE;
+
+#endif // LLVM_LIBC_TYPES_EFI_ALLOCATE_TYPE_H
diff --git a/libc/include/llvm-libc-types/EFI_BOOT_SERVICES.h b/libc/include/llvm-libc-types/EFI_BOOT_SERVICES.h
new file mode 100644
index 0000000000000..8b7a6aadd7a24
--- /dev/null
+++ b/libc/include/llvm-libc-types/EFI_BOOT_SERVICES.h
@@ -0,0 +1,250 @@
+//===-- Definition of EFI_BOOT_SERVICES type ------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_EFI_BOOT_SERVICES_H
+#define LLVM_LIBC_TYPES_EFI_BOOT_SERVICES_H
+
+#include "../llvm-libc-macros/EFIAPI-macros.h"
+#include "EFI_ALLOCATE_TYPE.h"
+#include "EFI_DEVICE_PATH_PROTOCOL.h"
+#include "EFI_EVENT.h"
+#include "EFI_GUID.h"
+#include "EFI_INTERFACE_TYPE.h"
+#include "EFI_LOCATE_SEARCH_TYPE.h"
+#include "EFI_MEMORY_DESCRIPTOR.h"
+#include "EFI_MEMORY_TYPE.h"
+#include "EFI_OPEN_PROTOCOL_INFORMATION_ENTRY.h"
+#include "EFI_PHYSICAL_ADDRESS.h"
+#include "EFI_STATUS.h"
+#include "EFI_TABLE_HEADER.h"
+#include "EFI_TIMER_DELAY.h"
+#include "EFI_TPL.h"
+#include "char16_t.h"
+#include "size_t.h"
+
+#define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42
+#define EFI_BOOT_SERVICES_REVISION EFI_SPECIFICATION_VERSION
+
+typedef EFI_TPL(EFIAPI *EFI_RAISE_TPL)(EFI_TPL NewTpl);
+typedef void(EFIAPI *EFI_RESTORE_TPL)(EFI_TPL OldTpl);
+
+typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_PAGES)(EFI_ALLOCATE_TYPE Type,
+                                               EFI_MEMORY_TYPE MemoryType,
+                                               size_t Pages,
+                                               EFI_PHYSICAL_ADDRESS *Memory);
+typedef EFI_STATUS(EFIAPI *EFI_FREE_PAGES)(EFI_PHYSICAL_ADDRESS Memory,
+                                           size_t Pages);
+typedef EFI_STATUS(EFIAPI *EFI_GET_MEMORY_MAP)(size_t *MemoryMapSize,
+                                               EFI_MEMORY_DESCRIPTOR *MemoryMap,
+                                               size_t *MapKey,
+                                               size_t *DescriptorSize,
+                                               uint32_t *DescriptorVersion);
+
+typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_POOL)(EFI_MEMORY_TYPE PoolType,
+                                              size_t Size, void **Buffer);
+typedef EFI_STATUS(EFIAPI *EFI_FREE_POOL)(void *Buffer);
+
+typedef void(EFIAPI *EFI_EVENT_NOTIFY)(EFI_EVENT Event, void *Context);
+
+typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT)(uint32_t Type, EFI_TPL NotifyTpl,
+                                             EFI_EVENT_NOTIFY NotifyFunction,
+                                             void *NotifyContext,
+                                             EFI_EVENT *Event);
+typedef EFI_STATUS(EFIAPI *EFI_SET_TIMER)(EFI_EVENT Event, EFI_TIMER_DELAY Type,
+                                          uint64_t TriggerTime);
+typedef EFI_STATUS(EFIAPI *EFI_WAIT_FOR_EVENT)(size_t NumberOfEvents,
+                                               EFI_EVENT *Event, size_t *Index);
+typedef EFI_STATUS(EFIAPI *EFI_SIGNAL_EVENT)(EFI_EVENT Event);
+typedef EFI_STATUS(EFIAPI *EFI_CLOSE_EVENT)(EFI_EVENT Event);
+typedef EFI_STATUS(EFIAPI *EFI_CHECK_EVENT)(EFI_EVENT Event);
+
+typedef EFI_STATUS(EFIAPI *EFI_INSTALL_PROTOCOL_INTERFACE)(
+    EFI_HANDLE *Handle, EFI_GUID *Protocol, EFI_INTERFACE_TYPE InterfaceType,
+    void *Interface);
+typedef EFI_STATUS(EFIAPI *EFI_REINSTALL_PROTOCOL_INTERFACE)(
+    EFI_HANDLE Handle, EFI_GUID *Protocol, void *OldInterface,
+    void *NewInterface);
+typedef EFI_STATUS(EFIAPI *EFI_UNINSTALL_PROTOCOL_INTERFACE)(EFI_HANDLE Handle,
+                                                             EFI_GUID *Protocol,
+                                                             void *Interface);
+
+typedef EFI_STATUS(EFIAPI *EFI_HANDLE_PROTOCOL)(EFI_HANDLE Handle,
+                                                EFI_GUID *Protocol,
+                                                void **Interface);
+typedef EFI_STATUS(EFIAPI *EFI_REGISTER_PROTOCOL_NOTIFY)(EFI_GUID *Protocol,
+                                                         EFI_EVENT Event,
+                                                         void **Registration);
+
+typedef EFI_STATUS(EFIAPI *EFI_LOCATE_HANDLE)(EFI_LOCATE_SEARCH_TYPE SearchType,
+                                              EFI_GUID *Protocol,
+                                              void *SearchKey,
+                                              size_t *BufferSize,
+                                              EFI_HANDLE *Buffer);
+typedef EFI_STATUS(EFIAPI *EFI_LOCATE_DEVICE_PATH)(
+    EFI_GUID *Protocol, EFI_DEVICE_PATH_PROTOCOL **DevicePath,
+    EFI_HANDLE *Device);
+
+typedef EFI_STATUS(EFIAPI *EFI_INSTALL_CONFIGURATION_TABLE)(EFI_GUID *Guid,
+                                                            void *Table);
+typedef EFI_STATUS(EFIAPI *EFI_IMAGE_UNLOAD)(EFI_HANDLE ImageHandle);
+typedef EFI_STATUS(EFIAPI *EFI_IMAGE_START)(EFI_HANDLE ImageHandle,
+                                            size_t *ExitDataSize,
+                                            char16_t **ExitData);
+
+typedef EFI_STATUS(EFIAPI *EFI_EXIT)(EFI_HANDLE ImageHandle,
+                                     EFI_STATUS ExitStatus, size_t ExitDataSize,
+                                     char16_t *ExitData);
+typedef EFI_STATUS(EFIAPI *EFI_EXIT_BOOT_SERVICES)(EFI_HANDLE ImageHandle,
+                                                   size_t MapKey);
+typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_MONOTONIC_COUNT)(uint64_t *Count);
+typedef EFI_STATUS(EFIAPI *EFI_STALL)(size_t Microseconds);
+typedef EFI_STATUS(EFIAPI *EFI_SET_WATCHDOG_TIMER)(size_t Timeout,
+                                                   uint64_t WatchdogCode,
+                                                   size_t DataSize,
+                                                   char16_t *WatchdogData);
+
+typedef EFI_STATUS(EFIAPI *EFI_CONNECT_CONTROLLER)(
+    EFI_HANDLE ControllerHandle, EFI_HANDLE *DriverImageHandle,
+    EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath, bool Recursive);
+
+typedef EFI_STATUS(EFIAPI *EFI_DISCONNECT_CONTROLLER)(
+    EFI_HANDLE ControllerHandle, EFI_HANDLE DriverImageHandle,
+    EFI_HANDLE ChildHandle);
+
+typedef EFI_STATUS(EFIAPI *EFI_OPEN_PROTOCOL)(
+    EFI_HANDLE Handle, EFI_GUID *Protocol, void **Interface,
+    EFI_HANDLE AgentHandle, EFI_HANDLE ControllerHandle, uint32_t Attributes);
+
+typedef EFI_STATUS(EFIAPI *EFI_CLOSE_PROTOCOL)(EFI_HANDLE Handle,
+                                               EFI_GUID *Protocol,
+                                               EFI_HANDLE AgentHandle,
+                                               EFI_HANDLE ControllerHandle);
+
+typedef EFI_STATUS(EFIAPI *EFI_OPEN_PROTOCOL_INFORMATION)(
+    EFI_HANDLE Handle, EFI_GUID *Protocol,
+    EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer, size_t *EntryCount);
+
+typedef EFI_STATUS(EFIAPI *EFI_PROTOCOLS_PER_HANDLE)(
+    EFI_HANDLE Handle, EFI_GUID ***ProtocolBuffer, size_t *ProtocolBufferCount);
+
+typedef EFI_STATUS(EFIAPI *EFI_LOCATE_HANDLE_BUFFER)(
+    EFI_LOCATE_SEARCH_TYPE SearchType, EFI_GUID *Protocol, void *SearchKey,
+    size_t *NoHandles, EFI_HANDLE **Buffer);
+
+typedef EFI_STATUS(EFIAPI *EFI_LOCATE_PROTOCOL)(EFI_GUID *Protocol,
+                                                void *Registration,
+                                                void **Interface);
+
+typedef EFI_STATUS(EFIAPI *EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)(
+    EFI_HANDLE Handle, ...);
+typedef EFI_STATUS(EFIAPI *EFI_CALCULATE_CRC32)(void *Data, size_t DataSize,
+                                                uint32_t *Crc32);
+
+typedef void(EFIAPI *EFI_COPY_MEM)(void *Destination, void *Source,
+                                   size_t Length);
+typedef void(EFIAPI *EFI_SET_MEM)(void *Buffer, size_t Size, uint8_t Value);
+
+typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT_EX)(
+    uint32_t Type, EFI_TPL NotifyTpl, EFI_EVENT_NOTIFY NotifyFunction,
+    const void *NotifyContext, const EFI_GUID *EventGroup, EFI_EVENT *Event);
+
+typedef struct {
+  EFI_TABLE_HEADER Hdr;
+
+  //
+  // Task Priority Services
+  //
+  EFI_RAISE_TPL RaiseTPL;     // EFI 1.0+
+  EFI_RESTORE_TPL RestoreTPL; // EFI 1.0+
+
+  //
+  // Memory Services
+  //
+  EFI_ALLOCATE_PAGES AllocatePages; // EFI 1.0+
+  EFI_FREE_PAGES FreePages;         // EFI 1.0+
+  EFI_GET_MEMORY_MAP GetMemoryMap;  // EFI 1.0+
+  EFI_ALLOCATE_POOL AllocatePool;   // EFI 1.0+
+  EFI_FREE_POOL FreePool;           // EFI 1.0+
+
+  //
+  // Event & Timer Services
+  //
+  EFI_CREATE_EVENT CreateEvent;    // EFI 1.0+
+  EFI_SET_TIMER SetTimer;          // EFI 1.0+
+  EFI_WAIT_FOR_EVENT WaitForEvent; // EFI 1.0+
+  EFI_SIGNAL_EVENT SignalEvent;    // EFI 1.0+
+  EFI_CLOSE_EVENT CloseEvent;      // EFI 1.0+
+  EFI_CHECK_EVENT CheckEvent;      // EFI 1.0+
+
+  //
+  // Protocol Handler Services
+  //
+  EFI_INSTALL_PROTOCOL_INTERFACE InstallProtocolInterface;     // EFI 1.0+
+  EFI_REINSTALL_PROTOCOL_INTERFACE ReinstallProtocolInterface; // EFI 1.0+
+  EFI_UNINSTALL_PROTOCOL_INTERFACE UninstallProtocolInterface; // EFI 1.0+
+  EFI_HANDLE_PROTOCOL HandleProtocol;                          // EFI 1.0+
+  void *Reserved;                                              // EFI 1.0+
+  EFI_REGISTER_PROTOCOL_NOTIFY RegisterProtocolNotify;         // EFI 1.0+
+  EFI_LOCATE_HANDLE LocateHandle;                              // EFI 1.+
+  EFI_LOCATE_DEVICE_PATH LocateDevicePath;                     // EFI 1.0+
+  EFI_INSTALL_CONFIGURATION_TABLE InstallConfigurationTable;   // EFI 1.0+
+
+  //
+  // Image Services
+  //
+  EFI_IMAGE_UNLOAD LoadImage;              // EFI 1.0+
+  EFI_IMAGE_START StartImage;              // EFI 1.0+
+  EFI_EXIT Exit;                           // EFI 1.0+
+  EFI_IMAGE_UNLOAD UnloadImage;            // EFI 1.0+
+  EFI_EXIT_BOOT_SERVICES ExitBootServices; // EFI 1.0+
+
+  //
+  // Miscellaneous Services
+  //
+  EFI_GET_NEXT_MONOTONIC_COUNT GetNextMonotonicCount; // EFI 1.0+
+  EFI_STALL Stall;                                    // EFI 1.0+
+  EFI_SET_WATCHDOG_TIMER SetWatchdogTimer;            // EFI 1.0+
+
+  //
+  // DriverSupport Services
+  //
+  EFI_CONNECT_CONTROLLER ConnectController;       // EFI 1.1
+  EFI_DISCONNECT_CONTROLLER DisconnectController; // EFI 1.1+
+
+  //
+  // Open and Close Protocol Services
+  //
+  EFI_OPEN_PROTOCOL OpenProtocol;                        // EFI 1.1+
+  EFI_CLOSE_PROTOCOL CloseProtocol;                      // EFI 1.1+
+  EFI_OPEN_PROTOCOL_INFORMATION OpenProtocolInformation; // EFI 1.1+
+
+  //
+  // Library Services
+  //
+  EFI_PROTOCOLS_PER_HANDLE ProtocolsPerHandle; // EFI 1.1+
+  EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer; // EFI 1.1+
+  EFI_LOCATE_PROTOCOL LocateProtocol;          // EFI 1.1+
+  EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES
+  InstallMultipleProtocolInterfaces; // EFI 1.1+
+  EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES
+  UninstallMultipleProtocolInterfaces; // EFI 1.1+*
+
+  //
+  // 32-bit CRC Services
+  //
+  EFI_CALCULATE_CRC32 CalculateCrc32; // EFI 1.1+
+
+  //
+  // Miscellaneous Services
+  //
+  EFI_COPY_MEM CopyMem;              // EFI 1.1+
+  EFI_SET_MEM SetMem;                // EFI 1.1+
+  EFI_CREATE_EVENT_EX CreateEventEx; // UEFI 2.0+
+} EFI_BOOT_SERVICES;
+
+#endif // LLVM_LIBC_TYPES_EFI_BOOT_SERVICES_H
diff --git a/libc/include/llvm-libc-types/EFI_CAPSULE.h b/libc/include/llvm-libc-types/EFI_CAPSULE.h
new file mode 100644
index 0000000000000..c7440c9b03b75
--- /dev/null
+++ b/libc/include/llvm-libc-types/EFI_CAPSULE.h
@@ -0,0 +1,26 @@
+//===-- Definition of EFI_CAPSULE type ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_EFI_CAPSULE_H
+#define LLVM_LIBC_TYPES_EFI_CAPSULE_H
+
+#include "../llvm-libc-macros/stdint-macros.h"
+#include "EFI_GUID.h"
+
+typedef struct {
+  EFI_GUID CapsuleGuid;
+  uint32_t HeaderSize;
+  uint32_t Flags;
+  uint32_t CapsuleImageSize;
+} EFI_CAPSULE_HEADER;
+
+#define CAPSULE_FLAGS_PERSIST_ACROSS_RESET 0x00010000
+#define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000
+#define CAPSULE_FLAGS_INITIATE_RESET 0x00040000
+
+#endif // LLVM_LIBC_TYPES_EFI_CAPSULE_H
diff --git a/libc/include/llvm-libc-types/EFI_CONFIGURATION_TABLE.h b/libc/include/llvm-libc-types/EFI_CONFIGURATION_TABLE.h
new file mode 100644
index 0000000000000..56cd3e4fbb587
--- /dev/null
+++ b/libc/include/llvm-libc-types/EFI_CONFIGURATION_TABLE.h
@@ -0,0 +1,19 @@
+//===-- Definition of EFI_CONFIGURATION_TABLE type ---------...
[truncated]

Copy link
Contributor

@jhuber6 jhuber6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly copied from the standard listing as I understand, so it's mostly just putting that through the LLVM libc interface. Hopefully the UEFI people at Google don't mind.

@ilovepi
Copy link
Contributor

ilovepi commented Feb 13, 2025

CC @Prabhuk @frobtech

@RossComputerGuy
Copy link
Member Author

Yeah, this all comes from the 2.10 specification which can be found on the UEFI website (https://uefi.org). There is a 2.11 specification but we can change it later on whenever we need something from 2.11 specifically.

@lntue lntue merged commit 9b6d0d7 into llvm:main Feb 28, 2025
13 checks passed
@RossComputerGuy RossComputerGuy deleted the feat/libc-uefi-headers branch February 28, 2025 16:44
cheezeburglar pushed a commit to cheezeburglar/llvm-project that referenced this pull request Feb 28, 2025
Originated from llvm#120687

This PR simply adds the necessary headers for UEFI which defines all the
necessary types. This PR unlocks the ability to work on other PR's for
UEFI support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants