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)
85 #define EFI_LOW32(a) (a & 0xFFFFFFFFULL)
87 #define EFI_HIGH32(a) (a >> 32)
90 * 64bit division by 10 implemented as multiplication by 1 / 10
92 * Decimals of one tenth: 0x1 / 0xA = 0x0.19999...
94 #define EFI_TENTH 0x199999999999999A
95 static u64 efi_div10(u64 a)
101 ret = EFI_HIGH32(a) * EFI_HIGH32(EFI_TENTH);
102 prod = EFI_HIGH32(a) * EFI_LOW32(EFI_TENTH);
103 rem = EFI_LOW32(prod);
104 ret += EFI_HIGH32(prod);
105 prod = EFI_LOW32(a) * EFI_HIGH32(EFI_TENTH);
106 rem += EFI_LOW32(prod);
107 ret += EFI_HIGH32(prod);
108 prod = EFI_LOW32(a) * EFI_LOW32(EFI_TENTH);
109 rem += EFI_HIGH32(prod);
110 ret += EFI_HIGH32(rem);
111 /* Round to nearest integer */
112 if (rem >= (1 << 31))
117 void efi_signal_event(struct efi_event *event)
122 if (event->type & EVT_NOTIFY_SIGNAL) {
123 EFI_EXIT(EFI_SUCCESS);
124 event->notify_function(event, event->notify_context);
125 EFI_ENTRY("returning from notification function");
129 static efi_status_t efi_unsupported(const char *funcname)
131 debug("EFI: App called into unimplemented function %s\n", funcname);
132 return EFI_EXIT(EFI_UNSUPPORTED);
135 static int guidcmp(const efi_guid_t *g1, const efi_guid_t *g2)
137 return memcmp(g1, g2, sizeof(efi_guid_t));
140 static unsigned long EFIAPI efi_raise_tpl(UINTN new_tpl)
142 EFI_ENTRY("0x%zx", new_tpl);
146 static void EFIAPI efi_restore_tpl(UINTN old_tpl)
148 EFI_ENTRY("0x%zx", old_tpl);
149 EFI_EXIT(efi_unsupported(__func__));
152 static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
158 EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory);
159 r = efi_allocate_pages(type, memory_type, pages, memory);
163 static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
168 EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages);
169 r = efi_free_pages(memory, pages);
173 static efi_status_t EFIAPI efi_get_memory_map_ext(
174 unsigned long *memory_map_size,
175 struct efi_mem_desc *memory_map,
176 unsigned long *map_key,
177 unsigned long *descriptor_size,
178 uint32_t *descriptor_version)
182 EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map,
183 map_key, descriptor_size, descriptor_version);
184 r = efi_get_memory_map(memory_map_size, memory_map, map_key,
185 descriptor_size, descriptor_version);
189 static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
195 EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer);
196 r = efi_allocate_pool(pool_type, size, buffer);
200 static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
204 EFI_ENTRY("%p", buffer);
205 r = efi_free_pool(buffer);
210 * Our event capabilities are very limited. Only a small limited
211 * number of events is allowed to coexist.
213 static struct efi_event efi_events[16];
215 efi_status_t efi_create_event(enum efi_event_type type, UINTN notify_tpl,
216 void (EFIAPI *notify_function) (
217 struct efi_event *event,
219 void *notify_context, struct efi_event **event)
224 return EFI_INVALID_PARAMETER;
226 if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
227 return EFI_INVALID_PARAMETER;
229 if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
230 notify_function == NULL)
231 return EFI_INVALID_PARAMETER;
233 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
234 if (efi_events[i].type)
236 efi_events[i].type = type;
237 efi_events[i].notify_tpl = notify_tpl;
238 efi_events[i].notify_function = notify_function;
239 efi_events[i].notify_context = notify_context;
240 /* Disable timers on bootup */
241 efi_events[i].trigger_next = -1ULL;
242 efi_events[i].signaled = 0;
243 *event = &efi_events[i];
246 return EFI_OUT_OF_RESOURCES;
249 static efi_status_t EFIAPI efi_create_event_ext(
250 enum efi_event_type type, UINTN notify_tpl,
251 void (EFIAPI *notify_function) (
252 struct efi_event *event,
254 void *notify_context, struct efi_event **event)
256 EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
258 return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
259 notify_context, event));
264 * Our timers have to work without interrupts, so we check whenever keyboard
265 * input or disk accesses happen if enough time elapsed for it to fire.
267 void efi_timer_check(void)
270 u64 now = timer_get_us();
272 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
273 if (!efi_events[i].type ||
274 !(efi_events[i].type & EVT_TIMER) ||
275 efi_events[i].trigger_type == EFI_TIMER_STOP ||
276 now < efi_events[i].trigger_next)
278 if (efi_events[i].trigger_type == EFI_TIMER_PERIODIC) {
279 efi_events[i].trigger_next +=
280 efi_events[i].trigger_time;
281 efi_events[i].signaled = 0;
283 efi_signal_event(&efi_events[i]);
288 efi_status_t efi_set_timer(struct efi_event *event, int type,
289 uint64_t trigger_time)
294 * The parameter defines a multiple of 100ns.
295 * We use multiples of 1000ns. So divide by 10.
297 trigger_time = efi_div10(trigger_time);
299 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
300 if (event != &efi_events[i])
303 if (!(event->type & EVT_TIMER))
307 event->trigger_next = -1ULL;
309 case EFI_TIMER_PERIODIC:
310 case EFI_TIMER_RELATIVE:
311 event->trigger_next =
312 timer_get_us() + trigger_time;
315 return EFI_INVALID_PARAMETER;
317 event->trigger_type = type;
318 event->trigger_time = trigger_time;
321 return EFI_INVALID_PARAMETER;
324 static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event, int type,
325 uint64_t trigger_time)
327 EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
328 return EFI_EXIT(efi_set_timer(event, type, trigger_time));
331 static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events,
332 struct efi_event **event,
333 unsigned long *index)
337 EFI_ENTRY("%ld, %p, %p", num_events, event, index);
339 /* Check parameters */
340 if (!num_events || !event)
341 return EFI_EXIT(EFI_INVALID_PARAMETER);
342 for (i = 0; i < num_events; ++i) {
343 for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
344 if (event[i] == &efi_events[j])
347 return EFI_EXIT(EFI_INVALID_PARAMETER);
349 if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
350 return EFI_EXIT(EFI_INVALID_PARAMETER);
353 /* Wait for signal */
355 for (i = 0; i < num_events; ++i) {
356 if (event[i]->signaled)
359 /* Allow events to occur. */
365 * Reset the signal which is passed to the caller to allow periodic
368 event[i]->signaled = 0;
372 return EFI_EXIT(EFI_SUCCESS);
375 static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
379 EFI_ENTRY("%p", event);
380 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
381 if (event != &efi_events[i])
383 efi_signal_event(event);
386 return EFI_EXIT(EFI_SUCCESS);
389 static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
393 EFI_ENTRY("%p", event);
394 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
395 if (event == &efi_events[i]) {
397 event->trigger_next = -1ULL;
399 return EFI_EXIT(EFI_SUCCESS);
402 return EFI_EXIT(EFI_INVALID_PARAMETER);
405 static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
409 EFI_ENTRY("%p", event);
411 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
412 if (event != &efi_events[i])
414 if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
417 return EFI_EXIT(EFI_SUCCESS);
418 return EFI_EXIT(EFI_NOT_READY);
420 return EFI_EXIT(EFI_INVALID_PARAMETER);
423 static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
424 efi_guid_t *protocol, int protocol_interface_type,
425 void *protocol_interface)
427 struct list_head *lhandle;
431 if (!handle || !protocol ||
432 protocol_interface_type != EFI_NATIVE_INTERFACE) {
433 r = EFI_INVALID_PARAMETER;
437 /* Create new handle if requested. */
439 r = EFI_OUT_OF_RESOURCES;
443 list_for_each(lhandle, &efi_obj_list) {
444 struct efi_object *efiobj;
445 efiobj = list_entry(lhandle, struct efi_object, link);
447 if (efiobj->handle != *handle)
449 /* Check if protocol is already installed on the handle. */
450 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
451 struct efi_handler *handler = &efiobj->protocols[i];
455 if (!guidcmp(handler->guid, protocol)) {
456 r = EFI_INVALID_PARAMETER;
460 /* Install protocol in first empty slot. */
461 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
462 struct efi_handler *handler = &efiobj->protocols[i];
467 handler->guid = protocol;
468 handler->protocol_interface = protocol_interface;
472 r = EFI_OUT_OF_RESOURCES;
475 r = EFI_INVALID_PARAMETER;
480 static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
481 efi_guid_t *protocol, int protocol_interface_type,
482 void *protocol_interface)
484 EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type,
487 return EFI_EXIT(efi_install_protocol_interface(handle, protocol,
488 protocol_interface_type,
489 protocol_interface));
492 static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
493 efi_guid_t *protocol, void *old_interface,
496 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, old_interface,
498 return EFI_EXIT(EFI_ACCESS_DENIED);
501 static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
502 efi_guid_t *protocol, void *protocol_interface)
504 struct list_head *lhandle;
506 efi_status_t r = EFI_NOT_FOUND;
508 if (!handle || !protocol) {
509 r = EFI_INVALID_PARAMETER;
513 list_for_each(lhandle, &efi_obj_list) {
514 struct efi_object *efiobj;
515 efiobj = list_entry(lhandle, struct efi_object, link);
517 if (efiobj->handle != handle)
520 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
521 struct efi_handler *handler = &efiobj->protocols[i];
522 const efi_guid_t *hprotocol = handler->guid;
526 if (!guidcmp(hprotocol, protocol)) {
527 if (handler->protocol_interface) {
528 r = EFI_ACCESS_DENIED;
542 static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle,
543 efi_guid_t *protocol, void *protocol_interface)
545 EFI_ENTRY("%p, %p, %p", handle, protocol, protocol_interface);
547 return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol,
548 protocol_interface));
551 static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol,
552 struct efi_event *event,
555 EFI_ENTRY("%p, %p, %p", protocol, event, registration);
556 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
559 static int efi_search(enum efi_locate_search_type search_type,
560 efi_guid_t *protocol, void *search_key,
561 struct efi_object *efiobj)
565 switch (search_type) {
568 case by_register_notify:
571 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
572 const efi_guid_t *guid = efiobj->protocols[i].guid;
573 if (guid && !guidcmp(guid, protocol))
582 static efi_status_t EFIAPI efi_locate_handle(
583 enum efi_locate_search_type search_type,
584 efi_guid_t *protocol, void *search_key,
585 unsigned long *buffer_size, efi_handle_t *buffer)
587 struct list_head *lhandle;
588 unsigned long size = 0;
590 /* Count how much space we need */
591 list_for_each(lhandle, &efi_obj_list) {
592 struct efi_object *efiobj;
593 efiobj = list_entry(lhandle, struct efi_object, link);
594 if (!efi_search(search_type, protocol, search_key, efiobj)) {
595 size += sizeof(void*);
599 if (*buffer_size < size) {
601 return EFI_BUFFER_TOO_SMALL;
604 /* Then fill the array */
605 list_for_each(lhandle, &efi_obj_list) {
606 struct efi_object *efiobj;
607 efiobj = list_entry(lhandle, struct efi_object, link);
608 if (!efi_search(search_type, protocol, search_key, efiobj)) {
609 *(buffer++) = efiobj->handle;
617 static efi_status_t EFIAPI efi_locate_handle_ext(
618 enum efi_locate_search_type search_type,
619 efi_guid_t *protocol, void *search_key,
620 unsigned long *buffer_size, efi_handle_t *buffer)
622 EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
623 buffer_size, buffer);
625 return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
626 buffer_size, buffer));
629 static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol,
630 struct efi_device_path **device_path,
631 efi_handle_t *device)
633 EFI_ENTRY("%p, %p, %p", protocol, device_path, device);
634 return EFI_EXIT(EFI_NOT_FOUND);
637 efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
641 /* Check for guid override */
642 for (i = 0; i < systab.nr_tables; i++) {
643 if (!guidcmp(guid, &efi_conf_table[i].guid)) {
644 efi_conf_table[i].table = table;
649 /* No override, check for overflow */
650 if (i >= ARRAY_SIZE(efi_conf_table))
651 return EFI_OUT_OF_RESOURCES;
653 /* Add a new entry */
654 memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
655 efi_conf_table[i].table = table;
656 systab.nr_tables = i + 1;
661 static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
664 EFI_ENTRY("%p, %p", guid, table);
665 return EFI_EXIT(efi_install_configuration_table(guid, table));
668 static efi_status_t EFIAPI efi_load_image(bool boot_policy,
669 efi_handle_t parent_image,
670 struct efi_device_path *file_path,
672 unsigned long source_size,
673 efi_handle_t *image_handle)
675 static struct efi_object loaded_image_info_obj = {
678 .guid = &efi_guid_loaded_image,
682 struct efi_loaded_image *info;
683 struct efi_object *obj;
685 EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
686 file_path, source_buffer, source_size, image_handle);
687 info = malloc(sizeof(*info));
688 loaded_image_info_obj.protocols[0].protocol_interface = info;
689 obj = malloc(sizeof(loaded_image_info_obj));
690 memset(info, 0, sizeof(*info));
691 memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj));
693 info->file_path = file_path;
694 info->reserved = efi_load_pe(source_buffer, info);
695 if (!info->reserved) {
698 return EFI_EXIT(EFI_UNSUPPORTED);
701 *image_handle = info;
702 list_add_tail(&obj->link, &efi_obj_list);
704 return EFI_EXIT(EFI_SUCCESS);
707 static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
708 unsigned long *exit_data_size,
711 ulong (*entry)(void *image_handle, struct efi_system_table *st);
712 struct efi_loaded_image *info = image_handle;
714 EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
715 entry = info->reserved;
717 efi_is_direct_boot = false;
719 /* call the image! */
720 if (setjmp(&info->exit_jmp)) {
721 /* We returned from the child image */
722 return EFI_EXIT(info->exit_status);
725 entry(image_handle, &systab);
727 /* Should usually never get here */
728 return EFI_EXIT(EFI_SUCCESS);
731 static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
732 efi_status_t exit_status, unsigned long exit_data_size,
735 struct efi_loaded_image *loaded_image_info = (void*)image_handle;
737 EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
738 exit_data_size, exit_data);
740 loaded_image_info->exit_status = exit_status;
741 longjmp(&loaded_image_info->exit_jmp, 1);
743 panic("EFI application exited");
746 static struct efi_object *efi_search_obj(void *handle)
748 struct list_head *lhandle;
750 list_for_each(lhandle, &efi_obj_list) {
751 struct efi_object *efiobj;
752 efiobj = list_entry(lhandle, struct efi_object, link);
753 if (efiobj->handle == handle)
760 static efi_status_t EFIAPI efi_unload_image(void *image_handle)
762 struct efi_object *efiobj;
764 EFI_ENTRY("%p", image_handle);
765 efiobj = efi_search_obj(image_handle);
767 list_del(&efiobj->link);
769 return EFI_EXIT(EFI_SUCCESS);
772 static void efi_exit_caches(void)
774 #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
776 * Grub on 32bit ARM needs to have caches disabled before jumping into
777 * a zImage, but does not know of all cache layers. Give it a hand.
779 if (efi_is_direct_boot)
780 cleanup_before_linux();
784 static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
785 unsigned long map_key)
787 EFI_ENTRY("%p, %ld", image_handle, map_key);
789 board_quiesce_devices();
791 /* Fix up caches for EFI payloads if necessary */
794 /* This stops all lingering devices */
795 bootm_disable_interrupts();
797 /* Give the payload some time to boot */
800 return EFI_EXIT(EFI_SUCCESS);
803 static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
805 static uint64_t mono = 0;
806 EFI_ENTRY("%p", count);
808 return EFI_EXIT(EFI_SUCCESS);
811 static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
813 EFI_ENTRY("%ld", microseconds);
814 udelay(microseconds);
815 return EFI_EXIT(EFI_SUCCESS);
818 static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
819 uint64_t watchdog_code,
820 unsigned long data_size,
821 uint16_t *watchdog_data)
823 EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
824 data_size, watchdog_data);
825 return EFI_EXIT(efi_unsupported(__func__));
828 static efi_status_t EFIAPI efi_connect_controller(
829 efi_handle_t controller_handle,
830 efi_handle_t *driver_image_handle,
831 struct efi_device_path *remain_device_path,
834 EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
835 remain_device_path, recursive);
836 return EFI_EXIT(EFI_NOT_FOUND);
839 static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
840 void *driver_image_handle,
843 EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
845 return EFI_EXIT(EFI_INVALID_PARAMETER);
848 static efi_status_t EFIAPI efi_close_protocol(void *handle,
849 efi_guid_t *protocol,
851 void *controller_handle)
853 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle,
855 return EFI_EXIT(EFI_NOT_FOUND);
858 static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
859 efi_guid_t *protocol,
860 struct efi_open_protocol_info_entry **entry_buffer,
861 unsigned long *entry_count)
863 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer,
865 return EFI_EXIT(EFI_NOT_FOUND);
868 static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
869 efi_guid_t ***protocol_buffer,
870 unsigned long *protocol_buffer_count)
872 EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
873 protocol_buffer_count);
874 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
877 static efi_status_t EFIAPI efi_locate_handle_buffer(
878 enum efi_locate_search_type search_type,
879 efi_guid_t *protocol, void *search_key,
880 unsigned long *no_handles, efi_handle_t **buffer)
883 unsigned long buffer_size = 0;
885 EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
888 if (!no_handles || !buffer) {
889 r = EFI_INVALID_PARAMETER;
894 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
896 if (r != EFI_BUFFER_TOO_SMALL)
898 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
900 if (r != EFI_SUCCESS)
902 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
904 if (r == EFI_SUCCESS)
905 *no_handles = buffer_size / sizeof(void *);
910 static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol,
912 void **protocol_interface)
914 struct list_head *lhandle;
917 EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface);
919 if (!protocol || !protocol_interface)
920 return EFI_EXIT(EFI_INVALID_PARAMETER);
922 list_for_each(lhandle, &efi_obj_list) {
923 struct efi_object *efiobj;
925 efiobj = list_entry(lhandle, struct efi_object, link);
926 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
927 struct efi_handler *handler = &efiobj->protocols[i];
931 if (!guidcmp(handler->guid, protocol)) {
932 *protocol_interface =
933 handler->protocol_interface;
934 return EFI_EXIT(EFI_SUCCESS);
938 *protocol_interface = NULL;
940 return EFI_EXIT(EFI_NOT_FOUND);
943 static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
946 EFI_ENTRY("%p", handle);
949 efi_guid_t *protocol;
950 void *protocol_interface;
951 efi_status_t r = EFI_SUCCESS;
955 return EFI_EXIT(EFI_INVALID_PARAMETER);
957 va_start(argptr, handle);
959 protocol = va_arg(argptr, efi_guid_t*);
962 protocol_interface = va_arg(argptr, void*);
963 r = efi_install_protocol_interface(handle, protocol,
964 EFI_NATIVE_INTERFACE,
966 if (r != EFI_SUCCESS)
971 if (r == EFI_SUCCESS)
974 /* If an error occured undo all changes. */
975 va_start(argptr, handle);
977 protocol = va_arg(argptr, efi_guid_t*);
978 protocol_interface = va_arg(argptr, void*);
979 efi_uninstall_protocol_interface(handle, protocol,
987 static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
990 EFI_ENTRY("%p", handle);
991 return EFI_EXIT(EFI_INVALID_PARAMETER);
994 static efi_status_t EFIAPI efi_calculate_crc32(void *data,
995 unsigned long data_size,
998 EFI_ENTRY("%p, %ld", data, data_size);
999 *crc32_p = crc32(0, data, data_size);
1000 return EFI_EXIT(EFI_SUCCESS);
1003 static void EFIAPI efi_copy_mem(void *destination, void *source,
1004 unsigned long length)
1006 EFI_ENTRY("%p, %p, %ld", destination, source, length);
1007 memcpy(destination, source, length);
1010 static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value)
1012 EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value);
1013 memset(buffer, value, size);
1016 static efi_status_t EFIAPI efi_open_protocol(
1017 void *handle, efi_guid_t *protocol,
1018 void **protocol_interface, void *agent_handle,
1019 void *controller_handle, uint32_t attributes)
1021 struct list_head *lhandle;
1023 efi_status_t r = EFI_INVALID_PARAMETER;
1025 EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol,
1026 protocol_interface, agent_handle, controller_handle,
1029 if (!handle || !protocol ||
1030 (!protocol_interface && attributes !=
1031 EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
1035 switch (attributes) {
1036 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
1037 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
1038 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
1040 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
1041 if (controller_handle == handle)
1043 case EFI_OPEN_PROTOCOL_BY_DRIVER:
1044 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
1045 if (controller_handle == NULL)
1047 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
1048 if (agent_handle == NULL)
1055 list_for_each(lhandle, &efi_obj_list) {
1056 struct efi_object *efiobj;
1057 efiobj = list_entry(lhandle, struct efi_object, link);
1059 if (efiobj->handle != handle)
1062 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1063 struct efi_handler *handler = &efiobj->protocols[i];
1064 const efi_guid_t *hprotocol = handler->guid;
1067 if (!guidcmp(hprotocol, protocol)) {
1069 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
1070 *protocol_interface =
1071 handler->protocol_interface;
1081 r = EFI_UNSUPPORTED;
1086 static efi_status_t EFIAPI efi_handle_protocol(void *handle,
1087 efi_guid_t *protocol,
1088 void **protocol_interface)
1090 return efi_open_protocol(handle, protocol, protocol_interface, NULL,
1091 NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
1094 static const struct efi_boot_services efi_boot_services = {
1096 .headersize = sizeof(struct efi_table_hdr),
1098 .raise_tpl = efi_raise_tpl,
1099 .restore_tpl = efi_restore_tpl,
1100 .allocate_pages = efi_allocate_pages_ext,
1101 .free_pages = efi_free_pages_ext,
1102 .get_memory_map = efi_get_memory_map_ext,
1103 .allocate_pool = efi_allocate_pool_ext,
1104 .free_pool = efi_free_pool_ext,
1105 .create_event = efi_create_event_ext,
1106 .set_timer = efi_set_timer_ext,
1107 .wait_for_event = efi_wait_for_event,
1108 .signal_event = efi_signal_event_ext,
1109 .close_event = efi_close_event,
1110 .check_event = efi_check_event,
1111 .install_protocol_interface = efi_install_protocol_interface_ext,
1112 .reinstall_protocol_interface = efi_reinstall_protocol_interface,
1113 .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext,
1114 .handle_protocol = efi_handle_protocol,
1116 .register_protocol_notify = efi_register_protocol_notify,
1117 .locate_handle = efi_locate_handle_ext,
1118 .locate_device_path = efi_locate_device_path,
1119 .install_configuration_table = efi_install_configuration_table_ext,
1120 .load_image = efi_load_image,
1121 .start_image = efi_start_image,
1123 .unload_image = efi_unload_image,
1124 .exit_boot_services = efi_exit_boot_services,
1125 .get_next_monotonic_count = efi_get_next_monotonic_count,
1127 .set_watchdog_timer = efi_set_watchdog_timer,
1128 .connect_controller = efi_connect_controller,
1129 .disconnect_controller = efi_disconnect_controller,
1130 .open_protocol = efi_open_protocol,
1131 .close_protocol = efi_close_protocol,
1132 .open_protocol_information = efi_open_protocol_information,
1133 .protocols_per_handle = efi_protocols_per_handle,
1134 .locate_handle_buffer = efi_locate_handle_buffer,
1135 .locate_protocol = efi_locate_protocol,
1136 .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
1137 .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
1138 .calculate_crc32 = efi_calculate_crc32,
1139 .copy_mem = efi_copy_mem,
1140 .set_mem = efi_set_mem,
1144 static uint16_t __efi_runtime_data firmware_vendor[] =
1145 { 'D','a','s',' ','U','-','b','o','o','t',0 };
1147 struct efi_system_table __efi_runtime_data systab = {
1149 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
1150 .revision = 0x20005, /* 2.5 */
1151 .headersize = sizeof(struct efi_table_hdr),
1153 .fw_vendor = (long)firmware_vendor,
1154 .con_in = (void*)&efi_con_in,
1155 .con_out = (void*)&efi_con_out,
1156 .std_err = (void*)&efi_con_out,
1157 .runtime = (void*)&efi_runtime_services,
1158 .boottime = (void*)&efi_boot_services,
1160 .tables = (void*)efi_conf_table,