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 redefine ARRAY_SIZE */
30 #undef ARRAY_SIZE
31 
32 /* EFI headers expect ICC to define __GNUC__ */
33 #if defined ( __ICC ) && ! defined ( __GNUC__ )
34 #define __GNUC__ 1
35 #endif
36 
37 /* EFI headers think your compiler uses the MS ABI by default on X64 */
38 #if __x86_64__
39 #define EFIAPI __attribute__((ms_abi))
40 #endif
41 
42 /* EFI headers assume regparm(0) on i386, but that is not the case for iPXE */
43 #if __i386__
44 #define EFIAPI __attribute__((cdecl,regparm(0)))
45 #endif
46 
47 /* EFI headers define EFI_HANDLE as a void pointer, which renders type
48  * checking somewhat useless.  Work around this bizarre sabotage
49  * attempt by redefining EFI_HANDLE as a pointer to an anonymous
50  * structure.
51  */
52 #define EFI_HANDLE STUPID_EFI_HANDLE
53 #include <ipxe/efi/Uefi/UefiBaseType.h>
54 #undef EFI_HANDLE
55 typedef struct {} *EFI_HANDLE;
56 
57 /* Include the top-level EFI header files */
58 #include <ipxe/efi/Uefi.h>
59 #include <ipxe/efi/PiDxe.h>
60 #include <ipxe/efi/Protocol/LoadedImage.h>
61 
62 /* Reset any trailing #pragma pack directives */
63 #pragma pack(1)
64 #pragma pack()
65 
66 #include <ipxe/tables.h>
67 #include <ipxe/uuid.h>
68 
69 /** An EFI protocol used by iPXE */
70 struct efi_protocol {
71 	/** GUID */
72 	EFI_GUID guid;
73 	/** Variable containing pointer to protocol structure */
74 	void **protocol;
75 	/** Protocol is required */
76 	int required;
77 };
78 
79 /** EFI protocol table */
80 #define EFI_PROTOCOLS __table ( struct efi_protocol, "efi_protocols" )
81 
82 /** Declare an EFI protocol used by iPXE */
83 #define __efi_protocol __table_entry ( EFI_PROTOCOLS, 01 )
84 
85 /** Declare an EFI protocol to be required by iPXE
86  *
87  * @v _protocol		EFI protocol name
88  * @v _ptr		Pointer to protocol instance
89  */
90 #define EFI_REQUIRE_PROTOCOL( _protocol, _ptr )				     \
91 	struct efi_protocol __ ## _protocol __efi_protocol = {		     \
92 		.guid = _protocol ## _GUID,				     \
93 		.protocol = ( ( void ** ) ( void * )			     \
94 			      ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ?  \
95 				(_ptr) : (_ptr) ) ),			     \
96 		.required = 1,						     \
97 	}
98 
99 /** Declare an EFI protocol to be requested by iPXE
100  *
101  * @v _protocol		EFI protocol name
102  * @v _ptr		Pointer to protocol instance
103  */
104 #define EFI_REQUEST_PROTOCOL( _protocol, _ptr )				     \
105 	struct efi_protocol __ ## _protocol __efi_protocol = {		     \
106 		.guid = _protocol ## _GUID,				     \
107 		.protocol = ( ( void ** ) ( void * )			     \
108 			      ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ?  \
109 				(_ptr) : (_ptr) ) ),			     \
110 		.required = 0,						     \
111 	}
112 
113 /** An EFI configuration table used by iPXE */
114 struct efi_config_table {
115 	/** GUID */
116 	EFI_GUID guid;
117 	/** Variable containing pointer to configuration table */
118 	void **table;
119 	/** Table is required for operation */
120 	int required;
121 };
122 
123 /** EFI configuration table table */
124 #define EFI_CONFIG_TABLES \
125 	__table ( struct efi_config_table, "efi_config_tables" )
126 
127 /** Declare an EFI configuration table used by iPXE */
128 #define __efi_config_table __table_entry ( EFI_CONFIG_TABLES, 01 )
129 
130 /** Declare an EFI configuration table to be used by iPXE
131  *
132  * @v _table		EFI configuration table name
133  * @v _ptr		Pointer to configuration table
134  * @v _required		Table is required for operation
135  */
136 #define EFI_USE_TABLE( _table, _ptr, _required )			     \
137 	struct efi_config_table __ ## _table __efi_config_table = {	     \
138 		.guid = _table ## _GUID,				     \
139 		.table = ( ( void ** ) ( void * ) (_ptr) ),		     \
140 		.required = (_required),				     \
141 	}
142 
143 /**
144  * Convert an iPXE status code to an EFI status code
145  *
146  * @v rc		iPXE status code
147  * @ret efirc		EFI status code
148  */
149 #define EFIRC( rc ) ERRNO_TO_PLATFORM ( -(rc) )
150 
151 /**
152  * Convert an EFI status code to an iPXE status code
153  *
154  * @v efirc		EFI status code
155  * @ret rc		iPXE status code (before negation)
156  */
157 #define EEFI( efirc ) EPLATFORM ( EINFO_EPLATFORM, efirc )
158 
159 extern EFI_GUID efi_absolute_pointer_protocol_guid;
160 extern EFI_GUID efi_acpi_table_protocol_guid;
161 extern EFI_GUID efi_apple_net_boot_protocol_guid;
162 extern EFI_GUID efi_arp_protocol_guid;
163 extern EFI_GUID efi_arp_service_binding_protocol_guid;
164 extern EFI_GUID efi_block_io_protocol_guid;
165 extern EFI_GUID efi_block_io2_protocol_guid;
166 extern EFI_GUID efi_bus_specific_driver_override_protocol_guid;
167 extern EFI_GUID efi_component_name_protocol_guid;
168 extern EFI_GUID efi_component_name2_protocol_guid;
169 extern EFI_GUID efi_console_control_protocol_guid;
170 extern EFI_GUID efi_device_path_protocol_guid;
171 extern EFI_GUID efi_dhcp4_protocol_guid;
172 extern EFI_GUID efi_dhcp4_service_binding_protocol_guid;
173 extern EFI_GUID efi_disk_io_protocol_guid;
174 extern EFI_GUID efi_driver_binding_protocol_guid;
175 extern EFI_GUID efi_graphics_output_protocol_guid;
176 extern EFI_GUID efi_hii_config_access_protocol_guid;
177 extern EFI_GUID efi_hii_font_protocol_guid;
178 extern EFI_GUID efi_ip4_protocol_guid;
179 extern EFI_GUID efi_ip4_config_protocol_guid;
180 extern EFI_GUID efi_ip4_service_binding_protocol_guid;
181 extern EFI_GUID efi_load_file_protocol_guid;
182 extern EFI_GUID efi_load_file2_protocol_guid;
183 extern EFI_GUID efi_loaded_image_protocol_guid;
184 extern EFI_GUID efi_loaded_image_device_path_protocol_guid;
185 extern EFI_GUID efi_managed_network_protocol_guid;
186 extern EFI_GUID efi_managed_network_service_binding_protocol_guid;
187 extern EFI_GUID efi_mtftp4_protocol_guid;
188 extern EFI_GUID efi_mtftp4_service_binding_protocol_guid;
189 extern EFI_GUID efi_nii_protocol_guid;
190 extern EFI_GUID efi_nii31_protocol_guid;
191 extern EFI_GUID efi_pci_io_protocol_guid;
192 extern EFI_GUID efi_pci_root_bridge_io_protocol_guid;
193 extern EFI_GUID efi_pxe_base_code_protocol_guid;
194 extern EFI_GUID efi_serial_io_protocol_guid;
195 extern EFI_GUID efi_simple_file_system_protocol_guid;
196 extern EFI_GUID efi_simple_network_protocol_guid;
197 extern EFI_GUID efi_simple_pointer_protocol_guid;
198 extern EFI_GUID efi_simple_text_input_protocol_guid;
199 extern EFI_GUID efi_simple_text_input_ex_protocol_guid;
200 extern EFI_GUID efi_simple_text_output_protocol_guid;
201 extern EFI_GUID efi_tcg_protocol_guid;
202 extern EFI_GUID efi_tcp4_protocol_guid;
203 extern EFI_GUID efi_tcp4_service_binding_protocol_guid;
204 extern EFI_GUID efi_tree_protocol_guid;
205 extern EFI_GUID efi_udp4_protocol_guid;
206 extern EFI_GUID efi_udp4_service_binding_protocol_guid;
207 extern EFI_GUID efi_uga_draw_protocol_guid;
208 extern EFI_GUID efi_unicode_collation_protocol_guid;
209 extern EFI_GUID efi_usb_hc_protocol_guid;
210 extern EFI_GUID efi_usb2_hc_protocol_guid;
211 extern EFI_GUID efi_usb_io_protocol_guid;
212 extern EFI_GUID efi_vlan_config_protocol_guid;
213 
214 extern EFI_GUID efi_file_info_id;
215 extern EFI_GUID efi_file_system_info_id;
216 
217 extern EFI_HANDLE efi_image_handle;
218 extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
219 extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
220 extern EFI_SYSTEM_TABLE *efi_systab;
221 extern int efi_shutdown_in_progress;
222 
223 extern const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid );
224 extern const __attribute__ (( pure )) char *
225 efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE search_type );
226 extern const __attribute__ (( pure )) char *
227 efi_open_attributes_name ( unsigned int attributes );
228 extern const __attribute__ (( pure )) char *
229 efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path );
230 extern const __attribute__ (( pure )) char *
231 efi_handle_name ( EFI_HANDLE handle );
232 
233 extern void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol );
234 extern void dbg_efi_protocols ( EFI_HANDLE handle );
235 
236 #define DBG_EFI_OPENERS_IF( level, handle, protocol ) do {	\
237 		if ( DBG_ ## level ) {				\
238 			dbg_efi_openers ( handle, protocol );	\
239 		}						\
240 	} while ( 0 )
241 
242 #define DBG_EFI_PROTOCOLS_IF( level, handle ) do {		\
243 		if ( DBG_ ## level ) {				\
244 			dbg_efi_protocols ( handle );		\
245 		}						\
246 	} while ( 0 )
247 
248 #define DBGC_EFI_OPENERS_IF( level, id, ... ) do {		\
249 		DBG_AC_IF ( level, id );			\
250 		DBG_EFI_OPENERS_IF ( level, __VA_ARGS__ );	\
251 		DBG_DC_IF ( level );				\
252 	} while ( 0 )
253 
254 #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do {		\
255 		DBG_AC_IF ( level, id );			\
256 		DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ );	\
257 		DBG_DC_IF ( level );				\
258 	} while ( 0 )
259 
260 #define DBGC_EFI_OPENERS( ... )					\
261 	DBGC_EFI_OPENERS_IF ( LOG, ##__VA_ARGS__ )
262 #define DBGC_EFI_PROTOCOLS( ... )				\
263 	DBGC_EFI_PROTOCOLS_IF ( LOG, ##__VA_ARGS__ )
264 
265 #define DBGC2_EFI_OPENERS( ... )				\
266 	DBGC_EFI_OPENERS_IF ( EXTRA, ##__VA_ARGS__ )
267 #define DBGC2_EFI_PROTOCOLS( ... )				\
268 	DBGC_EFI_PROTOCOLS_IF ( EXTRA, ##__VA_ARGS__ )
269 
270 #define DBGCP_EFI_OPENERS( ... )				\
271 	DBGC_EFI_OPENERS_IF ( PROFILE, ##__VA_ARGS__ )
272 #define DBGCP_EFI_PROTOCOLS( ... )				\
273 	DBGC_EFI_PROTOCOLS_IF ( PROFILE, ##__VA_ARGS__ )
274 
275 extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
276 			     EFI_SYSTEM_TABLE *systab );
277 
278 #endif /* _IPXE_EFI_H */
279