2 * EFI application boot time services
4 * Copyright (c) 2016 Alexander Graf
6 * SPDX-License-Identifier: GPL-2.0+
10 #include <efi_loader.h>
12 #include <asm/global_data.h>
13 #include <libfdt_env.h>
14 #include <u-boot/crc.h>
19 DECLARE_GLOBAL_DATA_PTR;
21 /* This list contains all the EFI objects our payload has access to */
22 LIST_HEAD(efi_obj_list);
25 * If we're running on nasty systems (32bit ARM booting into non-EFI Linux)
26 * we need to do trickery with caches. Since we don't want to break the EFI
27 * aware boot path, only apply hacks when loading exiting directly (breaking
28 * direct Linux EFI booting along the way - oh well).
30 static bool efi_is_direct_boot = true;
33 * EFI can pass arbitrary additional "tables" containing vendor specific
34 * information to the payload. One such table is the FDT table which contains
35 * a pointer to a flattened device tree blob.
37 * In most cases we want to pass an FDT to the payload, so reserve one slot of
38 * config table space for it. The pointer gets populated by do_bootefi_exec().
40 static struct efi_configuration_table __efi_runtime_data efi_conf_table[2];
44 * The "gd" pointer lives in a register on ARM and AArch64 that we declare
45 * fixed when compiling U-Boot. However, the payload does not know about that
46 * restriction so we need to manually swap its and our view of that register on
47 * EFI callback entry/exit.
49 static volatile void *efi_gd, *app_gd;
52 /* Called from do_bootefi_exec() */
53 void efi_save_gd(void)
60 /* Called on every callback entry */
61 void efi_restore_gd(void)
64 /* Only restore if we're already in EFI context */
74 /* Called on every callback exit */
75 efi_status_t efi_exit_func(efi_status_t ret)
84 static void efi_signal_event(struct efi_event *event)
89 if (event->type & EVT_NOTIFY_SIGNAL) {
90 EFI_EXIT(EFI_SUCCESS);
91 event->notify_function(event, event->notify_context);
92 EFI_ENTRY("returning from notification function");
96 static efi_status_t efi_unsupported(const char *funcname)
98 debug("EFI: App called into unimplemented function %s\n", funcname);
99 return EFI_EXIT(EFI_UNSUPPORTED);
102 static int guidcmp(const efi_guid_t *g1, const efi_guid_t *g2)
104 return memcmp(g1, g2, sizeof(efi_guid_t));
107 static unsigned long EFIAPI efi_raise_tpl(UINTN new_tpl)
109 EFI_ENTRY("0x%zx", new_tpl);
113 static void EFIAPI efi_restore_tpl(UINTN old_tpl)
115 EFI_ENTRY("0x%zx", old_tpl);
116 EFI_EXIT(efi_unsupported(__func__));
119 static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
125 EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory);
126 r = efi_allocate_pages(type, memory_type, pages, memory);
130 static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
135 EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages);
136 r = efi_free_pages(memory, pages);
140 static efi_status_t EFIAPI efi_get_memory_map_ext(
141 unsigned long *memory_map_size,
142 struct efi_mem_desc *memory_map,
143 unsigned long *map_key,
144 unsigned long *descriptor_size,
145 uint32_t *descriptor_version)
149 EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map,
150 map_key, descriptor_size, descriptor_version);
151 r = efi_get_memory_map(memory_map_size, memory_map, map_key,
152 descriptor_size, descriptor_version);
156 static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
162 EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer);
163 r = efi_allocate_pool(pool_type, size, buffer);
167 static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
171 EFI_ENTRY("%p", buffer);
172 r = efi_free_pool(buffer);
177 * Our event capabilities are very limited. Only a small limited
178 * number of events is allowed to coexist.
180 static struct efi_event efi_events[16];
182 efi_status_t efi_create_event(enum efi_event_type type, UINTN notify_tpl,
183 void (EFIAPI *notify_function) (
184 struct efi_event *event,
186 void *notify_context, struct efi_event **event)
191 return EFI_INVALID_PARAMETER;
193 if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
194 return EFI_INVALID_PARAMETER;
196 if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
197 notify_function == NULL)
198 return EFI_INVALID_PARAMETER;
200 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
201 if (efi_events[i].type)
203 efi_events[i].type = type;
204 efi_events[i].notify_tpl = notify_tpl;
205 efi_events[i].notify_function = notify_function;
206 efi_events[i].notify_context = notify_context;
207 /* Disable timers on bootup */
208 efi_events[i].trigger_next = -1ULL;
209 efi_events[i].signaled = 0;
210 *event = &efi_events[i];
213 return EFI_OUT_OF_RESOURCES;
216 static efi_status_t EFIAPI efi_create_event_ext(
217 enum efi_event_type type, UINTN notify_tpl,
218 void (EFIAPI *notify_function) (
219 struct efi_event *event,
221 void *notify_context, struct efi_event **event)
223 EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
225 return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
226 notify_context, event));
231 * Our timers have to work without interrupts, so we check whenever keyboard
232 * input or disk accesses happen if enough time elapsed for it to fire.
234 void efi_timer_check(void)
237 u64 now = timer_get_us();
239 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
240 if (!efi_events[i].type ||
241 !(efi_events[i].type & EVT_TIMER) ||
242 efi_events[i].trigger_type == EFI_TIMER_STOP ||
243 now < efi_events[i].trigger_next)
245 if (efi_events[i].trigger_type == EFI_TIMER_PERIODIC) {
246 efi_events[i].trigger_next +=
247 efi_events[i].trigger_time / 10;
248 efi_events[i].signaled = 0;
250 efi_signal_event(&efi_events[i]);
255 efi_status_t efi_set_timer(struct efi_event *event, int type,
256 uint64_t trigger_time)
258 /* We don't have 64bit division available everywhere, so limit timer
259 * distances to 32bit bits. */
260 u32 trigger32 = trigger_time;
263 if (trigger32 < trigger_time) {
264 printf("WARNING: Truncating timer from %"PRIx64" to %x\n",
265 trigger_time, trigger32);
268 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
269 if (event != &efi_events[i])
272 if (!(event->type & EVT_TIMER))
276 event->trigger_next = -1ULL;
278 case EFI_TIMER_PERIODIC:
279 case EFI_TIMER_RELATIVE:
280 event->trigger_next =
281 timer_get_us() + (trigger32 / 10);
284 return EFI_INVALID_PARAMETER;
286 event->trigger_type = type;
287 event->trigger_time = trigger_time;
290 return EFI_INVALID_PARAMETER;
293 static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event, int type,
294 uint64_t trigger_time)
296 EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
297 return EFI_EXIT(efi_set_timer(event, type, trigger_time));
300 static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events,
301 struct efi_event **event,
302 unsigned long *index)
306 EFI_ENTRY("%ld, %p, %p", num_events, event, index);
308 /* Check parameters */
309 if (!num_events || !event)
310 return EFI_EXIT(EFI_INVALID_PARAMETER);
311 for (i = 0; i < num_events; ++i) {
312 for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
313 if (event[i] == &efi_events[j])
316 return EFI_EXIT(EFI_INVALID_PARAMETER);
318 if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
319 return EFI_EXIT(EFI_INVALID_PARAMETER);
322 /* Wait for signal */
324 for (i = 0; i < num_events; ++i) {
325 if (event[i]->signaled)
328 /* Allow events to occur. */
334 * Reset the signal which is passed to the caller to allow periodic
337 event[i]->signaled = 0;
341 return EFI_EXIT(EFI_SUCCESS);
344 static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
348 EFI_ENTRY("%p", event);
349 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
350 if (event != &efi_events[i])
352 efi_signal_event(event);
355 return EFI_EXIT(EFI_SUCCESS);
358 static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
362 EFI_ENTRY("%p", event);
363 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
364 if (event == &efi_events[i]) {
366 event->trigger_next = -1ULL;
368 return EFI_EXIT(EFI_SUCCESS);
371 return EFI_EXIT(EFI_INVALID_PARAMETER);
374 static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
378 EFI_ENTRY("%p", event);
380 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
381 if (event != &efi_events[i])
383 if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
386 return EFI_EXIT(EFI_SUCCESS);
387 return EFI_EXIT(EFI_NOT_READY);
389 return EFI_EXIT(EFI_INVALID_PARAMETER);
392 static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
393 efi_guid_t *protocol, int protocol_interface_type,
394 void *protocol_interface)
396 struct list_head *lhandle;
400 if (!handle || !protocol ||
401 protocol_interface_type != EFI_NATIVE_INTERFACE) {
402 r = EFI_INVALID_PARAMETER;
406 /* Create new handle if requested. */
408 r = EFI_OUT_OF_RESOURCES;
412 list_for_each(lhandle, &efi_obj_list) {
413 struct efi_object *efiobj;
414 efiobj = list_entry(lhandle, struct efi_object, link);
416 if (efiobj->handle != *handle)
418 /* Check if protocol is already installed on the handle. */
419 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
420 struct efi_handler *handler = &efiobj->protocols[i];
424 if (!guidcmp(handler->guid, protocol)) {
425 r = EFI_INVALID_PARAMETER;
429 /* Install protocol in first empty slot. */
430 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
431 struct efi_handler *handler = &efiobj->protocols[i];
436 handler->guid = protocol;
437 handler->protocol_interface = protocol_interface;
441 r = EFI_OUT_OF_RESOURCES;
444 r = EFI_INVALID_PARAMETER;
449 static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
450 efi_guid_t *protocol, int protocol_interface_type,
451 void *protocol_interface)
453 EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type,
456 return EFI_EXIT(efi_install_protocol_interface(handle, protocol,
457 protocol_interface_type,
458 protocol_interface));
461 static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
462 efi_guid_t *protocol, void *old_interface,
465 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, old_interface,
467 return EFI_EXIT(EFI_ACCESS_DENIED);
470 static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
471 efi_guid_t *protocol, void *protocol_interface)
473 struct list_head *lhandle;
475 efi_status_t r = EFI_NOT_FOUND;
477 if (!handle || !protocol) {
478 r = EFI_INVALID_PARAMETER;
482 list_for_each(lhandle, &efi_obj_list) {
483 struct efi_object *efiobj;
484 efiobj = list_entry(lhandle, struct efi_object, link);
486 if (efiobj->handle != handle)
489 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
490 struct efi_handler *handler = &efiobj->protocols[i];
491 const efi_guid_t *hprotocol = handler->guid;
495 if (!guidcmp(hprotocol, protocol)) {
496 if (handler->protocol_interface) {
497 r = EFI_ACCESS_DENIED;
511 static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle,
512 efi_guid_t *protocol, void *protocol_interface)
514 EFI_ENTRY("%p, %p, %p", handle, protocol, protocol_interface);
516 return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol,
517 protocol_interface));
520 static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol,
521 struct efi_event *event,
524 EFI_ENTRY("%p, %p, %p", protocol, event, registration);
525 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
528 static int efi_search(enum efi_locate_search_type search_type,
529 efi_guid_t *protocol, void *search_key,
530 struct efi_object *efiobj)
534 switch (search_type) {
537 case by_register_notify:
540 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
541 const efi_guid_t *guid = efiobj->protocols[i].guid;
542 if (guid && !guidcmp(guid, protocol))
551 static efi_status_t EFIAPI efi_locate_handle(
552 enum efi_locate_search_type search_type,
553 efi_guid_t *protocol, void *search_key,
554 unsigned long *buffer_size, efi_handle_t *buffer)
556 struct list_head *lhandle;
557 unsigned long size = 0;
559 /* Count how much space we need */
560 list_for_each(lhandle, &efi_obj_list) {
561 struct efi_object *efiobj;
562 efiobj = list_entry(lhandle, struct efi_object, link);
563 if (!efi_search(search_type, protocol, search_key, efiobj)) {
564 size += sizeof(void*);
568 if (*buffer_size < size) {
570 return EFI_BUFFER_TOO_SMALL;
573 /* Then fill the array */
574 list_for_each(lhandle, &efi_obj_list) {
575 struct efi_object *efiobj;
576 efiobj = list_entry(lhandle, struct efi_object, link);
577 if (!efi_search(search_type, protocol, search_key, efiobj)) {
578 *(buffer++) = efiobj->handle;
586 static efi_status_t EFIAPI efi_locate_handle_ext(
587 enum efi_locate_search_type search_type,
588 efi_guid_t *protocol, void *search_key,
589 unsigned long *buffer_size, efi_handle_t *buffer)
591 EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
592 buffer_size, buffer);
594 return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
595 buffer_size, buffer));
598 static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol,
599 struct efi_device_path **device_path,
600 efi_handle_t *device)
602 EFI_ENTRY("%p, %p, %p", protocol, device_path, device);
603 return EFI_EXIT(EFI_NOT_FOUND);
606 efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
610 /* Check for guid override */
611 for (i = 0; i < systab.nr_tables; i++) {
612 if (!guidcmp(guid, &efi_conf_table[i].guid)) {
613 efi_conf_table[i].table = table;
618 /* No override, check for overflow */
619 if (i >= ARRAY_SIZE(efi_conf_table))
620 return EFI_OUT_OF_RESOURCES;
622 /* Add a new entry */
623 memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
624 efi_conf_table[i].table = table;
625 systab.nr_tables = i + 1;
630 static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
633 EFI_ENTRY("%p, %p", guid, table);
634 return EFI_EXIT(efi_install_configuration_table(guid, table));
637 static efi_status_t EFIAPI efi_load_image(bool boot_policy,
638 efi_handle_t parent_image,
639 struct efi_device_path *file_path,
641 unsigned long source_size,
642 efi_handle_t *image_handle)
644 static struct efi_object loaded_image_info_obj = {
647 .guid = &efi_guid_loaded_image,
651 struct efi_loaded_image *info;
652 struct efi_object *obj;
654 EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
655 file_path, source_buffer, source_size, image_handle);
656 info = malloc(sizeof(*info));
657 loaded_image_info_obj.protocols[0].protocol_interface = info;
658 obj = malloc(sizeof(loaded_image_info_obj));
659 memset(info, 0, sizeof(*info));
660 memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj));
662 info->file_path = file_path;
663 info->reserved = efi_load_pe(source_buffer, info);
664 if (!info->reserved) {
667 return EFI_EXIT(EFI_UNSUPPORTED);
670 *image_handle = info;
671 list_add_tail(&obj->link, &efi_obj_list);
673 return EFI_EXIT(EFI_SUCCESS);
676 static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
677 unsigned long *exit_data_size,
680 ulong (*entry)(void *image_handle, struct efi_system_table *st);
681 struct efi_loaded_image *info = image_handle;
683 EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
684 entry = info->reserved;
686 efi_is_direct_boot = false;
688 /* call the image! */
689 if (setjmp(&info->exit_jmp)) {
690 /* We returned from the child image */
691 return EFI_EXIT(info->exit_status);
694 entry(image_handle, &systab);
696 /* Should usually never get here */
697 return EFI_EXIT(EFI_SUCCESS);
700 static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
701 efi_status_t exit_status, unsigned long exit_data_size,
704 struct efi_loaded_image *loaded_image_info = (void*)image_handle;
706 EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
707 exit_data_size, exit_data);
709 loaded_image_info->exit_status = exit_status;
710 longjmp(&loaded_image_info->exit_jmp, 1);
712 panic("EFI application exited");
715 static struct efi_object *efi_search_obj(void *handle)
717 struct list_head *lhandle;
719 list_for_each(lhandle, &efi_obj_list) {
720 struct efi_object *efiobj;
721 efiobj = list_entry(lhandle, struct efi_object, link);
722 if (efiobj->handle == handle)
729 static efi_status_t EFIAPI efi_unload_image(void *image_handle)
731 struct efi_object *efiobj;
733 EFI_ENTRY("%p", image_handle);
734 efiobj = efi_search_obj(image_handle);
736 list_del(&efiobj->link);
738 return EFI_EXIT(EFI_SUCCESS);
741 static void efi_exit_caches(void)
743 #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
745 * Grub on 32bit ARM needs to have caches disabled before jumping into
746 * a zImage, but does not know of all cache layers. Give it a hand.
748 if (efi_is_direct_boot)
749 cleanup_before_linux();
753 static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
754 unsigned long map_key)
756 EFI_ENTRY("%p, %ld", image_handle, map_key);
758 board_quiesce_devices();
760 /* Fix up caches for EFI payloads if necessary */
763 /* This stops all lingering devices */
764 bootm_disable_interrupts();
766 /* Give the payload some time to boot */
769 return EFI_EXIT(EFI_SUCCESS);
772 static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
774 static uint64_t mono = 0;
775 EFI_ENTRY("%p", count);
777 return EFI_EXIT(EFI_SUCCESS);
780 static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
782 EFI_ENTRY("%ld", microseconds);
783 udelay(microseconds);
784 return EFI_EXIT(EFI_SUCCESS);
787 static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
788 uint64_t watchdog_code,
789 unsigned long data_size,
790 uint16_t *watchdog_data)
792 EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
793 data_size, watchdog_data);
794 return EFI_EXIT(efi_unsupported(__func__));
797 static efi_status_t EFIAPI efi_connect_controller(
798 efi_handle_t controller_handle,
799 efi_handle_t *driver_image_handle,
800 struct efi_device_path *remain_device_path,
803 EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
804 remain_device_path, recursive);
805 return EFI_EXIT(EFI_NOT_FOUND);
808 static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
809 void *driver_image_handle,
812 EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
814 return EFI_EXIT(EFI_INVALID_PARAMETER);
817 static efi_status_t EFIAPI efi_close_protocol(void *handle,
818 efi_guid_t *protocol,
820 void *controller_handle)
822 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle,
824 return EFI_EXIT(EFI_NOT_FOUND);
827 static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
828 efi_guid_t *protocol,
829 struct efi_open_protocol_info_entry **entry_buffer,
830 unsigned long *entry_count)
832 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer,
834 return EFI_EXIT(EFI_NOT_FOUND);
837 static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
838 efi_guid_t ***protocol_buffer,
839 unsigned long *protocol_buffer_count)
841 EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
842 protocol_buffer_count);
843 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
846 static efi_status_t EFIAPI efi_locate_handle_buffer(
847 enum efi_locate_search_type search_type,
848 efi_guid_t *protocol, void *search_key,
849 unsigned long *no_handles, efi_handle_t **buffer)
852 unsigned long buffer_size = 0;
854 EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
857 if (!no_handles || !buffer) {
858 r = EFI_INVALID_PARAMETER;
863 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
865 if (r != EFI_BUFFER_TOO_SMALL)
867 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
869 if (r != EFI_SUCCESS)
871 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
873 if (r == EFI_SUCCESS)
874 *no_handles = buffer_size / sizeof(void *);
879 static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol,
881 void **protocol_interface)
883 struct list_head *lhandle;
886 EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface);
888 if (!protocol || !protocol_interface)
889 return EFI_EXIT(EFI_INVALID_PARAMETER);
891 list_for_each(lhandle, &efi_obj_list) {
892 struct efi_object *efiobj;
894 efiobj = list_entry(lhandle, struct efi_object, link);
895 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
896 struct efi_handler *handler = &efiobj->protocols[i];
900 if (!guidcmp(handler->guid, protocol)) {
901 *protocol_interface =
902 handler->protocol_interface;
903 return EFI_EXIT(EFI_SUCCESS);
907 *protocol_interface = NULL;
909 return EFI_EXIT(EFI_NOT_FOUND);
912 static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
915 EFI_ENTRY("%p", handle);
918 efi_guid_t *protocol;
919 void *protocol_interface;
920 efi_status_t r = EFI_SUCCESS;
924 return EFI_EXIT(EFI_INVALID_PARAMETER);
926 va_start(argptr, handle);
928 protocol = va_arg(argptr, efi_guid_t*);
931 protocol_interface = va_arg(argptr, void*);
932 r = efi_install_protocol_interface(handle, protocol,
933 EFI_NATIVE_INTERFACE,
935 if (r != EFI_SUCCESS)
940 if (r == EFI_SUCCESS)
943 /* If an error occured undo all changes. */
944 va_start(argptr, handle);
946 protocol = va_arg(argptr, efi_guid_t*);
947 protocol_interface = va_arg(argptr, void*);
948 efi_uninstall_protocol_interface(handle, protocol,
956 static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
959 EFI_ENTRY("%p", handle);
960 return EFI_EXIT(EFI_INVALID_PARAMETER);
963 static efi_status_t EFIAPI efi_calculate_crc32(void *data,
964 unsigned long data_size,
967 EFI_ENTRY("%p, %ld", data, data_size);
968 *crc32_p = crc32(0, data, data_size);
969 return EFI_EXIT(EFI_SUCCESS);
972 static void EFIAPI efi_copy_mem(void *destination, void *source,
973 unsigned long length)
975 EFI_ENTRY("%p, %p, %ld", destination, source, length);
976 memcpy(destination, source, length);
979 static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value)
981 EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value);
982 memset(buffer, value, size);
985 static efi_status_t EFIAPI efi_open_protocol(
986 void *handle, efi_guid_t *protocol,
987 void **protocol_interface, void *agent_handle,
988 void *controller_handle, uint32_t attributes)
990 struct list_head *lhandle;
992 efi_status_t r = EFI_INVALID_PARAMETER;
994 EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol,
995 protocol_interface, agent_handle, controller_handle,
998 if (!handle || !protocol ||
999 (!protocol_interface && attributes !=
1000 EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
1004 switch (attributes) {
1005 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
1006 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
1007 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
1009 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
1010 if (controller_handle == handle)
1012 case EFI_OPEN_PROTOCOL_BY_DRIVER:
1013 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
1014 if (controller_handle == NULL)
1016 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
1017 if (agent_handle == NULL)
1024 list_for_each(lhandle, &efi_obj_list) {
1025 struct efi_object *efiobj;
1026 efiobj = list_entry(lhandle, struct efi_object, link);
1028 if (efiobj->handle != handle)
1031 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1032 struct efi_handler *handler = &efiobj->protocols[i];
1033 const efi_guid_t *hprotocol = handler->guid;
1036 if (!guidcmp(hprotocol, protocol)) {
1038 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
1039 *protocol_interface =
1040 handler->protocol_interface;
1050 r = EFI_UNSUPPORTED;
1055 static efi_status_t EFIAPI efi_handle_protocol(void *handle,
1056 efi_guid_t *protocol,
1057 void **protocol_interface)
1059 return efi_open_protocol(handle, protocol, protocol_interface, NULL,
1060 NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
1063 static const struct efi_boot_services efi_boot_services = {
1065 .headersize = sizeof(struct efi_table_hdr),
1067 .raise_tpl = efi_raise_tpl,
1068 .restore_tpl = efi_restore_tpl,
1069 .allocate_pages = efi_allocate_pages_ext,
1070 .free_pages = efi_free_pages_ext,
1071 .get_memory_map = efi_get_memory_map_ext,
1072 .allocate_pool = efi_allocate_pool_ext,
1073 .free_pool = efi_free_pool_ext,
1074 .create_event = efi_create_event_ext,
1075 .set_timer = efi_set_timer_ext,
1076 .wait_for_event = efi_wait_for_event,
1077 .signal_event = efi_signal_event_ext,
1078 .close_event = efi_close_event,
1079 .check_event = efi_check_event,
1080 .install_protocol_interface = efi_install_protocol_interface_ext,
1081 .reinstall_protocol_interface = efi_reinstall_protocol_interface,
1082 .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext,
1083 .handle_protocol = efi_handle_protocol,
1085 .register_protocol_notify = efi_register_protocol_notify,
1086 .locate_handle = efi_locate_handle_ext,
1087 .locate_device_path = efi_locate_device_path,
1088 .install_configuration_table = efi_install_configuration_table_ext,
1089 .load_image = efi_load_image,
1090 .start_image = efi_start_image,
1092 .unload_image = efi_unload_image,
1093 .exit_boot_services = efi_exit_boot_services,
1094 .get_next_monotonic_count = efi_get_next_monotonic_count,
1096 .set_watchdog_timer = efi_set_watchdog_timer,
1097 .connect_controller = efi_connect_controller,
1098 .disconnect_controller = efi_disconnect_controller,
1099 .open_protocol = efi_open_protocol,
1100 .close_protocol = efi_close_protocol,
1101 .open_protocol_information = efi_open_protocol_information,
1102 .protocols_per_handle = efi_protocols_per_handle,
1103 .locate_handle_buffer = efi_locate_handle_buffer,
1104 .locate_protocol = efi_locate_protocol,
1105 .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
1106 .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
1107 .calculate_crc32 = efi_calculate_crc32,
1108 .copy_mem = efi_copy_mem,
1109 .set_mem = efi_set_mem,
1113 static uint16_t __efi_runtime_data firmware_vendor[] =
1114 { 'D','a','s',' ','U','-','b','o','o','t',0 };
1116 struct efi_system_table __efi_runtime_data systab = {
1118 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
1119 .revision = 0x20005, /* 2.5 */
1120 .headersize = sizeof(struct efi_table_hdr),
1122 .fw_vendor = (long)firmware_vendor,
1123 .con_in = (void*)&efi_con_in,
1124 .con_out = (void*)&efi_con_out,
1125 .std_err = (void*)&efi_con_out,
1126 .runtime = (void*)&efi_runtime_services,
1127 .boottime = (void*)&efi_boot_services,
1129 .tables = (void*)efi_conf_table,