]> git.sur5r.net Git - u-boot/blob - lib/efi_loader/efi_boottime.c
900cb1aad89620096ceafcd7fcb1cf5c61683222
[u-boot] / lib / efi_loader / efi_boottime.c
1 /*
2  *  EFI application boot time services
3  *
4  *  Copyright (c) 2016 Alexander Graf
5  *
6  *  SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <common.h>
10 #include <div64.h>
11 #include <efi_loader.h>
12 #include <environment.h>
13 #include <malloc.h>
14 #include <asm/global_data.h>
15 #include <libfdt_env.h>
16 #include <u-boot/crc.h>
17 #include <bootm.h>
18 #include <inttypes.h>
19 #include <watchdog.h>
20
21 DECLARE_GLOBAL_DATA_PTR;
22
23 /* Task priority level */
24 static efi_uintn_t efi_tpl = TPL_APPLICATION;
25
26 /* This list contains all the EFI objects our payload has access to */
27 LIST_HEAD(efi_obj_list);
28
29 /*
30  * If we're running on nasty systems (32bit ARM booting into non-EFI Linux)
31  * we need to do trickery with caches. Since we don't want to break the EFI
32  * aware boot path, only apply hacks when loading exiting directly (breaking
33  * direct Linux EFI booting along the way - oh well).
34  */
35 static bool efi_is_direct_boot = true;
36
37 /*
38  * EFI can pass arbitrary additional "tables" containing vendor specific
39  * information to the payload. One such table is the FDT table which contains
40  * a pointer to a flattened device tree blob.
41  *
42  * In most cases we want to pass an FDT to the payload, so reserve one slot of
43  * config table space for it. The pointer gets populated by do_bootefi_exec().
44  */
45 static struct efi_configuration_table __efi_runtime_data efi_conf_table[2];
46
47 #ifdef CONFIG_ARM
48 /*
49  * The "gd" pointer lives in a register on ARM and AArch64 that we declare
50  * fixed when compiling U-Boot. However, the payload does not know about that
51  * restriction so we need to manually swap its and our view of that register on
52  * EFI callback entry/exit.
53  */
54 static volatile void *efi_gd, *app_gd;
55 #endif
56
57 static int entry_count;
58 static int nesting_level;
59
60 /* Called on every callback entry */
61 int __efi_entry_check(void)
62 {
63         int ret = entry_count++ == 0;
64 #ifdef CONFIG_ARM
65         assert(efi_gd);
66         app_gd = gd;
67         gd = efi_gd;
68 #endif
69         return ret;
70 }
71
72 /* Called on every callback exit */
73 int __efi_exit_check(void)
74 {
75         int ret = --entry_count == 0;
76 #ifdef CONFIG_ARM
77         gd = app_gd;
78 #endif
79         return ret;
80 }
81
82 /* Called from do_bootefi_exec() */
83 void efi_save_gd(void)
84 {
85 #ifdef CONFIG_ARM
86         efi_gd = gd;
87 #endif
88 }
89
90 /*
91  * Special case handler for error/abort that just forces things back
92  * to u-boot world so we can dump out an abort msg, without any care
93  * about returning back to UEFI world.
94  */
95 void efi_restore_gd(void)
96 {
97 #ifdef CONFIG_ARM
98         /* Only restore if we're already in EFI context */
99         if (!efi_gd)
100                 return;
101         gd = efi_gd;
102 #endif
103 }
104
105 /*
106  * Two spaces per indent level, maxing out at 10.. which ought to be
107  * enough for anyone ;-)
108  */
109 static const char *indent_string(int level)
110 {
111         const char *indent = "                    ";
112         const int max = strlen(indent);
113         level = min(max, level * 2);
114         return &indent[max - level];
115 }
116
117 const char *__efi_nesting(void)
118 {
119         return indent_string(nesting_level);
120 }
121
122 const char *__efi_nesting_inc(void)
123 {
124         return indent_string(nesting_level++);
125 }
126
127 const char *__efi_nesting_dec(void)
128 {
129         return indent_string(--nesting_level);
130 }
131
132 /*
133  * Queue an EFI event.
134  *
135  * This function queues the notification function of the event for future
136  * execution.
137  *
138  * The notification function is called if the task priority level of the
139  * event is higher than the current task priority level.
140  *
141  * For the SignalEvent service see efi_signal_event_ext.
142  *
143  * @event       event to signal
144  */
145 void efi_signal_event(struct efi_event *event)
146 {
147         if (event->notify_function) {
148                 event->is_queued = true;
149                 /* Check TPL */
150                 if (efi_tpl >= event->notify_tpl)
151                         return;
152                 EFI_CALL_VOID(event->notify_function(event,
153                                                      event->notify_context));
154         }
155         event->is_queued = false;
156 }
157
158 /*
159  * Raise the task priority level.
160  *
161  * This function implements the RaiseTpl service.
162  * See the Unified Extensible Firmware Interface (UEFI) specification
163  * for details.
164  *
165  * @new_tpl     new value of the task priority level
166  * @return      old value of the task priority level
167  */
168 static unsigned long EFIAPI efi_raise_tpl(efi_uintn_t new_tpl)
169 {
170         efi_uintn_t old_tpl = efi_tpl;
171
172         EFI_ENTRY("0x%zx", new_tpl);
173
174         if (new_tpl < efi_tpl)
175                 debug("WARNING: new_tpl < current_tpl in %s\n", __func__);
176         efi_tpl = new_tpl;
177         if (efi_tpl > TPL_HIGH_LEVEL)
178                 efi_tpl = TPL_HIGH_LEVEL;
179
180         EFI_EXIT(EFI_SUCCESS);
181         return old_tpl;
182 }
183
184 /*
185  * Lower the task priority level.
186  *
187  * This function implements the RestoreTpl service.
188  * See the Unified Extensible Firmware Interface (UEFI) specification
189  * for details.
190  *
191  * @old_tpl     value of the task priority level to be restored
192  */
193 static void EFIAPI efi_restore_tpl(efi_uintn_t old_tpl)
194 {
195         EFI_ENTRY("0x%zx", old_tpl);
196
197         if (old_tpl > efi_tpl)
198                 debug("WARNING: old_tpl > current_tpl in %s\n", __func__);
199         efi_tpl = old_tpl;
200         if (efi_tpl > TPL_HIGH_LEVEL)
201                 efi_tpl = TPL_HIGH_LEVEL;
202
203         EFI_EXIT(EFI_SUCCESS);
204 }
205
206 /*
207  * Allocate memory pages.
208  *
209  * This function implements the AllocatePages service.
210  * See the Unified Extensible Firmware Interface (UEFI) specification
211  * for details.
212  *
213  * @type                type of allocation to be performed
214  * @memory_type         usage type of the allocated memory
215  * @pages               number of pages to be allocated
216  * @memory              allocated memory
217  * @return              status code
218  */
219 static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
220                                                   efi_uintn_t pages,
221                                                   uint64_t *memory)
222 {
223         efi_status_t r;
224
225         EFI_ENTRY("%d, %d, 0x%zx, %p", type, memory_type, pages, memory);
226         r = efi_allocate_pages(type, memory_type, pages, memory);
227         return EFI_EXIT(r);
228 }
229
230 /*
231  * Free memory pages.
232  *
233  * This function implements the FreePages service.
234  * See the Unified Extensible Firmware Interface (UEFI) specification
235  * for details.
236  *
237  * @memory      start of the memory area to be freed
238  * @pages       number of pages to be freed
239  * @return      status code
240  */
241 static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
242                                               efi_uintn_t pages)
243 {
244         efi_status_t r;
245
246         EFI_ENTRY("%"PRIx64", 0x%zx", memory, pages);
247         r = efi_free_pages(memory, pages);
248         return EFI_EXIT(r);
249 }
250
251 /*
252  * Get map describing memory usage.
253  *
254  * This function implements the GetMemoryMap service.
255  * See the Unified Extensible Firmware Interface (UEFI) specification
256  * for details.
257  *
258  * @memory_map_size     on entry the size, in bytes, of the memory map buffer,
259  *                      on exit the size of the copied memory map
260  * @memory_map          buffer to which the memory map is written
261  * @map_key             key for the memory map
262  * @descriptor_size     size of an individual memory descriptor
263  * @descriptor_version  version number of the memory descriptor structure
264  * @return              status code
265  */
266 static efi_status_t EFIAPI efi_get_memory_map_ext(
267                                         efi_uintn_t *memory_map_size,
268                                         struct efi_mem_desc *memory_map,
269                                         efi_uintn_t *map_key,
270                                         efi_uintn_t *descriptor_size,
271                                         uint32_t *descriptor_version)
272 {
273         efi_status_t r;
274
275         EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map,
276                   map_key, descriptor_size, descriptor_version);
277         r = efi_get_memory_map(memory_map_size, memory_map, map_key,
278                                descriptor_size, descriptor_version);
279         return EFI_EXIT(r);
280 }
281
282 /*
283  * Allocate memory from pool.
284  *
285  * This function implements the AllocatePool service.
286  * See the Unified Extensible Firmware Interface (UEFI) specification
287  * for details.
288  *
289  * @pool_type   type of the pool from which memory is to be allocated
290  * @size        number of bytes to be allocated
291  * @buffer      allocated memory
292  * @return      status code
293  */
294 static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
295                                                  efi_uintn_t size,
296                                                  void **buffer)
297 {
298         efi_status_t r;
299
300         EFI_ENTRY("%d, %zd, %p", pool_type, size, buffer);
301         r = efi_allocate_pool(pool_type, size, buffer);
302         return EFI_EXIT(r);
303 }
304
305 /*
306  * Free memory from pool.
307  *
308  * This function implements the FreePool service.
309  * See the Unified Extensible Firmware Interface (UEFI) specification
310  * for details.
311  *
312  * @buffer      start of memory to be freed
313  * @return      status code
314  */
315 static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
316 {
317         efi_status_t r;
318
319         EFI_ENTRY("%p", buffer);
320         r = efi_free_pool(buffer);
321         return EFI_EXIT(r);
322 }
323
324 /*
325  * Create handle.
326  *
327  * @handle      new handle
328  * @return      status code
329  */
330 efi_status_t efi_create_handle(void **handle)
331 {
332         struct efi_object *obj;
333         efi_status_t r;
334
335         r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
336                               sizeof(struct efi_object),
337                               (void **)&obj);
338         if (r != EFI_SUCCESS)
339                 return r;
340         memset(obj, 0, sizeof(struct efi_object));
341         obj->handle = obj;
342         list_add_tail(&obj->link, &efi_obj_list);
343         *handle = obj;
344         return r;
345 }
346
347 /*
348  * Our event capabilities are very limited. Only a small limited
349  * number of events is allowed to coexist.
350  */
351 static struct efi_event efi_events[16];
352
353 /*
354  * Create an event.
355  *
356  * This function is used inside U-Boot code to create an event.
357  *
358  * For the API function implementing the CreateEvent service see
359  * efi_create_event_ext.
360  *
361  * @type                type of the event to create
362  * @notify_tpl          task priority level of the event
363  * @notify_function     notification function of the event
364  * @notify_context      pointer passed to the notification function
365  * @event               created event
366  * @return              status code
367  */
368 efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl,
369                               void (EFIAPI *notify_function) (
370                                         struct efi_event *event,
371                                         void *context),
372                               void *notify_context, struct efi_event **event)
373 {
374         int i;
375
376         if (event == NULL)
377                 return EFI_INVALID_PARAMETER;
378
379         if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
380                 return EFI_INVALID_PARAMETER;
381
382         if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
383             notify_function == NULL)
384                 return EFI_INVALID_PARAMETER;
385
386         for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
387                 if (efi_events[i].type)
388                         continue;
389                 efi_events[i].type = type;
390                 efi_events[i].notify_tpl = notify_tpl;
391                 efi_events[i].notify_function = notify_function;
392                 efi_events[i].notify_context = notify_context;
393                 /* Disable timers on bootup */
394                 efi_events[i].trigger_next = -1ULL;
395                 efi_events[i].is_queued = false;
396                 efi_events[i].is_signaled = false;
397                 *event = &efi_events[i];
398                 return EFI_SUCCESS;
399         }
400         return EFI_OUT_OF_RESOURCES;
401 }
402
403 /*
404  * Create an event.
405  *
406  * This function implements the CreateEvent service.
407  * See the Unified Extensible Firmware Interface (UEFI) specification
408  * for details.
409  *
410  * @type                type of the event to create
411  * @notify_tpl          task priority level of the event
412  * @notify_function     notification function of the event
413  * @notify_context      pointer passed to the notification function
414  * @event               created event
415  * @return              status code
416  */
417 static efi_status_t EFIAPI efi_create_event_ext(
418                         uint32_t type, efi_uintn_t notify_tpl,
419                         void (EFIAPI *notify_function) (
420                                         struct efi_event *event,
421                                         void *context),
422                         void *notify_context, struct efi_event **event)
423 {
424         EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
425                   notify_context);
426         return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
427                                          notify_context, event));
428 }
429
430
431 /*
432  * Check if a timer event has occurred or a queued notification function should
433  * be called.
434  *
435  * Our timers have to work without interrupts, so we check whenever keyboard
436  * input or disk accesses happen if enough time elapsed for them to fire.
437  */
438 void efi_timer_check(void)
439 {
440         int i;
441         u64 now = timer_get_us();
442
443         for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
444                 if (!efi_events[i].type)
445                         continue;
446                 if (efi_events[i].is_queued)
447                         efi_signal_event(&efi_events[i]);
448                 if (!(efi_events[i].type & EVT_TIMER) ||
449                     now < efi_events[i].trigger_next)
450                         continue;
451                 switch (efi_events[i].trigger_type) {
452                 case EFI_TIMER_RELATIVE:
453                         efi_events[i].trigger_type = EFI_TIMER_STOP;
454                         break;
455                 case EFI_TIMER_PERIODIC:
456                         efi_events[i].trigger_next +=
457                                 efi_events[i].trigger_time;
458                         break;
459                 default:
460                         continue;
461                 }
462                 efi_events[i].is_signaled = true;
463                 efi_signal_event(&efi_events[i]);
464         }
465         WATCHDOG_RESET();
466 }
467
468 /*
469  * Set the trigger time for a timer event or stop the event.
470  *
471  * This is the function for internal usage in U-Boot. For the API function
472  * implementing the SetTimer service see efi_set_timer_ext.
473  *
474  * @event               event for which the timer is set
475  * @type                type of the timer
476  * @trigger_time        trigger period in multiples of 100ns
477  * @return              status code
478  */
479 efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
480                            uint64_t trigger_time)
481 {
482         int i;
483
484         /*
485          * The parameter defines a multiple of 100ns.
486          * We use multiples of 1000ns. So divide by 10.
487          */
488         do_div(trigger_time, 10);
489
490         for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
491                 if (event != &efi_events[i])
492                         continue;
493
494                 if (!(event->type & EVT_TIMER))
495                         break;
496                 switch (type) {
497                 case EFI_TIMER_STOP:
498                         event->trigger_next = -1ULL;
499                         break;
500                 case EFI_TIMER_PERIODIC:
501                 case EFI_TIMER_RELATIVE:
502                         event->trigger_next =
503                                 timer_get_us() + trigger_time;
504                         break;
505                 default:
506                         return EFI_INVALID_PARAMETER;
507                 }
508                 event->trigger_type = type;
509                 event->trigger_time = trigger_time;
510                 event->is_signaled = false;
511                 return EFI_SUCCESS;
512         }
513         return EFI_INVALID_PARAMETER;
514 }
515
516 /*
517  * Set the trigger time for a timer event or stop the event.
518  *
519  * This function implements the SetTimer service.
520  * See the Unified Extensible Firmware Interface (UEFI) specification
521  * for details.
522  *
523  * @event               event for which the timer is set
524  * @type                type of the timer
525  * @trigger_time        trigger period in multiples of 100ns
526  * @return              status code
527  */
528 static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event,
529                                              enum efi_timer_delay type,
530                                              uint64_t trigger_time)
531 {
532         EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
533         return EFI_EXIT(efi_set_timer(event, type, trigger_time));
534 }
535
536 /*
537  * Wait for events to be signaled.
538  *
539  * This function implements the WaitForEvent service.
540  * See the Unified Extensible Firmware Interface (UEFI) specification
541  * for details.
542  *
543  * @num_events  number of events to be waited for
544  * @events      events to be waited for
545  * @index       index of the event that was signaled
546  * @return      status code
547  */
548 static efi_status_t EFIAPI efi_wait_for_event(efi_uintn_t num_events,
549                                               struct efi_event **event,
550                                               efi_uintn_t *index)
551 {
552         int i, j;
553
554         EFI_ENTRY("%zd, %p, %p", num_events, event, index);
555
556         /* Check parameters */
557         if (!num_events || !event)
558                 return EFI_EXIT(EFI_INVALID_PARAMETER);
559         /* Check TPL */
560         if (efi_tpl != TPL_APPLICATION)
561                 return EFI_EXIT(EFI_UNSUPPORTED);
562         for (i = 0; i < num_events; ++i) {
563                 for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
564                         if (event[i] == &efi_events[j])
565                                 goto known_event;
566                 }
567                 return EFI_EXIT(EFI_INVALID_PARAMETER);
568 known_event:
569                 if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
570                         return EFI_EXIT(EFI_INVALID_PARAMETER);
571                 if (!event[i]->is_signaled)
572                         efi_signal_event(event[i]);
573         }
574
575         /* Wait for signal */
576         for (;;) {
577                 for (i = 0; i < num_events; ++i) {
578                         if (event[i]->is_signaled)
579                                 goto out;
580                 }
581                 /* Allow events to occur. */
582                 efi_timer_check();
583         }
584
585 out:
586         /*
587          * Reset the signal which is passed to the caller to allow periodic
588          * events to occur.
589          */
590         event[i]->is_signaled = false;
591         if (index)
592                 *index = i;
593
594         return EFI_EXIT(EFI_SUCCESS);
595 }
596
597 /*
598  * Signal an EFI event.
599  *
600  * This function implements the SignalEvent service.
601  * See the Unified Extensible Firmware Interface (UEFI) specification
602  * for details.
603  *
604  * This functions sets the signaled state of the event and queues the
605  * notification function for execution.
606  *
607  * @event       event to signal
608  * @return      status code
609  */
610 static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
611 {
612         int i;
613
614         EFI_ENTRY("%p", event);
615         for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
616                 if (event != &efi_events[i])
617                         continue;
618                 if (event->is_signaled)
619                         break;
620                 event->is_signaled = true;
621                 if (event->type & EVT_NOTIFY_SIGNAL)
622                         efi_signal_event(event);
623                 break;
624         }
625         return EFI_EXIT(EFI_SUCCESS);
626 }
627
628 /*
629  * Close an EFI event.
630  *
631  * This function implements the CloseEvent service.
632  * See the Unified Extensible Firmware Interface (UEFI) specification
633  * for details.
634  *
635  * @event       event to close
636  * @return      status code
637  */
638 static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
639 {
640         int i;
641
642         EFI_ENTRY("%p", event);
643         for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
644                 if (event == &efi_events[i]) {
645                         event->type = 0;
646                         event->trigger_next = -1ULL;
647                         event->is_queued = false;
648                         event->is_signaled = false;
649                         return EFI_EXIT(EFI_SUCCESS);
650                 }
651         }
652         return EFI_EXIT(EFI_INVALID_PARAMETER);
653 }
654
655 /*
656  * Check if an event is signaled.
657  *
658  * This function implements the CheckEvent service.
659  * See the Unified Extensible Firmware Interface (UEFI) specification
660  * for details.
661  *
662  * If an event is not signaled yet the notification function is queued.
663  *
664  * @event       event to check
665  * @return      status code
666  */
667 static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
668 {
669         int i;
670
671         EFI_ENTRY("%p", event);
672         efi_timer_check();
673         for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
674                 if (event != &efi_events[i])
675                         continue;
676                 if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
677                         break;
678                 if (!event->is_signaled)
679                         efi_signal_event(event);
680                 if (event->is_signaled)
681                         return EFI_EXIT(EFI_SUCCESS);
682                 return EFI_EXIT(EFI_NOT_READY);
683         }
684         return EFI_EXIT(EFI_INVALID_PARAMETER);
685 }
686
687 /*
688  * Find the internal EFI object for a handle.
689  *
690  * @handle      handle to find
691  * @return      EFI object
692  */
693 struct efi_object *efi_search_obj(const void *handle)
694 {
695         struct efi_object *efiobj;
696
697         list_for_each_entry(efiobj, &efi_obj_list, link) {
698                 if (efiobj->handle == handle)
699                         return efiobj;
700         }
701
702         return NULL;
703 }
704
705 /*
706  * Find a protocol on a handle.
707  *
708  * @handle              handle
709  * @protocol_guid       GUID of the protocol
710  * @handler             reference to the protocol
711  * @return              status code
712  */
713 efi_status_t efi_search_protocol(const void *handle,
714                                  const efi_guid_t *protocol_guid,
715                                  struct efi_handler **handler)
716 {
717         struct efi_object *efiobj;
718         size_t i;
719         struct efi_handler *protocol;
720
721         if (!handle || !protocol_guid)
722                 return EFI_INVALID_PARAMETER;
723         efiobj = efi_search_obj(handle);
724         if (!efiobj)
725                 return EFI_INVALID_PARAMETER;
726         for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
727                 protocol = &efiobj->protocols[i];
728                 if (!protocol->guid)
729                         continue;
730                 if (!guidcmp(protocol->guid, protocol_guid)) {
731                         if (handler)
732                                 *handler = protocol;
733                         return EFI_SUCCESS;
734                 }
735         }
736         return EFI_NOT_FOUND;
737 }
738
739 /*
740  * Install new protocol on a handle.
741  *
742  * @handle                      handle on which the protocol shall be installed
743  * @protocol                    GUID of the protocol to be installed
744  * @protocol_interface          interface of the protocol implementation
745  * @return                      status code
746  */
747 efi_status_t efi_add_protocol(const void *handle, const efi_guid_t *protocol,
748                               void *protocol_interface)
749 {
750         struct efi_object *efiobj;
751         struct efi_handler *handler;
752         efi_status_t ret;
753         size_t i;
754
755         efiobj = efi_search_obj(handle);
756         if (!efiobj)
757                 return EFI_INVALID_PARAMETER;
758         ret = efi_search_protocol(handle, protocol, NULL);
759         if (ret != EFI_NOT_FOUND)
760                 return EFI_INVALID_PARAMETER;
761         handler = calloc(1, sizeof(struct efi_handler));
762         if (!handler)
763                 return EFI_OUT_OF_RESOURCES;
764         /* Install protocol in first empty slot. */
765         for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
766                 handler = &efiobj->protocols[i];
767                 if (handler->guid)
768                         continue;
769                 handler->guid = protocol;
770                 handler->protocol_interface = protocol_interface;
771                 return EFI_SUCCESS;
772         }
773         return EFI_OUT_OF_RESOURCES;
774 }
775
776 /*
777  * Delete protocol from a handle.
778  *
779  * @handle                      handle from which the protocol shall be deleted
780  * @protocol                    GUID of the protocol to be deleted
781  * @protocol_interface          interface of the protocol implementation
782  * @return                      status code
783  */
784 efi_status_t efi_remove_protocol(const void *handle, const efi_guid_t *protocol,
785                                  void *protocol_interface)
786 {
787         struct efi_handler *handler;
788         efi_status_t ret;
789
790         ret = efi_search_protocol(handle, protocol, &handler);
791         if (ret != EFI_SUCCESS)
792                 return ret;
793         if (handler->protocol_interface != protocol_interface)
794                 return EFI_NOT_FOUND;
795         handler->guid = NULL;
796         handler->protocol_interface = NULL;
797         return EFI_SUCCESS;
798 }
799
800 /*
801  * Delete all protocols from a handle.
802  *
803  * @handle                      handle from which the protocols shall be deleted
804  * @return                      status code
805  */
806 efi_status_t efi_remove_all_protocols(const void *handle)
807 {
808         struct efi_object *efiobj;
809         struct efi_handler *handler;
810         size_t i;
811
812         efiobj = efi_search_obj(handle);
813         if (!efiobj)
814                 return EFI_INVALID_PARAMETER;
815
816         for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
817                 handler = &efiobj->protocols[i];
818                 handler->guid = NULL;
819                 handler->protocol_interface = NULL;
820         }
821         return EFI_SUCCESS;
822 }
823
824 /*
825  * Install protocol interface.
826  *
827  * This function implements the InstallProtocolInterface service.
828  * See the Unified Extensible Firmware Interface (UEFI) specification
829  * for details.
830  *
831  * @handle                      handle on which the protocol shall be installed
832  * @protocol                    GUID of the protocol to be installed
833  * @protocol_interface_type     type of the interface to be installed,
834  *                              always EFI_NATIVE_INTERFACE
835  * @protocol_interface          interface of the protocol implementation
836  * @return                      status code
837  */
838 static efi_status_t EFIAPI efi_install_protocol_interface(
839                         void **handle, const efi_guid_t *protocol,
840                         int protocol_interface_type, void *protocol_interface)
841 {
842         efi_status_t r;
843
844         EFI_ENTRY("%p, %pUl, %d, %p", handle, protocol, protocol_interface_type,
845                   protocol_interface);
846
847         if (!handle || !protocol ||
848             protocol_interface_type != EFI_NATIVE_INTERFACE) {
849                 r = EFI_INVALID_PARAMETER;
850                 goto out;
851         }
852
853         /* Create new handle if requested. */
854         if (!*handle) {
855                 r = efi_create_handle(handle);
856                 if (r != EFI_SUCCESS)
857                         goto out;
858                 debug("%sEFI: new handle %p\n", indent_string(nesting_level),
859                       *handle);
860         } else {
861                 debug("%sEFI: handle %p\n", indent_string(nesting_level),
862                       *handle);
863         }
864         /* Add new protocol */
865         r = efi_add_protocol(*handle, protocol, protocol_interface);
866 out:
867         return EFI_EXIT(r);
868 }
869
870 /*
871  * Reinstall protocol interface.
872  *
873  * This function implements the ReinstallProtocolInterface service.
874  * See the Unified Extensible Firmware Interface (UEFI) specification
875  * for details.
876  *
877  * @handle                      handle on which the protocol shall be
878  *                              reinstalled
879  * @protocol                    GUID of the protocol to be installed
880  * @old_interface               interface to be removed
881  * @new_interface               interface to be installed
882  * @return                      status code
883  */
884 static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
885                         const efi_guid_t *protocol, void *old_interface,
886                         void *new_interface)
887 {
888         EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, old_interface,
889                   new_interface);
890         return EFI_EXIT(EFI_ACCESS_DENIED);
891 }
892
893 /*
894  * Uninstall protocol interface.
895  *
896  * This function implements the UninstallProtocolInterface service.
897  * See the Unified Extensible Firmware Interface (UEFI) specification
898  * for details.
899  *
900  * @handle                      handle from which the protocol shall be removed
901  * @protocol                    GUID of the protocol to be removed
902  * @protocol_interface          interface to be removed
903  * @return                      status code
904  */
905 static efi_status_t EFIAPI efi_uninstall_protocol_interface(
906                                 void *handle, const efi_guid_t *protocol,
907                                 void *protocol_interface)
908 {
909         struct list_head *lhandle;
910         int i;
911         efi_status_t r = EFI_NOT_FOUND;
912
913         EFI_ENTRY("%p, %pUl, %p", handle, protocol, protocol_interface);
914
915         if (!handle || !protocol) {
916                 r = EFI_INVALID_PARAMETER;
917                 goto out;
918         }
919
920         list_for_each(lhandle, &efi_obj_list) {
921                 struct efi_object *efiobj;
922                 efiobj = list_entry(lhandle, struct efi_object, link);
923
924                 if (efiobj->handle != handle)
925                         continue;
926
927                 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
928                         struct efi_handler *handler = &efiobj->protocols[i];
929                         const efi_guid_t *hprotocol = handler->guid;
930
931                         if (!hprotocol)
932                                 continue;
933                         if (!guidcmp(hprotocol, protocol)) {
934                                 if (handler->protocol_interface) {
935                                         r = EFI_ACCESS_DENIED;
936                                 } else {
937                                         handler->guid = 0;
938                                         r = EFI_SUCCESS;
939                                 }
940                                 goto out;
941                         }
942                 }
943         }
944
945 out:
946         return EFI_EXIT(r);
947 }
948
949 /*
950  * Register an event for notification when a protocol is installed.
951  *
952  * This function implements the RegisterProtocolNotify service.
953  * See the Unified Extensible Firmware Interface (UEFI) specification
954  * for details.
955  *
956  * @protocol            GUID of the protocol whose installation shall be
957  *                      notified
958  * @event               event to be signaled upon installation of the protocol
959  * @registration        key for retrieving the registration information
960  * @return              status code
961  */
962 static efi_status_t EFIAPI efi_register_protocol_notify(
963                                                 const efi_guid_t *protocol,
964                                                 struct efi_event *event,
965                                                 void **registration)
966 {
967         EFI_ENTRY("%pUl, %p, %p", protocol, event, registration);
968         return EFI_EXIT(EFI_OUT_OF_RESOURCES);
969 }
970
971 /*
972  * Determine if an EFI handle implements a protocol.
973  *
974  * See the documentation of the LocateHandle service in the UEFI specification.
975  *
976  * @search_type         selection criterion
977  * @protocol            GUID of the protocol
978  * @search_key          registration key
979  * @efiobj              handle
980  * @return              0 if the handle implements the protocol
981  */
982 static int efi_search(enum efi_locate_search_type search_type,
983                       const efi_guid_t *protocol, void *search_key,
984                       struct efi_object *efiobj)
985 {
986         int i;
987
988         switch (search_type) {
989         case ALL_HANDLES:
990                 return 0;
991         case BY_REGISTER_NOTIFY:
992                 /* RegisterProtocolNotify is not implemented yet */
993                 return -1;
994         case BY_PROTOCOL:
995                 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
996                         const efi_guid_t *guid = efiobj->protocols[i].guid;
997                         if (guid && !guidcmp(guid, protocol))
998                                 return 0;
999                 }
1000                 return -1;
1001         }
1002
1003         return -1;
1004 }
1005
1006 /*
1007  * Locate handles implementing a protocol.
1008  *
1009  * This function is meant for U-Boot internal calls. For the API implementation
1010  * of the LocateHandle service see efi_locate_handle_ext.
1011  *
1012  * @search_type         selection criterion
1013  * @protocol            GUID of the protocol
1014  * @search_key          registration key
1015  * @buffer_size         size of the buffer to receive the handles in bytes
1016  * @buffer              buffer to receive the relevant handles
1017  * @return              status code
1018  */
1019 static efi_status_t efi_locate_handle(
1020                         enum efi_locate_search_type search_type,
1021                         const efi_guid_t *protocol, void *search_key,
1022                         efi_uintn_t *buffer_size, efi_handle_t *buffer)
1023 {
1024         struct efi_object *efiobj;
1025         efi_uintn_t size = 0;
1026
1027         /* Check parameters */
1028         switch (search_type) {
1029         case ALL_HANDLES:
1030                 break;
1031         case BY_REGISTER_NOTIFY:
1032                 if (!search_key)
1033                         return EFI_INVALID_PARAMETER;
1034                 /* RegisterProtocolNotify is not implemented yet */
1035                 return EFI_UNSUPPORTED;
1036         case BY_PROTOCOL:
1037                 if (!protocol)
1038                         return EFI_INVALID_PARAMETER;
1039                 break;
1040         default:
1041                 return EFI_INVALID_PARAMETER;
1042         }
1043
1044         /*
1045          * efi_locate_handle_buffer uses this function for
1046          * the calculation of the necessary buffer size.
1047          * So do not require a buffer for buffersize == 0.
1048          */
1049         if (!buffer_size || (*buffer_size && !buffer))
1050                 return EFI_INVALID_PARAMETER;
1051
1052         /* Count how much space we need */
1053         list_for_each_entry(efiobj, &efi_obj_list, link) {
1054                 if (!efi_search(search_type, protocol, search_key, efiobj))
1055                         size += sizeof(void*);
1056         }
1057
1058         if (*buffer_size < size) {
1059                 *buffer_size = size;
1060                 return EFI_BUFFER_TOO_SMALL;
1061         }
1062
1063         *buffer_size = size;
1064         if (size == 0)
1065                 return EFI_NOT_FOUND;
1066
1067         /* Then fill the array */
1068         list_for_each_entry(efiobj, &efi_obj_list, link) {
1069                 if (!efi_search(search_type, protocol, search_key, efiobj))
1070                         *buffer++ = efiobj->handle;
1071         }
1072
1073         return EFI_SUCCESS;
1074 }
1075
1076 /*
1077  * Locate handles implementing a protocol.
1078  *
1079  * This function implements the LocateHandle service.
1080  * See the Unified Extensible Firmware Interface (UEFI) specification
1081  * for details.
1082  *
1083  * @search_type         selection criterion
1084  * @protocol            GUID of the protocol
1085  * @search_key          registration key
1086  * @buffer_size         size of the buffer to receive the handles in bytes
1087  * @buffer              buffer to receive the relevant handles
1088  * @return              0 if the handle implements the protocol
1089  */
1090 static efi_status_t EFIAPI efi_locate_handle_ext(
1091                         enum efi_locate_search_type search_type,
1092                         const efi_guid_t *protocol, void *search_key,
1093                         efi_uintn_t *buffer_size, efi_handle_t *buffer)
1094 {
1095         EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
1096                   buffer_size, buffer);
1097
1098         return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
1099                         buffer_size, buffer));
1100 }
1101
1102 /*
1103  * Get the device path and handle of an device implementing a protocol.
1104  *
1105  * This function implements the LocateDevicePath service.
1106  * See the Unified Extensible Firmware Interface (UEFI) specification
1107  * for details.
1108  *
1109  * @protocol            GUID of the protocol
1110  * @device_path         device path
1111  * @device              handle of the device
1112  * @return              status code
1113  */
1114 static efi_status_t EFIAPI efi_locate_device_path(
1115                         const efi_guid_t *protocol,
1116                         struct efi_device_path **device_path,
1117                         efi_handle_t *device)
1118 {
1119         struct efi_object *efiobj;
1120
1121         EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device);
1122
1123         efiobj = efi_dp_find_obj(*device_path, device_path);
1124         if (!efiobj)
1125                 return EFI_EXIT(EFI_NOT_FOUND);
1126
1127         *device = efiobj->handle;
1128
1129         return EFI_EXIT(EFI_SUCCESS);
1130 }
1131
1132 /* Collapses configuration table entries, removing index i */
1133 static void efi_remove_configuration_table(int i)
1134 {
1135         struct efi_configuration_table *this = &efi_conf_table[i];
1136         struct efi_configuration_table *next = &efi_conf_table[i+1];
1137         struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables];
1138
1139         memmove(this, next, (ulong)end - (ulong)next);
1140         systab.nr_tables--;
1141 }
1142
1143 /*
1144  * Adds, updates, or removes a configuration table.
1145  *
1146  * This function is used for internal calls. For the API implementation of the
1147  * InstallConfigurationTable service see efi_install_configuration_table_ext.
1148  *
1149  * @guid                GUID of the installed table
1150  * @table               table to be installed
1151  * @return              status code
1152  */
1153 efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
1154 {
1155         int i;
1156
1157         /* Check for guid override */
1158         for (i = 0; i < systab.nr_tables; i++) {
1159                 if (!guidcmp(guid, &efi_conf_table[i].guid)) {
1160                         if (table)
1161                                 efi_conf_table[i].table = table;
1162                         else
1163                                 efi_remove_configuration_table(i);
1164                         return EFI_SUCCESS;
1165                 }
1166         }
1167
1168         if (!table)
1169                 return EFI_NOT_FOUND;
1170
1171         /* No override, check for overflow */
1172         if (i >= ARRAY_SIZE(efi_conf_table))
1173                 return EFI_OUT_OF_RESOURCES;
1174
1175         /* Add a new entry */
1176         memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
1177         efi_conf_table[i].table = table;
1178         systab.nr_tables = i + 1;
1179
1180         return EFI_SUCCESS;
1181 }
1182
1183 /*
1184  * Adds, updates, or removes a configuration table.
1185  *
1186  * This function implements the InstallConfigurationTable service.
1187  * See the Unified Extensible Firmware Interface (UEFI) specification
1188  * for details.
1189  *
1190  * @guid                GUID of the installed table
1191  * @table               table to be installed
1192  * @return              status code
1193  */
1194 static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
1195                                                                void *table)
1196 {
1197         EFI_ENTRY("%pUl, %p", guid, table);
1198         return EFI_EXIT(efi_install_configuration_table(guid, table));
1199 }
1200
1201 /*
1202  * Initialize a loaded_image_info + loaded_image_info object with correct
1203  * protocols, boot-device, etc.
1204  *
1205  * @info                loaded image info to be passed to the entry point of the
1206  *                      image
1207  * @obj                 internal object associated with the loaded image
1208  * @device_path         device path of the loaded image
1209  * @file_path           file path of the loaded image
1210  */
1211 void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *obj,
1212                             struct efi_device_path *device_path,
1213                             struct efi_device_path *file_path)
1214 {
1215         obj->handle = info;
1216
1217         /*
1218          * When asking for the device path interface, return
1219          * bootefi_device_path
1220          */
1221         obj->protocols[0].guid = &efi_guid_device_path;
1222         obj->protocols[0].protocol_interface = device_path;
1223
1224         /*
1225          * When asking for the loaded_image interface, just
1226          * return handle which points to loaded_image_info
1227          */
1228         obj->protocols[1].guid = &efi_guid_loaded_image;
1229         obj->protocols[1].protocol_interface = info;
1230
1231         obj->protocols[2].guid = &efi_guid_console_control;
1232         obj->protocols[2].protocol_interface = (void *)&efi_console_control;
1233
1234         obj->protocols[3].guid = &efi_guid_device_path_to_text_protocol;
1235         obj->protocols[3].protocol_interface =
1236                 (void *)&efi_device_path_to_text;
1237
1238         info->file_path = file_path;
1239         if (device_path)
1240                 info->device_handle = efi_dp_find_obj(device_path, NULL);
1241
1242         list_add_tail(&obj->link, &efi_obj_list);
1243 }
1244
1245 /*
1246  * Load an image using a file path.
1247  *
1248  * @file_path           the path of the image to load
1249  * @buffer              buffer containing the loaded image
1250  * @return              status code
1251  */
1252 efi_status_t efi_load_image_from_path(struct efi_device_path *file_path,
1253                                       void **buffer)
1254 {
1255         struct efi_file_info *info = NULL;
1256         struct efi_file_handle *f;
1257         static efi_status_t ret;
1258         uint64_t bs;
1259
1260         f = efi_file_from_path(file_path);
1261         if (!f)
1262                 return EFI_DEVICE_ERROR;
1263
1264         bs = 0;
1265         EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1266                                   &bs, info));
1267         if (ret == EFI_BUFFER_TOO_SMALL) {
1268                 info = malloc(bs);
1269                 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1270                                           &bs, info));
1271         }
1272         if (ret != EFI_SUCCESS)
1273                 goto error;
1274
1275         ret = efi_allocate_pool(EFI_LOADER_DATA, info->file_size, buffer);
1276         if (ret)
1277                 goto error;
1278
1279         EFI_CALL(ret = f->read(f, &info->file_size, *buffer));
1280
1281 error:
1282         free(info);
1283         EFI_CALL(f->close(f));
1284
1285         if (ret != EFI_SUCCESS) {
1286                 efi_free_pool(*buffer);
1287                 *buffer = NULL;
1288         }
1289
1290         return ret;
1291 }
1292
1293 /*
1294  * Load an EFI image into memory.
1295  *
1296  * This function implements the LoadImage service.
1297  * See the Unified Extensible Firmware Interface (UEFI) specification
1298  * for details.
1299  *
1300  * @boot_policy         true for request originating from the boot manager
1301  * @parent_image        the calles's image handle
1302  * @file_path           the path of the image to load
1303  * @source_buffer       memory location from which the image is installed
1304  * @source_size         size of the memory area from which the image is
1305  *                      installed
1306  * @image_handle        handle for the newly installed image
1307  * @return              status code
1308  */
1309 static efi_status_t EFIAPI efi_load_image(bool boot_policy,
1310                                           efi_handle_t parent_image,
1311                                           struct efi_device_path *file_path,
1312                                           void *source_buffer,
1313                                           unsigned long source_size,
1314                                           efi_handle_t *image_handle)
1315 {
1316         struct efi_loaded_image *info;
1317         struct efi_object *obj;
1318
1319         EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
1320                   file_path, source_buffer, source_size, image_handle);
1321
1322         info = calloc(1, sizeof(*info));
1323         obj = calloc(1, sizeof(*obj));
1324
1325         if (!source_buffer) {
1326                 struct efi_device_path *dp, *fp;
1327                 efi_status_t ret;
1328
1329                 ret = efi_load_image_from_path(file_path, &source_buffer);
1330                 if (ret != EFI_SUCCESS) {
1331                         free(info);
1332                         free(obj);
1333                         return EFI_EXIT(ret);
1334                 }
1335
1336                 /*
1337                  * split file_path which contains both the device and
1338                  * file parts:
1339                  */
1340                 efi_dp_split_file_path(file_path, &dp, &fp);
1341
1342                 efi_setup_loaded_image(info, obj, dp, fp);
1343         } else {
1344                 /* In this case, file_path is the "device" path, ie.
1345                  * something like a HARDWARE_DEVICE:MEMORY_MAPPED
1346                  */
1347                 efi_setup_loaded_image(info, obj, file_path, NULL);
1348         }
1349
1350         info->reserved = efi_load_pe(source_buffer, info);
1351         if (!info->reserved) {
1352                 free(info);
1353                 free(obj);
1354                 return EFI_EXIT(EFI_UNSUPPORTED);
1355         }
1356
1357         info->system_table = &systab;
1358         info->parent_handle = parent_image;
1359         *image_handle = info;
1360
1361         return EFI_EXIT(EFI_SUCCESS);
1362 }
1363
1364 /*
1365  * Call the entry point of an image.
1366  *
1367  * This function implements the StartImage service.
1368  * See the Unified Extensible Firmware Interface (UEFI) specification
1369  * for details.
1370  *
1371  * @image_handle        handle of the image
1372  * @exit_data_size      size of the buffer
1373  * @exit_data           buffer to receive the exit data of the called image
1374  * @return              status code
1375  */
1376 static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
1377                                            unsigned long *exit_data_size,
1378                                            s16 **exit_data)
1379 {
1380         ulong (*entry)(void *image_handle, struct efi_system_table *st);
1381         struct efi_loaded_image *info = image_handle;
1382
1383         EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
1384         entry = info->reserved;
1385
1386         efi_is_direct_boot = false;
1387
1388         /* call the image! */
1389         if (setjmp(&info->exit_jmp)) {
1390                 /* We returned from the child image */
1391                 return EFI_EXIT(info->exit_status);
1392         }
1393
1394         __efi_nesting_dec();
1395         __efi_exit_check();
1396         entry(image_handle, &systab);
1397         __efi_entry_check();
1398         __efi_nesting_inc();
1399
1400         /* Should usually never get here */
1401         return EFI_EXIT(EFI_SUCCESS);
1402 }
1403
1404 /*
1405  * Leave an EFI application or driver.
1406  *
1407  * This function implements the Exit service.
1408  * See the Unified Extensible Firmware Interface (UEFI) specification
1409  * for details.
1410  *
1411  * @image_handle        handle of the application or driver that is exiting
1412  * @exit_status         status code
1413  * @exit_data_size      size of the buffer in bytes
1414  * @exit_data           buffer with data describing an error
1415  * @return              status code
1416  */
1417 static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
1418                         efi_status_t exit_status, unsigned long exit_data_size,
1419                         int16_t *exit_data)
1420 {
1421         struct efi_loaded_image *loaded_image_info = (void*)image_handle;
1422
1423         EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
1424                   exit_data_size, exit_data);
1425
1426         /* Make sure entry/exit counts for EFI world cross-overs match */
1427         __efi_exit_check();
1428
1429         /*
1430          * But longjmp out with the U-Boot gd, not the application's, as
1431          * the other end is a setjmp call inside EFI context.
1432          */
1433         efi_restore_gd();
1434
1435         loaded_image_info->exit_status = exit_status;
1436         longjmp(&loaded_image_info->exit_jmp, 1);
1437
1438         panic("EFI application exited");
1439 }
1440
1441 /*
1442  * Unload an EFI image.
1443  *
1444  * This function implements the UnloadImage service.
1445  * See the Unified Extensible Firmware Interface (UEFI) specification
1446  * for details.
1447  *
1448  * @image_handle        handle of the image to be unloaded
1449  * @return              status code
1450  */
1451 static efi_status_t EFIAPI efi_unload_image(void *image_handle)
1452 {
1453         struct efi_object *efiobj;
1454
1455         EFI_ENTRY("%p", image_handle);
1456         efiobj = efi_search_obj(image_handle);
1457         if (efiobj)
1458                 list_del(&efiobj->link);
1459
1460         return EFI_EXIT(EFI_SUCCESS);
1461 }
1462
1463 /*
1464  * Fix up caches for EFI payloads if necessary.
1465  */
1466 static void efi_exit_caches(void)
1467 {
1468 #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
1469         /*
1470          * Grub on 32bit ARM needs to have caches disabled before jumping into
1471          * a zImage, but does not know of all cache layers. Give it a hand.
1472          */
1473         if (efi_is_direct_boot)
1474                 cleanup_before_linux();
1475 #endif
1476 }
1477
1478 /*
1479  * Stop boot services.
1480  *
1481  * This function implements the ExitBootServices service.
1482  * See the Unified Extensible Firmware Interface (UEFI) specification
1483  * for details.
1484  *
1485  * @image_handle        handle of the loaded image
1486  * @map_key             key of the memory map
1487  * @return              status code
1488  */
1489 static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
1490                                                   unsigned long map_key)
1491 {
1492         int i;
1493
1494         EFI_ENTRY("%p, %ld", image_handle, map_key);
1495
1496         /* Notify that ExitBootServices is invoked. */
1497         for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
1498                 if (efi_events[i].type != EVT_SIGNAL_EXIT_BOOT_SERVICES)
1499                         continue;
1500                 efi_signal_event(&efi_events[i]);
1501         }
1502         /* Make sure that notification functions are not called anymore */
1503         efi_tpl = TPL_HIGH_LEVEL;
1504
1505         /* XXX Should persist EFI variables here */
1506
1507         board_quiesce_devices();
1508
1509         /* Fix up caches for EFI payloads if necessary */
1510         efi_exit_caches();
1511
1512         /* This stops all lingering devices */
1513         bootm_disable_interrupts();
1514
1515         /* Give the payload some time to boot */
1516         efi_set_watchdog(0);
1517         WATCHDOG_RESET();
1518
1519         return EFI_EXIT(EFI_SUCCESS);
1520 }
1521
1522 /*
1523  * Get next value of the counter.
1524  *
1525  * This function implements the NextMonotonicCount service.
1526  * See the Unified Extensible Firmware Interface (UEFI) specification
1527  * for details.
1528  *
1529  * @count       returned value of the counter
1530  * @return      status code
1531  */
1532 static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
1533 {
1534         static uint64_t mono = 0;
1535         EFI_ENTRY("%p", count);
1536         *count = mono++;
1537         return EFI_EXIT(EFI_SUCCESS);
1538 }
1539
1540 /*
1541  * Sleep.
1542  *
1543  * This function implements the Stall sercive.
1544  * See the Unified Extensible Firmware Interface (UEFI) specification
1545  * for details.
1546  *
1547  * @microseconds        period to sleep in microseconds
1548  * @return              status code
1549  */
1550 static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
1551 {
1552         EFI_ENTRY("%ld", microseconds);
1553         udelay(microseconds);
1554         return EFI_EXIT(EFI_SUCCESS);
1555 }
1556
1557 /*
1558  * Reset the watchdog timer.
1559  *
1560  * This function implements the SetWatchdogTimer service.
1561  * See the Unified Extensible Firmware Interface (UEFI) specification
1562  * for details.
1563  *
1564  * @timeout             seconds before reset by watchdog
1565  * @watchdog_code       code to be logged when resetting
1566  * @data_size           size of buffer in bytes
1567  * @watchdog_data       buffer with data describing the reset reason
1568  * @return              status code
1569  */
1570 static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
1571                                                   uint64_t watchdog_code,
1572                                                   unsigned long data_size,
1573                                                   uint16_t *watchdog_data)
1574 {
1575         EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
1576                   data_size, watchdog_data);
1577         return EFI_EXIT(efi_set_watchdog(timeout));
1578 }
1579
1580 /*
1581  * Connect a controller to a driver.
1582  *
1583  * This function implements the ConnectController service.
1584  * See the Unified Extensible Firmware Interface (UEFI) specification
1585  * for details.
1586  *
1587  * @controller_handle   handle of the controller
1588  * @driver_image_handle handle of the driver
1589  * @remain_device_path  device path of a child controller
1590  * @recursive           true to connect all child controllers
1591  * @return              status code
1592  */
1593 static efi_status_t EFIAPI efi_connect_controller(
1594                         efi_handle_t controller_handle,
1595                         efi_handle_t *driver_image_handle,
1596                         struct efi_device_path *remain_device_path,
1597                         bool recursive)
1598 {
1599         EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
1600                   remain_device_path, recursive);
1601         return EFI_EXIT(EFI_NOT_FOUND);
1602 }
1603
1604 /*
1605  * Disconnect a controller from a driver.
1606  *
1607  * This function implements the DisconnectController service.
1608  * See the Unified Extensible Firmware Interface (UEFI) specification
1609  * for details.
1610  *
1611  * @controller_handle   handle of the controller
1612  * @driver_image_handle handle of the driver
1613  * @child_handle        handle of the child to destroy
1614  * @return              status code
1615  */
1616 static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
1617                                                      void *driver_image_handle,
1618                                                      void *child_handle)
1619 {
1620         EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
1621                   child_handle);
1622         return EFI_EXIT(EFI_INVALID_PARAMETER);
1623 }
1624
1625 /*
1626  * Close a protocol.
1627  *
1628  * This function implements the CloseProtocol service.
1629  * See the Unified Extensible Firmware Interface (UEFI) specification
1630  * for details.
1631  *
1632  * @handle              handle on which the protocol shall be closed
1633  * @protocol            GUID of the protocol to close
1634  * @agent_handle        handle of the driver
1635  * @controller_handle   handle of the controller
1636  * @return              status code
1637  */
1638 static efi_status_t EFIAPI efi_close_protocol(void *handle,
1639                                               const efi_guid_t *protocol,
1640                                               void *agent_handle,
1641                                               void *controller_handle)
1642 {
1643         EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, agent_handle,
1644                   controller_handle);
1645         return EFI_EXIT(EFI_NOT_FOUND);
1646 }
1647
1648 /*
1649  * Provide information about then open status of a protocol on a handle
1650  *
1651  * This function implements the OpenProtocolInformation service.
1652  * See the Unified Extensible Firmware Interface (UEFI) specification
1653  * for details.
1654  *
1655  * @handle              handle for which the information shall be retrieved
1656  * @protocol            GUID of the protocol
1657  * @entry_buffer        buffer to receive the open protocol information
1658  * @entry_count         number of entries available in the buffer
1659  * @return              status code
1660  */
1661 static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
1662                         const efi_guid_t *protocol,
1663                         struct efi_open_protocol_info_entry **entry_buffer,
1664                         efi_uintn_t *entry_count)
1665 {
1666         EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, entry_buffer,
1667                   entry_count);
1668         return EFI_EXIT(EFI_NOT_FOUND);
1669 }
1670
1671 /*
1672  * Get protocols installed on a handle.
1673  *
1674  * This function implements the ProtocolsPerHandleService.
1675  * See the Unified Extensible Firmware Interface (UEFI) specification
1676  * for details.
1677  *
1678  * @handle                      handle for which the information is retrieved
1679  * @protocol_buffer             buffer with protocol GUIDs
1680  * @protocol_buffer_count       number of entries in the buffer
1681  * @return                      status code
1682  */
1683 static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
1684                         efi_guid_t ***protocol_buffer,
1685                         efi_uintn_t *protocol_buffer_count)
1686 {
1687         unsigned long buffer_size;
1688         struct efi_object *efiobj;
1689         unsigned long i, j;
1690         struct list_head *lhandle;
1691         efi_status_t r;
1692
1693         EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
1694                   protocol_buffer_count);
1695
1696         if (!handle || !protocol_buffer || !protocol_buffer_count)
1697                 return EFI_EXIT(EFI_INVALID_PARAMETER);
1698
1699         *protocol_buffer = NULL;
1700         *protocol_buffer_count = 0;
1701         list_for_each(lhandle, &efi_obj_list) {
1702                 efiobj = list_entry(lhandle, struct efi_object, link);
1703
1704                 if (efiobj->handle != handle)
1705                         continue;
1706
1707                 /* Count protocols */
1708                 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1709                         if (efiobj->protocols[i].guid)
1710                                 ++*protocol_buffer_count;
1711                 }
1712                 /* Copy guids */
1713                 if (*protocol_buffer_count) {
1714                         buffer_size = sizeof(efi_guid_t *) *
1715                                         *protocol_buffer_count;
1716                         r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
1717                                               buffer_size,
1718                                               (void **)protocol_buffer);
1719                         if (r != EFI_SUCCESS)
1720                                 return EFI_EXIT(r);
1721                         j = 0;
1722                         for (i = 0; i < ARRAY_SIZE(efiobj->protocols); ++i) {
1723                                 if (efiobj->protocols[i].guid) {
1724                                         (*protocol_buffer)[j] = (void *)
1725                                                 efiobj->protocols[i].guid;
1726                                         ++j;
1727                                 }
1728                         }
1729                 }
1730                 break;
1731         }
1732
1733         return EFI_EXIT(EFI_SUCCESS);
1734 }
1735
1736 /*
1737  * Locate handles implementing a protocol.
1738  *
1739  * This function implements the LocateHandleBuffer service.
1740  * See the Unified Extensible Firmware Interface (UEFI) specification
1741  * for details.
1742  *
1743  * @search_type         selection criterion
1744  * @protocol            GUID of the protocol
1745  * @search_key          registration key
1746  * @no_handles          number of returned handles
1747  * @buffer              buffer with the returned handles
1748  * @return              status code
1749  */
1750 static efi_status_t EFIAPI efi_locate_handle_buffer(
1751                         enum efi_locate_search_type search_type,
1752                         const efi_guid_t *protocol, void *search_key,
1753                         efi_uintn_t *no_handles, efi_handle_t **buffer)
1754 {
1755         efi_status_t r;
1756         efi_uintn_t buffer_size = 0;
1757
1758         EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
1759                   no_handles, buffer);
1760
1761         if (!no_handles || !buffer) {
1762                 r = EFI_INVALID_PARAMETER;
1763                 goto out;
1764         }
1765         *no_handles = 0;
1766         *buffer = NULL;
1767         r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
1768                               *buffer);
1769         if (r != EFI_BUFFER_TOO_SMALL)
1770                 goto out;
1771         r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
1772                               (void **)buffer);
1773         if (r != EFI_SUCCESS)
1774                 goto out;
1775         r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
1776                               *buffer);
1777         if (r == EFI_SUCCESS)
1778                 *no_handles = buffer_size / sizeof(void *);
1779 out:
1780         return EFI_EXIT(r);
1781 }
1782
1783 /*
1784  * Find an interface implementing a protocol.
1785  *
1786  * This function implements the LocateProtocol service.
1787  * See the Unified Extensible Firmware Interface (UEFI) specification
1788  * for details.
1789  *
1790  * @protocol            GUID of the protocol
1791  * @registration        registration key passed to the notification function
1792  * @protocol_interface  interface implementing the protocol
1793  * @return              status code
1794  */
1795 static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,
1796                                                void *registration,
1797                                                void **protocol_interface)
1798 {
1799         struct list_head *lhandle;
1800         int i;
1801
1802         EFI_ENTRY("%pUl, %p, %p", protocol, registration, protocol_interface);
1803
1804         if (!protocol || !protocol_interface)
1805                 return EFI_EXIT(EFI_INVALID_PARAMETER);
1806
1807         EFI_PRINT_GUID("protocol", protocol);
1808
1809         list_for_each(lhandle, &efi_obj_list) {
1810                 struct efi_object *efiobj;
1811
1812                 efiobj = list_entry(lhandle, struct efi_object, link);
1813                 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1814                         struct efi_handler *handler = &efiobj->protocols[i];
1815
1816                         if (!handler->guid)
1817                                 continue;
1818                         if (!guidcmp(handler->guid, protocol)) {
1819                                 *protocol_interface =
1820                                         handler->protocol_interface;
1821                                 return EFI_EXIT(EFI_SUCCESS);
1822                         }
1823                 }
1824         }
1825         *protocol_interface = NULL;
1826
1827         return EFI_EXIT(EFI_NOT_FOUND);
1828 }
1829
1830 /*
1831  * Install multiple protocol interfaces.
1832  *
1833  * This function implements the MultipleProtocolInterfaces service.
1834  * See the Unified Extensible Firmware Interface (UEFI) specification
1835  * for details.
1836  *
1837  * @handle      handle on which the protocol interfaces shall be installed
1838  * @...         NULL terminated argument list with pairs of protocol GUIDS and
1839  *              interfaces
1840  * @return      status code
1841  */
1842 static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
1843                         void **handle, ...)
1844 {
1845         EFI_ENTRY("%p", handle);
1846
1847         va_list argptr;
1848         const efi_guid_t *protocol;
1849         void *protocol_interface;
1850         efi_status_t r = EFI_SUCCESS;
1851         int i = 0;
1852
1853         if (!handle)
1854                 return EFI_EXIT(EFI_INVALID_PARAMETER);
1855
1856         va_start(argptr, handle);
1857         for (;;) {
1858                 protocol = va_arg(argptr, efi_guid_t*);
1859                 if (!protocol)
1860                         break;
1861                 protocol_interface = va_arg(argptr, void*);
1862                 r = EFI_CALL(efi_install_protocol_interface(
1863                                                 handle, protocol,
1864                                                 EFI_NATIVE_INTERFACE,
1865                                                 protocol_interface));
1866                 if (r != EFI_SUCCESS)
1867                         break;
1868                 i++;
1869         }
1870         va_end(argptr);
1871         if (r == EFI_SUCCESS)
1872                 return EFI_EXIT(r);
1873
1874         /* If an error occurred undo all changes. */
1875         va_start(argptr, handle);
1876         for (; i; --i) {
1877                 protocol = va_arg(argptr, efi_guid_t*);
1878                 protocol_interface = va_arg(argptr, void*);
1879                 EFI_CALL(efi_uninstall_protocol_interface(handle, protocol,
1880                                                           protocol_interface));
1881         }
1882         va_end(argptr);
1883
1884         return EFI_EXIT(r);
1885 }
1886
1887 /*
1888  * Uninstall multiple protocol interfaces.
1889  *
1890  * This function implements the UninstallMultipleProtocolInterfaces service.
1891  * See the Unified Extensible Firmware Interface (UEFI) specification
1892  * for details.
1893  *
1894  * @handle      handle from which the protocol interfaces shall be removed
1895  * @...         NULL terminated argument list with pairs of protocol GUIDS and
1896  *              interfaces
1897  * @return      status code
1898  */
1899 static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
1900                         void *handle, ...)
1901 {
1902         EFI_ENTRY("%p", handle);
1903
1904         va_list argptr;
1905         const efi_guid_t *protocol;
1906         void *protocol_interface;
1907         efi_status_t r = EFI_SUCCESS;
1908         size_t i = 0;
1909
1910         if (!handle)
1911                 return EFI_EXIT(EFI_INVALID_PARAMETER);
1912
1913         va_start(argptr, handle);
1914         for (;;) {
1915                 protocol = va_arg(argptr, efi_guid_t*);
1916                 if (!protocol)
1917                         break;
1918                 protocol_interface = va_arg(argptr, void*);
1919                 r = EFI_CALL(efi_uninstall_protocol_interface(
1920                                                 handle, protocol,
1921                                                 protocol_interface));
1922                 if (r != EFI_SUCCESS)
1923                         break;
1924                 i++;
1925         }
1926         va_end(argptr);
1927         if (r == EFI_SUCCESS)
1928                 return EFI_EXIT(r);
1929
1930         /* If an error occurred undo all changes. */
1931         va_start(argptr, handle);
1932         for (; i; --i) {
1933                 protocol = va_arg(argptr, efi_guid_t*);
1934                 protocol_interface = va_arg(argptr, void*);
1935                 EFI_CALL(efi_install_protocol_interface(&handle, protocol,
1936                                                         EFI_NATIVE_INTERFACE,
1937                                                         protocol_interface));
1938         }
1939         va_end(argptr);
1940
1941         return EFI_EXIT(r);
1942 }
1943
1944 /*
1945  * Calculate cyclic redundancy code.
1946  *
1947  * This function implements the CalculateCrc32 service.
1948  * See the Unified Extensible Firmware Interface (UEFI) specification
1949  * for details.
1950  *
1951  * @data        buffer with data
1952  * @data_size   size of buffer in bytes
1953  * @crc32_p     cyclic redundancy code
1954  * @return      status code
1955  */
1956 static efi_status_t EFIAPI efi_calculate_crc32(void *data,
1957                                                unsigned long data_size,
1958                                                uint32_t *crc32_p)
1959 {
1960         EFI_ENTRY("%p, %ld", data, data_size);
1961         *crc32_p = crc32(0, data, data_size);
1962         return EFI_EXIT(EFI_SUCCESS);
1963 }
1964
1965 /*
1966  * Copy memory.
1967  *
1968  * This function implements the CopyMem service.
1969  * See the Unified Extensible Firmware Interface (UEFI) specification
1970  * for details.
1971  *
1972  * @destination         destination of the copy operation
1973  * @source              source of the copy operation
1974  * @length              number of bytes to copy
1975  */
1976 static void EFIAPI efi_copy_mem(void *destination, const void *source,
1977                                 size_t length)
1978 {
1979         EFI_ENTRY("%p, %p, %ld", destination, source, (unsigned long)length);
1980         memcpy(destination, source, length);
1981         EFI_EXIT(EFI_SUCCESS);
1982 }
1983
1984 /*
1985  * Fill memory with a byte value.
1986  *
1987  * This function implements the SetMem service.
1988  * See the Unified Extensible Firmware Interface (UEFI) specification
1989  * for details.
1990  *
1991  * @buffer              buffer to fill
1992  * @size                size of buffer in bytes
1993  * @value               byte to copy to the buffer
1994  */
1995 static void EFIAPI efi_set_mem(void *buffer, size_t size, uint8_t value)
1996 {
1997         EFI_ENTRY("%p, %ld, 0x%x", buffer, (unsigned long)size, value);
1998         memset(buffer, value, size);
1999         EFI_EXIT(EFI_SUCCESS);
2000 }
2001
2002 /*
2003  * Open protocol interface on a handle.
2004  *
2005  * This function implements the OpenProtocol interface.
2006  * See the Unified Extensible Firmware Interface (UEFI) specification
2007  * for details.
2008  *
2009  * @handle              handle on which the protocol shall be opened
2010  * @protocol            GUID of the protocol
2011  * @protocol_interface  interface implementing the protocol
2012  * @agent_handle        handle of the driver
2013  * @controller_handle   handle of the controller
2014  * @attributes          attributes indicating how to open the protocol
2015  * @return              status code
2016  */
2017 static efi_status_t EFIAPI efi_open_protocol(
2018                         void *handle, const efi_guid_t *protocol,
2019                         void **protocol_interface, void *agent_handle,
2020                         void *controller_handle, uint32_t attributes)
2021 {
2022         struct list_head *lhandle;
2023         int i;
2024         efi_status_t r = EFI_INVALID_PARAMETER;
2025
2026         EFI_ENTRY("%p, %pUl, %p, %p, %p, 0x%x", handle, protocol,
2027                   protocol_interface, agent_handle, controller_handle,
2028                   attributes);
2029
2030         if (!handle || !protocol ||
2031             (!protocol_interface && attributes !=
2032              EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
2033                 goto out;
2034         }
2035
2036         EFI_PRINT_GUID("protocol", protocol);
2037
2038         switch (attributes) {
2039         case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
2040         case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
2041         case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
2042                 break;
2043         case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
2044                 if (controller_handle == handle)
2045                         goto out;
2046         case EFI_OPEN_PROTOCOL_BY_DRIVER:
2047         case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
2048                 if (controller_handle == NULL)
2049                         goto out;
2050         case EFI_OPEN_PROTOCOL_EXCLUSIVE:
2051                 if (agent_handle == NULL)
2052                         goto out;
2053                 break;
2054         default:
2055                 goto out;
2056         }
2057
2058         list_for_each(lhandle, &efi_obj_list) {
2059                 struct efi_object *efiobj;
2060                 efiobj = list_entry(lhandle, struct efi_object, link);
2061
2062                 if (efiobj->handle != handle)
2063                         continue;
2064
2065                 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
2066                         struct efi_handler *handler = &efiobj->protocols[i];
2067                         const efi_guid_t *hprotocol = handler->guid;
2068                         if (!hprotocol)
2069                                 continue;
2070                         if (!guidcmp(hprotocol, protocol)) {
2071                                 if (attributes !=
2072                                     EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
2073                                         *protocol_interface =
2074                                                 handler->protocol_interface;
2075                                 }
2076                                 r = EFI_SUCCESS;
2077                                 goto out;
2078                         }
2079                 }
2080                 goto unsupported;
2081         }
2082
2083 unsupported:
2084         r = EFI_UNSUPPORTED;
2085 out:
2086         return EFI_EXIT(r);
2087 }
2088
2089 /*
2090  * Get interface of a protocol on a handle.
2091  *
2092  * This function implements the HandleProtocol service.
2093  * See the Unified Extensible Firmware Interface (UEFI) specification
2094  * for details.
2095  *
2096  * @handle              handle on which the protocol shall be opened
2097  * @protocol            GUID of the protocol
2098  * @protocol_interface  interface implementing the protocol
2099  * @return              status code
2100  */
2101 static efi_status_t EFIAPI efi_handle_protocol(void *handle,
2102                                                const efi_guid_t *protocol,
2103                                                void **protocol_interface)
2104 {
2105         return efi_open_protocol(handle, protocol, protocol_interface, NULL,
2106                                  NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
2107 }
2108
2109 static const struct efi_boot_services efi_boot_services = {
2110         .hdr = {
2111                 .headersize = sizeof(struct efi_table_hdr),
2112         },
2113         .raise_tpl = efi_raise_tpl,
2114         .restore_tpl = efi_restore_tpl,
2115         .allocate_pages = efi_allocate_pages_ext,
2116         .free_pages = efi_free_pages_ext,
2117         .get_memory_map = efi_get_memory_map_ext,
2118         .allocate_pool = efi_allocate_pool_ext,
2119         .free_pool = efi_free_pool_ext,
2120         .create_event = efi_create_event_ext,
2121         .set_timer = efi_set_timer_ext,
2122         .wait_for_event = efi_wait_for_event,
2123         .signal_event = efi_signal_event_ext,
2124         .close_event = efi_close_event,
2125         .check_event = efi_check_event,
2126         .install_protocol_interface = efi_install_protocol_interface,
2127         .reinstall_protocol_interface = efi_reinstall_protocol_interface,
2128         .uninstall_protocol_interface = efi_uninstall_protocol_interface,
2129         .handle_protocol = efi_handle_protocol,
2130         .reserved = NULL,
2131         .register_protocol_notify = efi_register_protocol_notify,
2132         .locate_handle = efi_locate_handle_ext,
2133         .locate_device_path = efi_locate_device_path,
2134         .install_configuration_table = efi_install_configuration_table_ext,
2135         .load_image = efi_load_image,
2136         .start_image = efi_start_image,
2137         .exit = efi_exit,
2138         .unload_image = efi_unload_image,
2139         .exit_boot_services = efi_exit_boot_services,
2140         .get_next_monotonic_count = efi_get_next_monotonic_count,
2141         .stall = efi_stall,
2142         .set_watchdog_timer = efi_set_watchdog_timer,
2143         .connect_controller = efi_connect_controller,
2144         .disconnect_controller = efi_disconnect_controller,
2145         .open_protocol = efi_open_protocol,
2146         .close_protocol = efi_close_protocol,
2147         .open_protocol_information = efi_open_protocol_information,
2148         .protocols_per_handle = efi_protocols_per_handle,
2149         .locate_handle_buffer = efi_locate_handle_buffer,
2150         .locate_protocol = efi_locate_protocol,
2151         .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
2152         .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
2153         .calculate_crc32 = efi_calculate_crc32,
2154         .copy_mem = efi_copy_mem,
2155         .set_mem = efi_set_mem,
2156 };
2157
2158
2159 static uint16_t __efi_runtime_data firmware_vendor[] =
2160         { 'D','a','s',' ','U','-','b','o','o','t',0 };
2161
2162 struct efi_system_table __efi_runtime_data systab = {
2163         .hdr = {
2164                 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
2165                 .revision = 0x20005, /* 2.5 */
2166                 .headersize = sizeof(struct efi_table_hdr),
2167         },
2168         .fw_vendor = (long)firmware_vendor,
2169         .con_in = (void*)&efi_con_in,
2170         .con_out = (void*)&efi_con_out,
2171         .std_err = (void*)&efi_con_out,
2172         .runtime = (void*)&efi_runtime_services,
2173         .boottime = (void*)&efi_boot_services,
2174         .nr_tables = 0,
2175         .tables = (void*)efi_conf_table,
2176 };