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 static efi_status_t EFIAPI efi_create_event(
183 enum efi_event_type type, UINTN notify_tpl,
184 void (EFIAPI *notify_function) (
185 struct efi_event *event,
187 void *notify_context, struct efi_event **event)
191 EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
194 return EFI_EXIT(EFI_INVALID_PARAMETER);
196 if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
197 return EFI_EXIT(EFI_INVALID_PARAMETER);
199 if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
200 notify_function == NULL)
201 return EFI_EXIT(EFI_INVALID_PARAMETER);
203 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
204 if (efi_events[i].type)
206 efi_events[i].type = type;
207 efi_events[i].notify_tpl = notify_tpl;
208 efi_events[i].notify_function = notify_function;
209 efi_events[i].notify_context = notify_context;
210 /* Disable timers on bootup */
211 efi_events[i].trigger_next = -1ULL;
212 efi_events[i].signaled = 0;
213 *event = &efi_events[i];
214 return EFI_EXIT(EFI_SUCCESS);
216 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
220 * Our timers have to work without interrupts, so we check whenever keyboard
221 * input or disk accesses happen if enough time elapsed for it to fire.
223 void efi_timer_check(void)
226 u64 now = timer_get_us();
228 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
229 if (!efi_events[i].type ||
230 !(efi_events[i].type & EVT_TIMER) ||
231 efi_events[i].trigger_type == EFI_TIMER_STOP ||
232 now < efi_events[i].trigger_next)
234 if (efi_events[i].trigger_type == EFI_TIMER_PERIODIC) {
235 efi_events[i].trigger_next +=
236 efi_events[i].trigger_time / 10;
237 efi_events[i].signaled = 0;
239 efi_signal_event(&efi_events[i]);
244 static efi_status_t EFIAPI efi_set_timer(struct efi_event *event, int type,
245 uint64_t trigger_time)
247 /* We don't have 64bit division available everywhere, so limit timer
248 * distances to 32bit bits. */
249 u32 trigger32 = trigger_time;
252 EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
254 if (trigger32 < trigger_time) {
255 printf("WARNING: Truncating timer from %"PRIx64" to %x\n",
256 trigger_time, trigger32);
259 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
260 if (event != &efi_events[i])
263 if (!(event->type & EVT_TIMER))
267 event->trigger_next = -1ULL;
269 case EFI_TIMER_PERIODIC:
270 case EFI_TIMER_RELATIVE:
271 event->trigger_next =
272 timer_get_us() + (trigger32 / 10);
275 return EFI_EXIT(EFI_INVALID_PARAMETER);
277 event->trigger_type = type;
278 event->trigger_time = trigger_time;
279 return EFI_EXIT(EFI_SUCCESS);
281 return EFI_EXIT(EFI_INVALID_PARAMETER);
284 static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events,
285 struct efi_event **event,
286 unsigned long *index)
290 EFI_ENTRY("%ld, %p, %p", num_events, event, index);
292 /* Check parameters */
293 if (!num_events || !event)
294 return EFI_EXIT(EFI_INVALID_PARAMETER);
295 for (i = 0; i < num_events; ++i) {
296 for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
297 if (event[i] == &efi_events[j])
300 return EFI_EXIT(EFI_INVALID_PARAMETER);
302 if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
303 return EFI_EXIT(EFI_INVALID_PARAMETER);
306 /* Wait for signal */
308 for (i = 0; i < num_events; ++i) {
309 if (event[i]->signaled)
312 /* Allow events to occur. */
318 * Reset the signal which is passed to the caller to allow periodic
321 event[i]->signaled = 0;
325 return EFI_EXIT(EFI_SUCCESS);
328 static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
332 EFI_ENTRY("%p", event);
333 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
334 if (event != &efi_events[i])
336 efi_signal_event(event);
339 return EFI_EXIT(EFI_SUCCESS);
342 static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
346 EFI_ENTRY("%p", event);
347 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
348 if (event == &efi_events[i]) {
350 event->trigger_next = -1ULL;
352 return EFI_EXIT(EFI_SUCCESS);
355 return EFI_EXIT(EFI_INVALID_PARAMETER);
358 static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
362 EFI_ENTRY("%p", event);
364 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
365 if (event != &efi_events[i])
367 if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
370 return EFI_EXIT(EFI_SUCCESS);
371 return EFI_EXIT(EFI_NOT_READY);
373 return EFI_EXIT(EFI_INVALID_PARAMETER);
376 static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
377 efi_guid_t *protocol, int protocol_interface_type,
378 void *protocol_interface)
380 struct list_head *lhandle;
384 if (!handle || !protocol ||
385 protocol_interface_type != EFI_NATIVE_INTERFACE) {
386 r = EFI_INVALID_PARAMETER;
390 /* Create new handle if requested. */
392 r = EFI_OUT_OF_RESOURCES;
396 list_for_each(lhandle, &efi_obj_list) {
397 struct efi_object *efiobj;
398 efiobj = list_entry(lhandle, struct efi_object, link);
400 if (efiobj->handle != *handle)
402 /* Check if protocol is already installed on the handle. */
403 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
404 struct efi_handler *handler = &efiobj->protocols[i];
408 if (!guidcmp(handler->guid, protocol)) {
409 r = EFI_INVALID_PARAMETER;
413 /* Install protocol in first empty slot. */
414 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
415 struct efi_handler *handler = &efiobj->protocols[i];
420 handler->guid = protocol;
421 handler->protocol_interface = protocol_interface;
425 r = EFI_OUT_OF_RESOURCES;
428 r = EFI_INVALID_PARAMETER;
433 static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
434 efi_guid_t *protocol, int protocol_interface_type,
435 void *protocol_interface)
437 EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type,
440 return EFI_EXIT(efi_install_protocol_interface(handle, protocol,
441 protocol_interface_type,
442 protocol_interface));
445 static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
446 efi_guid_t *protocol, void *old_interface,
449 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, old_interface,
451 return EFI_EXIT(EFI_ACCESS_DENIED);
454 static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
455 efi_guid_t *protocol, void *protocol_interface)
457 struct list_head *lhandle;
459 efi_status_t r = EFI_NOT_FOUND;
461 if (!handle || !protocol) {
462 r = EFI_INVALID_PARAMETER;
466 list_for_each(lhandle, &efi_obj_list) {
467 struct efi_object *efiobj;
468 efiobj = list_entry(lhandle, struct efi_object, link);
470 if (efiobj->handle != handle)
473 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
474 struct efi_handler *handler = &efiobj->protocols[i];
475 const efi_guid_t *hprotocol = handler->guid;
479 if (!guidcmp(hprotocol, protocol)) {
480 if (handler->protocol_interface) {
481 r = EFI_ACCESS_DENIED;
495 static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle,
496 efi_guid_t *protocol, void *protocol_interface)
498 EFI_ENTRY("%p, %p, %p", handle, protocol, protocol_interface);
500 return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol,
501 protocol_interface));
504 static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol,
505 struct efi_event *event,
508 EFI_ENTRY("%p, %p, %p", protocol, event, registration);
509 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
512 static int efi_search(enum efi_locate_search_type search_type,
513 efi_guid_t *protocol, void *search_key,
514 struct efi_object *efiobj)
518 switch (search_type) {
521 case by_register_notify:
524 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
525 const efi_guid_t *guid = efiobj->protocols[i].guid;
526 if (guid && !guidcmp(guid, protocol))
535 static efi_status_t EFIAPI efi_locate_handle(
536 enum efi_locate_search_type search_type,
537 efi_guid_t *protocol, void *search_key,
538 unsigned long *buffer_size, efi_handle_t *buffer)
540 struct list_head *lhandle;
541 unsigned long size = 0;
543 /* Count how much space we need */
544 list_for_each(lhandle, &efi_obj_list) {
545 struct efi_object *efiobj;
546 efiobj = list_entry(lhandle, struct efi_object, link);
547 if (!efi_search(search_type, protocol, search_key, efiobj)) {
548 size += sizeof(void*);
552 if (*buffer_size < size) {
554 return EFI_BUFFER_TOO_SMALL;
557 /* Then fill the array */
558 list_for_each(lhandle, &efi_obj_list) {
559 struct efi_object *efiobj;
560 efiobj = list_entry(lhandle, struct efi_object, link);
561 if (!efi_search(search_type, protocol, search_key, efiobj)) {
562 *(buffer++) = efiobj->handle;
570 static efi_status_t EFIAPI efi_locate_handle_ext(
571 enum efi_locate_search_type search_type,
572 efi_guid_t *protocol, void *search_key,
573 unsigned long *buffer_size, efi_handle_t *buffer)
575 EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
576 buffer_size, buffer);
578 return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
579 buffer_size, buffer));
582 static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol,
583 struct efi_device_path **device_path,
584 efi_handle_t *device)
586 EFI_ENTRY("%p, %p, %p", protocol, device_path, device);
587 return EFI_EXIT(EFI_NOT_FOUND);
590 efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
594 /* Check for guid override */
595 for (i = 0; i < systab.nr_tables; i++) {
596 if (!guidcmp(guid, &efi_conf_table[i].guid)) {
597 efi_conf_table[i].table = table;
602 /* No override, check for overflow */
603 if (i >= ARRAY_SIZE(efi_conf_table))
604 return EFI_OUT_OF_RESOURCES;
606 /* Add a new entry */
607 memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
608 efi_conf_table[i].table = table;
609 systab.nr_tables = i + 1;
614 static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
617 EFI_ENTRY("%p, %p", guid, table);
618 return EFI_EXIT(efi_install_configuration_table(guid, table));
621 static efi_status_t EFIAPI efi_load_image(bool boot_policy,
622 efi_handle_t parent_image,
623 struct efi_device_path *file_path,
625 unsigned long source_size,
626 efi_handle_t *image_handle)
628 static struct efi_object loaded_image_info_obj = {
631 .guid = &efi_guid_loaded_image,
635 struct efi_loaded_image *info;
636 struct efi_object *obj;
638 EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
639 file_path, source_buffer, source_size, image_handle);
640 info = malloc(sizeof(*info));
641 loaded_image_info_obj.protocols[0].protocol_interface = info;
642 obj = malloc(sizeof(loaded_image_info_obj));
643 memset(info, 0, sizeof(*info));
644 memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj));
646 info->file_path = file_path;
647 info->reserved = efi_load_pe(source_buffer, info);
648 if (!info->reserved) {
651 return EFI_EXIT(EFI_UNSUPPORTED);
654 *image_handle = info;
655 list_add_tail(&obj->link, &efi_obj_list);
657 return EFI_EXIT(EFI_SUCCESS);
660 static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
661 unsigned long *exit_data_size,
664 ulong (*entry)(void *image_handle, struct efi_system_table *st);
665 struct efi_loaded_image *info = image_handle;
667 EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
668 entry = info->reserved;
670 efi_is_direct_boot = false;
672 /* call the image! */
673 if (setjmp(&info->exit_jmp)) {
674 /* We returned from the child image */
675 return EFI_EXIT(info->exit_status);
678 entry(image_handle, &systab);
680 /* Should usually never get here */
681 return EFI_EXIT(EFI_SUCCESS);
684 static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
685 efi_status_t exit_status, unsigned long exit_data_size,
688 struct efi_loaded_image *loaded_image_info = (void*)image_handle;
690 EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
691 exit_data_size, exit_data);
693 loaded_image_info->exit_status = exit_status;
694 longjmp(&loaded_image_info->exit_jmp, 1);
696 panic("EFI application exited");
699 static struct efi_object *efi_search_obj(void *handle)
701 struct list_head *lhandle;
703 list_for_each(lhandle, &efi_obj_list) {
704 struct efi_object *efiobj;
705 efiobj = list_entry(lhandle, struct efi_object, link);
706 if (efiobj->handle == handle)
713 static efi_status_t EFIAPI efi_unload_image(void *image_handle)
715 struct efi_object *efiobj;
717 EFI_ENTRY("%p", image_handle);
718 efiobj = efi_search_obj(image_handle);
720 list_del(&efiobj->link);
722 return EFI_EXIT(EFI_SUCCESS);
725 static void efi_exit_caches(void)
727 #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
729 * Grub on 32bit ARM needs to have caches disabled before jumping into
730 * a zImage, but does not know of all cache layers. Give it a hand.
732 if (efi_is_direct_boot)
733 cleanup_before_linux();
737 static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
738 unsigned long map_key)
740 EFI_ENTRY("%p, %ld", image_handle, map_key);
742 board_quiesce_devices();
744 /* Fix up caches for EFI payloads if necessary */
747 /* This stops all lingering devices */
748 bootm_disable_interrupts();
750 /* Give the payload some time to boot */
753 return EFI_EXIT(EFI_SUCCESS);
756 static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
758 static uint64_t mono = 0;
759 EFI_ENTRY("%p", count);
761 return EFI_EXIT(EFI_SUCCESS);
764 static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
766 EFI_ENTRY("%ld", microseconds);
767 udelay(microseconds);
768 return EFI_EXIT(EFI_SUCCESS);
771 static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
772 uint64_t watchdog_code,
773 unsigned long data_size,
774 uint16_t *watchdog_data)
776 EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
777 data_size, watchdog_data);
778 return EFI_EXIT(efi_unsupported(__func__));
781 static efi_status_t EFIAPI efi_connect_controller(
782 efi_handle_t controller_handle,
783 efi_handle_t *driver_image_handle,
784 struct efi_device_path *remain_device_path,
787 EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
788 remain_device_path, recursive);
789 return EFI_EXIT(EFI_NOT_FOUND);
792 static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
793 void *driver_image_handle,
796 EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
798 return EFI_EXIT(EFI_INVALID_PARAMETER);
801 static efi_status_t EFIAPI efi_close_protocol(void *handle,
802 efi_guid_t *protocol,
804 void *controller_handle)
806 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle,
808 return EFI_EXIT(EFI_NOT_FOUND);
811 static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
812 efi_guid_t *protocol,
813 struct efi_open_protocol_info_entry **entry_buffer,
814 unsigned long *entry_count)
816 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer,
818 return EFI_EXIT(EFI_NOT_FOUND);
821 static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
822 efi_guid_t ***protocol_buffer,
823 unsigned long *protocol_buffer_count)
825 EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
826 protocol_buffer_count);
827 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
830 static efi_status_t EFIAPI efi_locate_handle_buffer(
831 enum efi_locate_search_type search_type,
832 efi_guid_t *protocol, void *search_key,
833 unsigned long *no_handles, efi_handle_t **buffer)
836 unsigned long buffer_size = 0;
838 EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
841 if (!no_handles || !buffer) {
842 r = EFI_INVALID_PARAMETER;
847 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
849 if (r != EFI_BUFFER_TOO_SMALL)
851 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
853 if (r != EFI_SUCCESS)
855 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
857 if (r == EFI_SUCCESS)
858 *no_handles = buffer_size / sizeof(void *);
863 static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol,
865 void **protocol_interface)
867 struct list_head *lhandle;
870 EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface);
872 if (!protocol || !protocol_interface)
873 return EFI_EXIT(EFI_INVALID_PARAMETER);
875 list_for_each(lhandle, &efi_obj_list) {
876 struct efi_object *efiobj;
878 efiobj = list_entry(lhandle, struct efi_object, link);
879 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
880 struct efi_handler *handler = &efiobj->protocols[i];
884 if (!guidcmp(handler->guid, protocol)) {
885 *protocol_interface =
886 handler->protocol_interface;
887 return EFI_EXIT(EFI_SUCCESS);
891 *protocol_interface = NULL;
893 return EFI_EXIT(EFI_NOT_FOUND);
896 static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
899 EFI_ENTRY("%p", handle);
902 efi_guid_t *protocol;
903 void *protocol_interface;
904 efi_status_t r = EFI_SUCCESS;
908 return EFI_EXIT(EFI_INVALID_PARAMETER);
910 va_start(argptr, handle);
912 protocol = va_arg(argptr, efi_guid_t*);
915 protocol_interface = va_arg(argptr, void*);
916 r = efi_install_protocol_interface(handle, protocol,
917 EFI_NATIVE_INTERFACE,
919 if (r != EFI_SUCCESS)
924 if (r == EFI_SUCCESS)
927 /* If an error occured undo all changes. */
928 va_start(argptr, handle);
930 protocol = va_arg(argptr, efi_guid_t*);
931 protocol_interface = va_arg(argptr, void*);
932 efi_uninstall_protocol_interface(handle, protocol,
940 static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
943 EFI_ENTRY("%p", handle);
944 return EFI_EXIT(EFI_INVALID_PARAMETER);
947 static efi_status_t EFIAPI efi_calculate_crc32(void *data,
948 unsigned long data_size,
951 EFI_ENTRY("%p, %ld", data, data_size);
952 *crc32_p = crc32(0, data, data_size);
953 return EFI_EXIT(EFI_SUCCESS);
956 static void EFIAPI efi_copy_mem(void *destination, void *source,
957 unsigned long length)
959 EFI_ENTRY("%p, %p, %ld", destination, source, length);
960 memcpy(destination, source, length);
963 static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value)
965 EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value);
966 memset(buffer, value, size);
969 static efi_status_t EFIAPI efi_open_protocol(
970 void *handle, efi_guid_t *protocol,
971 void **protocol_interface, void *agent_handle,
972 void *controller_handle, uint32_t attributes)
974 struct list_head *lhandle;
976 efi_status_t r = EFI_INVALID_PARAMETER;
978 EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol,
979 protocol_interface, agent_handle, controller_handle,
982 if (!handle || !protocol ||
983 (!protocol_interface && attributes !=
984 EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
988 switch (attributes) {
989 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
990 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
991 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
993 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
994 if (controller_handle == handle)
996 case EFI_OPEN_PROTOCOL_BY_DRIVER:
997 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
998 if (controller_handle == NULL)
1000 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
1001 if (agent_handle == NULL)
1008 list_for_each(lhandle, &efi_obj_list) {
1009 struct efi_object *efiobj;
1010 efiobj = list_entry(lhandle, struct efi_object, link);
1012 if (efiobj->handle != handle)
1015 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1016 struct efi_handler *handler = &efiobj->protocols[i];
1017 const efi_guid_t *hprotocol = handler->guid;
1020 if (!guidcmp(hprotocol, protocol)) {
1022 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
1023 *protocol_interface =
1024 handler->protocol_interface;
1034 r = EFI_UNSUPPORTED;
1039 static efi_status_t EFIAPI efi_handle_protocol(void *handle,
1040 efi_guid_t *protocol,
1041 void **protocol_interface)
1043 return efi_open_protocol(handle, protocol, protocol_interface, NULL,
1044 NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
1047 static const struct efi_boot_services efi_boot_services = {
1049 .headersize = sizeof(struct efi_table_hdr),
1051 .raise_tpl = efi_raise_tpl,
1052 .restore_tpl = efi_restore_tpl,
1053 .allocate_pages = efi_allocate_pages_ext,
1054 .free_pages = efi_free_pages_ext,
1055 .get_memory_map = efi_get_memory_map_ext,
1056 .allocate_pool = efi_allocate_pool_ext,
1057 .free_pool = efi_free_pool_ext,
1058 .create_event = efi_create_event,
1059 .set_timer = efi_set_timer,
1060 .wait_for_event = efi_wait_for_event,
1061 .signal_event = efi_signal_event_ext,
1062 .close_event = efi_close_event,
1063 .check_event = efi_check_event,
1064 .install_protocol_interface = efi_install_protocol_interface_ext,
1065 .reinstall_protocol_interface = efi_reinstall_protocol_interface,
1066 .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext,
1067 .handle_protocol = efi_handle_protocol,
1069 .register_protocol_notify = efi_register_protocol_notify,
1070 .locate_handle = efi_locate_handle_ext,
1071 .locate_device_path = efi_locate_device_path,
1072 .install_configuration_table = efi_install_configuration_table_ext,
1073 .load_image = efi_load_image,
1074 .start_image = efi_start_image,
1076 .unload_image = efi_unload_image,
1077 .exit_boot_services = efi_exit_boot_services,
1078 .get_next_monotonic_count = efi_get_next_monotonic_count,
1080 .set_watchdog_timer = efi_set_watchdog_timer,
1081 .connect_controller = efi_connect_controller,
1082 .disconnect_controller = efi_disconnect_controller,
1083 .open_protocol = efi_open_protocol,
1084 .close_protocol = efi_close_protocol,
1085 .open_protocol_information = efi_open_protocol_information,
1086 .protocols_per_handle = efi_protocols_per_handle,
1087 .locate_handle_buffer = efi_locate_handle_buffer,
1088 .locate_protocol = efi_locate_protocol,
1089 .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
1090 .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
1091 .calculate_crc32 = efi_calculate_crc32,
1092 .copy_mem = efi_copy_mem,
1093 .set_mem = efi_set_mem,
1097 static uint16_t __efi_runtime_data firmware_vendor[] =
1098 { 'D','a','s',' ','U','-','b','o','o','t',0 };
1100 struct efi_system_table __efi_runtime_data systab = {
1102 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
1103 .revision = 0x20005, /* 2.5 */
1104 .headersize = sizeof(struct efi_table_hdr),
1106 .fw_vendor = (long)firmware_vendor,
1107 .con_in = (void*)&efi_con_in,
1108 .con_out = (void*)&efi_con_out,
1109 .std_err = (void*)&efi_con_out,
1110 .runtime = (void*)&efi_runtime_services,
1111 .boottime = (void*)&efi_boot_services,
1113 .tables = (void*)efi_conf_table,