177943Sdfr/* $FreeBSD$ */
277943Sdfr/*++
377943Sdfr
4163898SmarcelCopyright (c)  1999 - 2003 Intel Corporation. All rights reserved
5163898SmarcelThis software and associated documentation (if any) is furnished
6163898Smarcelunder a license and may only be used or copied in accordance
7163898Smarcelwith the terms of the license. Except as permitted by such
8163898Smarcellicense, no part of this software or documentation may be
9163898Smarcelreproduced, stored in a retrieval system, or transmitted in any
10163898Smarcelform or by any means without the express written consent of
11163898SmarcelIntel Corporation.
1277943Sdfr
1377943SdfrModule Name:
1477943Sdfr
1577943Sdfr    efefind.h
1677943Sdfr
1777943SdfrAbstract:
1877943Sdfr
1977943Sdfr    EFI to compile bindings
2077943Sdfr
2177943Sdfr
2277943Sdfr
2377943Sdfr
2477943SdfrRevision History
2577943Sdfr
2677943Sdfr--*/
2777943Sdfr
28163898Smarcel#pragma pack()
29163898Smarcel
30163898Smarcel
31163898Smarcel#ifdef __FreeBSD__
3285892Smike#include <sys/stdint.h>
33163898Smarcel#else
34163898Smarcel//
35163898Smarcel// Basic int types of various widths
36163898Smarcel//
3777943Sdfr
38163898Smarcel#if (__STDC_VERSION__ < 199901L )
3977943Sdfr
40163898Smarcel    // No ANSI C 1999/2000 stdint.h integer width declarations
41163898Smarcel
42163898Smarcel    #if _MSC_EXTENSIONS
43163898Smarcel
44163898Smarcel        // Use Microsoft C compiler integer width declarations
45163898Smarcel
46163898Smarcel        typedef unsigned __int64    uint64_t;
47163898Smarcel        typedef __int64             int64_t;
48163898Smarcel        typedef unsigned __int32    uint32_t;
49163898Smarcel        typedef __int32             int32_t;
50163898Smarcel        typedef unsigned __int16    uint16_t;
51163898Smarcel        typedef __int16             int16_t;
52163898Smarcel        typedef unsigned __int8     uint8_t;
53163898Smarcel        typedef __int8              int8_t;
54163898Smarcel    #else
55163898Smarcel        #ifdef UNIX_LP64
56163898Smarcel
57163898Smarcel            // Use LP64 programming model from C_FLAGS for integer width declarations
58163898Smarcel
59163898Smarcel            typedef unsigned long       uint64_t;
60163898Smarcel            typedef long                int64_t;
61163898Smarcel            typedef unsigned int        uint32_t;
62163898Smarcel            typedef int                 int32_t;
63163898Smarcel            typedef unsigned short      uint16_t;
64163898Smarcel            typedef short               int16_t;
65163898Smarcel            typedef unsigned char       uint8_t;
66163898Smarcel            typedef char                int8_t;
67163898Smarcel        #else
68163898Smarcel
69163898Smarcel            // Assume P64 programming model from C_FLAGS for integer width declarations
70163898Smarcel
71163898Smarcel            typedef unsigned long long  uint64_t;
72163898Smarcel            typedef long long           int64_t;
73163898Smarcel            typedef unsigned int        uint32_t;
74163898Smarcel            typedef int                 int32_t;
75163898Smarcel            typedef unsigned short      uint16_t;
76163898Smarcel            typedef short               int16_t;
77163898Smarcel            typedef unsigned char       uint8_t;
78163898Smarcel            typedef char                int8_t;
79163898Smarcel        #endif
80163898Smarcel    #endif
81163898Smarcel#endif
82163898Smarcel#endif	/* __FreeBSD__ */
83163898Smarcel
84163898Smarcel//
85163898Smarcel// Basic EFI types of various widths
86163898Smarcel//
87163898Smarcel
88163898Smarcel
8977943Sdfrtypedef uint64_t   UINT64;
9077943Sdfrtypedef int64_t    INT64;
9177943Sdfrtypedef uint32_t   UINT32;
9277943Sdfrtypedef int32_t    INT32;
9377943Sdfrtypedef uint16_t   UINT16;
9477943Sdfrtypedef int16_t    INT16;
9577943Sdfrtypedef uint8_t    UINT8;
9677943Sdfrtypedef int8_t     INT8;
9777943Sdfr
9877943Sdfr
9977943Sdfr#undef VOID
10077943Sdfr#define VOID    void
10177943Sdfr
10277943Sdfr
10377943Sdfrtypedef int64_t    INTN;
10477943Sdfrtypedef uint64_t   UINTN;
10577943Sdfr
106163898Smarcel//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107163898Smarcel// BugBug: Code to debug
108163898Smarcel//
10977943Sdfr#define BIT63   0x8000000000000000
11077943Sdfr
111163898Smarcel#define PLATFORM_IOBASE_ADDRESS   (0xffffc000000 | BIT63)
11277943Sdfr#define PORT_TO_MEMD(_Port) (PLATFORM_IOBASE_ADDRESS | ( ( ( (_Port) & 0xfffc) << 10 ) | ( (_Port) & 0x0fff) ) )
113163898Smarcel
114163898Smarcel//
115163898Smarcel// Macro's with casts make this much easier to use and read.
116163898Smarcel//
11777943Sdfr#define PORT_TO_MEM8D(_Port)  (*(UINT8  *)(PORT_TO_MEMD(_Port)))
11877943Sdfr#define POST_CODE(_Data)  (PORT_TO_MEM8D(0x80) = (_Data))
119163898Smarcel//
120163898Smarcel// BugBug: End Debug Code!!!
121163898Smarcel//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12277943Sdfr
12377943Sdfr#define EFIERR(a)           (0x8000000000000000 | a)
12477943Sdfr#define EFI_ERROR_MASK      0x8000000000000000
12577943Sdfr#define EFIERR_OEM(a)       (0xc000000000000000 | a)
12677943Sdfr
12777943Sdfr#define BAD_POINTER         0xFBFBFBFBFBFBFBFB
12877943Sdfr#define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
12977943Sdfr
130163898Smarcel#pragma intrinsic (__break)
131163898Smarcel#define BREAKPOINT()  __break(0)
13277943Sdfr
133163898Smarcel//
134163898Smarcel// Pointers must be aligned to these address to function
135163898Smarcel//  you will get an alignment fault if this value is less than 8
136163898Smarcel//
13777943Sdfr#define MIN_ALIGNMENT_SIZE  8
13877943Sdfr
13977943Sdfr#define ALIGN_VARIABLE(Value , Adjustment) \
14077943Sdfr            (UINTN) Adjustment = 0; \
14177943Sdfr            if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
14277943Sdfr                (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
14377943Sdfr            Value = (UINTN)Value + (UINTN)Adjustment
14477943Sdfr
145163898Smarcel//
146163898Smarcel// Define macros to create data structure signatures.
147163898Smarcel//
14877943Sdfr
14977943Sdfr#define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
15077943Sdfr#define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
15177943Sdfr#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))
15277943Sdfr
153163898Smarcel//
154163898Smarcel// EFIAPI - prototype calling convention for EFI function pointers
155163898Smarcel// BOOTSERVICE - prototype for implementation of a boot service interface
156163898Smarcel// RUNTIMESERVICE - prototype for implementation of a runtime service interface
157163898Smarcel// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
158163898Smarcel// RUNTIME_CODE - pragma macro for declaring runtime code
159163898Smarcel//
16077943Sdfr
161163898Smarcel#ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
162163898Smarcel    #if _MSC_EXTENSIONS
163163898Smarcel        #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
164163898Smarcel    #else
165163898Smarcel        #define EFIAPI          // Substitute expresion to force C calling convention
166163898Smarcel    #endif
16777943Sdfr#endif
16877943Sdfr
16977943Sdfr#define BOOTSERVICE
17077943Sdfr#define RUNTIMESERVICE
17177943Sdfr#define RUNTIMEFUNCTION
17277943Sdfr
17377943Sdfr#define RUNTIME_CODE(a)         alloc_text("rtcode", a)
17477943Sdfr#define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
175163898Smarcel#define END_RUNTIME_DATA()      data_seg()
17677943Sdfr
17777943Sdfr#define VOLATILE    volatile
17877943Sdfr
179163898Smarcel//
180163898Smarcel// BugBug: Need to find out if this is portable accross compliers.
181163898Smarcel//
182163898Smarcelvoid __mfa (void);
183163898Smarcel#pragma intrinsic (__mfa)
184163898Smarcel#define MEMORY_FENCE()    __mfa()
185163898Smarcel
186163898Smarcel#ifdef EFI_NO_INTERFACE_DECL
187163898Smarcel  #define EFI_FORWARD_DECLARATION(x)
188163898Smarcel  #define EFI_INTERFACE_DECL(x)
189163898Smarcel#else
190163898Smarcel  #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
191163898Smarcel  #define EFI_INTERFACE_DECL(x) typedef struct x
19277943Sdfr#endif
19377943Sdfr
194163898Smarcel//
195163898Smarcel// When build similiar to FW, then link everything together as
196163898Smarcel// one big module.
197163898Smarcel//
19877943Sdfr
19977943Sdfr#define EFI_DRIVER_ENTRY_POINT(InitFunction)
20077943Sdfr
20177943Sdfr#define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
202163898Smarcel            (_if)->LoadInternal(type, name, entry)
203163898Smarcel//        entry(NULL, ST)
20477943Sdfr
205163898Smarcel#ifdef __FreeBSD__
20677943Sdfr#define INTERFACE_DECL(x) struct x
207163898Smarcel#else
208163898Smarcel//
209163898Smarcel// Some compilers don't support the forward reference construct:
210163898Smarcel//  typedef struct XXXXX
211163898Smarcel//
212163898Smarcel// The following macro provide a workaround for such cases.
213163898Smarcel//
214163898Smarcel#ifdef NO_INTERFACE_DECL
215163898Smarcel#define INTERFACE_DECL(x)
216163898Smarcel#else
217163898Smarcel#define INTERFACE_DECL(x) typedef struct x
218163898Smarcel#endif
219163898Smarcel#endif
220