1530d68baSNigel Croxon /*++ 2530d68baSNigel Croxon 3530d68baSNigel Croxon Copyright (c) 1998 Intel Corporation 4530d68baSNigel Croxon 5530d68baSNigel Croxon Module Name: 6530d68baSNigel Croxon 7530d68baSNigel Croxon efefind.h 8530d68baSNigel Croxon 9530d68baSNigel Croxon Abstract: 10530d68baSNigel Croxon 11530d68baSNigel Croxon EFI to compile bindings 12530d68baSNigel Croxon 13530d68baSNigel Croxon 14530d68baSNigel Croxon 15530d68baSNigel Croxon 16530d68baSNigel Croxon Revision History 17530d68baSNigel Croxon 18530d68baSNigel Croxon --*/ 19530d68baSNigel Croxon 20530d68baSNigel Croxon #pragma pack() 21530d68baSNigel Croxon 22530d68baSNigel Croxon 23530d68baSNigel Croxon // 24530d68baSNigel Croxon // Basic int types of various widths 25530d68baSNigel Croxon // 26530d68baSNigel Croxon 276685cd00SAlexander von Gluck IV #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L ) && !defined(__cplusplus) 28530d68baSNigel Croxon 29530d68baSNigel Croxon // No ANSI C 1999/2000 stdint.h integer width declarations 30530d68baSNigel Croxon 31530d68baSNigel Croxon #ifdef _MSC_EXTENSIONS 32530d68baSNigel Croxon // Use Microsoft C compiler integer width declarations 33530d68baSNigel Croxon 34530d68baSNigel Croxon typedef unsigned __int64 uint64_t; 35530d68baSNigel Croxon typedef __int64 int64_t; 36530d68baSNigel Croxon typedef unsigned __int32 uint32_t; 37530d68baSNigel Croxon typedef __int32 int32_t; 38530d68baSNigel Croxon typedef unsigned __int16 uint16_t; 39530d68baSNigel Croxon typedef __int16 int16_t; 40530d68baSNigel Croxon typedef unsigned __int8 uint8_t; 41530d68baSNigel Croxon typedef __int8 int8_t; 42530d68baSNigel Croxon #elif defined(UNIX_LP64) 43530d68baSNigel Croxon // Use LP64 programming model from C_FLAGS for integer width declarations 44530d68baSNigel Croxon 45530d68baSNigel Croxon typedef unsigned long uint64_t; 46530d68baSNigel Croxon typedef long int64_t; 47530d68baSNigel Croxon typedef unsigned int uint32_t; 48530d68baSNigel Croxon typedef int int32_t; 49530d68baSNigel Croxon typedef unsigned short uint16_t; 50530d68baSNigel Croxon typedef short int16_t; 51530d68baSNigel Croxon typedef unsigned char uint8_t; 52530d68baSNigel Croxon typedef char int8_t; 53530d68baSNigel Croxon #else 54530d68baSNigel Croxon // Assume P64 programming model from C_FLAGS for integer width declarations 55530d68baSNigel Croxon 56530d68baSNigel Croxon typedef unsigned long long uint64_t; 57530d68baSNigel Croxon typedef long long int64_t; 58530d68baSNigel Croxon typedef unsigned int uint32_t; 59530d68baSNigel Croxon typedef int int32_t; 60530d68baSNigel Croxon typedef unsigned short uint16_t; 61530d68baSNigel Croxon typedef short int16_t; 62530d68baSNigel Croxon typedef unsigned char uint8_t; 63530d68baSNigel Croxon typedef char int8_t; 64530d68baSNigel Croxon #endif 651a53d8f8SEsben Haabendal typedef uint64_t uintptr_t; 661a53d8f8SEsben Haabendal typedef int64_t intptr_t; 67530d68baSNigel Croxon #elif defined(__GNUC__) 68530d68baSNigel Croxon #include <stdint.h> 69530d68baSNigel Croxon #endif 70530d68baSNigel Croxon 71530d68baSNigel Croxon // 72530d68baSNigel Croxon // Basic EFI types of various widths 73530d68baSNigel Croxon // 74189200d0SCallum Farmer 75189200d0SCallum Farmer #include <stddef.h> 76189200d0SCallum Farmer 77189200d0SCallum Farmer typedef wchar_t CHAR16; 78189200d0SCallum Farmer #define WCHAR CHAR16 79530d68baSNigel Croxon 80530d68baSNigel Croxon typedef uint64_t UINT64; 81530d68baSNigel Croxon typedef int64_t INT64; 8214899d89SPeter Jones 83530d68baSNigel Croxon typedef uint32_t UINT32; 84530d68baSNigel Croxon typedef int32_t INT32; 85530d68baSNigel Croxon 8614899d89SPeter Jones typedef uint16_t UINT16; 8714899d89SPeter Jones typedef int16_t INT16; 8814899d89SPeter Jones 8914899d89SPeter Jones typedef uint8_t UINT8; 9014899d89SPeter Jones typedef char CHAR8; 9114899d89SPeter Jones typedef int8_t INT8; 9214899d89SPeter Jones 93530d68baSNigel Croxon #undef VOID 94*056bdaa5SCallum Farmer typedef void VOID; 95530d68baSNigel Croxon 96530d68baSNigel Croxon 97530d68baSNigel Croxon typedef int64_t INTN; 98530d68baSNigel Croxon typedef uint64_t UINTN; 99530d68baSNigel Croxon 100530d68baSNigel Croxon //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 101530d68baSNigel Croxon // BugBug: Code to debug 102530d68baSNigel Croxon // 103530d68baSNigel Croxon #define BIT63 0x8000000000000000 104530d68baSNigel Croxon 105530d68baSNigel Croxon #define PLATFORM_IOBASE_ADDRESS (0xffffc000000 | BIT63) 106530d68baSNigel Croxon #define PORT_TO_MEMD(_Port) (PLATFORM_IOBASE_ADDRESS | ( ( ( (_Port) & 0xfffc) << 10 ) | ( (_Port) & 0x0fff) ) ) 107530d68baSNigel Croxon 108530d68baSNigel Croxon // 109530d68baSNigel Croxon // Macro's with casts make this much easier to use and read. 110530d68baSNigel Croxon // 111530d68baSNigel Croxon #define PORT_TO_MEM8D(_Port) (*(UINT8 *)(PORT_TO_MEMD(_Port))) 112530d68baSNigel Croxon #define POST_CODE(_Data) (PORT_TO_MEM8D(0x80) = (_Data)) 113530d68baSNigel Croxon // 114530d68baSNigel Croxon // BugBug: End Debug Code!!! 115530d68baSNigel Croxon //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 116530d68baSNigel Croxon 117530d68baSNigel Croxon #define EFIERR(a) (0x8000000000000000 | a) 118530d68baSNigel Croxon #define EFI_ERROR_MASK 0x8000000000000000 119530d68baSNigel Croxon #define EFIERR_OEM(a) (0xc000000000000000 | a) 120530d68baSNigel Croxon 121530d68baSNigel Croxon #define BAD_POINTER 0xFBFBFBFBFBFBFBFB 122530d68baSNigel Croxon #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF 123530d68baSNigel Croxon 124530d68baSNigel Croxon #define BREAKPOINT() while (TRUE) 125530d68baSNigel Croxon 126530d68baSNigel Croxon // 127530d68baSNigel Croxon // Pointers must be aligned to these address to function 128530d68baSNigel Croxon // you will get an alignment fault if this value is less than 8 129530d68baSNigel Croxon // 130530d68baSNigel Croxon #define MIN_ALIGNMENT_SIZE 8 131530d68baSNigel Croxon 132530d68baSNigel Croxon #define ALIGN_VARIABLE(Value , Adjustment) \ 133530d68baSNigel Croxon (UINTN) Adjustment = 0; \ 134530d68baSNigel Croxon if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ 135530d68baSNigel Croxon (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ 136530d68baSNigel Croxon Value = (UINTN)Value + (UINTN)Adjustment 137530d68baSNigel Croxon 138530d68baSNigel Croxon // 139530d68baSNigel Croxon // Define macros to create data structure signatures. 140530d68baSNigel Croxon // 141530d68baSNigel Croxon 142530d68baSNigel Croxon #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) 143530d68baSNigel Croxon #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) 144530d68baSNigel Croxon #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)) 145530d68baSNigel Croxon // 146530d68baSNigel Croxon // To export & import functions in the EFI emulator environment 147530d68baSNigel Croxon // 148530d68baSNigel Croxon 149530d68baSNigel Croxon #define EXPORTAPI 150530d68baSNigel Croxon 151530d68baSNigel Croxon // 152530d68baSNigel Croxon // EFIAPI - prototype calling convention for EFI function pointers 153530d68baSNigel Croxon // BOOTSERVICE - prototype for implementation of a boot service interface 154530d68baSNigel Croxon // RUNTIMESERVICE - prototype for implementation of a runtime service interface 155530d68baSNigel Croxon // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service 156530d68baSNigel Croxon // RUNTIME_CODE - pragma macro for declaring runtime code 157530d68baSNigel Croxon // 158530d68baSNigel Croxon 159530d68baSNigel Croxon #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 160530d68baSNigel Croxon #ifdef _MSC_EXTENSIONS 161530d68baSNigel Croxon #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler 162530d68baSNigel Croxon #else 163530d68baSNigel Croxon #define EFIAPI // Substitute expresion to force C calling convention 164530d68baSNigel Croxon #endif 165530d68baSNigel Croxon #endif 166530d68baSNigel Croxon 167530d68baSNigel Croxon #define BOOTSERVICE 168530d68baSNigel Croxon #define RUNTIMESERVICE 169530d68baSNigel Croxon #define RUNTIMEFUNCTION 170530d68baSNigel Croxon 171530d68baSNigel Croxon #define RUNTIME_CODE(a) alloc_text("rtcode", a) 172530d68baSNigel Croxon #define BEGIN_RUNTIME_DATA() data_seg("rtdata") 173530d68baSNigel Croxon #define END_RUNTIME_DATA() data_seg("") 174530d68baSNigel Croxon 175530d68baSNigel Croxon #define VOLATILE volatile 176530d68baSNigel Croxon 177530d68baSNigel Croxon // 178530d68baSNigel Croxon // BugBug: Need to find out if this is portable accross compliers. 179530d68baSNigel Croxon // 180530d68baSNigel Croxon #ifdef __GNUC__ 181530d68baSNigel Croxon #define MEMORY_FENCE() __asm__ __volatile__ ("mf.a" ::: "memory") 182530d68baSNigel Croxon #else 183530d68baSNigel Croxon void __mf (void); 184530d68baSNigel Croxon #pragma intrinsic (__mf) 185530d68baSNigel Croxon #define MEMORY_FENCE() __mf() 186530d68baSNigel Croxon #endif 18709027207SNigel Croxon 188530d68baSNigel Croxon // 189530d68baSNigel Croxon // When build similiar to FW, then link everything together as 19009027207SNigel Croxon // one big module. For the MSVC toolchain, we simply tell the 19109027207SNigel Croxon // linker what our driver init function is using /ENTRY. 192530d68baSNigel Croxon // 19309027207SNigel Croxon #if defined(_MSC_EXTENSIONS) 19409027207SNigel Croxon #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 19509027207SNigel Croxon __pragma(comment(linker, "/ENTRY:" # InitFunction)) 19609027207SNigel Croxon #else 197530d68baSNigel Croxon #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 198530d68baSNigel Croxon UINTN \ 199530d68baSNigel Croxon InitializeDriver ( \ 200530d68baSNigel Croxon VOID *ImageHandle, \ 201530d68baSNigel Croxon VOID *SystemTable \ 202530d68baSNigel Croxon ) \ 203530d68baSNigel Croxon { \ 204530d68baSNigel Croxon return InitFunction(ImageHandle, \ 205530d68baSNigel Croxon SystemTable); \ 206530d68baSNigel Croxon } \ 207530d68baSNigel Croxon \ 208530d68baSNigel Croxon EFI_STATUS efi_main( \ 209530d68baSNigel Croxon EFI_HANDLE image, \ 210530d68baSNigel Croxon EFI_SYSTEM_TABLE *systab \ 211530d68baSNigel Croxon ) __attribute__((weak, \ 212530d68baSNigel Croxon alias ("InitializeDriver"))); 21309027207SNigel Croxon #endif 214530d68baSNigel Croxon 215530d68baSNigel Croxon #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 216530d68baSNigel Croxon (_if)->LoadInternal(type, name, entry) 217530d68baSNigel Croxon 218530d68baSNigel Croxon // 219530d68baSNigel Croxon // Some compilers don't support the forward reference construct: 220530d68baSNigel Croxon // typedef struct XXXXX 221530d68baSNigel Croxon // 222530d68baSNigel Croxon // The following macro provide a workaround for such cases. 223530d68baSNigel Croxon // 224530d68baSNigel Croxon #ifdef NO_INTERFACE_DECL 225530d68baSNigel Croxon #define INTERFACE_DECL(x) 226530d68baSNigel Croxon #else 2270b5f181aSNigel Croxon #if defined(__GNUC__) || defined(_MSC_EXTENSIONS) 228530d68baSNigel Croxon #define INTERFACE_DECL(x) struct x 229530d68baSNigel Croxon #else 230530d68baSNigel Croxon #define INTERFACE_DECL(x) typedef struct x 231530d68baSNigel Croxon #endif 232530d68baSNigel Croxon #endif 233530d68baSNigel Croxon 234530d68baSNigel Croxon /* No efi call wrapper for IA32 architecture */ 235530d68baSNigel Croxon #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) 236530d68baSNigel Croxon #define EFI_FUNCTION 237