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