Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / efi / efi.h
1 #ifndef _IPXE_EFI_H
2 #define _IPXE_EFI_H
3
4 /** @file
5  *
6  * EFI API
7  *
8  * The intention is to include near-verbatim copies of the EFI headers
9  * required by iPXE.  This is achieved using the import.pl script in
10  * this directory.  Run the import script to update the local copies
11  * of the headers:
12  *
13  *     ./import.pl /path/to/edk2/edk2
14  *
15  * where /path/to/edk2/edk2 is the path to your local checkout of the
16  * EFI Development Kit.
17  *
18  * Note that import.pl will modify any #include lines in each imported
19  * header to reflect its new location within the iPXE tree.  It will
20  * also tidy up the file by removing carriage return characters and
21  * trailing whitespace.
22  */
23
24 FILE_LICENCE ( GPL2_OR_LATER );
25
26 /* EFI headers rudely redefine NULL */
27 #undef NULL
28
29 /* EFI headers expect ICC to define __GNUC__ */
30 #if defined ( __ICC ) && ! defined ( __GNUC__ )
31 #define __GNUC__ 1
32 #endif
33
34 /* EFI headers think your compiler uses the MS ABI by default on X64 */
35 #if __x86_64__
36 #define EFIAPI __attribute__((ms_abi))
37 #endif
38
39 /* EFI headers assume regparm(0) on i386, but that is not the case for iPXE */
40 #if __i386__
41 #define EFIAPI __attribute__((cdecl,regparm(0)))
42 #endif
43
44 /* EFI headers define EFI_HANDLE as a void pointer, which renders type
45  * checking somewhat useless.  Work around this bizarre sabotage
46  * attempt by redefining EFI_HANDLE as a pointer to an anonymous
47  * structure.
48  */
49 #define EFI_HANDLE STUPID_EFI_HANDLE
50 #include <ipxe/efi/Uefi/UefiBaseType.h>
51 #undef EFI_HANDLE
52 typedef struct {} *EFI_HANDLE;
53
54 /* Include the top-level EFI header files */
55 #include <ipxe/efi/Uefi.h>
56 #include <ipxe/efi/PiDxe.h>
57 #include <ipxe/efi/Protocol/LoadedImage.h>
58
59 /* Reset any trailing #pragma pack directives */
60 #pragma pack(1)
61 #pragma pack()
62
63 #include <ipxe/tables.h>
64 #include <ipxe/uuid.h>
65
66 /** An EFI protocol used by iPXE */
67 struct efi_protocol {
68         /** GUID */
69         EFI_GUID guid;
70         /** Variable containing pointer to protocol structure */
71         void **protocol;
72         /** Protocol is required */
73         int required;
74 };
75
76 /** EFI protocol table */
77 #define EFI_PROTOCOLS __table ( struct efi_protocol, "efi_protocols" )
78
79 /** Declare an EFI protocol used by iPXE */
80 #define __efi_protocol __table_entry ( EFI_PROTOCOLS, 01 )
81
82 /** Declare an EFI protocol to be required by iPXE
83  *
84  * @v _protocol         EFI protocol name
85  * @v _ptr              Pointer to protocol instance
86  */
87 #define EFI_REQUIRE_PROTOCOL( _protocol, _ptr )                              \
88         struct efi_protocol __ ## _protocol __efi_protocol = {               \
89                 .guid = _protocol ## _GUID,                                  \
90                 .protocol = ( ( void ** ) ( void * )                         \
91                               ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ?  \
92                                 (_ptr) : (_ptr) ) ),                         \
93                 .required = 1,                                               \
94         }
95
96 /** Declare an EFI protocol to be requested by iPXE
97  *
98  * @v _protocol         EFI protocol name
99  * @v _ptr              Pointer to protocol instance
100  */
101 #define EFI_REQUEST_PROTOCOL( _protocol, _ptr )                              \
102         struct efi_protocol __ ## _protocol __efi_protocol = {               \
103                 .guid = _protocol ## _GUID,                                  \
104                 .protocol = ( ( void ** ) ( void * )                         \
105                               ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ?  \
106                                 (_ptr) : (_ptr) ) ),                         \
107                 .required = 0,                                               \
108         }
109
110 /** An EFI configuration table used by iPXE */
111 struct efi_config_table {
112         /** GUID */
113         EFI_GUID guid;
114         /** Variable containing pointer to configuration table */
115         void **table;
116         /** Table is required for operation */
117         int required;
118 };
119
120 /** EFI configuration table table */
121 #define EFI_CONFIG_TABLES \
122         __table ( struct efi_config_table, "efi_config_tables" )
123
124 /** Declare an EFI configuration table used by iPXE */
125 #define __efi_config_table __table_entry ( EFI_CONFIG_TABLES, 01 )
126
127 /** Declare an EFI configuration table to be used by iPXE
128  *
129  * @v _table            EFI configuration table name
130  * @v _ptr              Pointer to configuration table
131  * @v _required         Table is required for operation
132  */
133 #define EFI_USE_TABLE( _table, _ptr, _required )                             \
134         struct efi_config_table __ ## _table __efi_config_table = {          \
135                 .guid = _table ## _GUID,                                     \
136                 .table = ( ( void ** ) ( void * ) (_ptr) ),                  \
137                 .required = (_required),                                     \
138         }
139
140 /**
141  * Convert an iPXE status code to an EFI status code
142  *
143  * @v rc                iPXE status code
144  * @ret efirc           EFI status code
145  */
146 #define EFIRC( rc ) ERRNO_TO_PLATFORM ( -(rc) )
147
148 /**
149  * Convert an EFI status code to an iPXE status code
150  *
151  * @v efirc             EFI status code
152  * @ret rc              iPXE status code (before negation)
153  */
154 #define EEFI( efirc ) EPLATFORM ( EINFO_EPLATFORM, efirc )
155
156 extern EFI_GUID efi_arp_protocol_guid;
157 extern EFI_GUID efi_arp_service_binding_protocol_guid;
158 extern EFI_GUID efi_block_io_protocol_guid;
159 extern EFI_GUID efi_bus_specific_driver_override_protocol_guid;
160 extern EFI_GUID efi_component_name_protocol_guid;
161 extern EFI_GUID efi_component_name2_protocol_guid;
162 extern EFI_GUID efi_device_path_protocol_guid;
163 extern EFI_GUID efi_dhcp4_protocol_guid;
164 extern EFI_GUID efi_dhcp4_service_binding_protocol_guid;
165 extern EFI_GUID efi_disk_io_protocol_guid;
166 extern EFI_GUID efi_driver_binding_protocol_guid;
167 extern EFI_GUID efi_graphics_output_protocol_guid;
168 extern EFI_GUID efi_hii_config_access_protocol_guid;
169 extern EFI_GUID efi_ip4_protocol_guid;
170 extern EFI_GUID efi_ip4_config_protocol_guid;
171 extern EFI_GUID efi_ip4_service_binding_protocol_guid;
172 extern EFI_GUID efi_load_file_protocol_guid;
173 extern EFI_GUID efi_load_file2_protocol_guid;
174 extern EFI_GUID efi_loaded_image_protocol_guid;
175 extern EFI_GUID efi_loaded_image_device_path_protocol_guid;
176 extern EFI_GUID efi_managed_network_protocol_guid;
177 extern EFI_GUID efi_managed_network_service_binding_protocol_guid;
178 extern EFI_GUID efi_mtftp4_protocol_guid;
179 extern EFI_GUID efi_mtftp4_service_binding_protocol_guid;
180 extern EFI_GUID efi_nii_protocol_guid;
181 extern EFI_GUID efi_nii31_protocol_guid;
182 extern EFI_GUID efi_pci_io_protocol_guid;
183 extern EFI_GUID efi_pci_root_bridge_io_protocol_guid;
184 extern EFI_GUID efi_pxe_base_code_protocol_guid;
185 extern EFI_GUID efi_simple_file_system_protocol_guid;
186 extern EFI_GUID efi_simple_network_protocol_guid;
187 extern EFI_GUID efi_tcg_protocol_guid;
188 extern EFI_GUID efi_tcp4_protocol_guid;
189 extern EFI_GUID efi_tcp4_service_binding_protocol_guid;
190 extern EFI_GUID efi_udp4_protocol_guid;
191 extern EFI_GUID efi_udp4_service_binding_protocol_guid;
192 extern EFI_GUID efi_vlan_config_protocol_guid;
193
194 extern EFI_HANDLE efi_image_handle;
195 extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
196 extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
197 extern EFI_SYSTEM_TABLE *efi_systab;
198
199 extern const char * efi_guid_ntoa ( EFI_GUID *guid );
200 extern const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path );
201 extern const char * efi_handle_name ( EFI_HANDLE handle );
202
203 extern void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol );
204 extern void dbg_efi_protocols ( EFI_HANDLE handle );
205
206 #define DBG_EFI_OPENERS_IF( level, handle, protocol ) do {      \
207                 if ( DBG_ ## level ) {                          \
208                         dbg_efi_openers ( handle, protocol );   \
209                 }                                               \
210         } while ( 0 )
211
212 #define DBG_EFI_PROTOCOLS_IF( level, handle ) do {              \
213                 if ( DBG_ ## level ) {                          \
214                         dbg_efi_protocols ( handle );           \
215                 }                                               \
216         } while ( 0 )
217
218 #define DBGC_EFI_OPENERS_IF( level, id, ... ) do {              \
219                 DBG_AC_IF ( level, id );                        \
220                 DBG_EFI_OPENERS_IF ( level, __VA_ARGS__ );      \
221                 DBG_DC_IF ( level );                            \
222         } while ( 0 )
223
224 #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do {            \
225                 DBG_AC_IF ( level, id );                        \
226                 DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ );    \
227                 DBG_DC_IF ( level );                            \
228         } while ( 0 )
229
230 #define DBGC_EFI_OPENERS( ... )                                 \
231         DBGC_EFI_OPENERS_IF ( LOG, ##__VA_ARGS__ )
232 #define DBGC_EFI_PROTOCOLS( ... )                               \
233         DBGC_EFI_PROTOCOLS_IF ( LOG, ##__VA_ARGS__ )
234
235 #define DBGC2_EFI_OPENERS( ... )                                \
236         DBGC_EFI_OPENERS_IF ( EXTRA, ##__VA_ARGS__ )
237 #define DBGC2_EFI_PROTOCOLS( ... )                              \
238         DBGC_EFI_PROTOCOLS_IF ( EXTRA, ##__VA_ARGS__ )
239
240 #define DBGCP_EFI_OPENERS( ... )                                \
241         DBGC_EFI_OPENERS_IF ( PROFILE, ##__VA_ARGS__ )
242 #define DBGCP_EFI_PROTOCOLS( ... )                              \
243         DBGC_EFI_PROTOCOLS_IF ( PROFILE, ##__VA_ARGS__ )
244
245 extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
246                              EFI_SYSTEM_TABLE *systab );
247
248 #endif /* _IPXE_EFI_H */