blob: df75dd903225d9f63523933bfb439ac35c967b1a [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>
10#include <efi_loader.h>
Rob Clark15f3d742017-09-13 18:05:37 -040011#include <environment.h>
Alexander Grafc15d9212016-03-04 01:09:59 +010012#include <malloc.h>
13#include <asm/global_data.h>
14#include <libfdt_env.h>
15#include <u-boot/crc.h>
16#include <bootm.h>
17#include <inttypes.h>
18#include <watchdog.h>
19
20DECLARE_GLOBAL_DATA_PTR;
21
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +020022/* Task priority level */
23static UINTN efi_tpl = TPL_APPLICATION;
24
Alexander Grafc15d9212016-03-04 01:09:59 +010025/* This list contains all the EFI objects our payload has access to */
26LIST_HEAD(efi_obj_list);
27
28/*
29 * If we're running on nasty systems (32bit ARM booting into non-EFI Linux)
30 * we need to do trickery with caches. Since we don't want to break the EFI
31 * aware boot path, only apply hacks when loading exiting directly (breaking
32 * direct Linux EFI booting along the way - oh well).
33 */
34static bool efi_is_direct_boot = true;
35
36/*
37 * EFI can pass arbitrary additional "tables" containing vendor specific
38 * information to the payload. One such table is the FDT table which contains
39 * a pointer to a flattened device tree blob.
40 *
41 * In most cases we want to pass an FDT to the payload, so reserve one slot of
42 * config table space for it. The pointer gets populated by do_bootefi_exec().
43 */
Alexander Graf393dd912016-10-14 13:45:30 +020044static struct efi_configuration_table __efi_runtime_data efi_conf_table[2];
Alexander Grafc15d9212016-03-04 01:09:59 +010045
Simon Glasscdfe6962016-09-25 15:27:35 -060046#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +010047/*
48 * The "gd" pointer lives in a register on ARM and AArch64 that we declare
49 * fixed when compiling U-Boot. However, the payload does not know about that
50 * restriction so we need to manually swap its and our view of that register on
51 * EFI callback entry/exit.
52 */
53static volatile void *efi_gd, *app_gd;
Simon Glasscdfe6962016-09-25 15:27:35 -060054#endif
Alexander Grafc15d9212016-03-04 01:09:59 +010055
Rob Clark86789d52017-07-27 08:04:18 -040056static int entry_count;
Rob Clarke7896c32017-07-27 08:04:19 -040057static int nesting_level;
Rob Clark86789d52017-07-27 08:04:18 -040058
59/* Called on every callback entry */
60int __efi_entry_check(void)
61{
62 int ret = entry_count++ == 0;
63#ifdef CONFIG_ARM
64 assert(efi_gd);
65 app_gd = gd;
66 gd = efi_gd;
67#endif
68 return ret;
69}
70
71/* Called on every callback exit */
72int __efi_exit_check(void)
73{
74 int ret = --entry_count == 0;
75#ifdef CONFIG_ARM
76 gd = app_gd;
77#endif
78 return ret;
79}
80
Alexander Grafc15d9212016-03-04 01:09:59 +010081/* Called from do_bootefi_exec() */
82void efi_save_gd(void)
83{
Simon Glasscdfe6962016-09-25 15:27:35 -060084#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +010085 efi_gd = gd;
Simon Glasscdfe6962016-09-25 15:27:35 -060086#endif
Alexander Grafc15d9212016-03-04 01:09:59 +010087}
88
Rob Clark86789d52017-07-27 08:04:18 -040089/*
90 * Special case handler for error/abort that just forces things back
91 * to u-boot world so we can dump out an abort msg, without any care
92 * about returning back to UEFI world.
93 */
Alexander Grafc15d9212016-03-04 01:09:59 +010094void efi_restore_gd(void)
95{
Simon Glasscdfe6962016-09-25 15:27:35 -060096#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +010097 /* Only restore if we're already in EFI context */
98 if (!efi_gd)
99 return;
Alexander Grafc15d9212016-03-04 01:09:59 +0100100 gd = efi_gd;
Simon Glasscdfe6962016-09-25 15:27:35 -0600101#endif
Alexander Grafc15d9212016-03-04 01:09:59 +0100102}
103
Rob Clarke7896c32017-07-27 08:04:19 -0400104/*
105 * Two spaces per indent level, maxing out at 10.. which ought to be
106 * enough for anyone ;-)
107 */
108static const char *indent_string(int level)
109{
110 const char *indent = " ";
111 const int max = strlen(indent);
112 level = min(max, level * 2);
113 return &indent[max - level];
114}
115
Heinrich Schuchardt4d664892017-08-18 17:45:16 +0200116const char *__efi_nesting(void)
117{
118 return indent_string(nesting_level);
119}
120
Rob Clarke7896c32017-07-27 08:04:19 -0400121const char *__efi_nesting_inc(void)
122{
123 return indent_string(nesting_level++);
124}
125
126const char *__efi_nesting_dec(void)
127{
128 return indent_string(--nesting_level);
129}
130
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200131/* Low 32 bit */
132#define EFI_LOW32(a) (a & 0xFFFFFFFFULL)
133/* High 32 bit */
134#define EFI_HIGH32(a) (a >> 32)
135
136/*
137 * 64bit division by 10 implemented as multiplication by 1 / 10
138 *
139 * Decimals of one tenth: 0x1 / 0xA = 0x0.19999...
140 */
141#define EFI_TENTH 0x199999999999999A
142static u64 efi_div10(u64 a)
143{
144 u64 prod;
145 u64 rem;
146 u64 ret;
147
148 ret = EFI_HIGH32(a) * EFI_HIGH32(EFI_TENTH);
149 prod = EFI_HIGH32(a) * EFI_LOW32(EFI_TENTH);
150 rem = EFI_LOW32(prod);
151 ret += EFI_HIGH32(prod);
152 prod = EFI_LOW32(a) * EFI_HIGH32(EFI_TENTH);
153 rem += EFI_LOW32(prod);
154 ret += EFI_HIGH32(prod);
155 prod = EFI_LOW32(a) * EFI_LOW32(EFI_TENTH);
156 rem += EFI_HIGH32(prod);
157 ret += EFI_HIGH32(rem);
158 /* Round to nearest integer */
159 if (rem >= (1 << 31))
160 ++ret;
161 return ret;
162}
163
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200164/*
165 * Queue an EFI event.
166 *
167 * This function queues the notification function of the event for future
168 * execution.
169 *
170 * The notification function is called if the task priority level of the
171 * event is higher than the current task priority level.
172 *
173 * For the SignalEvent service see efi_signal_event_ext.
174 *
175 * @event event to signal
176 */
xypron.glpk@gmx.de54c7a8e2017-07-18 20:17:22 +0200177void efi_signal_event(struct efi_event *event)
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200178{
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200179 if (event->notify_function) {
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200180 event->is_queued = true;
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200181 /* Check TPL */
182 if (efi_tpl >= event->notify_tpl)
183 return;
Heinrich Schuchardt91e5b8a2017-09-15 10:06:10 +0200184 EFI_CALL_VOID(event->notify_function(event,
185 event->notify_context));
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200186 }
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200187 event->is_queued = false;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200188}
189
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200190/*
191 * Write a debug message for an EPI API service that is not implemented yet.
192 *
193 * @funcname function that is not yet implemented
194 * @return EFI_UNSUPPORTED
195 */
Alexander Grafc15d9212016-03-04 01:09:59 +0100196static efi_status_t efi_unsupported(const char *funcname)
197{
Alexander Graf62a67482016-06-02 11:38:27 +0200198 debug("EFI: App called into unimplemented function %s\n", funcname);
Alexander Grafc15d9212016-03-04 01:09:59 +0100199 return EFI_EXIT(EFI_UNSUPPORTED);
200}
201
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200202/*
203 * Raise the task priority level.
204 *
205 * This function implements the RaiseTpl service.
206 * See the Unified Extensible Firmware Interface (UEFI) specification
207 * for details.
208 *
209 * @new_tpl new value of the task priority level
210 * @return old value of the task priority level
211 */
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200212static unsigned long EFIAPI efi_raise_tpl(UINTN new_tpl)
Alexander Grafc15d9212016-03-04 01:09:59 +0100213{
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200214 UINTN old_tpl = efi_tpl;
215
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200216 EFI_ENTRY("0x%zx", new_tpl);
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200217
218 if (new_tpl < efi_tpl)
219 debug("WARNING: new_tpl < current_tpl in %s\n", __func__);
220 efi_tpl = new_tpl;
221 if (efi_tpl > TPL_HIGH_LEVEL)
222 efi_tpl = TPL_HIGH_LEVEL;
223
224 EFI_EXIT(EFI_SUCCESS);
225 return old_tpl;
Alexander Grafc15d9212016-03-04 01:09:59 +0100226}
227
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200228/*
229 * Lower the task priority level.
230 *
231 * This function implements the RestoreTpl service.
232 * See the Unified Extensible Firmware Interface (UEFI) specification
233 * for details.
234 *
235 * @old_tpl value of the task priority level to be restored
236 */
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200237static void EFIAPI efi_restore_tpl(UINTN old_tpl)
Alexander Grafc15d9212016-03-04 01:09:59 +0100238{
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200239 EFI_ENTRY("0x%zx", old_tpl);
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200240
241 if (old_tpl > efi_tpl)
242 debug("WARNING: old_tpl > current_tpl in %s\n", __func__);
243 efi_tpl = old_tpl;
244 if (efi_tpl > TPL_HIGH_LEVEL)
245 efi_tpl = TPL_HIGH_LEVEL;
246
247 EFI_EXIT(EFI_SUCCESS);
Alexander Grafc15d9212016-03-04 01:09:59 +0100248}
249
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200250/*
251 * Allocate memory pages.
252 *
253 * This function implements the AllocatePages service.
254 * See the Unified Extensible Firmware Interface (UEFI) specification
255 * for details.
256 *
257 * @type type of allocation to be performed
258 * @memory_type usage type of the allocated memory
259 * @pages number of pages to be allocated
260 * @memory allocated memory
261 * @return status code
262 */
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900263static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
264 unsigned long pages,
265 uint64_t *memory)
Alexander Grafc15d9212016-03-04 01:09:59 +0100266{
267 efi_status_t r;
268
269 EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory);
270 r = efi_allocate_pages(type, memory_type, pages, memory);
271 return EFI_EXIT(r);
272}
273
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200274/*
275 * Free memory pages.
276 *
277 * This function implements the FreePages service.
278 * See the Unified Extensible Firmware Interface (UEFI) specification
279 * for details.
280 *
281 * @memory start of the memory area to be freed
282 * @pages number of pages to be freed
283 * @return status code
284 */
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900285static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
286 unsigned long pages)
Alexander Grafc15d9212016-03-04 01:09:59 +0100287{
288 efi_status_t r;
289
290 EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages);
291 r = efi_free_pages(memory, pages);
292 return EFI_EXIT(r);
293}
294
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200295/*
296 * Get map describing memory usage.
297 *
298 * This function implements the GetMemoryMap service.
299 * See the Unified Extensible Firmware Interface (UEFI) specification
300 * for details.
301 *
302 * @memory_map_size on entry the size, in bytes, of the memory map buffer,
303 * on exit the size of the copied memory map
304 * @memory_map buffer to which the memory map is written
305 * @map_key key for the memory map
306 * @descriptor_size size of an individual memory descriptor
307 * @descriptor_version version number of the memory descriptor structure
308 * @return status code
309 */
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900310static efi_status_t EFIAPI efi_get_memory_map_ext(
311 unsigned long *memory_map_size,
312 struct efi_mem_desc *memory_map,
313 unsigned long *map_key,
314 unsigned long *descriptor_size,
315 uint32_t *descriptor_version)
Alexander Grafc15d9212016-03-04 01:09:59 +0100316{
317 efi_status_t r;
318
319 EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map,
320 map_key, descriptor_size, descriptor_version);
321 r = efi_get_memory_map(memory_map_size, memory_map, map_key,
322 descriptor_size, descriptor_version);
323 return EFI_EXIT(r);
324}
325
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200326/*
327 * Allocate memory from pool.
328 *
329 * This function implements the AllocatePool service.
330 * See the Unified Extensible Firmware Interface (UEFI) specification
331 * for details.
332 *
333 * @pool_type type of the pool from which memory is to be allocated
334 * @size number of bytes to be allocated
335 * @buffer allocated memory
336 * @return status code
337 */
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200338static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
339 unsigned long size,
340 void **buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +0100341{
Alexander Graf1c34fa82016-03-24 01:37:37 +0100342 efi_status_t r;
343
344 EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer);
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200345 r = efi_allocate_pool(pool_type, size, buffer);
Alexander Graf1c34fa82016-03-24 01:37:37 +0100346 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100347}
348
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200349/*
350 * Free memory from pool.
351 *
352 * This function implements the FreePool service.
353 * See the Unified Extensible Firmware Interface (UEFI) specification
354 * for details.
355 *
356 * @buffer start of memory to be freed
357 * @return status code
358 */
Stefan Brüns67b67d92016-10-09 22:17:26 +0200359static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +0100360{
Alexander Graf1c34fa82016-03-24 01:37:37 +0100361 efi_status_t r;
362
363 EFI_ENTRY("%p", buffer);
Stefan Brüns67b67d92016-10-09 22:17:26 +0200364 r = efi_free_pool(buffer);
Alexander Graf1c34fa82016-03-24 01:37:37 +0100365 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100366}
367
Heinrich Schuchardtcd522cb2017-08-27 00:51:09 +0200368static efi_status_t efi_create_handle(void **handle)
369{
370 struct efi_object *obj;
371 efi_status_t r;
372
373 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
374 sizeof(struct efi_object),
375 (void **)&obj);
376 if (r != EFI_SUCCESS)
377 return r;
378 memset(obj, 0, sizeof(struct efi_object));
379 obj->handle = obj;
380 list_add_tail(&obj->link, &efi_obj_list);
381 *handle = obj;
382 return r;
383}
384
Alexander Grafc15d9212016-03-04 01:09:59 +0100385/*
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200386 * Our event capabilities are very limited. Only a small limited
387 * number of events is allowed to coexist.
Alexander Grafc15d9212016-03-04 01:09:59 +0100388 */
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200389static struct efi_event efi_events[16];
Alexander Grafc15d9212016-03-04 01:09:59 +0100390
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200391/*
392 * Create an event.
393 *
394 * This function is used inside U-Boot code to create an event.
395 *
396 * For the API function implementing the CreateEvent service see
397 * efi_create_event_ext.
398 *
399 * @type type of the event to create
400 * @notify_tpl task priority level of the event
401 * @notify_function notification function of the event
402 * @notify_context pointer passed to the notification function
403 * @event created event
404 * @return status code
405 */
xypron.glpk@gmx.de3ecc6bd2017-07-19 19:22:34 +0200406efi_status_t efi_create_event(uint32_t type, UINTN notify_tpl,
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200407 void (EFIAPI *notify_function) (
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200408 struct efi_event *event,
409 void *context),
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200410 void *notify_context, struct efi_event **event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100411{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200412 int i;
413
Jonathan Gray7758b212017-03-12 19:26:07 +1100414 if (event == NULL)
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200415 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100416
417 if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200418 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100419
420 if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
421 notify_function == NULL)
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200422 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100423
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200424 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
425 if (efi_events[i].type)
426 continue;
427 efi_events[i].type = type;
428 efi_events[i].notify_tpl = notify_tpl;
429 efi_events[i].notify_function = notify_function;
430 efi_events[i].notify_context = notify_context;
431 /* Disable timers on bootup */
432 efi_events[i].trigger_next = -1ULL;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200433 efi_events[i].is_queued = false;
434 efi_events[i].is_signaled = false;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200435 *event = &efi_events[i];
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200436 return EFI_SUCCESS;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200437 }
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200438 return EFI_OUT_OF_RESOURCES;
Alexander Grafc15d9212016-03-04 01:09:59 +0100439}
440
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200441/*
442 * Create an event.
443 *
444 * This function implements the CreateEvent service.
445 * See the Unified Extensible Firmware Interface (UEFI) specification
446 * for details.
447 *
448 * @type type of the event to create
449 * @notify_tpl task priority level of the event
450 * @notify_function notification function of the event
451 * @notify_context pointer passed to the notification function
452 * @event created event
453 * @return status code
454 */
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200455static efi_status_t EFIAPI efi_create_event_ext(
xypron.glpk@gmx.de3ecc6bd2017-07-19 19:22:34 +0200456 uint32_t type, UINTN notify_tpl,
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200457 void (EFIAPI *notify_function) (
458 struct efi_event *event,
459 void *context),
460 void *notify_context, struct efi_event **event)
461{
462 EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
463 notify_context);
464 return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
465 notify_context, event));
466}
467
468
Alexander Grafc15d9212016-03-04 01:09:59 +0100469/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200470 * Check if a timer event has occurred or a queued notification function should
471 * be called.
472 *
Alexander Grafc15d9212016-03-04 01:09:59 +0100473 * Our timers have to work without interrupts, so we check whenever keyboard
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200474 * input or disk accesses happen if enough time elapsed for them to fire.
Alexander Grafc15d9212016-03-04 01:09:59 +0100475 */
476void efi_timer_check(void)
477{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200478 int i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100479 u64 now = timer_get_us();
480
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200481 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200482 if (!efi_events[i].type)
483 continue;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200484 if (efi_events[i].is_queued)
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200485 efi_signal_event(&efi_events[i]);
486 if (!(efi_events[i].type & EVT_TIMER) ||
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200487 now < efi_events[i].trigger_next)
488 continue;
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200489 switch (efi_events[i].trigger_type) {
490 case EFI_TIMER_RELATIVE:
491 efi_events[i].trigger_type = EFI_TIMER_STOP;
492 break;
493 case EFI_TIMER_PERIODIC:
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200494 efi_events[i].trigger_next +=
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200495 efi_events[i].trigger_time;
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200496 break;
497 default:
498 continue;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200499 }
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200500 efi_events[i].is_signaled = true;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200501 efi_signal_event(&efi_events[i]);
Alexander Grafc15d9212016-03-04 01:09:59 +0100502 }
Alexander Grafc15d9212016-03-04 01:09:59 +0100503 WATCHDOG_RESET();
504}
505
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200506/*
507 * Set the trigger time for a timer event or stop the event.
508 *
509 * This is the function for internal usage in U-Boot. For the API function
510 * implementing the SetTimer service see efi_set_timer_ext.
511 *
512 * @event event for which the timer is set
513 * @type type of the timer
514 * @trigger_time trigger period in multiples of 100ns
515 * @return status code
516 */
xypron.glpk@gmx.de3ecc6bd2017-07-19 19:22:34 +0200517efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200518 uint64_t trigger_time)
Alexander Grafc15d9212016-03-04 01:09:59 +0100519{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200520 int i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100521
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200522 /*
523 * The parameter defines a multiple of 100ns.
524 * We use multiples of 1000ns. So divide by 10.
525 */
526 trigger_time = efi_div10(trigger_time);
Alexander Grafc15d9212016-03-04 01:09:59 +0100527
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200528 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
529 if (event != &efi_events[i])
530 continue;
Alexander Grafc15d9212016-03-04 01:09:59 +0100531
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200532 if (!(event->type & EVT_TIMER))
533 break;
534 switch (type) {
535 case EFI_TIMER_STOP:
536 event->trigger_next = -1ULL;
537 break;
538 case EFI_TIMER_PERIODIC:
539 case EFI_TIMER_RELATIVE:
540 event->trigger_next =
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200541 timer_get_us() + trigger_time;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200542 break;
543 default:
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200544 return EFI_INVALID_PARAMETER;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200545 }
546 event->trigger_type = type;
547 event->trigger_time = trigger_time;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200548 event->is_signaled = false;
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200549 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +0100550 }
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200551 return EFI_INVALID_PARAMETER;
Alexander Grafc15d9212016-03-04 01:09:59 +0100552}
553
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200554/*
555 * Set the trigger time for a timer event or stop the event.
556 *
557 * This function implements the SetTimer service.
558 * See the Unified Extensible Firmware Interface (UEFI) specification
559 * for details.
560 *
561 * @event event for which the timer is set
562 * @type type of the timer
563 * @trigger_time trigger period in multiples of 100ns
564 * @return status code
565 */
xypron.glpk@gmx.de3ecc6bd2017-07-19 19:22:34 +0200566static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event,
567 enum efi_timer_delay type,
568 uint64_t trigger_time)
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200569{
570 EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
571 return EFI_EXIT(efi_set_timer(event, type, trigger_time));
572}
573
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200574/*
575 * Wait for events to be signaled.
576 *
577 * This function implements the WaitForEvent service.
578 * See the Unified Extensible Firmware Interface (UEFI) specification
579 * for details.
580 *
581 * @num_events number of events to be waited for
582 * @events events to be waited for
583 * @index index of the event that was signaled
584 * @return status code
585 */
Alexander Grafc15d9212016-03-04 01:09:59 +0100586static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events,
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200587 struct efi_event **event,
588 unsigned long *index)
Alexander Grafc15d9212016-03-04 01:09:59 +0100589{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200590 int i, j;
Alexander Grafc15d9212016-03-04 01:09:59 +0100591
592 EFI_ENTRY("%ld, %p, %p", num_events, event, index);
593
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200594 /* Check parameters */
595 if (!num_events || !event)
596 return EFI_EXIT(EFI_INVALID_PARAMETER);
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200597 /* Check TPL */
598 if (efi_tpl != TPL_APPLICATION)
599 return EFI_EXIT(EFI_UNSUPPORTED);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200600 for (i = 0; i < num_events; ++i) {
601 for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
602 if (event[i] == &efi_events[j])
603 goto known_event;
604 }
605 return EFI_EXIT(EFI_INVALID_PARAMETER);
606known_event:
607 if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
608 return EFI_EXIT(EFI_INVALID_PARAMETER);
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200609 if (!event[i]->is_signaled)
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200610 efi_signal_event(event[i]);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200611 }
612
613 /* Wait for signal */
614 for (;;) {
615 for (i = 0; i < num_events; ++i) {
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200616 if (event[i]->is_signaled)
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200617 goto out;
618 }
619 /* Allow events to occur. */
620 efi_timer_check();
621 }
622
623out:
624 /*
625 * Reset the signal which is passed to the caller to allow periodic
626 * events to occur.
627 */
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200628 event[i]->is_signaled = false;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200629 if (index)
630 *index = i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100631
632 return EFI_EXIT(EFI_SUCCESS);
633}
634
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200635/*
636 * Signal an EFI event.
637 *
638 * This function implements the SignalEvent service.
639 * See the Unified Extensible Firmware Interface (UEFI) specification
640 * for details.
641 *
642 * This functions sets the signaled state of the event and queues the
643 * notification function for execution.
644 *
645 * @event event to signal
646 */
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200647static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100648{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200649 int i;
650
Alexander Grafc15d9212016-03-04 01:09:59 +0100651 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200652 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
653 if (event != &efi_events[i])
654 continue;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200655 if (event->is_signaled)
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200656 break;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200657 event->is_signaled = true;
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200658 if (event->type & EVT_NOTIFY_SIGNAL)
659 efi_signal_event(event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200660 break;
661 }
Alexander Grafc15d9212016-03-04 01:09:59 +0100662 return EFI_EXIT(EFI_SUCCESS);
663}
664
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200665/*
666 * Close an EFI event.
667 *
668 * This function implements the CloseEvent service.
669 * See the Unified Extensible Firmware Interface (UEFI) specification
670 * for details.
671 *
672 * @event event to close
673 * @return status code
674 */
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200675static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100676{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200677 int i;
678
Alexander Grafc15d9212016-03-04 01:09:59 +0100679 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200680 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
681 if (event == &efi_events[i]) {
682 event->type = 0;
683 event->trigger_next = -1ULL;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200684 event->is_queued = false;
685 event->is_signaled = false;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200686 return EFI_EXIT(EFI_SUCCESS);
687 }
688 }
689 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafc15d9212016-03-04 01:09:59 +0100690}
691
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200692/*
693 * Check if an event is signaled.
694 *
695 * This function implements the CheckEvent service.
696 * See the Unified Extensible Firmware Interface (UEFI) specification
697 * for details.
698 *
699 * If an event is not signaled yet the notification function is queued.
700 *
701 * @event event to check
702 * @return status code
703 */
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200704static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100705{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200706 int i;
707
Alexander Grafc15d9212016-03-04 01:09:59 +0100708 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200709 efi_timer_check();
710 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
711 if (event != &efi_events[i])
712 continue;
713 if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
714 break;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200715 if (!event->is_signaled)
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200716 efi_signal_event(event);
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200717 if (event->is_signaled)
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200718 return EFI_EXIT(EFI_SUCCESS);
719 return EFI_EXIT(EFI_NOT_READY);
720 }
721 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafc15d9212016-03-04 01:09:59 +0100722}
723
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200724/*
725 * Install protocol interface.
726 *
727 * This is the function for internal calls. For the API implementation of the
728 * InstallProtocolInterface service see function
729 * efi_install_protocol_interface_ext.
730 *
731 * @handle handle on which the protocol shall be installed
732 * @protocol GUID of the protocol to be installed
733 * @protocol_interface_type type of the interface to be installed,
734 * always EFI_NATIVE_INTERFACE
735 * @protocol_interface interface of the protocol implementation
736 * @return status code
737 */
Alexander Grafc15d9212016-03-04 01:09:59 +0100738static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
739 efi_guid_t *protocol, int protocol_interface_type,
740 void *protocol_interface)
741{
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200742 struct list_head *lhandle;
743 int i;
744 efi_status_t r;
745
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200746 if (!handle || !protocol ||
747 protocol_interface_type != EFI_NATIVE_INTERFACE) {
748 r = EFI_INVALID_PARAMETER;
749 goto out;
750 }
751
752 /* Create new handle if requested. */
753 if (!*handle) {
Heinrich Schuchardtcd522cb2017-08-27 00:51:09 +0200754 r = efi_create_handle(handle);
755 if (r != EFI_SUCCESS)
756 goto out;
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200757 }
758 /* Find object. */
759 list_for_each(lhandle, &efi_obj_list) {
760 struct efi_object *efiobj;
761 efiobj = list_entry(lhandle, struct efi_object, link);
762
763 if (efiobj->handle != *handle)
764 continue;
765 /* Check if protocol is already installed on the handle. */
766 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
767 struct efi_handler *handler = &efiobj->protocols[i];
768
769 if (!handler->guid)
770 continue;
771 if (!guidcmp(handler->guid, protocol)) {
772 r = EFI_INVALID_PARAMETER;
773 goto out;
774 }
775 }
776 /* Install protocol in first empty slot. */
777 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
778 struct efi_handler *handler = &efiobj->protocols[i];
779
780 if (handler->guid)
781 continue;
782
783 handler->guid = protocol;
784 handler->protocol_interface = protocol_interface;
785 r = EFI_SUCCESS;
786 goto out;
787 }
788 r = EFI_OUT_OF_RESOURCES;
789 goto out;
790 }
791 r = EFI_INVALID_PARAMETER;
792out:
xypron.glpk@gmx.de8b7b5df2017-07-11 22:06:18 +0200793 return r;
794}
795
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200796/*
797 * Install protocol interface.
798 *
799 * This function implements the InstallProtocolInterface service.
800 * See the Unified Extensible Firmware Interface (UEFI) specification
801 * for details.
802 *
803 * @handle handle on which the protocol shall be installed
804 * @protocol GUID of the protocol to be installed
805 * @protocol_interface_type type of the interface to be installed,
806 * always EFI_NATIVE_INTERFACE
807 * @protocol_interface interface of the protocol implementation
808 * @return status code
809 */
xypron.glpk@gmx.de8b7b5df2017-07-11 22:06:18 +0200810static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
811 efi_guid_t *protocol, int protocol_interface_type,
812 void *protocol_interface)
813{
Rob Clark238f88c2017-09-13 18:05:41 -0400814 EFI_ENTRY("%p, %pUl, %d, %p", handle, protocol, protocol_interface_type,
xypron.glpk@gmx.de8b7b5df2017-07-11 22:06:18 +0200815 protocol_interface);
816
817 return EFI_EXIT(efi_install_protocol_interface(handle, protocol,
818 protocol_interface_type,
819 protocol_interface));
Alexander Grafc15d9212016-03-04 01:09:59 +0100820}
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200821
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200822/*
823 * Reinstall protocol interface.
824 *
825 * This function implements the ReinstallProtocolInterface service.
826 * See the Unified Extensible Firmware Interface (UEFI) specification
827 * for details.
828 *
829 * @handle handle on which the protocol shall be
830 * reinstalled
831 * @protocol GUID of the protocol to be installed
832 * @old_interface interface to be removed
833 * @new_interface interface to be installed
834 * @return status code
835 */
Alexander Grafc15d9212016-03-04 01:09:59 +0100836static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
837 efi_guid_t *protocol, void *old_interface,
838 void *new_interface)
839{
Rob Clark238f88c2017-09-13 18:05:41 -0400840 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, old_interface,
Alexander Grafc15d9212016-03-04 01:09:59 +0100841 new_interface);
842 return EFI_EXIT(EFI_ACCESS_DENIED);
843}
844
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200845/*
846 * Uninstall protocol interface.
847 *
848 * This is the function for internal calls. For the API implementation of the
849 * UninstallProtocolInterface service see function
850 * efi_uninstall_protocol_interface_ext.
851 *
852 * @handle handle from which the protocol shall be removed
853 * @protocol GUID of the protocol to be removed
854 * @protocol_interface interface to be removed
855 * @return status code
856 */
Alexander Grafc15d9212016-03-04 01:09:59 +0100857static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
858 efi_guid_t *protocol, void *protocol_interface)
859{
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +0200860 struct list_head *lhandle;
861 int i;
862 efi_status_t r = EFI_NOT_FOUND;
863
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +0200864 if (!handle || !protocol) {
865 r = EFI_INVALID_PARAMETER;
866 goto out;
867 }
868
869 list_for_each(lhandle, &efi_obj_list) {
870 struct efi_object *efiobj;
871 efiobj = list_entry(lhandle, struct efi_object, link);
872
873 if (efiobj->handle != handle)
874 continue;
875
876 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
877 struct efi_handler *handler = &efiobj->protocols[i];
878 const efi_guid_t *hprotocol = handler->guid;
879
880 if (!hprotocol)
881 continue;
882 if (!guidcmp(hprotocol, protocol)) {
883 if (handler->protocol_interface) {
884 r = EFI_ACCESS_DENIED;
885 } else {
886 handler->guid = 0;
887 r = EFI_SUCCESS;
888 }
889 goto out;
890 }
891 }
892 }
893
894out:
xypron.glpk@gmx.dea453e462017-07-11 22:06:19 +0200895 return r;
896}
897
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200898/*
899 * Uninstall protocol interface.
900 *
901 * This function implements the UninstallProtocolInterface service.
902 * See the Unified Extensible Firmware Interface (UEFI) specification
903 * for details.
904 *
905 * @handle handle from which the protocol shall be removed
906 * @protocol GUID of the protocol to be removed
907 * @protocol_interface interface to be removed
908 * @return status code
909 */
xypron.glpk@gmx.dea453e462017-07-11 22:06:19 +0200910static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle,
911 efi_guid_t *protocol, void *protocol_interface)
912{
Rob Clark238f88c2017-09-13 18:05:41 -0400913 EFI_ENTRY("%p, %pUl, %p", handle, protocol, protocol_interface);
xypron.glpk@gmx.dea453e462017-07-11 22:06:19 +0200914
915 return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol,
916 protocol_interface));
Alexander Grafc15d9212016-03-04 01:09:59 +0100917}
918
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200919/*
920 * Register an event for notification when a protocol is installed.
921 *
922 * This function implements the RegisterProtocolNotify service.
923 * See the Unified Extensible Firmware Interface (UEFI) specification
924 * for details.
925 *
926 * @protocol GUID of the protocol whose installation shall be
927 * notified
928 * @event event to be signaled upon installation of the protocol
929 * @registration key for retrieving the registration information
930 * @return status code
931 */
Alexander Grafc15d9212016-03-04 01:09:59 +0100932static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol,
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200933 struct efi_event *event,
Alexander Grafc15d9212016-03-04 01:09:59 +0100934 void **registration)
935{
Rob Clark238f88c2017-09-13 18:05:41 -0400936 EFI_ENTRY("%pUl, %p, %p", protocol, event, registration);
Alexander Grafc15d9212016-03-04 01:09:59 +0100937 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
938}
939
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200940/*
941 * Determine if an EFI handle implements a protocol.
942 *
943 * See the documentation of the LocateHandle service in the UEFI specification.
944 *
945 * @search_type selection criterion
946 * @protocol GUID of the protocol
947 * @search_key registration key
948 * @efiobj handle
949 * @return 0 if the handle implements the protocol
950 */
Alexander Grafc15d9212016-03-04 01:09:59 +0100951static int efi_search(enum efi_locate_search_type search_type,
952 efi_guid_t *protocol, void *search_key,
953 struct efi_object *efiobj)
954{
955 int i;
956
957 switch (search_type) {
958 case all_handles:
959 return 0;
960 case by_register_notify:
961 return -1;
962 case by_protocol:
963 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
964 const efi_guid_t *guid = efiobj->protocols[i].guid;
965 if (guid && !guidcmp(guid, protocol))
966 return 0;
967 }
968 return -1;
969 }
970
971 return -1;
972}
973
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200974/*
975 * Locate handles implementing a protocol.
976 *
977 * This function is meant for U-Boot internal calls. For the API implementation
978 * of the LocateHandle service see efi_locate_handle_ext.
979 *
980 * @search_type selection criterion
981 * @protocol GUID of the protocol
982 * @search_key registration key
983 * @buffer_size size of the buffer to receive the handles in bytes
984 * @buffer buffer to receive the relevant handles
985 * @return status code
986 */
xypron.glpk@gmx.decab4dd52017-08-09 20:55:00 +0200987static efi_status_t efi_locate_handle(
Alexander Grafc15d9212016-03-04 01:09:59 +0100988 enum efi_locate_search_type search_type,
989 efi_guid_t *protocol, void *search_key,
990 unsigned long *buffer_size, efi_handle_t *buffer)
991{
992 struct list_head *lhandle;
993 unsigned long size = 0;
994
Alexander Grafc15d9212016-03-04 01:09:59 +0100995 /* Count how much space we need */
996 list_for_each(lhandle, &efi_obj_list) {
997 struct efi_object *efiobj;
998 efiobj = list_entry(lhandle, struct efi_object, link);
999 if (!efi_search(search_type, protocol, search_key, efiobj)) {
1000 size += sizeof(void*);
1001 }
1002 }
1003
1004 if (*buffer_size < size) {
1005 *buffer_size = size;
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001006 return EFI_BUFFER_TOO_SMALL;
Alexander Grafc15d9212016-03-04 01:09:59 +01001007 }
1008
Rob Clarkcdee3372017-08-06 14:10:07 -04001009 *buffer_size = size;
1010 if (size == 0)
1011 return EFI_NOT_FOUND;
1012
Alexander Grafc15d9212016-03-04 01:09:59 +01001013 /* Then fill the array */
1014 list_for_each(lhandle, &efi_obj_list) {
1015 struct efi_object *efiobj;
1016 efiobj = list_entry(lhandle, struct efi_object, link);
1017 if (!efi_search(search_type, protocol, search_key, efiobj)) {
1018 *(buffer++) = efiobj->handle;
1019 }
1020 }
1021
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001022 return EFI_SUCCESS;
1023}
1024
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001025/*
1026 * Locate handles implementing a protocol.
1027 *
1028 * This function implements the LocateHandle service.
1029 * See the Unified Extensible Firmware Interface (UEFI) specification
1030 * for details.
1031 *
1032 * @search_type selection criterion
1033 * @protocol GUID of the protocol
1034 * @search_key registration key
1035 * @buffer_size size of the buffer to receive the handles in bytes
1036 * @buffer buffer to receive the relevant handles
1037 * @return 0 if the handle implements the protocol
1038 */
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001039static efi_status_t EFIAPI efi_locate_handle_ext(
1040 enum efi_locate_search_type search_type,
1041 efi_guid_t *protocol, void *search_key,
1042 unsigned long *buffer_size, efi_handle_t *buffer)
1043{
Rob Clark238f88c2017-09-13 18:05:41 -04001044 EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001045 buffer_size, buffer);
1046
1047 return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
1048 buffer_size, buffer));
Alexander Grafc15d9212016-03-04 01:09:59 +01001049}
1050
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001051/*
1052 * Get the device path and handle of an device implementing a protocol.
1053 *
1054 * This function implements the LocateDevicePath service.
1055 * See the Unified Extensible Firmware Interface (UEFI) specification
1056 * for details.
1057 *
1058 * @protocol GUID of the protocol
1059 * @device_path device path
1060 * @device handle of the device
1061 * @return status code
1062 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001063static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol,
1064 struct efi_device_path **device_path,
1065 efi_handle_t *device)
1066{
Rob Clarkf90cb9f2017-09-13 18:05:28 -04001067 struct efi_object *efiobj;
1068
1069 EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device);
1070
1071 efiobj = efi_dp_find_obj(*device_path, device_path);
1072 if (!efiobj)
1073 return EFI_EXIT(EFI_NOT_FOUND);
1074
1075 *device = efiobj->handle;
1076
1077 return EFI_EXIT(EFI_SUCCESS);
Alexander Grafc15d9212016-03-04 01:09:59 +01001078}
1079
Alexander Graffe3366f2017-07-26 13:41:04 +02001080/* Collapses configuration table entries, removing index i */
1081static void efi_remove_configuration_table(int i)
1082{
1083 struct efi_configuration_table *this = &efi_conf_table[i];
1084 struct efi_configuration_table *next = &efi_conf_table[i+1];
1085 struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables];
1086
1087 memmove(this, next, (ulong)end - (ulong)next);
1088 systab.nr_tables--;
1089}
1090
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001091/*
1092 * Adds, updates, or removes a configuration table.
1093 *
1094 * This function is used for internal calls. For the API implementation of the
1095 * InstallConfigurationTable service see efi_install_configuration_table_ext.
1096 *
1097 * @guid GUID of the installed table
1098 * @table table to be installed
1099 * @return status code
1100 */
Alexander Grafc5c11632016-08-19 01:23:24 +02001101efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
Alexander Grafc15d9212016-03-04 01:09:59 +01001102{
1103 int i;
1104
Alexander Grafc15d9212016-03-04 01:09:59 +01001105 /* Check for guid override */
1106 for (i = 0; i < systab.nr_tables; i++) {
1107 if (!guidcmp(guid, &efi_conf_table[i].guid)) {
Alexander Graffe3366f2017-07-26 13:41:04 +02001108 if (table)
1109 efi_conf_table[i].table = table;
1110 else
1111 efi_remove_configuration_table(i);
Alexander Grafc5c11632016-08-19 01:23:24 +02001112 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +01001113 }
1114 }
1115
Alexander Graffe3366f2017-07-26 13:41:04 +02001116 if (!table)
1117 return EFI_NOT_FOUND;
1118
Alexander Grafc15d9212016-03-04 01:09:59 +01001119 /* No override, check for overflow */
1120 if (i >= ARRAY_SIZE(efi_conf_table))
Alexander Grafc5c11632016-08-19 01:23:24 +02001121 return EFI_OUT_OF_RESOURCES;
Alexander Grafc15d9212016-03-04 01:09:59 +01001122
1123 /* Add a new entry */
1124 memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
1125 efi_conf_table[i].table = table;
Alexander Graf9982e672016-08-19 01:23:30 +02001126 systab.nr_tables = i + 1;
Alexander Grafc15d9212016-03-04 01:09:59 +01001127
Alexander Grafc5c11632016-08-19 01:23:24 +02001128 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +01001129}
1130
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001131/*
1132 * Adds, updates, or removes a configuration table.
1133 *
1134 * This function implements the InstallConfigurationTable service.
1135 * See the Unified Extensible Firmware Interface (UEFI) specification
1136 * for details.
1137 *
1138 * @guid GUID of the installed table
1139 * @table table to be installed
1140 * @return status code
1141 */
Alexander Grafc5c11632016-08-19 01:23:24 +02001142static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
1143 void *table)
1144{
Rob Clark238f88c2017-09-13 18:05:41 -04001145 EFI_ENTRY("%pUl, %p", guid, table);
Alexander Grafc5c11632016-08-19 01:23:24 +02001146 return EFI_EXIT(efi_install_configuration_table(guid, table));
1147}
1148
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001149/*
1150 * Initialize a loaded_image_info + loaded_image_info object with correct
Rob Clarkf8db9222017-09-13 18:05:33 -04001151 * protocols, boot-device, etc.
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001152 *
1153 * @info loaded image info to be passed to the enty point of the
1154 * image
1155 * @obj internal object associated with the loaded image
1156 * @device_path device path of the loaded image
1157 * @file_path file path of the loaded image
Rob Clarkf8db9222017-09-13 18:05:33 -04001158 */
1159void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *obj,
1160 struct efi_device_path *device_path,
1161 struct efi_device_path *file_path)
1162{
1163 obj->handle = info;
1164
1165 /*
1166 * When asking for the device path interface, return
1167 * bootefi_device_path
1168 */
1169 obj->protocols[0].guid = &efi_guid_device_path;
1170 obj->protocols[0].protocol_interface = device_path;
1171
1172 /*
1173 * When asking for the loaded_image interface, just
1174 * return handle which points to loaded_image_info
1175 */
1176 obj->protocols[1].guid = &efi_guid_loaded_image;
1177 obj->protocols[1].protocol_interface = info;
1178
1179 obj->protocols[2].guid = &efi_guid_console_control;
1180 obj->protocols[2].protocol_interface = (void *)&efi_console_control;
1181
1182 obj->protocols[3].guid = &efi_guid_device_path_to_text_protocol;
1183 obj->protocols[3].protocol_interface =
1184 (void *)&efi_device_path_to_text;
1185
1186 info->file_path = file_path;
1187 info->device_handle = efi_dp_find_obj(device_path, NULL);
1188
1189 list_add_tail(&obj->link, &efi_obj_list);
1190}
1191
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001192/*
1193 * Load an image using a file path.
1194 *
1195 * @file_path the path of the image to load
1196 * @buffer buffer containing the loaded image
1197 */
Rob Clarkc84c1102017-09-13 18:05:38 -04001198efi_status_t efi_load_image_from_path(struct efi_device_path *file_path,
1199 void **buffer)
Rob Clark857a1222017-09-13 18:05:35 -04001200{
1201 struct efi_file_info *info = NULL;
1202 struct efi_file_handle *f;
1203 static efi_status_t ret;
1204 uint64_t bs;
1205
1206 f = efi_file_from_path(file_path);
1207 if (!f)
1208 return EFI_DEVICE_ERROR;
1209
1210 bs = 0;
1211 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1212 &bs, info));
1213 if (ret == EFI_BUFFER_TOO_SMALL) {
1214 info = malloc(bs);
1215 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1216 &bs, info));
1217 }
1218 if (ret != EFI_SUCCESS)
1219 goto error;
1220
1221 ret = efi_allocate_pool(EFI_LOADER_DATA, info->file_size, buffer);
1222 if (ret)
1223 goto error;
1224
1225 EFI_CALL(ret = f->read(f, &info->file_size, *buffer));
1226
1227error:
1228 free(info);
1229 EFI_CALL(f->close(f));
1230
1231 if (ret != EFI_SUCCESS) {
1232 efi_free_pool(*buffer);
1233 *buffer = NULL;
1234 }
1235
1236 return ret;
1237}
1238
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001239/*
1240 * Load an EFI image into memory.
1241 *
1242 * This function implements the LoadImage service.
1243 * See the Unified Extensible Firmware Interface (UEFI) specification
1244 * for details.
1245 *
1246 * @boot_policy true for request originating from the boot manager
1247 * @parent_image the calles's image handle
1248 * @file_path the path of the image to load
1249 * @source_buffer memory location from which the image is installed
1250 * @source_size size of the memory area from which the image is
1251 * installed
1252 * @image_handle handle for the newly installed image
1253 * @return status code
1254 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001255static efi_status_t EFIAPI efi_load_image(bool boot_policy,
1256 efi_handle_t parent_image,
1257 struct efi_device_path *file_path,
1258 void *source_buffer,
1259 unsigned long source_size,
1260 efi_handle_t *image_handle)
1261{
Alexander Grafc15d9212016-03-04 01:09:59 +01001262 struct efi_loaded_image *info;
1263 struct efi_object *obj;
1264
1265 EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
1266 file_path, source_buffer, source_size, image_handle);
Rob Clark857a1222017-09-13 18:05:35 -04001267
1268 info = calloc(1, sizeof(*info));
1269 obj = calloc(1, sizeof(*obj));
1270
1271 if (!source_buffer) {
1272 struct efi_device_path *dp, *fp;
1273 efi_status_t ret;
1274
Rob Clarkc84c1102017-09-13 18:05:38 -04001275 ret = efi_load_image_from_path(file_path, &source_buffer);
Rob Clark857a1222017-09-13 18:05:35 -04001276 if (ret != EFI_SUCCESS) {
1277 free(info);
1278 free(obj);
1279 return EFI_EXIT(ret);
1280 }
1281
1282 /*
1283 * split file_path which contains both the device and
1284 * file parts:
1285 */
1286 efi_dp_split_file_path(file_path, &dp, &fp);
1287
1288 efi_setup_loaded_image(info, obj, dp, fp);
1289 } else {
1290 /* In this case, file_path is the "device" path, ie.
1291 * something like a HARDWARE_DEVICE:MEMORY_MAPPED
1292 */
1293 efi_setup_loaded_image(info, obj, file_path, NULL);
1294 }
1295
Alexander Grafc15d9212016-03-04 01:09:59 +01001296 info->reserved = efi_load_pe(source_buffer, info);
1297 if (!info->reserved) {
1298 free(info);
1299 free(obj);
1300 return EFI_EXIT(EFI_UNSUPPORTED);
1301 }
1302
1303 *image_handle = info;
Alexander Grafc15d9212016-03-04 01:09:59 +01001304
1305 return EFI_EXIT(EFI_SUCCESS);
1306}
1307
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001308/*
1309 * Call the entry point of an image.
1310 *
1311 * This function implements the StartImage service.
1312 * See the Unified Extensible Firmware Interface (UEFI) specification
1313 * for details.
1314 *
1315 * @image_handle handle of the image
1316 * @exit_data_size size of the buffer
1317 * @exit_data buffer to receive the exit data of the called image
1318 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001319static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
1320 unsigned long *exit_data_size,
1321 s16 **exit_data)
1322{
1323 ulong (*entry)(void *image_handle, struct efi_system_table *st);
1324 struct efi_loaded_image *info = image_handle;
1325
1326 EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
1327 entry = info->reserved;
1328
1329 efi_is_direct_boot = false;
1330
1331 /* call the image! */
Alexander Graf988c0662016-05-20 23:28:23 +02001332 if (setjmp(&info->exit_jmp)) {
1333 /* We returned from the child image */
1334 return EFI_EXIT(info->exit_status);
1335 }
1336
Rob Clarke7896c32017-07-27 08:04:19 -04001337 __efi_nesting_dec();
Rob Clark86789d52017-07-27 08:04:18 -04001338 __efi_exit_check();
Alexander Grafc15d9212016-03-04 01:09:59 +01001339 entry(image_handle, &systab);
Rob Clark86789d52017-07-27 08:04:18 -04001340 __efi_entry_check();
Rob Clarke7896c32017-07-27 08:04:19 -04001341 __efi_nesting_inc();
Alexander Grafc15d9212016-03-04 01:09:59 +01001342
1343 /* Should usually never get here */
1344 return EFI_EXIT(EFI_SUCCESS);
1345}
1346
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001347/*
1348 * Leave an EFI application or driver.
1349 *
1350 * This function implements the Exit service.
1351 * See the Unified Extensible Firmware Interface (UEFI) specification
1352 * for details.
1353 *
1354 * @image_handle handle of the application or driver that is exiting
1355 * @exit_status status code
1356 * @exit_data_size size of the buffer in bytes
1357 * @exit_data buffer with data describing an error
1358 */
Alexander Graf988c0662016-05-20 23:28:23 +02001359static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
1360 efi_status_t exit_status, unsigned long exit_data_size,
1361 int16_t *exit_data)
Alexander Grafc15d9212016-03-04 01:09:59 +01001362{
Alexander Graf988c0662016-05-20 23:28:23 +02001363 struct efi_loaded_image *loaded_image_info = (void*)image_handle;
1364
Alexander Grafc15d9212016-03-04 01:09:59 +01001365 EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
1366 exit_data_size, exit_data);
Alexander Graf988c0662016-05-20 23:28:23 +02001367
Alexander Graf87e787a2017-09-03 14:14:17 +02001368 /* Make sure entry/exit counts for EFI world cross-overs match */
Heinrich Schuchardt4a4c6462017-08-25 19:53:14 +02001369 __efi_exit_check();
1370
Alexander Graf87e787a2017-09-03 14:14:17 +02001371 /*
1372 * But longjmp out with the U-Boot gd, not the application's, as
1373 * the other end is a setjmp call inside EFI context.
1374 */
1375 efi_restore_gd();
1376
Alexander Graf988c0662016-05-20 23:28:23 +02001377 loaded_image_info->exit_status = exit_status;
Alexander Graf9d006b72016-09-27 09:30:32 +02001378 longjmp(&loaded_image_info->exit_jmp, 1);
Alexander Graf988c0662016-05-20 23:28:23 +02001379
1380 panic("EFI application exited");
Alexander Grafc15d9212016-03-04 01:09:59 +01001381}
1382
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001383/*
1384 * Find the internal EFI object for a handle.
1385 *
1386 * @handle handle to find
1387 * @return EFI object
1388 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001389static struct efi_object *efi_search_obj(void *handle)
1390{
1391 struct list_head *lhandle;
1392
1393 list_for_each(lhandle, &efi_obj_list) {
1394 struct efi_object *efiobj;
1395 efiobj = list_entry(lhandle, struct efi_object, link);
1396 if (efiobj->handle == handle)
1397 return efiobj;
1398 }
1399
1400 return NULL;
1401}
1402
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001403/*
1404 * Unload an EFI image.
1405 *
1406 * This function implements the UnloadImage service.
1407 * See the Unified Extensible Firmware Interface (UEFI) specification
1408 * for details.
1409 *
1410 * @image_handle handle of the image to be unloaded
1411 * @return status code
1412 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001413static efi_status_t EFIAPI efi_unload_image(void *image_handle)
1414{
1415 struct efi_object *efiobj;
1416
1417 EFI_ENTRY("%p", image_handle);
1418 efiobj = efi_search_obj(image_handle);
1419 if (efiobj)
1420 list_del(&efiobj->link);
1421
1422 return EFI_EXIT(EFI_SUCCESS);
1423}
1424
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001425/*
1426 * Fix up caches for EFI payloads if necessary.
1427 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001428static void efi_exit_caches(void)
1429{
1430#if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
1431 /*
1432 * Grub on 32bit ARM needs to have caches disabled before jumping into
1433 * a zImage, but does not know of all cache layers. Give it a hand.
1434 */
1435 if (efi_is_direct_boot)
1436 cleanup_before_linux();
1437#endif
1438}
1439
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001440/*
1441 * Stop boot services.
1442 *
1443 * This function implements the ExitBootServices service.
1444 * See the Unified Extensible Firmware Interface (UEFI) specification
1445 * for details.
1446 *
1447 * @image_handle handle of the loaded image
1448 * @map_key key of the memory map
1449 * @return status code
1450 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001451static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
1452 unsigned long map_key)
1453{
Heinrich Schuchardt2d4c7382017-09-15 10:06:18 +02001454 int i;
1455
Alexander Grafc15d9212016-03-04 01:09:59 +01001456 EFI_ENTRY("%p, %ld", image_handle, map_key);
1457
Heinrich Schuchardt2d4c7382017-09-15 10:06:18 +02001458 /* Notify that ExitBootServices is invoked. */
1459 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
1460 if (efi_events[i].type != EVT_SIGNAL_EXIT_BOOT_SERVICES)
1461 continue;
1462 efi_signal_event(&efi_events[i]);
1463 }
1464 /* Make sure that notification functions are not called anymore */
1465 efi_tpl = TPL_HIGH_LEVEL;
1466
Rob Clark15f3d742017-09-13 18:05:37 -04001467#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1468 /* save any EFI variables that have been written: */
1469 env_save();
1470#endif
1471
Alexander Graf2ebeb442016-11-17 01:02:57 +01001472 board_quiesce_devices();
1473
Alexander Grafc15d9212016-03-04 01:09:59 +01001474 /* Fix up caches for EFI payloads if necessary */
1475 efi_exit_caches();
1476
1477 /* This stops all lingering devices */
1478 bootm_disable_interrupts();
1479
1480 /* Give the payload some time to boot */
1481 WATCHDOG_RESET();
1482
1483 return EFI_EXIT(EFI_SUCCESS);
1484}
1485
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001486/*
1487 * Get next value of the counter.
1488 *
1489 * This function implements the NextMonotonicCount service.
1490 * See the Unified Extensible Firmware Interface (UEFI) specification
1491 * for details.
1492 *
1493 * @count returned value of the counter
1494 * @return status code
1495 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001496static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
1497{
1498 static uint64_t mono = 0;
1499 EFI_ENTRY("%p", count);
1500 *count = mono++;
1501 return EFI_EXIT(EFI_SUCCESS);
1502}
1503
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001504/*
1505 * Sleep.
1506 *
1507 * This function implements the Stall sercive.
1508 * See the Unified Extensible Firmware Interface (UEFI) specification
1509 * for details.
1510 *
1511 * @microseconds period to sleep in microseconds
1512 * @return status code
1513 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001514static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
1515{
1516 EFI_ENTRY("%ld", microseconds);
1517 udelay(microseconds);
1518 return EFI_EXIT(EFI_SUCCESS);
1519}
1520
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001521/*
1522 * Reset the watchdog timer.
1523 *
1524 * This function implements the WatchdogTimer service.
1525 * See the Unified Extensible Firmware Interface (UEFI) specification
1526 * for details.
1527 *
1528 * @timeout seconds before reset by watchdog
1529 * @watchdog_code code to be logged when resetting
1530 * @data_size size of buffer in bytes
1531 * @watchdog_data buffer with data describing the reset reason
1532 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001533static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
1534 uint64_t watchdog_code,
1535 unsigned long data_size,
1536 uint16_t *watchdog_data)
1537{
1538 EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
1539 data_size, watchdog_data);
Rob Clarkd417d2b2017-07-25 20:17:59 -04001540 return efi_unsupported(__func__);
Alexander Grafc15d9212016-03-04 01:09:59 +01001541}
1542
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001543/*
1544 * Connect a controller to a driver.
1545 *
1546 * This function implements the ConnectController service.
1547 * See the Unified Extensible Firmware Interface (UEFI) specification
1548 * for details.
1549 *
1550 * @controller_handle handle of the controller
1551 * @driver_image_handle handle of the driver
1552 * @remain_device_path device path of a child controller
1553 * @recursive true to connect all child controllers
1554 * @return status code
1555 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001556static efi_status_t EFIAPI efi_connect_controller(
1557 efi_handle_t controller_handle,
1558 efi_handle_t *driver_image_handle,
1559 struct efi_device_path *remain_device_path,
1560 bool recursive)
1561{
1562 EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
1563 remain_device_path, recursive);
1564 return EFI_EXIT(EFI_NOT_FOUND);
1565}
1566
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001567/*
1568 * Disconnect a controller from a driver.
1569 *
1570 * This function implements the DisconnectController service.
1571 * See the Unified Extensible Firmware Interface (UEFI) specification
1572 * for details.
1573 *
1574 * @controller_handle handle of the controller
1575 * @driver_image_handle handle of the driver
1576 * @child_handle handle of the child to destroy
1577 * @return status code
1578 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001579static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
1580 void *driver_image_handle,
1581 void *child_handle)
1582{
1583 EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
1584 child_handle);
1585 return EFI_EXIT(EFI_INVALID_PARAMETER);
1586}
1587
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001588/*
1589 * Close a protocol.
1590 *
1591 * This function implements the CloseProtocol service.
1592 * See the Unified Extensible Firmware Interface (UEFI) specification
1593 * for details.
1594 *
1595 * @handle handle on which the protocol shall be closed
1596 * @protocol GUID of the protocol to close
1597 * @agent_handle handle of the driver
1598 * @controller_handle handle of the controller
1599 * @return status code
1600 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001601static efi_status_t EFIAPI efi_close_protocol(void *handle,
1602 efi_guid_t *protocol,
1603 void *agent_handle,
1604 void *controller_handle)
1605{
Rob Clark238f88c2017-09-13 18:05:41 -04001606 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, agent_handle,
Alexander Grafc15d9212016-03-04 01:09:59 +01001607 controller_handle);
1608 return EFI_EXIT(EFI_NOT_FOUND);
1609}
1610
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001611/*
1612 * Provide information about then open status of a protocol on a handle
1613 *
1614 * This function implements the OpenProtocolInformation service.
1615 * See the Unified Extensible Firmware Interface (UEFI) specification
1616 * for details.
1617 *
1618 * @handle handle for which the information shall be retrieved
1619 * @protocol GUID of the protocol
1620 * @entry_buffer buffer to receive the open protocol information
1621 * @entry_count number of entries available in the buffer
1622 * @return status code
1623 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001624static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
1625 efi_guid_t *protocol,
1626 struct efi_open_protocol_info_entry **entry_buffer,
1627 unsigned long *entry_count)
1628{
Rob Clark238f88c2017-09-13 18:05:41 -04001629 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, entry_buffer,
Alexander Grafc15d9212016-03-04 01:09:59 +01001630 entry_count);
1631 return EFI_EXIT(EFI_NOT_FOUND);
1632}
1633
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001634/*
1635 * Get protocols installed on a handle.
1636 *
1637 * This function implements the ProtocolsPerHandleService.
1638 * See the Unified Extensible Firmware Interface (UEFI) specification
1639 * for details.
1640 *
1641 * @handle handle for which the information is retrieved
1642 * @protocol_buffer buffer with protocol GUIDs
1643 * @protocol_buffer_count number of entries in the buffer
1644 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001645static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
1646 efi_guid_t ***protocol_buffer,
1647 unsigned long *protocol_buffer_count)
1648{
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001649 unsigned long buffer_size;
1650 struct efi_object *efiobj;
1651 unsigned long i, j;
1652 struct list_head *lhandle;
1653 efi_status_t r;
1654
Alexander Grafc15d9212016-03-04 01:09:59 +01001655 EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
1656 protocol_buffer_count);
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001657
1658 if (!handle || !protocol_buffer || !protocol_buffer_count)
1659 return EFI_EXIT(EFI_INVALID_PARAMETER);
1660
1661 *protocol_buffer = NULL;
Rob Clarkd51b8ca2017-07-20 07:59:39 -04001662 *protocol_buffer_count = 0;
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001663 list_for_each(lhandle, &efi_obj_list) {
1664 efiobj = list_entry(lhandle, struct efi_object, link);
1665
1666 if (efiobj->handle != handle)
1667 continue;
1668
1669 /* Count protocols */
1670 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1671 if (efiobj->protocols[i].guid)
1672 ++*protocol_buffer_count;
1673 }
1674 /* Copy guids */
1675 if (*protocol_buffer_count) {
1676 buffer_size = sizeof(efi_guid_t *) *
1677 *protocol_buffer_count;
1678 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
1679 buffer_size,
1680 (void **)protocol_buffer);
1681 if (r != EFI_SUCCESS)
1682 return EFI_EXIT(r);
1683 j = 0;
1684 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); ++i) {
1685 if (efiobj->protocols[i].guid) {
1686 (*protocol_buffer)[j] = (void *)
1687 efiobj->protocols[i].guid;
1688 ++j;
1689 }
1690 }
1691 }
1692 break;
1693 }
1694
1695 return EFI_EXIT(EFI_SUCCESS);
Alexander Grafc15d9212016-03-04 01:09:59 +01001696}
1697
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001698/*
1699 * Locate handles implementing a protocol.
1700 *
1701 * This function implements the LocateHandleBuffer service.
1702 * See the Unified Extensible Firmware Interface (UEFI) specification
1703 * for details.
1704 *
1705 * @search_type selection criterion
1706 * @protocol GUID of the protocol
1707 * @search_key registration key
1708 * @no_handles number of returned handles
1709 * @buffer buffer with the returned handles
1710 * @return status code
1711 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001712static efi_status_t EFIAPI efi_locate_handle_buffer(
1713 enum efi_locate_search_type search_type,
1714 efi_guid_t *protocol, void *search_key,
1715 unsigned long *no_handles, efi_handle_t **buffer)
1716{
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +02001717 efi_status_t r;
1718 unsigned long buffer_size = 0;
1719
Rob Clark238f88c2017-09-13 18:05:41 -04001720 EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
Alexander Grafc15d9212016-03-04 01:09:59 +01001721 no_handles, buffer);
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +02001722
1723 if (!no_handles || !buffer) {
1724 r = EFI_INVALID_PARAMETER;
1725 goto out;
1726 }
1727 *no_handles = 0;
1728 *buffer = NULL;
1729 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
1730 *buffer);
1731 if (r != EFI_BUFFER_TOO_SMALL)
1732 goto out;
1733 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
1734 (void **)buffer);
1735 if (r != EFI_SUCCESS)
1736 goto out;
1737 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
1738 *buffer);
1739 if (r == EFI_SUCCESS)
1740 *no_handles = buffer_size / sizeof(void *);
1741out:
1742 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01001743}
1744
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001745/*
1746 * Find an interface implementing a protocol.
1747 *
1748 * This function implements the LocateProtocol service.
1749 * See the Unified Extensible Firmware Interface (UEFI) specification
1750 * for details.
1751 *
1752 * @protocol GUID of the protocol
1753 * @registration registration key passed to the notification function
1754 * @protocol_interface interface implementing the protocol
1755 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001756static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol,
1757 void *registration,
1758 void **protocol_interface)
1759{
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02001760 struct list_head *lhandle;
Alexander Grafc15d9212016-03-04 01:09:59 +01001761 int i;
1762
Rob Clark238f88c2017-09-13 18:05:41 -04001763 EFI_ENTRY("%pUl, %p, %p", protocol, registration, protocol_interface);
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02001764
1765 if (!protocol || !protocol_interface)
1766 return EFI_EXIT(EFI_INVALID_PARAMETER);
1767
Heinrich Schuchardt4d664892017-08-18 17:45:16 +02001768 EFI_PRINT_GUID("protocol", protocol);
1769
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02001770 list_for_each(lhandle, &efi_obj_list) {
1771 struct efi_object *efiobj;
1772
1773 efiobj = list_entry(lhandle, struct efi_object, link);
1774 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1775 struct efi_handler *handler = &efiobj->protocols[i];
1776
1777 if (!handler->guid)
1778 continue;
1779 if (!guidcmp(handler->guid, protocol)) {
1780 *protocol_interface =
1781 handler->protocol_interface;
1782 return EFI_EXIT(EFI_SUCCESS);
1783 }
Alexander Grafc15d9212016-03-04 01:09:59 +01001784 }
1785 }
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02001786 *protocol_interface = NULL;
Alexander Grafc15d9212016-03-04 01:09:59 +01001787
1788 return EFI_EXIT(EFI_NOT_FOUND);
1789}
1790
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001791/*
1792 * Install multiple protocol interfaces.
1793 *
1794 * This function implements the MultipleProtocolInterfaces service.
1795 * See the Unified Extensible Firmware Interface (UEFI) specification
1796 * for details.
1797 *
1798 * @handle handle on which the protocol interfaces shall be installed
1799 * @... NULL terminated argument list with pairs of protocol GUIDS and
1800 * interfaces
1801 * @return status code
1802 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001803static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
1804 void **handle, ...)
1805{
1806 EFI_ENTRY("%p", handle);
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +02001807
1808 va_list argptr;
1809 efi_guid_t *protocol;
1810 void *protocol_interface;
1811 efi_status_t r = EFI_SUCCESS;
1812 int i = 0;
1813
1814 if (!handle)
1815 return EFI_EXIT(EFI_INVALID_PARAMETER);
1816
1817 va_start(argptr, handle);
1818 for (;;) {
1819 protocol = va_arg(argptr, efi_guid_t*);
1820 if (!protocol)
1821 break;
1822 protocol_interface = va_arg(argptr, void*);
1823 r = efi_install_protocol_interface(handle, protocol,
1824 EFI_NATIVE_INTERFACE,
1825 protocol_interface);
1826 if (r != EFI_SUCCESS)
1827 break;
1828 i++;
1829 }
1830 va_end(argptr);
1831 if (r == EFI_SUCCESS)
1832 return EFI_EXIT(r);
1833
1834 /* If an error occured undo all changes. */
1835 va_start(argptr, handle);
1836 for (; i; --i) {
1837 protocol = va_arg(argptr, efi_guid_t*);
1838 protocol_interface = va_arg(argptr, void*);
1839 efi_uninstall_protocol_interface(handle, protocol,
1840 protocol_interface);
1841 }
1842 va_end(argptr);
1843
1844 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01001845}
1846
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001847/*
1848 * Uninstall multiple protocol interfaces.
1849 *
1850 * This function implements the UninstallMultipleProtocolInterfaces service.
1851 * See the Unified Extensible Firmware Interface (UEFI) specification
1852 * for details.
1853 *
1854 * @handle handle from which the protocol interfaces shall be removed
1855 * @... NULL terminated argument list with pairs of protocol GUIDS and
1856 * interfaces
1857 * @return status code
1858 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001859static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
1860 void *handle, ...)
1861{
1862 EFI_ENTRY("%p", handle);
1863 return EFI_EXIT(EFI_INVALID_PARAMETER);
1864}
1865
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001866/*
1867 * Calculate cyclic redundancy code.
1868 *
1869 * This function implements the CalculateCrc32 service.
1870 * See the Unified Extensible Firmware Interface (UEFI) specification
1871 * for details.
1872 *
1873 * @data buffer with data
1874 * @data_size size of buffer in bytes
1875 * @crc32_p cyclic redundancy code
1876 * @return status code
1877 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001878static efi_status_t EFIAPI efi_calculate_crc32(void *data,
1879 unsigned long data_size,
1880 uint32_t *crc32_p)
1881{
1882 EFI_ENTRY("%p, %ld", data, data_size);
1883 *crc32_p = crc32(0, data, data_size);
1884 return EFI_EXIT(EFI_SUCCESS);
1885}
1886
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001887/*
1888 * Copy memory.
1889 *
1890 * This function implements the CopyMem service.
1891 * See the Unified Extensible Firmware Interface (UEFI) specification
1892 * for details.
1893 *
1894 * @destination destination of the copy operation
1895 * @source source of the copy operation
1896 * @length number of bytes to copy
1897 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001898static void EFIAPI efi_copy_mem(void *destination, void *source,
1899 unsigned long length)
1900{
1901 EFI_ENTRY("%p, %p, %ld", destination, source, length);
1902 memcpy(destination, source, length);
1903}
1904
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001905/*
1906 * Fill memory with a byte value.
1907 *
1908 * This function implements the SetMem service.
1909 * See the Unified Extensible Firmware Interface (UEFI) specification
1910 * for details.
1911 *
1912 * @buffer buffer to fill
1913 * @size size of buffer in bytes
1914 * @value byte to copy to the buffer
1915 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001916static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value)
1917{
1918 EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value);
1919 memset(buffer, value, size);
1920}
1921
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001922/*
1923 * Open protocol interface on a handle.
1924 *
1925 * This function implements the OpenProtocol interface.
1926 * See the Unified Extensible Firmware Interface (UEFI) specification
1927 * for details.
1928 *
1929 * @handle handle on which the protocol shall be opened
1930 * @protocol GUID of the protocol
1931 * @protocol_interface interface implementing the protocol
1932 * @agent_handle handle of the driver
1933 * @controller_handle handle of the controller
1934 * @attributes attributes indicating how to open the protocol
1935 * @return status code
1936 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001937static efi_status_t EFIAPI efi_open_protocol(
1938 void *handle, efi_guid_t *protocol,
1939 void **protocol_interface, void *agent_handle,
1940 void *controller_handle, uint32_t attributes)
1941{
1942 struct list_head *lhandle;
1943 int i;
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001944 efi_status_t r = EFI_INVALID_PARAMETER;
Alexander Grafc15d9212016-03-04 01:09:59 +01001945
Rob Clark238f88c2017-09-13 18:05:41 -04001946 EFI_ENTRY("%p, %pUl, %p, %p, %p, 0x%x", handle, protocol,
Alexander Grafc15d9212016-03-04 01:09:59 +01001947 protocol_interface, agent_handle, controller_handle,
1948 attributes);
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02001949
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001950 if (!handle || !protocol ||
1951 (!protocol_interface && attributes !=
1952 EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02001953 goto out;
1954 }
1955
Heinrich Schuchardt4d664892017-08-18 17:45:16 +02001956 EFI_PRINT_GUID("protocol", protocol);
1957
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001958 switch (attributes) {
1959 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
1960 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
1961 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
1962 break;
1963 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
1964 if (controller_handle == handle)
1965 goto out;
1966 case EFI_OPEN_PROTOCOL_BY_DRIVER:
1967 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
1968 if (controller_handle == NULL)
1969 goto out;
1970 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
1971 if (agent_handle == NULL)
1972 goto out;
1973 break;
1974 default:
1975 goto out;
1976 }
1977
Alexander Grafc15d9212016-03-04 01:09:59 +01001978 list_for_each(lhandle, &efi_obj_list) {
1979 struct efi_object *efiobj;
1980 efiobj = list_entry(lhandle, struct efi_object, link);
1981
1982 if (efiobj->handle != handle)
1983 continue;
1984
1985 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1986 struct efi_handler *handler = &efiobj->protocols[i];
1987 const efi_guid_t *hprotocol = handler->guid;
1988 if (!hprotocol)
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +02001989 continue;
Alexander Grafc15d9212016-03-04 01:09:59 +01001990 if (!guidcmp(hprotocol, protocol)) {
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02001991 if (attributes !=
1992 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
1993 *protocol_interface =
1994 handler->protocol_interface;
1995 }
1996 r = EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +01001997 goto out;
1998 }
1999 }
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002000 goto unsupported;
Alexander Grafc15d9212016-03-04 01:09:59 +01002001 }
2002
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002003unsupported:
2004 r = EFI_UNSUPPORTED;
Alexander Grafc15d9212016-03-04 01:09:59 +01002005out:
2006 return EFI_EXIT(r);
2007}
2008
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002009/*
2010 * Get interface of a protocol on a handle.
2011 *
2012 * This function implements the HandleProtocol service.
2013 * See the Unified Extensible Firmware Interface (UEFI) specification
2014 * for details.
2015 *
2016 * @handle handle on which the protocol shall be opened
2017 * @protocol GUID of the protocol
2018 * @protocol_interface interface implementing the protocol
2019 * @return status code
2020 */
Alexander Grafc15d9212016-03-04 01:09:59 +01002021static efi_status_t EFIAPI efi_handle_protocol(void *handle,
2022 efi_guid_t *protocol,
2023 void **protocol_interface)
2024{
xypron.glpk@gmx.de1bf5d872017-06-29 21:16:19 +02002025 return efi_open_protocol(handle, protocol, protocol_interface, NULL,
2026 NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
Alexander Grafc15d9212016-03-04 01:09:59 +01002027}
2028
2029static const struct efi_boot_services efi_boot_services = {
2030 .hdr = {
2031 .headersize = sizeof(struct efi_table_hdr),
2032 },
2033 .raise_tpl = efi_raise_tpl,
2034 .restore_tpl = efi_restore_tpl,
2035 .allocate_pages = efi_allocate_pages_ext,
2036 .free_pages = efi_free_pages_ext,
2037 .get_memory_map = efi_get_memory_map_ext,
Stefan Brüns5a09aef2016-10-09 22:17:18 +02002038 .allocate_pool = efi_allocate_pool_ext,
Stefan Brüns67b67d92016-10-09 22:17:26 +02002039 .free_pool = efi_free_pool_ext,
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +02002040 .create_event = efi_create_event_ext,
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +02002041 .set_timer = efi_set_timer_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002042 .wait_for_event = efi_wait_for_event,
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +02002043 .signal_event = efi_signal_event_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002044 .close_event = efi_close_event,
2045 .check_event = efi_check_event,
xypron.glpk@gmx.de8b7b5df2017-07-11 22:06:18 +02002046 .install_protocol_interface = efi_install_protocol_interface_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002047 .reinstall_protocol_interface = efi_reinstall_protocol_interface,
xypron.glpk@gmx.dea453e462017-07-11 22:06:19 +02002048 .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002049 .handle_protocol = efi_handle_protocol,
2050 .reserved = NULL,
2051 .register_protocol_notify = efi_register_protocol_notify,
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02002052 .locate_handle = efi_locate_handle_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002053 .locate_device_path = efi_locate_device_path,
Alexander Grafc5c11632016-08-19 01:23:24 +02002054 .install_configuration_table = efi_install_configuration_table_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002055 .load_image = efi_load_image,
2056 .start_image = efi_start_image,
Alexander Graf988c0662016-05-20 23:28:23 +02002057 .exit = efi_exit,
Alexander Grafc15d9212016-03-04 01:09:59 +01002058 .unload_image = efi_unload_image,
2059 .exit_boot_services = efi_exit_boot_services,
2060 .get_next_monotonic_count = efi_get_next_monotonic_count,
2061 .stall = efi_stall,
2062 .set_watchdog_timer = efi_set_watchdog_timer,
2063 .connect_controller = efi_connect_controller,
2064 .disconnect_controller = efi_disconnect_controller,
2065 .open_protocol = efi_open_protocol,
2066 .close_protocol = efi_close_protocol,
2067 .open_protocol_information = efi_open_protocol_information,
2068 .protocols_per_handle = efi_protocols_per_handle,
2069 .locate_handle_buffer = efi_locate_handle_buffer,
2070 .locate_protocol = efi_locate_protocol,
2071 .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
2072 .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
2073 .calculate_crc32 = efi_calculate_crc32,
2074 .copy_mem = efi_copy_mem,
2075 .set_mem = efi_set_mem,
2076};
2077
2078
Alexander Graf393dd912016-10-14 13:45:30 +02002079static uint16_t __efi_runtime_data firmware_vendor[] =
Alexander Grafc15d9212016-03-04 01:09:59 +01002080 { 'D','a','s',' ','U','-','b','o','o','t',0 };
2081
Alexander Graf393dd912016-10-14 13:45:30 +02002082struct efi_system_table __efi_runtime_data systab = {
Alexander Grafc15d9212016-03-04 01:09:59 +01002083 .hdr = {
2084 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
2085 .revision = 0x20005, /* 2.5 */
2086 .headersize = sizeof(struct efi_table_hdr),
2087 },
2088 .fw_vendor = (long)firmware_vendor,
2089 .con_in = (void*)&efi_con_in,
2090 .con_out = (void*)&efi_con_out,
2091 .std_err = (void*)&efi_con_out,
2092 .runtime = (void*)&efi_runtime_services,
2093 .boottime = (void*)&efi_boot_services,
2094 .nr_tables = 0,
2095 .tables = (void*)efi_conf_table,
2096};