1199767fToomas Soome/* $FreeBSD$ */
2199767fToomas Soome/*++
3199767fToomas Soome
4199767fToomas SoomeCopyright (c)  1999 - 2003 Intel Corporation. All rights reserved
5199767fToomas SoomeThis software and associated documentation (if any) is furnished
6199767fToomas Soomeunder a license and may only be used or copied in accordance
7199767fToomas Soomewith the terms of the license. Except as permitted by such
8199767fToomas Soomelicense, no part of this software or documentation may be
9199767fToomas Soomereproduced, stored in a retrieval system, or transmitted in any
10199767fToomas Soomeform or by any means without the express written consent of
11199767fToomas SoomeIntel Corporation.
12199767fToomas Soome
13199767fToomas SoomeModule Name:
14199767fToomas Soome
15199767fToomas Soome    efefind.h
16199767fToomas Soome
17199767fToomas SoomeAbstract:
18199767fToomas Soome
19199767fToomas Soome    EFI to compile bindings
20199767fToomas Soome
21199767fToomas Soome
22199767fToomas Soome
23199767fToomas Soome
24199767fToomas SoomeRevision History
25199767fToomas Soome
26199767fToomas Soome--*/
27199767fToomas Soome
28199767fToomas Soome#pragma pack()
29199767fToomas Soome
30199767fToomas Soome
31199767fToomas Soome#ifdef __FreeBSD__
32199767fToomas Soome#include <sys/stdint.h>
33199767fToomas Soome#else
34199767fToomas Soome//
35199767fToomas Soome// Basic int types of various widths
36199767fToomas Soome//
37199767fToomas Soome
38199767fToomas Soome#if (__STDC_VERSION__ < 199901L )
39199767fToomas Soome
40199767fToomas Soome    // No ANSI C 1999/2000 stdint.h integer width declarations
41199767fToomas Soome
42199767fToomas Soome    #ifdef _MSC_EXTENSIONS
43199767fToomas Soome
44199767fToomas Soome        // Use Microsoft C compiler integer width declarations
45199767fToomas Soome
46199767fToomas Soome        typedef unsigned __int64    uint64_t;
47199767fToomas Soome        typedef __int64             int64_t;
48199767fToomas Soome        typedef unsigned __int32    uint32_t;
49199767fToomas Soome        typedef __int32             int32_t;
50199767fToomas Soome        typedef unsigned __int16    uint16_t;
51199767fToomas Soome        typedef __int16             int16_t;
52199767fToomas Soome        typedef unsigned __int8     uint8_t;
53199767fToomas Soome        typedef __int8              int8_t;
54199767fToomas Soome    #else
55199767fToomas Soome        #ifdef UNIX_LP64
56199767fToomas Soome
57199767fToomas Soome            // Use LP64 programming model from C_FLAGS for integer width declarations
58199767fToomas Soome
59199767fToomas Soome            typedef unsigned long       uint64_t;
60199767fToomas Soome            typedef long                int64_t;
61199767fToomas Soome            typedef unsigned int        uint32_t;
62199767fToomas Soome            typedef int                 int32_t;
63199767fToomas Soome            typedef unsigned short      uint16_t;
64199767fToomas Soome            typedef short               int16_t;
65199767fToomas Soome            typedef unsigned char       uint8_t;
66199767fToomas Soome            typedef char                int8_t;
67199767fToomas Soome        #else
68199767fToomas Soome
69199767fToomas Soome            // Assume P64 programming model from C_FLAGS for integer width declarations
70199767fToomas Soome
71199767fToomas Soome            typedef unsigned long long  uint64_t;
72199767fToomas Soome            typedef long long           int64_t;
73199767fToomas Soome            typedef unsigned int        uint32_t;
74199767fToomas Soome            typedef int                 int32_t;
75199767fToomas Soome            typedef unsigned short      uint16_t;
76199767fToomas Soome            typedef short               int16_t;
77199767fToomas Soome            typedef unsigned char       uint8_t;
78199767fToomas Soome            typedef char                int8_t;
79199767fToomas Soome        #endif
80199767fToomas Soome    #endif
81199767fToomas Soome#endif
82199767fToomas Soome#endif	/* __FreeBSD__ */
83199767fToomas Soome
84199767fToomas Soome//
85199767fToomas Soome// Basic EFI types of various widths
86199767fToomas Soome//
87199767fToomas Soome
88199767fToomas Soome
89199767fToomas Soometypedef uint64_t   UINT64;
90199767fToomas Soometypedef int64_t    INT64;
91199767fToomas Soometypedef uint32_t   UINT32;
92199767fToomas Soometypedef int32_t    INT32;
93199767fToomas Soometypedef uint16_t   UINT16;
94199767fToomas Soometypedef int16_t    INT16;
95199767fToomas Soometypedef uint8_t    UINT8;
96199767fToomas Soometypedef int8_t     INT8;
97199767fToomas Soome
98199767fToomas Soome
99199767fToomas Soome#undef VOID
100199767fToomas Soome#define VOID    void
101199767fToomas Soome
102199767fToomas Soome
103199767fToomas Soometypedef int64_t    INTN;
104199767fToomas Soometypedef uint64_t   UINTN;
105199767fToomas Soome
106199767fToomas Soome//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107199767fToomas Soome// BugBug: Code to debug
108199767fToomas Soome//
109199767fToomas Soome#define BIT63   0x8000000000000000
110199767fToomas Soome
111199767fToomas Soome#define PLATFORM_IOBASE_ADDRESS   (0xffffc000000 | BIT63)
112199767fToomas Soome#define PORT_TO_MEMD(_Port) (PLATFORM_IOBASE_ADDRESS | ( ( ( (_Port) & 0xfffc) << 10 ) | ( (_Port) & 0x0fff) ) )
113199767fToomas Soome
114199767fToomas Soome//
115199767fToomas Soome// Macro's with casts make this much easier to use and read.
116199767fToomas Soome//
117199767fToomas Soome#define PORT_TO_MEM8D(_Port)  (*(UINT8  *)(PORT_TO_MEMD(_Port)))
118199767fToomas Soome#define POST_CODE(_Data)  (PORT_TO_MEM8D(0x80) = (_Data))
119199767fToomas Soome//
120199767fToomas Soome// BugBug: End Debug Code!!!
121199767fToomas Soome//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122199767fToomas Soome
123199767fToomas Soome#define EFIERR(a)           (0x8000000000000000 | a)
124199767fToomas Soome#define EFI_ERROR_MASK      0x8000000000000000
125199767fToomas Soome#define EFIERR_OEM(a)       (0xc000000000000000 | a)
126199767fToomas Soome
127199767fToomas Soome#define BAD_POINTER         0xFBFBFBFBFBFBFBFB
128199767fToomas Soome#define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
129199767fToomas Soome
130199767fToomas Soome#define BREAKPOINT()  __break(0)
131199767fToomas Soome
132199767fToomas Soome//
133199767fToomas Soome// Pointers must be aligned to these address to function
134199767fToomas Soome//  you will get an alignment fault if this value is less than 8
135199767fToomas Soome//
136199767fToomas Soome#define MIN_ALIGNMENT_SIZE  8
137199767fToomas Soome
138199767fToomas Soome#define ALIGN_VARIABLE(Value , Adjustment) \
139199767fToomas Soome            (UINTN) Adjustment = 0; \
140199767fToomas Soome            if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
141199767fToomas Soome                (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
142199767fToomas Soome            Value = (UINTN)Value + (UINTN)Adjustment
143199767fToomas Soome
144199767fToomas Soome//
145199767fToomas Soome// Define macros to create data structure signatures.
146199767fToomas Soome//
147199767fToomas Soome
148199767fToomas Soome#define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
149199767fToomas Soome#define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
150199767fToomas Soome#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))
151199767fToomas Soome
152199767fToomas Soome//
153199767fToomas Soome// EFIAPI - prototype calling convention for EFI function pointers
154199767fToomas Soome// BOOTSERVICE - prototype for implementation of a boot service interface
155199767fToomas Soome// RUNTIMESERVICE - prototype for implementation of a runtime service interface
156199767fToomas Soome// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
157199767fToomas Soome// RUNTIME_CODE - pragma macro for declaring runtime code
158199767fToomas Soome//
159199767fToomas Soome
160199767fToomas Soome#ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
161199767fToomas Soome    #ifdef _MSC_EXTENSIONS
162199767fToomas Soome        #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
163199767fToomas Soome    #else
164199767fToomas Soome        #define EFIAPI          // Substitute expresion to force C calling convention
165199767fToomas Soome    #endif
166199767fToomas Soome#endif
167199767fToomas Soome
168199767fToomas Soome#define BOOTSERVICE
169199767fToomas Soome#define RUNTIMESERVICE
170199767fToomas Soome#define RUNTIMEFUNCTION
171199767fToomas Soome
172199767fToomas Soome#define RUNTIME_CODE(a)         alloc_text("rtcode", a)
173199767fToomas Soome#define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
174199767fToomas Soome#define END_RUNTIME_DATA()      data_seg()
175199767fToomas Soome
176199767fToomas Soome#define VOLATILE    volatile
177199767fToomas Soome
178199767fToomas Soome//
1790350272Toomas Soome// BugBug: Need to find out if this is portable across compilers.
180199767fToomas Soome//
1810350272Toomas Soomevoid __mfa (void);
182199767fToomas Soome#define MEMORY_FENCE()    __mfa()
183199767fToomas Soome
184199767fToomas Soome#ifdef EFI_NO_INTERFACE_DECL
185199767fToomas Soome  #define EFI_FORWARD_DECLARATION(x)
186199767fToomas Soome  #define EFI_INTERFACE_DECL(x)
187199767fToomas Soome#else
188199767fToomas Soome  #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
189199767fToomas Soome  #define EFI_INTERFACE_DECL(x) typedef struct x
190199767fToomas Soome#endif
191199767fToomas Soome
192199767fToomas Soome//
1930350272Toomas Soome// When building similar to FW, link everything together as
194199767fToomas Soome// one big module.
195199767fToomas Soome//
196199767fToomas Soome
197199767fToomas Soome#define EFI_DRIVER_ENTRY_POINT(InitFunction)
198199767fToomas Soome
199199767fToomas Soome#define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
200199767fToomas Soome            (_if)->LoadInternal(type, name, entry)
201199767fToomas Soome//        entry(NULL, ST)
202199767fToomas Soome
203199767fToomas Soome#ifdef __FreeBSD__
204199767fToomas Soome#define INTERFACE_DECL(x) struct x
205199767fToomas Soome#else
206199767fToomas Soome//
207199767fToomas Soome// Some compilers don't support the forward reference construct:
208199767fToomas Soome//  typedef struct XXXXX
209199767fToomas Soome//
210199767fToomas Soome// The following macro provide a workaround for such cases.
211199767fToomas Soome//
212199767fToomas Soome#ifdef NO_INTERFACE_DECL
213199767fToomas Soome#define INTERFACE_DECL(x)
214199767fToomas Soome#else
215199767fToomas Soome#define INTERFACE_DECL(x) typedef struct x
216199767fToomas Soome#endif
217199767fToomas Soome#endif