blob: 673c66a4aa367d17387aa6b99a85e1afcd07d133 [file] [log] [blame]
Alexander Grafc15d9212016-03-04 01:09:59 +01001/*
2 * EFI application boot time services
3 *
4 * Copyright (c) 2016 Alexander Graf
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
Alexander Grafc15d9212016-03-04 01:09:59 +01009#include <common.h>
Heinrich Schuchardt368ca642017-10-05 16:14:14 +020010#include <div64.h>
Alexander Grafc15d9212016-03-04 01:09:59 +010011#include <efi_loader.h>
Rob Clark15f3d742017-09-13 18:05:37 -040012#include <environment.h>
Alexander Grafc15d9212016-03-04 01:09:59 +010013#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
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +020023/* Task priority level */
Heinrich Schuchardtf8d4ec32017-11-06 21:17:47 +010024static efi_uintn_t efi_tpl = TPL_APPLICATION;
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +020025
Alexander Grafc15d9212016-03-04 01:09:59 +010026/* 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 */
Alexander Graf393dd912016-10-14 13:45:30 +020045static struct efi_configuration_table __efi_runtime_data efi_conf_table[2];
Alexander Grafc15d9212016-03-04 01:09:59 +010046
Simon Glasscdfe6962016-09-25 15:27:35 -060047#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +010048/*
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;
Simon Glasscdfe6962016-09-25 15:27:35 -060055#endif
Alexander Grafc15d9212016-03-04 01:09:59 +010056
Rob Clark86789d52017-07-27 08:04:18 -040057static int entry_count;
Rob Clarke7896c32017-07-27 08:04:19 -040058static int nesting_level;
Rob Clark86789d52017-07-27 08:04:18 -040059
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
Alexander Grafc15d9212016-03-04 01:09:59 +010082/* Called from do_bootefi_exec() */
83void efi_save_gd(void)
84{
Simon Glasscdfe6962016-09-25 15:27:35 -060085#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +010086 efi_gd = gd;
Simon Glasscdfe6962016-09-25 15:27:35 -060087#endif
Alexander Grafc15d9212016-03-04 01:09:59 +010088}
89
Rob Clark86789d52017-07-27 08:04:18 -040090/*
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 */
Alexander Grafc15d9212016-03-04 01:09:59 +010095void efi_restore_gd(void)
96{
Simon Glasscdfe6962016-09-25 15:27:35 -060097#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +010098 /* Only restore if we're already in EFI context */
99 if (!efi_gd)
100 return;
Alexander Grafc15d9212016-03-04 01:09:59 +0100101 gd = efi_gd;
Simon Glasscdfe6962016-09-25 15:27:35 -0600102#endif
Alexander Grafc15d9212016-03-04 01:09:59 +0100103}
104
Rob Clarke7896c32017-07-27 08:04:19 -0400105/*
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
Heinrich Schuchardt4d664892017-08-18 17:45:16 +0200117const char *__efi_nesting(void)
118{
119 return indent_string(nesting_level);
120}
121
Rob Clarke7896c32017-07-27 08:04:19 -0400122const 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
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200132/*
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 */
xypron.glpk@gmx.de54c7a8e2017-07-18 20:17:22 +0200145void efi_signal_event(struct efi_event *event)
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200146{
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200147 if (event->notify_function) {
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200148 event->is_queued = true;
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200149 /* Check TPL */
150 if (efi_tpl >= event->notify_tpl)
151 return;
Heinrich Schuchardt91e5b8a2017-09-15 10:06:10 +0200152 EFI_CALL_VOID(event->notify_function(event,
153 event->notify_context));
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200154 }
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200155 event->is_queued = false;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200156}
157
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200158/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200159 * 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 */
Heinrich Schuchardtf8d4ec32017-11-06 21:17:47 +0100168static unsigned long EFIAPI efi_raise_tpl(efi_uintn_t new_tpl)
Alexander Grafc15d9212016-03-04 01:09:59 +0100169{
Heinrich Schuchardtf8d4ec32017-11-06 21:17:47 +0100170 efi_uintn_t old_tpl = efi_tpl;
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200171
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200172 EFI_ENTRY("0x%zx", new_tpl);
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200173
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;
Alexander Grafc15d9212016-03-04 01:09:59 +0100182}
183
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200184/*
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 */
Heinrich Schuchardtf8d4ec32017-11-06 21:17:47 +0100193static void EFIAPI efi_restore_tpl(efi_uintn_t old_tpl)
Alexander Grafc15d9212016-03-04 01:09:59 +0100194{
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200195 EFI_ENTRY("0x%zx", old_tpl);
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200196
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);
Alexander Grafc15d9212016-03-04 01:09:59 +0100204}
205
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200206/*
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 */
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900219static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100220 efi_uintn_t pages,
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900221 uint64_t *memory)
Alexander Grafc15d9212016-03-04 01:09:59 +0100222{
223 efi_status_t r;
224
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100225 EFI_ENTRY("%d, %d, 0x%zx, %p", type, memory_type, pages, memory);
Alexander Grafc15d9212016-03-04 01:09:59 +0100226 r = efi_allocate_pages(type, memory_type, pages, memory);
227 return EFI_EXIT(r);
228}
229
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200230/*
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 */
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900241static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100242 efi_uintn_t pages)
Alexander Grafc15d9212016-03-04 01:09:59 +0100243{
244 efi_status_t r;
245
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100246 EFI_ENTRY("%"PRIx64", 0x%zx", memory, pages);
Alexander Grafc15d9212016-03-04 01:09:59 +0100247 r = efi_free_pages(memory, pages);
248 return EFI_EXIT(r);
249}
250
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200251/*
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 */
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900266static efi_status_t EFIAPI efi_get_memory_map_ext(
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100267 efi_uintn_t *memory_map_size,
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900268 struct efi_mem_desc *memory_map,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100269 efi_uintn_t *map_key,
270 efi_uintn_t *descriptor_size,
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900271 uint32_t *descriptor_version)
Alexander Grafc15d9212016-03-04 01:09:59 +0100272{
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
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200282/*
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 */
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200294static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100295 efi_uintn_t size,
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200296 void **buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +0100297{
Alexander Graf1c34fa82016-03-24 01:37:37 +0100298 efi_status_t r;
299
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100300 EFI_ENTRY("%d, %zd, %p", pool_type, size, buffer);
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200301 r = efi_allocate_pool(pool_type, size, buffer);
Alexander Graf1c34fa82016-03-24 01:37:37 +0100302 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100303}
304
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200305/*
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 */
Stefan Brüns67b67d92016-10-09 22:17:26 +0200315static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +0100316{
Alexander Graf1c34fa82016-03-24 01:37:37 +0100317 efi_status_t r;
318
319 EFI_ENTRY("%p", buffer);
Stefan Brüns67b67d92016-10-09 22:17:26 +0200320 r = efi_free_pool(buffer);
Alexander Graf1c34fa82016-03-24 01:37:37 +0100321 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100322}
323
Heinrich Schuchardteb6106e2017-10-26 19:25:49 +0200324/*
Heinrich Schuchardt967d7de2017-11-26 14:05:23 +0100325 * Add a new object to the object list.
326 *
327 * The protocols list is initialized.
328 * The object handle is set.
329 *
330 * @obj object to be added
331 */
332void efi_add_handle(struct efi_object *obj)
333{
334 if (!obj)
335 return;
336 INIT_LIST_HEAD(&obj->protocols);
337 obj->handle = obj;
338 list_add_tail(&obj->link, &efi_obj_list);
339}
340
341/*
Heinrich Schuchardteb6106e2017-10-26 19:25:49 +0200342 * Create handle.
343 *
344 * @handle new handle
345 * @return status code
346 */
347efi_status_t efi_create_handle(void **handle)
Heinrich Schuchardtcd522cb2017-08-27 00:51:09 +0200348{
349 struct efi_object *obj;
350 efi_status_t r;
351
352 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
353 sizeof(struct efi_object),
354 (void **)&obj);
355 if (r != EFI_SUCCESS)
356 return r;
Heinrich Schuchardt967d7de2017-11-26 14:05:23 +0100357 efi_add_handle(obj);
358 *handle = obj->handle;
Heinrich Schuchardtcd522cb2017-08-27 00:51:09 +0200359 return r;
360}
361
Alexander Grafc15d9212016-03-04 01:09:59 +0100362/*
Heinrich Schuchardt7d135462017-12-04 18:03:02 +0100363 * Find a protocol on a handle.
364 *
365 * @handle handle
366 * @protocol_guid GUID of the protocol
367 * @handler reference to the protocol
368 * @return status code
369 */
370efi_status_t efi_search_protocol(const void *handle,
371 const efi_guid_t *protocol_guid,
372 struct efi_handler **handler)
373{
374 struct efi_object *efiobj;
375 struct list_head *lhandle;
376
377 if (!handle || !protocol_guid)
378 return EFI_INVALID_PARAMETER;
379 efiobj = efi_search_obj(handle);
380 if (!efiobj)
381 return EFI_INVALID_PARAMETER;
382 list_for_each(lhandle, &efiobj->protocols) {
383 struct efi_handler *protocol;
384
385 protocol = list_entry(lhandle, struct efi_handler, link);
386 if (!guidcmp(protocol->guid, protocol_guid)) {
387 if (handler)
388 *handler = protocol;
389 return EFI_SUCCESS;
390 }
391 }
392 return EFI_NOT_FOUND;
393}
394
395/*
396 * Delete protocol from a handle.
397 *
398 * @handle handle from which the protocol shall be deleted
399 * @protocol GUID of the protocol to be deleted
400 * @protocol_interface interface of the protocol implementation
401 * @return status code
402 */
403efi_status_t efi_remove_protocol(const void *handle, const efi_guid_t *protocol,
404 void *protocol_interface)
405{
406 struct efi_handler *handler;
407 efi_status_t ret;
408
409 ret = efi_search_protocol(handle, protocol, &handler);
410 if (ret != EFI_SUCCESS)
411 return ret;
412 if (guidcmp(handler->guid, protocol))
413 return EFI_INVALID_PARAMETER;
414 list_del(&handler->link);
415 free(handler);
416 return EFI_SUCCESS;
417}
418
419/*
420 * Delete all protocols from a handle.
421 *
422 * @handle handle from which the protocols shall be deleted
423 * @return status code
424 */
425efi_status_t efi_remove_all_protocols(const void *handle)
426{
427 struct efi_object *efiobj;
Heinrich Schuchardta84731d2018-01-11 08:15:55 +0100428 struct efi_handler *protocol;
429 struct efi_handler *pos;
Heinrich Schuchardt7d135462017-12-04 18:03:02 +0100430
431 efiobj = efi_search_obj(handle);
432 if (!efiobj)
433 return EFI_INVALID_PARAMETER;
Heinrich Schuchardta84731d2018-01-11 08:15:55 +0100434 list_for_each_entry_safe(protocol, pos, &efiobj->protocols, link) {
Heinrich Schuchardt7d135462017-12-04 18:03:02 +0100435 efi_status_t ret;
436
Heinrich Schuchardt7d135462017-12-04 18:03:02 +0100437 ret = efi_remove_protocol(handle, protocol->guid,
438 protocol->protocol_interface);
439 if (ret != EFI_SUCCESS)
440 return ret;
441 }
442 return EFI_SUCCESS;
443}
444
445/*
446 * Delete handle.
447 *
448 * @handle handle to delete
449 */
450void efi_delete_handle(struct efi_object *obj)
451{
452 if (!obj)
453 return;
454 efi_remove_all_protocols(obj->handle);
455 list_del(&obj->link);
456 free(obj);
457}
458
459/*
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200460 * Our event capabilities are very limited. Only a small limited
461 * number of events is allowed to coexist.
Alexander Grafc15d9212016-03-04 01:09:59 +0100462 */
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200463static struct efi_event efi_events[16];
Alexander Grafc15d9212016-03-04 01:09:59 +0100464
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200465/*
466 * Create an event.
467 *
468 * This function is used inside U-Boot code to create an event.
469 *
470 * For the API function implementing the CreateEvent service see
471 * efi_create_event_ext.
472 *
473 * @type type of the event to create
474 * @notify_tpl task priority level of the event
475 * @notify_function notification function of the event
476 * @notify_context pointer passed to the notification function
477 * @event created event
478 * @return status code
479 */
Heinrich Schuchardtf8d4ec32017-11-06 21:17:47 +0100480efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl,
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200481 void (EFIAPI *notify_function) (
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200482 struct efi_event *event,
483 void *context),
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200484 void *notify_context, struct efi_event **event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100485{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200486 int i;
487
Jonathan Gray7758b212017-03-12 19:26:07 +1100488 if (event == NULL)
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200489 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100490
491 if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200492 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100493
494 if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
495 notify_function == NULL)
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200496 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100497
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200498 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
499 if (efi_events[i].type)
500 continue;
501 efi_events[i].type = type;
502 efi_events[i].notify_tpl = notify_tpl;
503 efi_events[i].notify_function = notify_function;
504 efi_events[i].notify_context = notify_context;
505 /* Disable timers on bootup */
506 efi_events[i].trigger_next = -1ULL;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200507 efi_events[i].is_queued = false;
508 efi_events[i].is_signaled = false;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200509 *event = &efi_events[i];
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200510 return EFI_SUCCESS;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200511 }
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200512 return EFI_OUT_OF_RESOURCES;
Alexander Grafc15d9212016-03-04 01:09:59 +0100513}
514
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200515/*
516 * Create an event.
517 *
518 * This function implements the CreateEvent service.
519 * See the Unified Extensible Firmware Interface (UEFI) specification
520 * for details.
521 *
522 * @type type of the event to create
523 * @notify_tpl task priority level of the event
524 * @notify_function notification function of the event
525 * @notify_context pointer passed to the notification function
526 * @event created event
527 * @return status code
528 */
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200529static efi_status_t EFIAPI efi_create_event_ext(
Heinrich Schuchardtf8d4ec32017-11-06 21:17:47 +0100530 uint32_t type, efi_uintn_t notify_tpl,
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200531 void (EFIAPI *notify_function) (
532 struct efi_event *event,
533 void *context),
534 void *notify_context, struct efi_event **event)
535{
536 EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
537 notify_context);
538 return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
539 notify_context, event));
540}
541
542
Alexander Grafc15d9212016-03-04 01:09:59 +0100543/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200544 * Check if a timer event has occurred or a queued notification function should
545 * be called.
546 *
Alexander Grafc15d9212016-03-04 01:09:59 +0100547 * Our timers have to work without interrupts, so we check whenever keyboard
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200548 * input or disk accesses happen if enough time elapsed for them to fire.
Alexander Grafc15d9212016-03-04 01:09:59 +0100549 */
550void efi_timer_check(void)
551{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200552 int i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100553 u64 now = timer_get_us();
554
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200555 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200556 if (!efi_events[i].type)
557 continue;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200558 if (efi_events[i].is_queued)
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200559 efi_signal_event(&efi_events[i]);
560 if (!(efi_events[i].type & EVT_TIMER) ||
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200561 now < efi_events[i].trigger_next)
562 continue;
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200563 switch (efi_events[i].trigger_type) {
564 case EFI_TIMER_RELATIVE:
565 efi_events[i].trigger_type = EFI_TIMER_STOP;
566 break;
567 case EFI_TIMER_PERIODIC:
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200568 efi_events[i].trigger_next +=
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200569 efi_events[i].trigger_time;
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200570 break;
571 default:
572 continue;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200573 }
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200574 efi_events[i].is_signaled = true;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200575 efi_signal_event(&efi_events[i]);
Alexander Grafc15d9212016-03-04 01:09:59 +0100576 }
Alexander Grafc15d9212016-03-04 01:09:59 +0100577 WATCHDOG_RESET();
578}
579
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200580/*
581 * Set the trigger time for a timer event or stop the event.
582 *
583 * This is the function for internal usage in U-Boot. For the API function
584 * implementing the SetTimer service see efi_set_timer_ext.
585 *
586 * @event event for which the timer is set
587 * @type type of the timer
588 * @trigger_time trigger period in multiples of 100ns
589 * @return status code
590 */
xypron.glpk@gmx.de3ecc6bd2017-07-19 19:22:34 +0200591efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200592 uint64_t trigger_time)
Alexander Grafc15d9212016-03-04 01:09:59 +0100593{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200594 int i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100595
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200596 /*
597 * The parameter defines a multiple of 100ns.
598 * We use multiples of 1000ns. So divide by 10.
599 */
Heinrich Schuchardt368ca642017-10-05 16:14:14 +0200600 do_div(trigger_time, 10);
Alexander Grafc15d9212016-03-04 01:09:59 +0100601
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200602 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
603 if (event != &efi_events[i])
604 continue;
Alexander Grafc15d9212016-03-04 01:09:59 +0100605
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200606 if (!(event->type & EVT_TIMER))
607 break;
608 switch (type) {
609 case EFI_TIMER_STOP:
610 event->trigger_next = -1ULL;
611 break;
612 case EFI_TIMER_PERIODIC:
613 case EFI_TIMER_RELATIVE:
614 event->trigger_next =
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200615 timer_get_us() + trigger_time;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200616 break;
617 default:
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200618 return EFI_INVALID_PARAMETER;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200619 }
620 event->trigger_type = type;
621 event->trigger_time = trigger_time;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200622 event->is_signaled = false;
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200623 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +0100624 }
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200625 return EFI_INVALID_PARAMETER;
Alexander Grafc15d9212016-03-04 01:09:59 +0100626}
627
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200628/*
629 * Set the trigger time for a timer event or stop the event.
630 *
631 * This function implements the SetTimer service.
632 * See the Unified Extensible Firmware Interface (UEFI) specification
633 * for details.
634 *
635 * @event event for which the timer is set
636 * @type type of the timer
637 * @trigger_time trigger period in multiples of 100ns
638 * @return status code
639 */
xypron.glpk@gmx.de3ecc6bd2017-07-19 19:22:34 +0200640static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event,
641 enum efi_timer_delay type,
642 uint64_t trigger_time)
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200643{
644 EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
645 return EFI_EXIT(efi_set_timer(event, type, trigger_time));
646}
647
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200648/*
649 * Wait for events to be signaled.
650 *
651 * This function implements the WaitForEvent service.
652 * See the Unified Extensible Firmware Interface (UEFI) specification
653 * for details.
654 *
655 * @num_events number of events to be waited for
656 * @events events to be waited for
657 * @index index of the event that was signaled
658 * @return status code
659 */
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100660static efi_status_t EFIAPI efi_wait_for_event(efi_uintn_t num_events,
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200661 struct efi_event **event,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100662 efi_uintn_t *index)
Alexander Grafc15d9212016-03-04 01:09:59 +0100663{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200664 int i, j;
Alexander Grafc15d9212016-03-04 01:09:59 +0100665
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100666 EFI_ENTRY("%zd, %p, %p", num_events, event, index);
Alexander Grafc15d9212016-03-04 01:09:59 +0100667
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200668 /* Check parameters */
669 if (!num_events || !event)
670 return EFI_EXIT(EFI_INVALID_PARAMETER);
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200671 /* Check TPL */
672 if (efi_tpl != TPL_APPLICATION)
673 return EFI_EXIT(EFI_UNSUPPORTED);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200674 for (i = 0; i < num_events; ++i) {
675 for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
676 if (event[i] == &efi_events[j])
677 goto known_event;
678 }
679 return EFI_EXIT(EFI_INVALID_PARAMETER);
680known_event:
681 if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
682 return EFI_EXIT(EFI_INVALID_PARAMETER);
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200683 if (!event[i]->is_signaled)
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200684 efi_signal_event(event[i]);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200685 }
686
687 /* Wait for signal */
688 for (;;) {
689 for (i = 0; i < num_events; ++i) {
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200690 if (event[i]->is_signaled)
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200691 goto out;
692 }
693 /* Allow events to occur. */
694 efi_timer_check();
695 }
696
697out:
698 /*
699 * Reset the signal which is passed to the caller to allow periodic
700 * events to occur.
701 */
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200702 event[i]->is_signaled = false;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200703 if (index)
704 *index = i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100705
706 return EFI_EXIT(EFI_SUCCESS);
707}
708
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200709/*
710 * Signal an EFI event.
711 *
712 * This function implements the SignalEvent service.
713 * See the Unified Extensible Firmware Interface (UEFI) specification
714 * for details.
715 *
716 * This functions sets the signaled state of the event and queues the
717 * notification function for execution.
718 *
719 * @event event to signal
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +0200720 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200721 */
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200722static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100723{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200724 int i;
725
Alexander Grafc15d9212016-03-04 01:09:59 +0100726 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200727 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
728 if (event != &efi_events[i])
729 continue;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200730 if (event->is_signaled)
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200731 break;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200732 event->is_signaled = true;
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200733 if (event->type & EVT_NOTIFY_SIGNAL)
734 efi_signal_event(event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200735 break;
736 }
Alexander Grafc15d9212016-03-04 01:09:59 +0100737 return EFI_EXIT(EFI_SUCCESS);
738}
739
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200740/*
741 * Close an EFI event.
742 *
743 * This function implements the CloseEvent service.
744 * See the Unified Extensible Firmware Interface (UEFI) specification
745 * for details.
746 *
747 * @event event to close
748 * @return status code
749 */
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200750static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100751{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200752 int i;
753
Alexander Grafc15d9212016-03-04 01:09:59 +0100754 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200755 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
756 if (event == &efi_events[i]) {
757 event->type = 0;
758 event->trigger_next = -1ULL;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200759 event->is_queued = false;
760 event->is_signaled = false;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200761 return EFI_EXIT(EFI_SUCCESS);
762 }
763 }
764 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafc15d9212016-03-04 01:09:59 +0100765}
766
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200767/*
768 * Check if an event is signaled.
769 *
770 * This function implements the CheckEvent service.
771 * See the Unified Extensible Firmware Interface (UEFI) specification
772 * for details.
773 *
774 * If an event is not signaled yet the notification function is queued.
775 *
776 * @event event to check
777 * @return status code
778 */
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200779static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100780{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200781 int i;
782
Alexander Grafc15d9212016-03-04 01:09:59 +0100783 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200784 efi_timer_check();
785 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
786 if (event != &efi_events[i])
787 continue;
788 if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
789 break;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200790 if (!event->is_signaled)
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200791 efi_signal_event(event);
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200792 if (event->is_signaled)
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200793 return EFI_EXIT(EFI_SUCCESS);
794 return EFI_EXIT(EFI_NOT_READY);
795 }
796 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafc15d9212016-03-04 01:09:59 +0100797}
798
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200799/*
Heinrich Schuchardt37ebcba2017-10-18 18:13:03 +0200800 * Find the internal EFI object for a handle.
801 *
802 * @handle handle to find
803 * @return EFI object
804 */
Heinrich Schuchardt1cdca3f2017-10-26 19:25:50 +0200805struct efi_object *efi_search_obj(const void *handle)
Heinrich Schuchardt37ebcba2017-10-18 18:13:03 +0200806{
Heinrich Schuchardt274cc872017-11-06 21:17:50 +0100807 struct efi_object *efiobj;
Heinrich Schuchardt37ebcba2017-10-18 18:13:03 +0200808
Heinrich Schuchardt274cc872017-11-06 21:17:50 +0100809 list_for_each_entry(efiobj, &efi_obj_list, link) {
Heinrich Schuchardt37ebcba2017-10-18 18:13:03 +0200810 if (efiobj->handle == handle)
811 return efiobj;
812 }
813
814 return NULL;
815}
816
817/*
Heinrich Schuchardta277d3a2018-01-11 08:15:57 +0100818 * Create open protocol info entry and add it to a protocol.
819 *
820 * @handler handler of a protocol
821 * @return open protocol info entry
822 */
823static struct efi_open_protocol_info_entry *efi_create_open_info(
824 struct efi_handler *handler)
825{
826 struct efi_open_protocol_info_item *item;
827
828 item = calloc(1, sizeof(struct efi_open_protocol_info_item));
829 if (!item)
830 return NULL;
831 /* Append the item to the open protocol info list. */
832 list_add_tail(&item->link, &handler->open_infos);
833
834 return &item->info;
835}
836
837/*
838 * Remove an open protocol info entry from a protocol.
839 *
840 * @handler handler of a protocol
841 * @return status code
842 */
843static efi_status_t efi_delete_open_info(
844 struct efi_open_protocol_info_item *item)
845{
846 list_del(&item->link);
847 free(item);
848 return EFI_SUCCESS;
849}
850
851/*
Heinrich Schuchardt5aef61d2017-10-26 19:25:53 +0200852 * Install new protocol on a handle.
853 *
854 * @handle handle on which the protocol shall be installed
855 * @protocol GUID of the protocol to be installed
856 * @protocol_interface interface of the protocol implementation
857 * @return status code
858 */
859efi_status_t efi_add_protocol(const void *handle, const efi_guid_t *protocol,
860 void *protocol_interface)
861{
862 struct efi_object *efiobj;
863 struct efi_handler *handler;
864 efi_status_t ret;
Heinrich Schuchardt5aef61d2017-10-26 19:25:53 +0200865
866 efiobj = efi_search_obj(handle);
867 if (!efiobj)
868 return EFI_INVALID_PARAMETER;
869 ret = efi_search_protocol(handle, protocol, NULL);
870 if (ret != EFI_NOT_FOUND)
871 return EFI_INVALID_PARAMETER;
872 handler = calloc(1, sizeof(struct efi_handler));
873 if (!handler)
874 return EFI_OUT_OF_RESOURCES;
Heinrich Schuchardt99ce2062017-11-26 14:05:17 +0100875 handler->guid = protocol;
876 handler->protocol_interface = protocol_interface;
Heinrich Schuchardta277d3a2018-01-11 08:15:57 +0100877 INIT_LIST_HEAD(&handler->open_infos);
Heinrich Schuchardt99ce2062017-11-26 14:05:17 +0100878 list_add_tail(&handler->link, &efiobj->protocols);
Heinrich Schuchardt3d2abc32018-01-11 08:16:01 +0100879 if (!guidcmp(&efi_guid_device_path, protocol))
880 EFI_PRINT("installed device path '%pD'\n", protocol_interface);
Heinrich Schuchardt99ce2062017-11-26 14:05:17 +0100881 return EFI_SUCCESS;
Heinrich Schuchardt5aef61d2017-10-26 19:25:53 +0200882}
883
884/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200885 * Install protocol interface.
886 *
Heinrich Schuchardt0a27ac82017-11-06 21:17:44 +0100887 * This function implements the InstallProtocolInterface service.
888 * See the Unified Extensible Firmware Interface (UEFI) specification
889 * for details.
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200890 *
891 * @handle handle on which the protocol shall be installed
892 * @protocol GUID of the protocol to be installed
893 * @protocol_interface_type type of the interface to be installed,
894 * always EFI_NATIVE_INTERFACE
895 * @protocol_interface interface of the protocol implementation
896 * @return status code
897 */
Heinrich Schuchardt0a27ac82017-11-06 21:17:44 +0100898static efi_status_t EFIAPI efi_install_protocol_interface(
899 void **handle, const efi_guid_t *protocol,
900 int protocol_interface_type, void *protocol_interface)
Alexander Grafc15d9212016-03-04 01:09:59 +0100901{
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200902 efi_status_t r;
903
Heinrich Schuchardt0a27ac82017-11-06 21:17:44 +0100904 EFI_ENTRY("%p, %pUl, %d, %p", handle, protocol, protocol_interface_type,
905 protocol_interface);
906
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200907 if (!handle || !protocol ||
908 protocol_interface_type != EFI_NATIVE_INTERFACE) {
909 r = EFI_INVALID_PARAMETER;
910 goto out;
911 }
912
913 /* Create new handle if requested. */
914 if (!*handle) {
Heinrich Schuchardtcd522cb2017-08-27 00:51:09 +0200915 r = efi_create_handle(handle);
916 if (r != EFI_SUCCESS)
917 goto out;
Heinrich Schuchardt50f02102017-10-26 19:25:43 +0200918 debug("%sEFI: new handle %p\n", indent_string(nesting_level),
919 *handle);
920 } else {
921 debug("%sEFI: handle %p\n", indent_string(nesting_level),
922 *handle);
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200923 }
Heinrich Schuchardt865d5f32017-10-26 19:25:54 +0200924 /* Add new protocol */
925 r = efi_add_protocol(*handle, protocol, protocol_interface);
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200926out:
Heinrich Schuchardt0a27ac82017-11-06 21:17:44 +0100927 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100928}
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200929
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200930/*
931 * Reinstall protocol interface.
932 *
933 * This function implements the ReinstallProtocolInterface service.
934 * See the Unified Extensible Firmware Interface (UEFI) specification
935 * for details.
936 *
937 * @handle handle on which the protocol shall be
938 * reinstalled
939 * @protocol GUID of the protocol to be installed
940 * @old_interface interface to be removed
941 * @new_interface interface to be installed
942 * @return status code
943 */
Alexander Grafc15d9212016-03-04 01:09:59 +0100944static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
Heinrich Schuchardte547c662017-10-05 16:35:53 +0200945 const efi_guid_t *protocol, void *old_interface,
Alexander Grafc15d9212016-03-04 01:09:59 +0100946 void *new_interface)
947{
Rob Clark238f88c2017-09-13 18:05:41 -0400948 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, old_interface,
Alexander Grafc15d9212016-03-04 01:09:59 +0100949 new_interface);
950 return EFI_EXIT(EFI_ACCESS_DENIED);
951}
952
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200953/*
954 * Uninstall protocol interface.
955 *
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +0100956 * This function implements the UninstallProtocolInterface service.
957 * See the Unified Extensible Firmware Interface (UEFI) specification
958 * for details.
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200959 *
960 * @handle handle from which the protocol shall be removed
961 * @protocol GUID of the protocol to be removed
962 * @protocol_interface interface to be removed
963 * @return status code
964 */
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +0100965static efi_status_t EFIAPI efi_uninstall_protocol_interface(
966 void *handle, const efi_guid_t *protocol,
967 void *protocol_interface)
Alexander Grafc15d9212016-03-04 01:09:59 +0100968{
Heinrich Schuchardt7538c272017-10-26 19:25:56 +0200969 struct efi_handler *handler;
970 efi_status_t r;
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +0200971
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +0100972 EFI_ENTRY("%p, %pUl, %p", handle, protocol, protocol_interface);
973
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +0200974 if (!handle || !protocol) {
975 r = EFI_INVALID_PARAMETER;
976 goto out;
977 }
978
Heinrich Schuchardt7538c272017-10-26 19:25:56 +0200979 /* Find the protocol on the handle */
980 r = efi_search_protocol(handle, protocol, &handler);
981 if (r != EFI_SUCCESS)
982 goto out;
983 if (handler->protocol_interface) {
984 /* TODO disconnect controllers */
985 r = EFI_ACCESS_DENIED;
986 } else {
987 r = efi_remove_protocol(handle, protocol, protocol_interface);
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +0200988 }
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +0200989out:
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +0100990 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100991}
992
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200993/*
994 * Register an event for notification when a protocol is installed.
995 *
996 * This function implements the RegisterProtocolNotify service.
997 * See the Unified Extensible Firmware Interface (UEFI) specification
998 * for details.
999 *
1000 * @protocol GUID of the protocol whose installation shall be
1001 * notified
1002 * @event event to be signaled upon installation of the protocol
1003 * @registration key for retrieving the registration information
1004 * @return status code
1005 */
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001006static efi_status_t EFIAPI efi_register_protocol_notify(
1007 const efi_guid_t *protocol,
1008 struct efi_event *event,
1009 void **registration)
Alexander Grafc15d9212016-03-04 01:09:59 +01001010{
Rob Clark238f88c2017-09-13 18:05:41 -04001011 EFI_ENTRY("%pUl, %p, %p", protocol, event, registration);
Alexander Grafc15d9212016-03-04 01:09:59 +01001012 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
1013}
1014
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001015/*
1016 * Determine if an EFI handle implements a protocol.
1017 *
1018 * See the documentation of the LocateHandle service in the UEFI specification.
1019 *
1020 * @search_type selection criterion
1021 * @protocol GUID of the protocol
1022 * @search_key registration key
1023 * @efiobj handle
1024 * @return 0 if the handle implements the protocol
1025 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001026static int efi_search(enum efi_locate_search_type search_type,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001027 const efi_guid_t *protocol, void *search_key,
Alexander Grafc15d9212016-03-04 01:09:59 +01001028 struct efi_object *efiobj)
1029{
Heinrich Schuchardt6a430752017-10-26 19:25:55 +02001030 efi_status_t ret;
Alexander Grafc15d9212016-03-04 01:09:59 +01001031
1032 switch (search_type) {
Heinrich Schuchardt68845f02017-11-06 21:17:42 +01001033 case ALL_HANDLES:
Alexander Grafc15d9212016-03-04 01:09:59 +01001034 return 0;
Heinrich Schuchardt68845f02017-11-06 21:17:42 +01001035 case BY_REGISTER_NOTIFY:
Heinrich Schuchardt6a430752017-10-26 19:25:55 +02001036 /* TODO: RegisterProtocolNotify is not implemented yet */
Alexander Grafc15d9212016-03-04 01:09:59 +01001037 return -1;
Heinrich Schuchardt68845f02017-11-06 21:17:42 +01001038 case BY_PROTOCOL:
Heinrich Schuchardt6a430752017-10-26 19:25:55 +02001039 ret = efi_search_protocol(efiobj->handle, protocol, NULL);
1040 return (ret != EFI_SUCCESS);
1041 default:
1042 /* Invalid search type */
Alexander Grafc15d9212016-03-04 01:09:59 +01001043 return -1;
1044 }
Alexander Grafc15d9212016-03-04 01:09:59 +01001045}
1046
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001047/*
1048 * Locate handles implementing a protocol.
1049 *
1050 * This function is meant for U-Boot internal calls. For the API implementation
1051 * of the LocateHandle service see efi_locate_handle_ext.
1052 *
1053 * @search_type selection criterion
1054 * @protocol GUID of the protocol
1055 * @search_key registration key
1056 * @buffer_size size of the buffer to receive the handles in bytes
1057 * @buffer buffer to receive the relevant handles
1058 * @return status code
1059 */
xypron.glpk@gmx.decab4dd52017-08-09 20:55:00 +02001060static efi_status_t efi_locate_handle(
Alexander Grafc15d9212016-03-04 01:09:59 +01001061 enum efi_locate_search_type search_type,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001062 const efi_guid_t *protocol, void *search_key,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01001063 efi_uintn_t *buffer_size, efi_handle_t *buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +01001064{
Heinrich Schuchardtec66fc82017-11-06 21:17:49 +01001065 struct efi_object *efiobj;
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01001066 efi_uintn_t size = 0;
Alexander Grafc15d9212016-03-04 01:09:59 +01001067
Heinrich Schuchardtec66fc82017-11-06 21:17:49 +01001068 /* Check parameters */
1069 switch (search_type) {
1070 case ALL_HANDLES:
1071 break;
1072 case BY_REGISTER_NOTIFY:
1073 if (!search_key)
1074 return EFI_INVALID_PARAMETER;
1075 /* RegisterProtocolNotify is not implemented yet */
1076 return EFI_UNSUPPORTED;
1077 case BY_PROTOCOL:
1078 if (!protocol)
1079 return EFI_INVALID_PARAMETER;
1080 break;
1081 default:
1082 return EFI_INVALID_PARAMETER;
1083 }
1084
1085 /*
1086 * efi_locate_handle_buffer uses this function for
1087 * the calculation of the necessary buffer size.
1088 * So do not require a buffer for buffersize == 0.
1089 */
1090 if (!buffer_size || (*buffer_size && !buffer))
1091 return EFI_INVALID_PARAMETER;
1092
Alexander Grafc15d9212016-03-04 01:09:59 +01001093 /* Count how much space we need */
Heinrich Schuchardtec66fc82017-11-06 21:17:49 +01001094 list_for_each_entry(efiobj, &efi_obj_list, link) {
1095 if (!efi_search(search_type, protocol, search_key, efiobj))
Alexander Grafc15d9212016-03-04 01:09:59 +01001096 size += sizeof(void*);
Alexander Grafc15d9212016-03-04 01:09:59 +01001097 }
1098
1099 if (*buffer_size < size) {
1100 *buffer_size = size;
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001101 return EFI_BUFFER_TOO_SMALL;
Alexander Grafc15d9212016-03-04 01:09:59 +01001102 }
1103
Rob Clarkcdee3372017-08-06 14:10:07 -04001104 *buffer_size = size;
1105 if (size == 0)
1106 return EFI_NOT_FOUND;
1107
Alexander Grafc15d9212016-03-04 01:09:59 +01001108 /* Then fill the array */
Heinrich Schuchardtec66fc82017-11-06 21:17:49 +01001109 list_for_each_entry(efiobj, &efi_obj_list, link) {
1110 if (!efi_search(search_type, protocol, search_key, efiobj))
1111 *buffer++ = efiobj->handle;
Alexander Grafc15d9212016-03-04 01:09:59 +01001112 }
1113
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001114 return EFI_SUCCESS;
1115}
1116
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001117/*
1118 * Locate handles implementing a protocol.
1119 *
1120 * This function implements the LocateHandle service.
1121 * See the Unified Extensible Firmware Interface (UEFI) specification
1122 * for details.
1123 *
1124 * @search_type selection criterion
1125 * @protocol GUID of the protocol
1126 * @search_key registration key
1127 * @buffer_size size of the buffer to receive the handles in bytes
1128 * @buffer buffer to receive the relevant handles
1129 * @return 0 if the handle implements the protocol
1130 */
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001131static efi_status_t EFIAPI efi_locate_handle_ext(
1132 enum efi_locate_search_type search_type,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001133 const efi_guid_t *protocol, void *search_key,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01001134 efi_uintn_t *buffer_size, efi_handle_t *buffer)
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001135{
Rob Clark238f88c2017-09-13 18:05:41 -04001136 EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001137 buffer_size, buffer);
1138
1139 return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
1140 buffer_size, buffer));
Alexander Grafc15d9212016-03-04 01:09:59 +01001141}
1142
Alexander Graffe3366f2017-07-26 13:41:04 +02001143/* Collapses configuration table entries, removing index i */
1144static void efi_remove_configuration_table(int i)
1145{
1146 struct efi_configuration_table *this = &efi_conf_table[i];
1147 struct efi_configuration_table *next = &efi_conf_table[i+1];
1148 struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables];
1149
1150 memmove(this, next, (ulong)end - (ulong)next);
1151 systab.nr_tables--;
1152}
1153
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001154/*
1155 * Adds, updates, or removes a configuration table.
1156 *
1157 * This function is used for internal calls. For the API implementation of the
1158 * InstallConfigurationTable service see efi_install_configuration_table_ext.
1159 *
1160 * @guid GUID of the installed table
1161 * @table table to be installed
1162 * @return status code
1163 */
Alexander Grafc5c11632016-08-19 01:23:24 +02001164efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
Alexander Grafc15d9212016-03-04 01:09:59 +01001165{
1166 int i;
1167
Alexander Grafc15d9212016-03-04 01:09:59 +01001168 /* Check for guid override */
1169 for (i = 0; i < systab.nr_tables; i++) {
1170 if (!guidcmp(guid, &efi_conf_table[i].guid)) {
Alexander Graffe3366f2017-07-26 13:41:04 +02001171 if (table)
1172 efi_conf_table[i].table = table;
1173 else
1174 efi_remove_configuration_table(i);
Alexander Grafc5c11632016-08-19 01:23:24 +02001175 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +01001176 }
1177 }
1178
Alexander Graffe3366f2017-07-26 13:41:04 +02001179 if (!table)
1180 return EFI_NOT_FOUND;
1181
Alexander Grafc15d9212016-03-04 01:09:59 +01001182 /* No override, check for overflow */
1183 if (i >= ARRAY_SIZE(efi_conf_table))
Alexander Grafc5c11632016-08-19 01:23:24 +02001184 return EFI_OUT_OF_RESOURCES;
Alexander Grafc15d9212016-03-04 01:09:59 +01001185
1186 /* Add a new entry */
1187 memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
1188 efi_conf_table[i].table = table;
Alexander Graf9982e672016-08-19 01:23:30 +02001189 systab.nr_tables = i + 1;
Alexander Grafc15d9212016-03-04 01:09:59 +01001190
Alexander Grafc5c11632016-08-19 01:23:24 +02001191 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +01001192}
1193
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001194/*
1195 * Adds, updates, or removes a configuration table.
1196 *
1197 * This function implements the InstallConfigurationTable service.
1198 * See the Unified Extensible Firmware Interface (UEFI) specification
1199 * for details.
1200 *
1201 * @guid GUID of the installed table
1202 * @table table to be installed
1203 * @return status code
1204 */
Alexander Grafc5c11632016-08-19 01:23:24 +02001205static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
1206 void *table)
1207{
Rob Clark238f88c2017-09-13 18:05:41 -04001208 EFI_ENTRY("%pUl, %p", guid, table);
Alexander Grafc5c11632016-08-19 01:23:24 +02001209 return EFI_EXIT(efi_install_configuration_table(guid, table));
1210}
1211
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001212/*
1213 * Initialize a loaded_image_info + loaded_image_info object with correct
Rob Clarkf8db9222017-09-13 18:05:33 -04001214 * protocols, boot-device, etc.
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001215 *
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001216 * @info loaded image info to be passed to the entry point of the
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001217 * image
1218 * @obj internal object associated with the loaded image
1219 * @device_path device path of the loaded image
1220 * @file_path file path of the loaded image
Heinrich Schuchardt7db9f892017-12-04 18:03:01 +01001221 * @return status code
Rob Clarkf8db9222017-09-13 18:05:33 -04001222 */
Heinrich Schuchardt7db9f892017-12-04 18:03:01 +01001223efi_status_t efi_setup_loaded_image(
1224 struct efi_loaded_image *info, struct efi_object *obj,
1225 struct efi_device_path *device_path,
1226 struct efi_device_path *file_path)
Rob Clarkf8db9222017-09-13 18:05:33 -04001227{
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001228 efi_status_t ret;
1229
Heinrich Schuchardt967d7de2017-11-26 14:05:23 +01001230 /* Add internal object to object list */
1231 efi_add_handle(obj);
1232 /* efi_exit() assumes that the handle points to the info */
Rob Clarkf8db9222017-09-13 18:05:33 -04001233 obj->handle = info;
1234
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001235 info->file_path = file_path;
1236 if (device_path)
1237 info->device_handle = efi_dp_find_obj(device_path, NULL);
1238
Rob Clarkf8db9222017-09-13 18:05:33 -04001239 /*
1240 * When asking for the device path interface, return
1241 * bootefi_device_path
1242 */
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001243 ret = efi_add_protocol(obj->handle, &efi_guid_device_path, device_path);
1244 if (ret != EFI_SUCCESS)
1245 goto failure;
Rob Clarkf8db9222017-09-13 18:05:33 -04001246
1247 /*
1248 * When asking for the loaded_image interface, just
1249 * return handle which points to loaded_image_info
1250 */
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001251 ret = efi_add_protocol(obj->handle, &efi_guid_loaded_image, info);
1252 if (ret != EFI_SUCCESS)
1253 goto failure;
Rob Clarkf8db9222017-09-13 18:05:33 -04001254
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001255 ret = efi_add_protocol(obj->handle, &efi_guid_console_control,
1256 (void *)&efi_console_control);
1257 if (ret != EFI_SUCCESS)
1258 goto failure;
Rob Clarkf8db9222017-09-13 18:05:33 -04001259
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001260 ret = efi_add_protocol(obj->handle,
1261 &efi_guid_device_path_to_text_protocol,
1262 (void *)&efi_device_path_to_text);
1263 if (ret != EFI_SUCCESS)
1264 goto failure;
Rob Clarkf8db9222017-09-13 18:05:33 -04001265
Heinrich Schuchardt7db9f892017-12-04 18:03:01 +01001266 return ret;
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001267failure:
1268 printf("ERROR: Failure to install protocols for loaded image\n");
Heinrich Schuchardt7db9f892017-12-04 18:03:01 +01001269 return ret;
Rob Clarkf8db9222017-09-13 18:05:33 -04001270}
1271
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001272/*
1273 * Load an image using a file path.
1274 *
1275 * @file_path the path of the image to load
1276 * @buffer buffer containing the loaded image
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001277 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001278 */
Rob Clarkc84c1102017-09-13 18:05:38 -04001279efi_status_t efi_load_image_from_path(struct efi_device_path *file_path,
1280 void **buffer)
Rob Clark857a1222017-09-13 18:05:35 -04001281{
1282 struct efi_file_info *info = NULL;
1283 struct efi_file_handle *f;
1284 static efi_status_t ret;
1285 uint64_t bs;
1286
1287 f = efi_file_from_path(file_path);
1288 if (!f)
1289 return EFI_DEVICE_ERROR;
1290
1291 bs = 0;
1292 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1293 &bs, info));
1294 if (ret == EFI_BUFFER_TOO_SMALL) {
1295 info = malloc(bs);
1296 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1297 &bs, info));
1298 }
1299 if (ret != EFI_SUCCESS)
1300 goto error;
1301
1302 ret = efi_allocate_pool(EFI_LOADER_DATA, info->file_size, buffer);
1303 if (ret)
1304 goto error;
1305
1306 EFI_CALL(ret = f->read(f, &info->file_size, *buffer));
1307
1308error:
1309 free(info);
1310 EFI_CALL(f->close(f));
1311
1312 if (ret != EFI_SUCCESS) {
1313 efi_free_pool(*buffer);
1314 *buffer = NULL;
1315 }
1316
1317 return ret;
1318}
1319
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001320/*
1321 * Load an EFI image into memory.
1322 *
1323 * This function implements the LoadImage service.
1324 * See the Unified Extensible Firmware Interface (UEFI) specification
1325 * for details.
1326 *
1327 * @boot_policy true for request originating from the boot manager
1328 * @parent_image the calles's image handle
1329 * @file_path the path of the image to load
1330 * @source_buffer memory location from which the image is installed
1331 * @source_size size of the memory area from which the image is
1332 * installed
1333 * @image_handle handle for the newly installed image
1334 * @return status code
1335 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001336static efi_status_t EFIAPI efi_load_image(bool boot_policy,
1337 efi_handle_t parent_image,
1338 struct efi_device_path *file_path,
1339 void *source_buffer,
1340 unsigned long source_size,
1341 efi_handle_t *image_handle)
1342{
Alexander Grafc15d9212016-03-04 01:09:59 +01001343 struct efi_loaded_image *info;
1344 struct efi_object *obj;
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001345 efi_status_t ret;
Alexander Grafc15d9212016-03-04 01:09:59 +01001346
1347 EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
1348 file_path, source_buffer, source_size, image_handle);
Rob Clark857a1222017-09-13 18:05:35 -04001349
1350 info = calloc(1, sizeof(*info));
1351 obj = calloc(1, sizeof(*obj));
1352
1353 if (!source_buffer) {
1354 struct efi_device_path *dp, *fp;
Rob Clark857a1222017-09-13 18:05:35 -04001355
Rob Clarkc84c1102017-09-13 18:05:38 -04001356 ret = efi_load_image_from_path(file_path, &source_buffer);
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001357 if (ret != EFI_SUCCESS)
1358 goto failure;
Rob Clark857a1222017-09-13 18:05:35 -04001359 /*
1360 * split file_path which contains both the device and
1361 * file parts:
1362 */
1363 efi_dp_split_file_path(file_path, &dp, &fp);
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001364 ret = efi_setup_loaded_image(info, obj, dp, fp);
1365 if (ret != EFI_SUCCESS)
1366 goto failure;
Rob Clark857a1222017-09-13 18:05:35 -04001367 } else {
1368 /* In this case, file_path is the "device" path, ie.
1369 * something like a HARDWARE_DEVICE:MEMORY_MAPPED
1370 */
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001371 ret = efi_setup_loaded_image(info, obj, file_path, NULL);
1372 if (ret != EFI_SUCCESS)
1373 goto failure;
Rob Clark857a1222017-09-13 18:05:35 -04001374 }
Alexander Grafc15d9212016-03-04 01:09:59 +01001375 info->reserved = efi_load_pe(source_buffer, info);
1376 if (!info->reserved) {
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001377 ret = EFI_UNSUPPORTED;
1378 goto failure;
Alexander Grafc15d9212016-03-04 01:09:59 +01001379 }
Heinrich Schuchardt1c176932017-10-18 18:13:20 +02001380 info->system_table = &systab;
1381 info->parent_handle = parent_image;
Heinrich Schuchardt754d4972017-11-26 14:05:22 +01001382 *image_handle = obj->handle;
Alexander Grafc15d9212016-03-04 01:09:59 +01001383 return EFI_EXIT(EFI_SUCCESS);
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001384failure:
1385 free(info);
1386 efi_delete_handle(obj);
1387 return EFI_EXIT(ret);
Alexander Grafc15d9212016-03-04 01:09:59 +01001388}
1389
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001390/*
1391 * Call the entry point of an image.
1392 *
1393 * This function implements the StartImage service.
1394 * See the Unified Extensible Firmware Interface (UEFI) specification
1395 * for details.
1396 *
1397 * @image_handle handle of the image
1398 * @exit_data_size size of the buffer
1399 * @exit_data buffer to receive the exit data of the called image
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001400 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001401 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001402static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
1403 unsigned long *exit_data_size,
1404 s16 **exit_data)
1405{
1406 ulong (*entry)(void *image_handle, struct efi_system_table *st);
1407 struct efi_loaded_image *info = image_handle;
Heinrich Schuchardt6dcd4842018-01-18 20:28:43 +01001408 efi_status_t ret;
Alexander Grafc15d9212016-03-04 01:09:59 +01001409
1410 EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
1411 entry = info->reserved;
1412
1413 efi_is_direct_boot = false;
1414
1415 /* call the image! */
Alexander Graf988c0662016-05-20 23:28:23 +02001416 if (setjmp(&info->exit_jmp)) {
Heinrich Schuchardt6dcd4842018-01-18 20:28:43 +01001417 /*
1418 * We called the entry point of the child image with EFI_CALL
1419 * in the lines below. The child image called the Exit() boot
1420 * service efi_exit() which executed the long jump that brought
1421 * us to the current line. This implies that the second half
1422 * of the EFI_CALL macro has not been executed.
1423 */
1424#ifdef CONFIG_ARM
1425 /*
1426 * efi_exit() called efi_restore_gd(). We have to undo this
1427 * otherwise __efi_entry_check() will put the wrong value into
1428 * app_gd.
1429 */
1430 gd = app_gd;
1431#endif
1432 /*
1433 * To get ready to call EFI_EXIT below we have to execute the
1434 * missed out steps of EFI_CALL.
1435 */
1436 assert(__efi_entry_check());
1437 debug("%sEFI: %lu returned by started image\n",
1438 __efi_nesting_dec(),
1439 (unsigned long)((uintptr_t)info->exit_status &
1440 ~EFI_ERROR_MASK));
Alexander Graf988c0662016-05-20 23:28:23 +02001441 return EFI_EXIT(info->exit_status);
1442 }
1443
Heinrich Schuchardt6dcd4842018-01-18 20:28:43 +01001444 ret = EFI_CALL(entry(image_handle, &systab));
Alexander Grafc15d9212016-03-04 01:09:59 +01001445
1446 /* Should usually never get here */
Heinrich Schuchardt6dcd4842018-01-18 20:28:43 +01001447 return EFI_EXIT(ret);
Alexander Grafc15d9212016-03-04 01:09:59 +01001448}
1449
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001450/*
1451 * Leave an EFI application or driver.
1452 *
1453 * This function implements the Exit service.
1454 * See the Unified Extensible Firmware Interface (UEFI) specification
1455 * for details.
1456 *
1457 * @image_handle handle of the application or driver that is exiting
1458 * @exit_status status code
1459 * @exit_data_size size of the buffer in bytes
1460 * @exit_data buffer with data describing an error
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001461 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001462 */
Alexander Graf988c0662016-05-20 23:28:23 +02001463static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
1464 efi_status_t exit_status, unsigned long exit_data_size,
1465 int16_t *exit_data)
Alexander Grafc15d9212016-03-04 01:09:59 +01001466{
Heinrich Schuchardt967d7de2017-11-26 14:05:23 +01001467 /*
1468 * We require that the handle points to the original loaded
1469 * image protocol interface.
1470 *
1471 * For getting the longjmp address this is safer than locating
1472 * the protocol because the protocol may have been reinstalled
1473 * pointing to another memory location.
1474 *
1475 * TODO: We should call the unload procedure of the loaded
1476 * image protocol.
1477 */
Alexander Graf988c0662016-05-20 23:28:23 +02001478 struct efi_loaded_image *loaded_image_info = (void*)image_handle;
1479
Alexander Grafc15d9212016-03-04 01:09:59 +01001480 EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
1481 exit_data_size, exit_data);
Alexander Graf988c0662016-05-20 23:28:23 +02001482
Alexander Graf87e787a2017-09-03 14:14:17 +02001483 /* Make sure entry/exit counts for EFI world cross-overs match */
Heinrich Schuchardt6dcd4842018-01-18 20:28:43 +01001484 EFI_EXIT(exit_status);
Heinrich Schuchardt4a4c6462017-08-25 19:53:14 +02001485
Alexander Graf87e787a2017-09-03 14:14:17 +02001486 /*
1487 * But longjmp out with the U-Boot gd, not the application's, as
1488 * the other end is a setjmp call inside EFI context.
1489 */
1490 efi_restore_gd();
1491
Alexander Graf988c0662016-05-20 23:28:23 +02001492 loaded_image_info->exit_status = exit_status;
Alexander Graf9d006b72016-09-27 09:30:32 +02001493 longjmp(&loaded_image_info->exit_jmp, 1);
Alexander Graf988c0662016-05-20 23:28:23 +02001494
1495 panic("EFI application exited");
Alexander Grafc15d9212016-03-04 01:09:59 +01001496}
1497
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001498/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001499 * Unload an EFI image.
1500 *
1501 * This function implements the UnloadImage service.
1502 * See the Unified Extensible Firmware Interface (UEFI) specification
1503 * for details.
1504 *
1505 * @image_handle handle of the image to be unloaded
1506 * @return status code
1507 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001508static efi_status_t EFIAPI efi_unload_image(void *image_handle)
1509{
1510 struct efi_object *efiobj;
1511
1512 EFI_ENTRY("%p", image_handle);
1513 efiobj = efi_search_obj(image_handle);
1514 if (efiobj)
1515 list_del(&efiobj->link);
1516
1517 return EFI_EXIT(EFI_SUCCESS);
1518}
1519
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001520/*
1521 * Fix up caches for EFI payloads if necessary.
1522 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001523static void efi_exit_caches(void)
1524{
1525#if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
1526 /*
1527 * Grub on 32bit ARM needs to have caches disabled before jumping into
1528 * a zImage, but does not know of all cache layers. Give it a hand.
1529 */
1530 if (efi_is_direct_boot)
1531 cleanup_before_linux();
1532#endif
1533}
1534
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001535/*
1536 * Stop boot services.
1537 *
1538 * This function implements the ExitBootServices service.
1539 * See the Unified Extensible Firmware Interface (UEFI) specification
1540 * for details.
1541 *
1542 * @image_handle handle of the loaded image
1543 * @map_key key of the memory map
1544 * @return status code
1545 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001546static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
1547 unsigned long map_key)
1548{
Heinrich Schuchardt2d4c7382017-09-15 10:06:18 +02001549 int i;
1550
Alexander Grafc15d9212016-03-04 01:09:59 +01001551 EFI_ENTRY("%p, %ld", image_handle, map_key);
1552
Heinrich Schuchardt2d4c7382017-09-15 10:06:18 +02001553 /* Notify that ExitBootServices is invoked. */
1554 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
1555 if (efi_events[i].type != EVT_SIGNAL_EXIT_BOOT_SERVICES)
1556 continue;
1557 efi_signal_event(&efi_events[i]);
1558 }
1559 /* Make sure that notification functions are not called anymore */
1560 efi_tpl = TPL_HIGH_LEVEL;
1561
Alexander Graf600af332017-10-19 23:23:50 +02001562 /* XXX Should persist EFI variables here */
Rob Clark15f3d742017-09-13 18:05:37 -04001563
Alexander Graf2ebeb442016-11-17 01:02:57 +01001564 board_quiesce_devices();
1565
Alexander Grafc15d9212016-03-04 01:09:59 +01001566 /* Fix up caches for EFI payloads if necessary */
1567 efi_exit_caches();
1568
1569 /* This stops all lingering devices */
1570 bootm_disable_interrupts();
1571
1572 /* Give the payload some time to boot */
Heinrich Schuchardt18081d42017-10-18 18:13:04 +02001573 efi_set_watchdog(0);
Alexander Grafc15d9212016-03-04 01:09:59 +01001574 WATCHDOG_RESET();
1575
1576 return EFI_EXIT(EFI_SUCCESS);
1577}
1578
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001579/*
1580 * Get next value of the counter.
1581 *
1582 * This function implements the NextMonotonicCount service.
1583 * See the Unified Extensible Firmware Interface (UEFI) specification
1584 * for details.
1585 *
1586 * @count returned value of the counter
1587 * @return status code
1588 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001589static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
1590{
1591 static uint64_t mono = 0;
1592 EFI_ENTRY("%p", count);
1593 *count = mono++;
1594 return EFI_EXIT(EFI_SUCCESS);
1595}
1596
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001597/*
1598 * Sleep.
1599 *
1600 * This function implements the Stall sercive.
1601 * See the Unified Extensible Firmware Interface (UEFI) specification
1602 * for details.
1603 *
1604 * @microseconds period to sleep in microseconds
1605 * @return status code
1606 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001607static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
1608{
1609 EFI_ENTRY("%ld", microseconds);
1610 udelay(microseconds);
1611 return EFI_EXIT(EFI_SUCCESS);
1612}
1613
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001614/*
1615 * Reset the watchdog timer.
1616 *
Heinrich Schuchardt18081d42017-10-18 18:13:04 +02001617 * This function implements the SetWatchdogTimer service.
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001618 * See the Unified Extensible Firmware Interface (UEFI) specification
1619 * for details.
1620 *
1621 * @timeout seconds before reset by watchdog
1622 * @watchdog_code code to be logged when resetting
1623 * @data_size size of buffer in bytes
1624 * @watchdog_data buffer with data describing the reset reason
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001625 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001626 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001627static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
1628 uint64_t watchdog_code,
1629 unsigned long data_size,
1630 uint16_t *watchdog_data)
1631{
1632 EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
1633 data_size, watchdog_data);
Heinrich Schuchardt18081d42017-10-18 18:13:04 +02001634 return EFI_EXIT(efi_set_watchdog(timeout));
Alexander Grafc15d9212016-03-04 01:09:59 +01001635}
1636
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001637/*
1638 * Connect a controller to a driver.
1639 *
1640 * This function implements the ConnectController service.
1641 * See the Unified Extensible Firmware Interface (UEFI) specification
1642 * for details.
1643 *
1644 * @controller_handle handle of the controller
1645 * @driver_image_handle handle of the driver
1646 * @remain_device_path device path of a child controller
1647 * @recursive true to connect all child controllers
1648 * @return status code
1649 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001650static efi_status_t EFIAPI efi_connect_controller(
1651 efi_handle_t controller_handle,
1652 efi_handle_t *driver_image_handle,
1653 struct efi_device_path *remain_device_path,
1654 bool recursive)
1655{
1656 EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
1657 remain_device_path, recursive);
1658 return EFI_EXIT(EFI_NOT_FOUND);
1659}
1660
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001661/*
1662 * Disconnect a controller from a driver.
1663 *
1664 * This function implements the DisconnectController service.
1665 * See the Unified Extensible Firmware Interface (UEFI) specification
1666 * for details.
1667 *
1668 * @controller_handle handle of the controller
1669 * @driver_image_handle handle of the driver
1670 * @child_handle handle of the child to destroy
1671 * @return status code
1672 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001673static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
1674 void *driver_image_handle,
1675 void *child_handle)
1676{
1677 EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
1678 child_handle);
1679 return EFI_EXIT(EFI_INVALID_PARAMETER);
1680}
1681
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001682/*
1683 * Close a protocol.
1684 *
1685 * This function implements the CloseProtocol service.
1686 * See the Unified Extensible Firmware Interface (UEFI) specification
1687 * for details.
1688 *
1689 * @handle handle on which the protocol shall be closed
1690 * @protocol GUID of the protocol to close
1691 * @agent_handle handle of the driver
1692 * @controller_handle handle of the controller
1693 * @return status code
1694 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001695static efi_status_t EFIAPI efi_close_protocol(void *handle,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001696 const efi_guid_t *protocol,
Alexander Grafc15d9212016-03-04 01:09:59 +01001697 void *agent_handle,
1698 void *controller_handle)
1699{
Heinrich Schuchardt4fd1ee22018-01-11 08:15:59 +01001700 struct efi_handler *handler;
1701 struct efi_open_protocol_info_item *item;
1702 struct efi_open_protocol_info_item *pos;
1703 efi_status_t r;
1704
Rob Clark238f88c2017-09-13 18:05:41 -04001705 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, agent_handle,
Alexander Grafc15d9212016-03-04 01:09:59 +01001706 controller_handle);
Heinrich Schuchardt4fd1ee22018-01-11 08:15:59 +01001707
1708 if (!agent_handle) {
1709 r = EFI_INVALID_PARAMETER;
1710 goto out;
1711 }
1712 r = efi_search_protocol(handle, protocol, &handler);
1713 if (r != EFI_SUCCESS)
1714 goto out;
1715
1716 r = EFI_NOT_FOUND;
1717 list_for_each_entry_safe(item, pos, &handler->open_infos, link) {
1718 if (item->info.agent_handle == agent_handle &&
1719 item->info.controller_handle == controller_handle) {
1720 efi_delete_open_info(item);
1721 r = EFI_SUCCESS;
1722 break;
1723 }
1724 }
1725out:
1726 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01001727}
1728
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001729/*
1730 * Provide information about then open status of a protocol on a handle
1731 *
1732 * This function implements the OpenProtocolInformation service.
1733 * See the Unified Extensible Firmware Interface (UEFI) specification
1734 * for details.
1735 *
1736 * @handle handle for which the information shall be retrieved
1737 * @protocol GUID of the protocol
1738 * @entry_buffer buffer to receive the open protocol information
1739 * @entry_count number of entries available in the buffer
1740 * @return status code
1741 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001742static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001743 const efi_guid_t *protocol,
Alexander Grafc15d9212016-03-04 01:09:59 +01001744 struct efi_open_protocol_info_entry **entry_buffer,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01001745 efi_uintn_t *entry_count)
Alexander Grafc15d9212016-03-04 01:09:59 +01001746{
Heinrich Schuchardtf2ef22e2018-01-11 08:16:00 +01001747 unsigned long buffer_size;
1748 unsigned long count;
1749 struct efi_handler *handler;
1750 struct efi_open_protocol_info_item *item;
1751 efi_status_t r;
1752
Rob Clark238f88c2017-09-13 18:05:41 -04001753 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, entry_buffer,
Alexander Grafc15d9212016-03-04 01:09:59 +01001754 entry_count);
Heinrich Schuchardtf2ef22e2018-01-11 08:16:00 +01001755
1756 /* Check parameters */
1757 if (!entry_buffer) {
1758 r = EFI_INVALID_PARAMETER;
1759 goto out;
1760 }
1761 r = efi_search_protocol(handle, protocol, &handler);
1762 if (r != EFI_SUCCESS)
1763 goto out;
1764
1765 /* Count entries */
1766 count = 0;
1767 list_for_each_entry(item, &handler->open_infos, link) {
1768 if (item->info.open_count)
1769 ++count;
1770 }
1771 *entry_count = count;
1772 *entry_buffer = NULL;
1773 if (!count) {
1774 r = EFI_SUCCESS;
1775 goto out;
1776 }
1777
1778 /* Copy entries */
1779 buffer_size = count * sizeof(struct efi_open_protocol_info_entry);
1780 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
1781 (void **)entry_buffer);
1782 if (r != EFI_SUCCESS)
1783 goto out;
1784 list_for_each_entry_reverse(item, &handler->open_infos, link) {
1785 if (item->info.open_count)
1786 (*entry_buffer)[--count] = item->info;
1787 }
1788out:
1789 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01001790}
1791
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001792/*
1793 * Get protocols installed on a handle.
1794 *
1795 * This function implements the ProtocolsPerHandleService.
1796 * See the Unified Extensible Firmware Interface (UEFI) specification
1797 * for details.
1798 *
1799 * @handle handle for which the information is retrieved
1800 * @protocol_buffer buffer with protocol GUIDs
1801 * @protocol_buffer_count number of entries in the buffer
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001802 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001803 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001804static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
1805 efi_guid_t ***protocol_buffer,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01001806 efi_uintn_t *protocol_buffer_count)
Alexander Grafc15d9212016-03-04 01:09:59 +01001807{
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001808 unsigned long buffer_size;
1809 struct efi_object *efiobj;
Heinrich Schuchardt99ce2062017-11-26 14:05:17 +01001810 struct list_head *protocol_handle;
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001811 efi_status_t r;
1812
Alexander Grafc15d9212016-03-04 01:09:59 +01001813 EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
1814 protocol_buffer_count);
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001815
1816 if (!handle || !protocol_buffer || !protocol_buffer_count)
1817 return EFI_EXIT(EFI_INVALID_PARAMETER);
1818
1819 *protocol_buffer = NULL;
Rob Clarkd51b8ca2017-07-20 07:59:39 -04001820 *protocol_buffer_count = 0;
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001821
Heinrich Schuchardt99ce2062017-11-26 14:05:17 +01001822 efiobj = efi_search_obj(handle);
1823 if (!efiobj)
1824 return EFI_EXIT(EFI_INVALID_PARAMETER);
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001825
Heinrich Schuchardt99ce2062017-11-26 14:05:17 +01001826 /* Count protocols */
1827 list_for_each(protocol_handle, &efiobj->protocols) {
1828 ++*protocol_buffer_count;
1829 }
1830
1831 /* Copy guids */
1832 if (*protocol_buffer_count) {
1833 size_t j = 0;
1834
1835 buffer_size = sizeof(efi_guid_t *) * *protocol_buffer_count;
1836 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
1837 (void **)protocol_buffer);
1838 if (r != EFI_SUCCESS)
1839 return EFI_EXIT(r);
1840 list_for_each(protocol_handle, &efiobj->protocols) {
1841 struct efi_handler *protocol;
1842
1843 protocol = list_entry(protocol_handle,
1844 struct efi_handler, link);
1845 (*protocol_buffer)[j] = (void *)protocol->guid;
1846 ++j;
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001847 }
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001848 }
1849
1850 return EFI_EXIT(EFI_SUCCESS);
Alexander Grafc15d9212016-03-04 01:09:59 +01001851}
1852
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001853/*
1854 * Locate handles implementing a protocol.
1855 *
1856 * This function implements the LocateHandleBuffer service.
1857 * See the Unified Extensible Firmware Interface (UEFI) specification
1858 * for details.
1859 *
1860 * @search_type selection criterion
1861 * @protocol GUID of the protocol
1862 * @search_key registration key
1863 * @no_handles number of returned handles
1864 * @buffer buffer with the returned handles
1865 * @return status code
1866 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001867static efi_status_t EFIAPI efi_locate_handle_buffer(
1868 enum efi_locate_search_type search_type,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001869 const efi_guid_t *protocol, void *search_key,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01001870 efi_uintn_t *no_handles, efi_handle_t **buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +01001871{
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +02001872 efi_status_t r;
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01001873 efi_uintn_t buffer_size = 0;
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +02001874
Rob Clark238f88c2017-09-13 18:05:41 -04001875 EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
Alexander Grafc15d9212016-03-04 01:09:59 +01001876 no_handles, buffer);
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +02001877
1878 if (!no_handles || !buffer) {
1879 r = EFI_INVALID_PARAMETER;
1880 goto out;
1881 }
1882 *no_handles = 0;
1883 *buffer = NULL;
1884 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
1885 *buffer);
1886 if (r != EFI_BUFFER_TOO_SMALL)
1887 goto out;
1888 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
1889 (void **)buffer);
1890 if (r != EFI_SUCCESS)
1891 goto out;
1892 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
1893 *buffer);
1894 if (r == EFI_SUCCESS)
1895 *no_handles = buffer_size / sizeof(void *);
1896out:
1897 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01001898}
1899
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001900/*
1901 * Find an interface implementing a protocol.
1902 *
1903 * This function implements the LocateProtocol service.
1904 * See the Unified Extensible Firmware Interface (UEFI) specification
1905 * for details.
1906 *
1907 * @protocol GUID of the protocol
1908 * @registration registration key passed to the notification function
1909 * @protocol_interface interface implementing the protocol
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001910 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001911 */
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001912static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,
Alexander Grafc15d9212016-03-04 01:09:59 +01001913 void *registration,
1914 void **protocol_interface)
1915{
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02001916 struct list_head *lhandle;
Heinrich Schuchardt57505e92017-10-26 19:25:57 +02001917 efi_status_t ret;
Alexander Grafc15d9212016-03-04 01:09:59 +01001918
Rob Clark238f88c2017-09-13 18:05:41 -04001919 EFI_ENTRY("%pUl, %p, %p", protocol, registration, protocol_interface);
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02001920
1921 if (!protocol || !protocol_interface)
1922 return EFI_EXIT(EFI_INVALID_PARAMETER);
1923
1924 list_for_each(lhandle, &efi_obj_list) {
1925 struct efi_object *efiobj;
Heinrich Schuchardt57505e92017-10-26 19:25:57 +02001926 struct efi_handler *handler;
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02001927
1928 efiobj = list_entry(lhandle, struct efi_object, link);
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02001929
Heinrich Schuchardt57505e92017-10-26 19:25:57 +02001930 ret = efi_search_protocol(efiobj->handle, protocol, &handler);
1931 if (ret == EFI_SUCCESS) {
1932 *protocol_interface = handler->protocol_interface;
1933 return EFI_EXIT(EFI_SUCCESS);
Alexander Grafc15d9212016-03-04 01:09:59 +01001934 }
1935 }
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02001936 *protocol_interface = NULL;
Alexander Grafc15d9212016-03-04 01:09:59 +01001937
1938 return EFI_EXIT(EFI_NOT_FOUND);
1939}
1940
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001941/*
Heinrich Schuchardt06ec6892017-11-26 14:05:10 +01001942 * Get the device path and handle of an device implementing a protocol.
1943 *
1944 * This function implements the LocateDevicePath service.
1945 * See the Unified Extensible Firmware Interface (UEFI) specification
1946 * for details.
1947 *
1948 * @protocol GUID of the protocol
1949 * @device_path device path
1950 * @device handle of the device
1951 * @return status code
1952 */
1953static efi_status_t EFIAPI efi_locate_device_path(
1954 const efi_guid_t *protocol,
1955 struct efi_device_path **device_path,
1956 efi_handle_t *device)
1957{
1958 struct efi_device_path *dp;
1959 size_t i;
1960 struct efi_handler *handler;
1961 efi_handle_t *handles;
1962 size_t len, len_dp;
1963 size_t len_best = 0;
1964 efi_uintn_t no_handles;
1965 u8 *remainder;
1966 efi_status_t ret;
1967
1968 EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device);
1969
1970 if (!protocol || !device_path || !*device_path || !device) {
1971 ret = EFI_INVALID_PARAMETER;
1972 goto out;
1973 }
1974
1975 /* Find end of device path */
1976 len = efi_dp_size(*device_path);
1977
1978 /* Get all handles implementing the protocol */
1979 ret = EFI_CALL(efi_locate_handle_buffer(BY_PROTOCOL, protocol, NULL,
1980 &no_handles, &handles));
1981 if (ret != EFI_SUCCESS)
1982 goto out;
1983
1984 for (i = 0; i < no_handles; ++i) {
1985 /* Find the device path protocol */
1986 ret = efi_search_protocol(handles[i], &efi_guid_device_path,
1987 &handler);
1988 if (ret != EFI_SUCCESS)
1989 continue;
1990 dp = (struct efi_device_path *)handler->protocol_interface;
1991 len_dp = efi_dp_size(dp);
1992 /*
1993 * This handle can only be a better fit
1994 * if its device path length is longer than the best fit and
1995 * if its device path length is shorter of equal the searched
1996 * device path.
1997 */
1998 if (len_dp <= len_best || len_dp > len)
1999 continue;
2000 /* Check if dp is a subpath of device_path */
2001 if (memcmp(*device_path, dp, len_dp))
2002 continue;
2003 *device = handles[i];
2004 len_best = len_dp;
2005 }
2006 if (len_best) {
2007 remainder = (u8 *)*device_path + len_best;
2008 *device_path = (struct efi_device_path *)remainder;
2009 ret = EFI_SUCCESS;
2010 } else {
2011 ret = EFI_NOT_FOUND;
2012 }
2013out:
2014 return EFI_EXIT(ret);
2015}
2016
2017/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002018 * Install multiple protocol interfaces.
2019 *
2020 * This function implements the MultipleProtocolInterfaces service.
2021 * See the Unified Extensible Firmware Interface (UEFI) specification
2022 * for details.
2023 *
2024 * @handle handle on which the protocol interfaces shall be installed
2025 * @... NULL terminated argument list with pairs of protocol GUIDS and
2026 * interfaces
2027 * @return status code
2028 */
Alexander Grafc15d9212016-03-04 01:09:59 +01002029static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
2030 void **handle, ...)
2031{
2032 EFI_ENTRY("%p", handle);
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +02002033
2034 va_list argptr;
Heinrich Schuchardte547c662017-10-05 16:35:53 +02002035 const efi_guid_t *protocol;
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +02002036 void *protocol_interface;
2037 efi_status_t r = EFI_SUCCESS;
2038 int i = 0;
2039
2040 if (!handle)
2041 return EFI_EXIT(EFI_INVALID_PARAMETER);
2042
2043 va_start(argptr, handle);
2044 for (;;) {
2045 protocol = va_arg(argptr, efi_guid_t*);
2046 if (!protocol)
2047 break;
2048 protocol_interface = va_arg(argptr, void*);
Heinrich Schuchardt0a27ac82017-11-06 21:17:44 +01002049 r = EFI_CALL(efi_install_protocol_interface(
2050 handle, protocol,
2051 EFI_NATIVE_INTERFACE,
2052 protocol_interface));
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +02002053 if (r != EFI_SUCCESS)
2054 break;
2055 i++;
2056 }
2057 va_end(argptr);
2058 if (r == EFI_SUCCESS)
2059 return EFI_EXIT(r);
2060
Heinrich Schuchardtec47f3e2017-10-26 19:25:42 +02002061 /* If an error occurred undo all changes. */
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +02002062 va_start(argptr, handle);
2063 for (; i; --i) {
2064 protocol = va_arg(argptr, efi_guid_t*);
2065 protocol_interface = va_arg(argptr, void*);
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +01002066 EFI_CALL(efi_uninstall_protocol_interface(handle, protocol,
2067 protocol_interface));
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +02002068 }
2069 va_end(argptr);
2070
2071 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01002072}
2073
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002074/*
2075 * Uninstall multiple protocol interfaces.
2076 *
2077 * This function implements the UninstallMultipleProtocolInterfaces service.
2078 * See the Unified Extensible Firmware Interface (UEFI) specification
2079 * for details.
2080 *
2081 * @handle handle from which the protocol interfaces shall be removed
2082 * @... NULL terminated argument list with pairs of protocol GUIDS and
2083 * interfaces
2084 * @return status code
2085 */
Alexander Grafc15d9212016-03-04 01:09:59 +01002086static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
2087 void *handle, ...)
2088{
2089 EFI_ENTRY("%p", handle);
Heinrich Schuchardta616dcf2017-10-26 19:25:44 +02002090
2091 va_list argptr;
2092 const efi_guid_t *protocol;
2093 void *protocol_interface;
2094 efi_status_t r = EFI_SUCCESS;
2095 size_t i = 0;
2096
2097 if (!handle)
2098 return EFI_EXIT(EFI_INVALID_PARAMETER);
2099
2100 va_start(argptr, handle);
2101 for (;;) {
2102 protocol = va_arg(argptr, efi_guid_t*);
2103 if (!protocol)
2104 break;
2105 protocol_interface = va_arg(argptr, void*);
2106 r = EFI_CALL(efi_uninstall_protocol_interface(
2107 handle, protocol,
2108 protocol_interface));
2109 if (r != EFI_SUCCESS)
2110 break;
2111 i++;
2112 }
2113 va_end(argptr);
2114 if (r == EFI_SUCCESS)
2115 return EFI_EXIT(r);
2116
2117 /* If an error occurred undo all changes. */
2118 va_start(argptr, handle);
2119 for (; i; --i) {
2120 protocol = va_arg(argptr, efi_guid_t*);
2121 protocol_interface = va_arg(argptr, void*);
2122 EFI_CALL(efi_install_protocol_interface(&handle, protocol,
2123 EFI_NATIVE_INTERFACE,
2124 protocol_interface));
2125 }
2126 va_end(argptr);
2127
2128 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01002129}
2130
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002131/*
2132 * Calculate cyclic redundancy code.
2133 *
2134 * This function implements the CalculateCrc32 service.
2135 * See the Unified Extensible Firmware Interface (UEFI) specification
2136 * for details.
2137 *
2138 * @data buffer with data
2139 * @data_size size of buffer in bytes
2140 * @crc32_p cyclic redundancy code
2141 * @return status code
2142 */
Alexander Grafc15d9212016-03-04 01:09:59 +01002143static efi_status_t EFIAPI efi_calculate_crc32(void *data,
2144 unsigned long data_size,
2145 uint32_t *crc32_p)
2146{
2147 EFI_ENTRY("%p, %ld", data, data_size);
2148 *crc32_p = crc32(0, data, data_size);
2149 return EFI_EXIT(EFI_SUCCESS);
2150}
2151
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002152/*
2153 * Copy memory.
2154 *
2155 * This function implements the CopyMem service.
2156 * See the Unified Extensible Firmware Interface (UEFI) specification
2157 * for details.
2158 *
2159 * @destination destination of the copy operation
2160 * @source source of the copy operation
2161 * @length number of bytes to copy
2162 */
Heinrich Schuchardtd0a349e2017-10-05 16:35:52 +02002163static void EFIAPI efi_copy_mem(void *destination, const void *source,
2164 size_t length)
Alexander Grafc15d9212016-03-04 01:09:59 +01002165{
Heinrich Schuchardtd0a349e2017-10-05 16:35:52 +02002166 EFI_ENTRY("%p, %p, %ld", destination, source, (unsigned long)length);
Alexander Grafc15d9212016-03-04 01:09:59 +01002167 memcpy(destination, source, length);
Heinrich Schuchardta5270e02017-10-05 16:35:51 +02002168 EFI_EXIT(EFI_SUCCESS);
Alexander Grafc15d9212016-03-04 01:09:59 +01002169}
2170
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002171/*
2172 * Fill memory with a byte value.
2173 *
2174 * This function implements the SetMem service.
2175 * See the Unified Extensible Firmware Interface (UEFI) specification
2176 * for details.
2177 *
2178 * @buffer buffer to fill
2179 * @size size of buffer in bytes
2180 * @value byte to copy to the buffer
2181 */
Heinrich Schuchardtd0a349e2017-10-05 16:35:52 +02002182static void EFIAPI efi_set_mem(void *buffer, size_t size, uint8_t value)
Alexander Grafc15d9212016-03-04 01:09:59 +01002183{
Heinrich Schuchardtd0a349e2017-10-05 16:35:52 +02002184 EFI_ENTRY("%p, %ld, 0x%x", buffer, (unsigned long)size, value);
Alexander Grafc15d9212016-03-04 01:09:59 +01002185 memset(buffer, value, size);
Heinrich Schuchardta5270e02017-10-05 16:35:51 +02002186 EFI_EXIT(EFI_SUCCESS);
Alexander Grafc15d9212016-03-04 01:09:59 +01002187}
2188
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002189/*
2190 * Open protocol interface on a handle.
2191 *
Heinrich Schuchardt8cb38c02018-01-11 08:15:58 +01002192 * @handler handler of a protocol
2193 * @protocol_interface interface implementing the protocol
2194 * @agent_handle handle of the driver
2195 * @controller_handle handle of the controller
2196 * @attributes attributes indicating how to open the protocol
2197 * @return status code
2198 */
2199static efi_status_t efi_protocol_open(
2200 struct efi_handler *handler,
2201 void **protocol_interface, void *agent_handle,
2202 void *controller_handle, uint32_t attributes)
2203{
2204 struct efi_open_protocol_info_item *item;
2205 struct efi_open_protocol_info_entry *match = NULL;
2206 bool opened_by_driver = false;
2207 bool opened_exclusive = false;
2208
2209 /* If there is no agent, only return the interface */
2210 if (!agent_handle)
2211 goto out;
2212
2213 /* For TEST_PROTOCOL ignore interface attribute */
2214 if (attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL)
2215 *protocol_interface = NULL;
2216
2217 /*
2218 * Check if the protocol is already opened by a driver with the same
2219 * attributes or opened exclusively
2220 */
2221 list_for_each_entry(item, &handler->open_infos, link) {
2222 if (item->info.agent_handle == agent_handle) {
2223 if ((attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) &&
2224 (item->info.attributes == attributes))
2225 return EFI_ALREADY_STARTED;
2226 }
2227 if (item->info.attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE)
2228 opened_exclusive = true;
2229 }
2230
2231 /* Only one controller can open the protocol exclusively */
2232 if (opened_exclusive && attributes &
2233 (EFI_OPEN_PROTOCOL_EXCLUSIVE | EFI_OPEN_PROTOCOL_BY_DRIVER))
2234 return EFI_ACCESS_DENIED;
2235
2236 /* Prepare exclusive opening */
2237 if (attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) {
2238 /* Try to disconnect controllers */
2239 list_for_each_entry(item, &handler->open_infos, link) {
2240 if (item->info.attributes ==
2241 EFI_OPEN_PROTOCOL_BY_DRIVER)
2242 EFI_CALL(efi_disconnect_controller(
2243 item->info.controller_handle,
2244 item->info.agent_handle,
2245 NULL));
2246 }
2247 opened_by_driver = false;
2248 /* Check if all controllers are disconnected */
2249 list_for_each_entry(item, &handler->open_infos, link) {
2250 if (item->info.attributes & EFI_OPEN_PROTOCOL_BY_DRIVER)
2251 opened_by_driver = true;
2252 }
2253 /* Only one controller can be conncected */
2254 if (opened_by_driver)
2255 return EFI_ACCESS_DENIED;
2256 }
2257
2258 /* Find existing entry */
2259 list_for_each_entry(item, &handler->open_infos, link) {
2260 if (item->info.agent_handle == agent_handle &&
2261 item->info.controller_handle == controller_handle)
2262 match = &item->info;
2263 }
2264 /* None found, create one */
2265 if (!match) {
2266 match = efi_create_open_info(handler);
2267 if (!match)
2268 return EFI_OUT_OF_RESOURCES;
2269 }
2270
2271 match->agent_handle = agent_handle;
2272 match->controller_handle = controller_handle;
2273 match->attributes = attributes;
2274 match->open_count++;
2275
2276out:
2277 /* For TEST_PROTOCOL ignore interface attribute. */
2278 if (attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL)
2279 *protocol_interface = handler->protocol_interface;
2280
2281 return EFI_SUCCESS;
2282}
2283
2284/*
2285 * Open protocol interface on a handle.
2286 *
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002287 * This function implements the OpenProtocol interface.
2288 * See the Unified Extensible Firmware Interface (UEFI) specification
2289 * for details.
2290 *
2291 * @handle handle on which the protocol shall be opened
2292 * @protocol GUID of the protocol
2293 * @protocol_interface interface implementing the protocol
2294 * @agent_handle handle of the driver
2295 * @controller_handle handle of the controller
2296 * @attributes attributes indicating how to open the protocol
2297 * @return status code
2298 */
Alexander Grafc15d9212016-03-04 01:09:59 +01002299static efi_status_t EFIAPI efi_open_protocol(
Heinrich Schuchardte547c662017-10-05 16:35:53 +02002300 void *handle, const efi_guid_t *protocol,
Alexander Grafc15d9212016-03-04 01:09:59 +01002301 void **protocol_interface, void *agent_handle,
2302 void *controller_handle, uint32_t attributes)
2303{
Heinrich Schuchardte5e78a32017-11-26 14:05:15 +01002304 struct efi_handler *handler;
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002305 efi_status_t r = EFI_INVALID_PARAMETER;
Alexander Grafc15d9212016-03-04 01:09:59 +01002306
Rob Clark238f88c2017-09-13 18:05:41 -04002307 EFI_ENTRY("%p, %pUl, %p, %p, %p, 0x%x", handle, protocol,
Alexander Grafc15d9212016-03-04 01:09:59 +01002308 protocol_interface, agent_handle, controller_handle,
2309 attributes);
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02002310
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002311 if (!handle || !protocol ||
2312 (!protocol_interface && attributes !=
2313 EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02002314 goto out;
2315 }
2316
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002317 switch (attributes) {
2318 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
2319 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
2320 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
2321 break;
2322 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
2323 if (controller_handle == handle)
2324 goto out;
Heinrich Schuchardt8cb38c02018-01-11 08:15:58 +01002325 /* fall-through */
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002326 case EFI_OPEN_PROTOCOL_BY_DRIVER:
2327 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
Heinrich Schuchardt8cb38c02018-01-11 08:15:58 +01002328 /* Check that the controller handle is valid */
2329 if (!efi_search_obj(controller_handle))
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002330 goto out;
Heinrich Schuchardt8cb38c02018-01-11 08:15:58 +01002331 /* fall-through */
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002332 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
Heinrich Schuchardt8cb38c02018-01-11 08:15:58 +01002333 /* Check that the agent handle is valid */
2334 if (!efi_search_obj(agent_handle))
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002335 goto out;
2336 break;
2337 default:
2338 goto out;
2339 }
2340
Heinrich Schuchardte5e78a32017-11-26 14:05:15 +01002341 r = efi_search_protocol(handle, protocol, &handler);
2342 if (r != EFI_SUCCESS)
2343 goto out;
Alexander Grafc15d9212016-03-04 01:09:59 +01002344
Heinrich Schuchardt8cb38c02018-01-11 08:15:58 +01002345 r = efi_protocol_open(handler, protocol_interface, agent_handle,
2346 controller_handle, attributes);
Alexander Grafc15d9212016-03-04 01:09:59 +01002347out:
2348 return EFI_EXIT(r);
2349}
2350
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002351/*
2352 * Get interface of a protocol on a handle.
2353 *
2354 * This function implements the HandleProtocol service.
2355 * See the Unified Extensible Firmware Interface (UEFI) specification
2356 * for details.
2357 *
2358 * @handle handle on which the protocol shall be opened
2359 * @protocol GUID of the protocol
2360 * @protocol_interface interface implementing the protocol
2361 * @return status code
2362 */
Alexander Grafc15d9212016-03-04 01:09:59 +01002363static efi_status_t EFIAPI efi_handle_protocol(void *handle,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02002364 const efi_guid_t *protocol,
Alexander Grafc15d9212016-03-04 01:09:59 +01002365 void **protocol_interface)
2366{
xypron.glpk@gmx.de1bf5d872017-06-29 21:16:19 +02002367 return efi_open_protocol(handle, protocol, protocol_interface, NULL,
2368 NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
Alexander Grafc15d9212016-03-04 01:09:59 +01002369}
2370
2371static const struct efi_boot_services efi_boot_services = {
2372 .hdr = {
2373 .headersize = sizeof(struct efi_table_hdr),
2374 },
2375 .raise_tpl = efi_raise_tpl,
2376 .restore_tpl = efi_restore_tpl,
2377 .allocate_pages = efi_allocate_pages_ext,
2378 .free_pages = efi_free_pages_ext,
2379 .get_memory_map = efi_get_memory_map_ext,
Stefan Brüns5a09aef2016-10-09 22:17:18 +02002380 .allocate_pool = efi_allocate_pool_ext,
Stefan Brüns67b67d92016-10-09 22:17:26 +02002381 .free_pool = efi_free_pool_ext,
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +02002382 .create_event = efi_create_event_ext,
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +02002383 .set_timer = efi_set_timer_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002384 .wait_for_event = efi_wait_for_event,
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +02002385 .signal_event = efi_signal_event_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002386 .close_event = efi_close_event,
2387 .check_event = efi_check_event,
Heinrich Schuchardt0a27ac82017-11-06 21:17:44 +01002388 .install_protocol_interface = efi_install_protocol_interface,
Alexander Grafc15d9212016-03-04 01:09:59 +01002389 .reinstall_protocol_interface = efi_reinstall_protocol_interface,
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +01002390 .uninstall_protocol_interface = efi_uninstall_protocol_interface,
Alexander Grafc15d9212016-03-04 01:09:59 +01002391 .handle_protocol = efi_handle_protocol,
2392 .reserved = NULL,
2393 .register_protocol_notify = efi_register_protocol_notify,
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02002394 .locate_handle = efi_locate_handle_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002395 .locate_device_path = efi_locate_device_path,
Alexander Grafc5c11632016-08-19 01:23:24 +02002396 .install_configuration_table = efi_install_configuration_table_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002397 .load_image = efi_load_image,
2398 .start_image = efi_start_image,
Alexander Graf988c0662016-05-20 23:28:23 +02002399 .exit = efi_exit,
Alexander Grafc15d9212016-03-04 01:09:59 +01002400 .unload_image = efi_unload_image,
2401 .exit_boot_services = efi_exit_boot_services,
2402 .get_next_monotonic_count = efi_get_next_monotonic_count,
2403 .stall = efi_stall,
2404 .set_watchdog_timer = efi_set_watchdog_timer,
2405 .connect_controller = efi_connect_controller,
2406 .disconnect_controller = efi_disconnect_controller,
2407 .open_protocol = efi_open_protocol,
2408 .close_protocol = efi_close_protocol,
2409 .open_protocol_information = efi_open_protocol_information,
2410 .protocols_per_handle = efi_protocols_per_handle,
2411 .locate_handle_buffer = efi_locate_handle_buffer,
2412 .locate_protocol = efi_locate_protocol,
2413 .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
2414 .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
2415 .calculate_crc32 = efi_calculate_crc32,
2416 .copy_mem = efi_copy_mem,
2417 .set_mem = efi_set_mem,
2418};
2419
2420
Heinrich Schuchardt3579b692017-12-11 20:10:20 +01002421static uint16_t __efi_runtime_data firmware_vendor[] = L"Das U-Boot";
Alexander Grafc15d9212016-03-04 01:09:59 +01002422
Alexander Graf393dd912016-10-14 13:45:30 +02002423struct efi_system_table __efi_runtime_data systab = {
Alexander Grafc15d9212016-03-04 01:09:59 +01002424 .hdr = {
2425 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
2426 .revision = 0x20005, /* 2.5 */
2427 .headersize = sizeof(struct efi_table_hdr),
2428 },
2429 .fw_vendor = (long)firmware_vendor,
2430 .con_in = (void*)&efi_con_in,
2431 .con_out = (void*)&efi_con_out,
2432 .std_err = (void*)&efi_con_out,
2433 .runtime = (void*)&efi_runtime_services,
2434 .boottime = (void*)&efi_boot_services,
2435 .nr_tables = 0,
2436 .tables = (void*)efi_conf_table,
2437};