efibind.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */
  2. /*
  3. * Copright (C) 2014 - 2015 Linaro Ltd.
  4. * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice and this list of conditions, without modification.
  11. * 2. The name of the author may not be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. * Alternatively, this software may be distributed under the terms of the
  15. * GNU General Public License as published by the Free Software Foundation;
  16. * either version 2 of the License, or (at your option) any later version.
  17. */
  18. #include <stdint.h>
  19. //
  20. // Basic EFI types of various widths
  21. //
  22. typedef uint64_t UINT64;
  23. typedef int64_t INT64;
  24. typedef uint32_t UINT32;
  25. typedef int32_t INT32;
  26. typedef uint16_t UINT16;
  27. typedef int16_t INT16;
  28. typedef uint8_t UINT8;
  29. typedef int8_t INT8;
  30. #ifndef __WCHAR_TYPE__
  31. #define __WCHAR_TYPE__ short
  32. #endif
  33. typedef __WCHAR_TYPE__ WCHAR;
  34. #ifndef BOOLEAN
  35. typedef uint8_t BOOLEAN;
  36. #endif
  37. #undef VOID
  38. #define VOID void
  39. typedef int64_t INTN;
  40. typedef uint64_t UINTN;
  41. #define EFI_ERROR_MASK 0x8000000000000000
  42. #define EFIERR(a) (EFI_ERROR_MASK | a)
  43. #define EFIERR_OEM(a) (0xc000000000000000 | a)
  44. #define BAD_POINTER 0xFBFBFBFBFBFBFBFB
  45. #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF
  46. #define BREAKPOINT() while(1);
  47. //
  48. // Pointers must be aligned to these address to function
  49. //
  50. #define MIN_ALIGNMENT_SIZE 8
  51. #define ALIGN_VARIABLE(Value, Adjustment) \
  52. (UINTN)Adjustment = 0; \
  53. if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
  54. (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
  55. Value = (UINTN)Value + (UINTN)Adjustment
  56. //
  57. // Define macros to build data structure signatures from characters.
  58. //
  59. #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
  60. #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
  61. #define EFI_SIGNATURE_64(A,B,C,D,E,F,G,H) (EFI_SIGNATURE_32(A,B,C,D) | ((UINT64)(EFI_SIGNATURE_32(E,F,G,H)) << 32))
  62. //
  63. // EFIAPI - prototype calling convention for EFI function pointers
  64. // BOOTSERVICE - prototype for implementation of a boot service interface
  65. // RUNTIMESERVICE - prototype for implementation of a runtime service interface
  66. // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
  67. // RUNTIME_CODE - pragma macro for declaring runtime code
  68. //
  69. #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
  70. #define EFIAPI // Substitute expresion to force C calling convention
  71. #endif
  72. #define BOOTSERVICE
  73. #define RUNTIMESERVICE
  74. #define RUNTIMEFUNCTION
  75. #define RUNTIME_CODE(a) alloc_text("rtcode", a)
  76. #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
  77. #define END_RUNTIME_DATA() data_seg("")
  78. #define VOLATILE volatile
  79. #define MEMORY_FENCE __sync_synchronize
  80. //
  81. // When build similiar to FW, then link everything together as
  82. // one big module. For the MSVC toolchain, we simply tell the
  83. // linker what our driver init function is using /ENTRY.
  84. //
  85. #if defined(_MSC_EXTENSIONS)
  86. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  87. __pragma(comment(linker, "/ENTRY:" # InitFunction))
  88. #else
  89. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  90. UINTN \
  91. InitializeDriver ( \
  92. VOID *ImageHandle, \
  93. VOID *SystemTable \
  94. ) \
  95. { \
  96. return InitFunction(ImageHandle, \
  97. SystemTable); \
  98. } \
  99. \
  100. EFI_STATUS efi_main( \
  101. EFI_HANDLE image, \
  102. EFI_SYSTEM_TABLE *systab \
  103. ) __attribute__((weak, \
  104. alias ("InitializeDriver")));
  105. #endif
  106. #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
  107. (_if)->LoadInternal(type, name, entry)
  108. //
  109. // Some compilers don't support the forward reference construct:
  110. // typedef struct XXXXX
  111. //
  112. // The following macro provide a workaround for such cases.
  113. #define INTERFACE_DECL(x) struct x
  114. #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
  115. #define EFI_FUNCTION