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