1
2
3
4
5
6
7
8#ifndef _EFI_LOADER_H
9#define _EFI_LOADER_H 1
10
11#include <common.h>
12#include <part_efi.h>
13#include <efi_api.h>
14
15static inline int guidcmp(const void *g1, const void *g2)
16{
17 return memcmp(g1, g2, sizeof(efi_guid_t));
18}
19
20
21#if CONFIG_IS_ENABLED(EFI_LOADER)
22
23#include <linux/list.h>
24
25
26#define EFI_MAX_CONFIGURATION_TABLES 16
27
28
29#define U_BOOT_GUID \
30 EFI_GUID(0xe61d73b9, 0xa384, 0x4acc, \
31 0xae, 0xab, 0x82, 0xe8, 0x28, 0xf3, 0x62, 0x8b)
32
33#define U_BOOT_HOST_DEV_GUID \
34 EFI_GUID(0xbbe4e671, 0x5773, 0x4ea1, \
35 0x9a, 0xab, 0x3a, 0x7d, 0xbf, 0x40, 0xc4, 0x82)
36
37
38extern efi_handle_t efi_root;
39
40int __efi_entry_check(void);
41int __efi_exit_check(void);
42const char *__efi_nesting(void);
43const char *__efi_nesting_inc(void);
44const char *__efi_nesting_dec(void);
45
46
47
48
49#define EFI_ENTRY(format, ...) do { \
50 assert(__efi_entry_check()); \
51 debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \
52 __func__, ##__VA_ARGS__); \
53 } while(0)
54
55
56
57
58#define EFI_EXIT(ret) ({ \
59 typeof(ret) _r = ret; \
60 debug("%sEFI: Exit: %s: %u\n", __efi_nesting_dec(), \
61 __func__, (u32)((uintptr_t) _r & ~EFI_ERROR_MASK)); \
62 assert(__efi_exit_check()); \
63 _r; \
64 })
65
66
67
68
69#define EFI_CALL(exp) ({ \
70 debug("%sEFI: Call: %s\n", __efi_nesting_inc(), #exp); \
71 assert(__efi_exit_check()); \
72 typeof(exp) _r = exp; \
73 assert(__efi_entry_check()); \
74 debug("%sEFI: %lu returned by %s\n", __efi_nesting_dec(), \
75 (unsigned long)((uintptr_t)_r & ~EFI_ERROR_MASK), #exp); \
76 _r; \
77})
78
79
80
81
82#define EFI_CALL_VOID(exp) do { \
83 debug("%sEFI: Call: %s\n", __efi_nesting_inc(), #exp); \
84 assert(__efi_exit_check()); \
85 exp; \
86 assert(__efi_entry_check()); \
87 debug("%sEFI: Return From: %s\n", __efi_nesting_dec(), #exp); \
88 } while(0)
89
90
91
92
93#define EFI_PRINT(format, ...) ({ \
94 debug("%sEFI: " format, __efi_nesting(), \
95 ##__VA_ARGS__); \
96 })
97
98#ifdef CONFIG_SYS_CACHELINE_SIZE
99#define EFI_CACHELINE_SIZE CONFIG_SYS_CACHELINE_SIZE
100#else
101
102#define EFI_CACHELINE_SIZE 128
103#endif
104
105
106extern efi_uintn_t efi_memory_map_key;
107
108extern struct efi_runtime_services efi_runtime_services;
109extern struct efi_system_table systab;
110
111extern struct efi_simple_text_output_protocol efi_con_out;
112extern struct efi_simple_text_input_protocol efi_con_in;
113extern struct efi_console_control_protocol efi_console_control;
114extern const struct efi_device_path_to_text_protocol efi_device_path_to_text;
115
116extern const struct efi_device_path_utilities_protocol
117 efi_device_path_utilities;
118
119extern const struct efi_unicode_collation_protocol
120 efi_unicode_collation_protocol;
121
122extern const struct efi_unicode_collation_protocol
123 efi_unicode_collation_protocol2;
124extern const struct efi_hii_config_routing_protocol efi_hii_config_routing;
125extern const struct efi_hii_config_access_protocol efi_hii_config_access;
126extern const struct efi_hii_database_protocol efi_hii_database;
127extern const struct efi_hii_string_protocol efi_hii_string;
128
129uint16_t *efi_dp_str(struct efi_device_path *dp);
130
131
132extern const efi_guid_t efi_u_boot_guid;
133#ifdef CONFIG_SANDBOX
134
135extern const efi_guid_t efi_guid_host_dev;
136#endif
137
138extern const efi_guid_t efi_block_io_guid;
139extern const efi_guid_t efi_global_variable_guid;
140extern const efi_guid_t efi_guid_console_control;
141extern const efi_guid_t efi_guid_device_path;
142
143extern const efi_guid_t efi_guid_driver_binding_protocol;
144
145extern const efi_guid_t efi_guid_event_group_exit_boot_services;
146
147extern const efi_guid_t efi_guid_event_group_virtual_address_change;
148
149extern const efi_guid_t efi_guid_event_group_memory_map_change;
150
151extern const efi_guid_t efi_guid_event_group_ready_to_boot;
152
153extern const efi_guid_t efi_guid_event_group_reset_system;
154
155extern const efi_guid_t efi_guid_fdt;
156extern const efi_guid_t efi_guid_loaded_image;
157extern const efi_guid_t efi_guid_loaded_image_device_path;
158extern const efi_guid_t efi_guid_device_path_to_text_protocol;
159extern const efi_guid_t efi_simple_file_system_protocol_guid;
160extern const efi_guid_t efi_file_info_guid;
161
162extern const efi_guid_t efi_file_system_info_guid;
163extern const efi_guid_t efi_guid_device_path_utilities_protocol;
164
165extern const efi_guid_t efi_guid_unicode_collation_protocol;
166
167extern const efi_guid_t efi_guid_unicode_collation_protocol2;
168extern const efi_guid_t efi_guid_hii_config_routing_protocol;
169extern const efi_guid_t efi_guid_hii_config_access_protocol;
170extern const efi_guid_t efi_guid_hii_database_protocol;
171extern const efi_guid_t efi_guid_hii_string_protocol;
172
173extern unsigned int __efi_runtime_start, __efi_runtime_stop;
174extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
175
176
177
178
179
180
181
182
183
184
185struct efi_open_protocol_info_item {
186 struct list_head link;
187 struct efi_open_protocol_info_entry info;
188};
189
190
191
192
193
194
195
196
197
198
199
200
201
202struct efi_handler {
203 struct list_head link;
204 const efi_guid_t *guid;
205 void *protocol_interface;
206 struct list_head open_infos;
207};
208
209
210
211
212
213
214
215enum efi_object_type {
216 EFI_OBJECT_TYPE_UNDEFINED = 0,
217 EFI_OBJECT_TYPE_U_BOOT_FIRMWARE,
218 EFI_OBJECT_TYPE_LOADED_IMAGE,
219 EFI_OBJECT_TYPE_STARTED_IMAGE,
220};
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239struct efi_object {
240
241 struct list_head link;
242
243 struct list_head protocols;
244 enum efi_object_type type;
245};
246
247
248
249
250
251
252
253
254
255
256
257struct efi_loaded_image_obj {
258 struct efi_object header;
259 efi_status_t exit_status;
260 efi_uintn_t *exit_data_size;
261 u16 **exit_data;
262 struct jmp_buf_data exit_jmp;
263 EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,
264 struct efi_system_table *st);
265 u16 image_type;
266};
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283struct efi_event {
284 struct list_head link;
285 struct list_head queue_link;
286 uint32_t type;
287 efi_uintn_t notify_tpl;
288 void (EFIAPI *notify_function)(struct efi_event *event, void *context);
289 void *notify_context;
290 const efi_guid_t *group;
291 u64 trigger_next;
292 u64 trigger_time;
293 enum efi_timer_delay trigger_type;
294 bool is_signaled;
295};
296
297
298extern struct list_head efi_obj_list;
299
300extern struct list_head efi_events;
301
302
303
304
305
306
307
308
309
310
311
312struct efi_protocol_notification {
313 struct list_head link;
314 efi_handle_t handle;
315};
316
317
318
319
320
321
322
323
324
325
326
327
328
329struct efi_register_notify_event {
330 struct list_head link;
331 struct efi_event *event;
332 efi_guid_t protocol;
333 struct list_head handles;
334};
335
336
337extern struct list_head efi_register_notify_events;
338
339
340efi_status_t efi_init_obj_list(void);
341
342efi_status_t efi_init_variables(void);
343
344void efi_variables_boot_exit_notify(void);
345
346efi_status_t efi_root_node_register(void);
347
348efi_status_t efi_initialize_system_table(void);
349
350void efi_runtime_detach(void);
351
352efi_status_t efi_console_register(void);
353
354efi_status_t efi_disk_register(void);
355
356int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
357 const char *if_typename, int diskid,
358 const char *pdevname);
359
360efi_status_t efi_gop_register(void);
361
362efi_status_t efi_net_register(void);
363
364efi_status_t efi_watchdog_register(void);
365
366
367
368
369
370
371
372
373efi_status_t efi_acpi_register(void);
374
375
376
377
378
379
380
381efi_status_t efi_smbios_register(void);
382
383struct efi_simple_file_system_protocol *
384efi_fs_from_path(struct efi_device_path *fp);
385
386
387void efi_net_set_dhcp_ack(void *pkt, int len);
388
389efi_status_t efi_set_watchdog(unsigned long timeout);
390
391
392void efi_timer_check(void);
393
394efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, void *efi,
395 struct efi_loaded_image *loaded_image_info);
396
397void efi_save_gd(void);
398
399
400void efi_restore_gd(void);
401
402void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map);
403
404void efi_set_bootdev(const char *dev, const char *devnr, const char *path);
405
406void efi_add_handle(efi_handle_t obj);
407
408efi_status_t efi_create_handle(efi_handle_t *handle);
409
410void efi_delete_handle(efi_handle_t obj);
411
412struct efi_object *efi_search_obj(const efi_handle_t handle);
413
414efi_status_t EFIAPI efi_load_image(bool boot_policy,
415 efi_handle_t parent_image,
416 struct efi_device_path *file_path,
417 void *source_buffer,
418 efi_uintn_t source_size,
419 efi_handle_t *image_handle);
420
421efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
422 efi_uintn_t *exit_data_size,
423 u16 **exit_data);
424
425efi_status_t EFIAPI efi_unload_image(efi_handle_t image_handle);
426
427efi_status_t efi_search_protocol(const efi_handle_t handle,
428 const efi_guid_t *protocol_guid,
429 struct efi_handler **handler);
430
431efi_status_t efi_add_protocol(const efi_handle_t handle,
432 const efi_guid_t *protocol,
433 void *protocol_interface);
434
435efi_status_t efi_remove_protocol(const efi_handle_t handle,
436 const efi_guid_t *protocol,
437 void *protocol_interface);
438
439efi_status_t efi_remove_all_protocols(const efi_handle_t handle);
440
441efi_status_t EFIAPI efi_install_multiple_protocol_interfaces
442 (efi_handle_t *handle, ...);
443
444efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl,
445 void (EFIAPI *notify_function) (
446 struct efi_event *event,
447 void *context),
448 void *notify_context, efi_guid_t *group,
449 struct efi_event **event);
450
451efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
452 uint64_t trigger_time);
453
454void efi_signal_event(struct efi_event *event);
455
456
457struct efi_simple_file_system_protocol *efi_simple_file_system(
458 struct blk_desc *desc, int part, struct efi_device_path *dp);
459
460
461struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp);
462
463
464
465
466
467
468
469
470
471
472#define efi_size_in_pages(size) ((size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT)
473
474void *efi_alloc(uint64_t len, int memory_type);
475
476efi_status_t efi_allocate_pages(int type, int memory_type, efi_uintn_t pages,
477 uint64_t *memory);
478
479efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages);
480
481efi_status_t efi_allocate_pool(int pool_type, efi_uintn_t size,
482 void **buffer);
483
484efi_status_t efi_free_pool(void *buffer);
485
486efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
487 struct efi_mem_desc *memory_map,
488 efi_uintn_t *map_key,
489 efi_uintn_t *descriptor_size,
490 uint32_t *descriptor_version);
491
492efi_status_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type,
493 bool overlap_only_ram);
494
495efi_status_t efi_add_conventional_memory_map(u64 ram_start, u64 ram_end,
496 u64 ram_top);
497
498
499efi_status_t efi_driver_init(void);
500
501int efi_memory_init(void);
502
503efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table);
504
505efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path,
506 struct efi_device_path *file_path,
507 struct efi_loaded_image_obj **handle_ptr,
508 struct efi_loaded_image **info_ptr);
509
510void efi_print_image_infos(void *pc);
511
512#ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
513extern void *efi_bounce_buffer;
514#define EFI_LOADER_BOUNCE_BUFFER_SIZE (64 * 1024 * 1024)
515#endif
516
517
518struct efi_device_path *efi_dp_next(const struct efi_device_path *dp);
519int efi_dp_match(const struct efi_device_path *a,
520 const struct efi_device_path *b);
521struct efi_object *efi_dp_find_obj(struct efi_device_path *dp,
522 struct efi_device_path **rem);
523
524efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp);
525
526efi_uintn_t efi_dp_size(const struct efi_device_path *dp);
527struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp);
528struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,
529 const struct efi_device_path *dp2);
530struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp,
531 const struct efi_device_path *node);
532
533struct efi_device_path *efi_dp_create_device_node(const u8 type,
534 const u8 sub_type,
535 const u16 length);
536
537struct efi_device_path *efi_dp_append_instance(
538 const struct efi_device_path *dp,
539 const struct efi_device_path *dpi);
540
541struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp,
542 efi_uintn_t *size);
543
544bool efi_dp_is_multi_instance(const struct efi_device_path *dp);
545
546struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part);
547
548struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part);
549struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
550 const char *path);
551struct efi_device_path *efi_dp_from_eth(void);
552struct efi_device_path *efi_dp_from_mem(uint32_t mem_type,
553 uint64_t start_address,
554 uint64_t end_address);
555
556const struct efi_device_path *efi_dp_last_node(
557 const struct efi_device_path *dp);
558efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path,
559 struct efi_device_path **device_path,
560 struct efi_device_path **file_path);
561efi_status_t efi_dp_from_name(const char *dev, const char *devnr,
562 const char *path,
563 struct efi_device_path **device,
564 struct efi_device_path **file);
565
566#define EFI_DP_TYPE(_dp, _type, _subtype) \
567 (((_dp)->type == DEVICE_PATH_TYPE_##_type) && \
568 ((_dp)->sub_type == DEVICE_PATH_SUB_TYPE_##_subtype))
569
570
571
572
573
574#define __efi_runtime_data __attribute__ ((section (".data.efi_runtime")))
575#define __efi_runtime __attribute__ ((section (".text.efi_runtime")))
576
577
578efi_status_t efi_init_runtime_supported(void);
579
580
581void __efi_runtime efi_update_table_header_crc32(struct efi_table_hdr *table);
582
583
584
585efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len);
586
587
588
589void __efi_runtime EFIAPI efi_reset_system(
590 enum efi_reset_type reset_type,
591 efi_status_t reset_status,
592 unsigned long data_size, void *reset_data);
593
594
595efi_status_t efi_reset_system_init(void);
596
597efi_status_t __efi_runtime EFIAPI efi_get_time(
598 struct efi_time *time,
599 struct efi_time_cap *capabilities);
600
601efi_status_t __efi_runtime EFIAPI efi_set_time(struct efi_time *time);
602
603#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
604
605
606
607
608efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
609 struct efi_system_table *systab);
610#endif
611
612efi_status_t EFIAPI efi_get_variable(u16 *variable_name,
613 const efi_guid_t *vendor, u32 *attributes,
614 efi_uintn_t *data_size, void *data);
615efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size,
616 u16 *variable_name,
617 const efi_guid_t *vendor);
618efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
619 const efi_guid_t *vendor, u32 attributes,
620 efi_uintn_t data_size, const void *data);
621
622efi_status_t EFIAPI efi_query_variable_info(
623 u32 attributes, u64 *maximum_variable_storage_size,
624 u64 *remaining_variable_storage_size,
625 u64 *maximum_variable_size);
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640struct efi_load_option {
641 u32 attributes;
642 u16 file_path_length;
643 u16 *label;
644 struct efi_device_path *file_path;
645 const u8 *optional_data;
646};
647
648void efi_deserialize_load_option(struct efi_load_option *lo, u8 *data);
649unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data);
650efi_status_t efi_bootmgr_load(efi_handle_t *handle);
651
652#else
653
654
655#define __efi_runtime_data
656#define __efi_runtime
657static inline efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len)
658{
659 return EFI_SUCCESS;
660}
661
662
663static inline void efi_restore_gd(void) { }
664static inline void efi_set_bootdev(const char *dev, const char *devnr,
665 const char *path) { }
666static inline void efi_net_set_dhcp_ack(void *pkt, int len) { }
667static inline void efi_print_image_infos(void *pc) { }
668
669#endif
670
671#endif
672