blob: c77da8a9c1bd9a1adc253a8f5efc46541f40ea81 [file] [log] [blame]
Alexander Grafbee91162016-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 Grafbee91162016-03-04 01:09:59 +01009#include <common.h>
Heinrich Schuchardt7d963322017-10-05 16:14:14 +020010#include <div64.h>
Alexander Grafbee91162016-03-04 01:09:59 +010011#include <efi_loader.h>
Rob Clarkad644e72017-09-13 18:05:37 -040012#include <environment.h>
Alexander Grafbee91162016-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 Schuchardt32f4b2f2017-09-15 10:06:16 +020023/* Task priority level */
24static UINTN efi_tpl = TPL_APPLICATION;
25
Alexander Grafbee91162016-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 Graf3c63db92016-10-14 13:45:30 +020045static struct efi_configuration_table __efi_runtime_data efi_conf_table[2];
Alexander Grafbee91162016-03-04 01:09:59 +010046
Simon Glass65e4c0b2016-09-25 15:27:35 -060047#ifdef CONFIG_ARM
Alexander Grafbee91162016-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 Glass65e4c0b2016-09-25 15:27:35 -060055#endif
Alexander Grafbee91162016-03-04 01:09:59 +010056
Rob Clarkc160d2f2017-07-27 08:04:18 -040057static int entry_count;
Rob Clarkaf65db82017-07-27 08:04:19 -040058static int nesting_level;
Rob Clarkc160d2f2017-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 Grafbee91162016-03-04 01:09:59 +010082/* Called from do_bootefi_exec() */
83void efi_save_gd(void)
84{
Simon Glass65e4c0b2016-09-25 15:27:35 -060085#ifdef CONFIG_ARM
Alexander Grafbee91162016-03-04 01:09:59 +010086 efi_gd = gd;
Simon Glass65e4c0b2016-09-25 15:27:35 -060087#endif
Alexander Grafbee91162016-03-04 01:09:59 +010088}
89
Rob Clarkc160d2f2017-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 Grafbee91162016-03-04 01:09:59 +010095void efi_restore_gd(void)
96{
Simon Glass65e4c0b2016-09-25 15:27:35 -060097#ifdef CONFIG_ARM
Alexander Grafbee91162016-03-04 01:09:59 +010098 /* Only restore if we're already in EFI context */
99 if (!efi_gd)
100 return;
Alexander Grafbee91162016-03-04 01:09:59 +0100101 gd = efi_gd;
Simon Glass65e4c0b2016-09-25 15:27:35 -0600102#endif
Alexander Grafbee91162016-03-04 01:09:59 +0100103}
104
Rob Clarkaf65db82017-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 Schuchardtae0bd3a2017-08-18 17:45:16 +0200117const char *__efi_nesting(void)
118{
119 return indent_string(nesting_level);
120}
121
Rob Clarkaf65db82017-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 Schuchardt332468f2017-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.de91be9a72017-07-18 20:17:22 +0200145void efi_signal_event(struct efi_event *event)
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200146{
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200147 if (event->notify_function) {
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200148 event->is_queued = true;
Heinrich Schuchardt32f4b2f2017-09-15 10:06:16 +0200149 /* Check TPL */
150 if (efi_tpl >= event->notify_tpl)
151 return;
Heinrich Schuchardtea630ce2017-09-15 10:06:10 +0200152 EFI_CALL_VOID(event->notify_function(event,
153 event->notify_context));
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200154 }
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200155 event->is_queued = false;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200156}
157
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200158/*
Heinrich Schuchardt332468f2017-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 */
xypron.glpk@gmx.de503f2692017-07-18 20:17:19 +0200168static unsigned long EFIAPI efi_raise_tpl(UINTN new_tpl)
Alexander Grafbee91162016-03-04 01:09:59 +0100169{
Heinrich Schuchardt32f4b2f2017-09-15 10:06:16 +0200170 UINTN old_tpl = efi_tpl;
171
xypron.glpk@gmx.de503f2692017-07-18 20:17:19 +0200172 EFI_ENTRY("0x%zx", new_tpl);
Heinrich Schuchardt32f4b2f2017-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 Grafbee91162016-03-04 01:09:59 +0100182}
183
Heinrich Schuchardt332468f2017-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 */
xypron.glpk@gmx.de503f2692017-07-18 20:17:19 +0200193static void EFIAPI efi_restore_tpl(UINTN old_tpl)
Alexander Grafbee91162016-03-04 01:09:59 +0100194{
xypron.glpk@gmx.de503f2692017-07-18 20:17:19 +0200195 EFI_ENTRY("0x%zx", old_tpl);
Heinrich Schuchardt32f4b2f2017-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 Grafbee91162016-03-04 01:09:59 +0100204}
205
Heinrich Schuchardt332468f2017-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 Yamada6e0bf8d2017-06-22 17:49:03 +0900219static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
220 unsigned long pages,
221 uint64_t *memory)
Alexander Grafbee91162016-03-04 01:09:59 +0100222{
223 efi_status_t r;
224
225 EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory);
226 r = efi_allocate_pages(type, memory_type, pages, memory);
227 return EFI_EXIT(r);
228}
229
Heinrich Schuchardt332468f2017-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 Yamada6e0bf8d2017-06-22 17:49:03 +0900241static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
242 unsigned long pages)
Alexander Grafbee91162016-03-04 01:09:59 +0100243{
244 efi_status_t r;
245
246 EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages);
247 r = efi_free_pages(memory, pages);
248 return EFI_EXIT(r);
249}
250
Heinrich Schuchardt332468f2017-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 Yamada6e0bf8d2017-06-22 17:49:03 +0900266static efi_status_t EFIAPI efi_get_memory_map_ext(
267 unsigned long *memory_map_size,
268 struct efi_mem_desc *memory_map,
269 unsigned long *map_key,
270 unsigned long *descriptor_size,
271 uint32_t *descriptor_version)
Alexander Grafbee91162016-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 Schuchardt332468f2017-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ünsead12742016-10-09 22:17:18 +0200294static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
295 unsigned long size,
296 void **buffer)
Alexander Grafbee91162016-03-04 01:09:59 +0100297{
Alexander Graf1cd29f02016-03-24 01:37:37 +0100298 efi_status_t r;
299
300 EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer);
Stefan Brünsead12742016-10-09 22:17:18 +0200301 r = efi_allocate_pool(pool_type, size, buffer);
Alexander Graf1cd29f02016-03-24 01:37:37 +0100302 return EFI_EXIT(r);
Alexander Grafbee91162016-03-04 01:09:59 +0100303}
304
Heinrich Schuchardt332468f2017-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üns42417bc2016-10-09 22:17:26 +0200315static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
Alexander Grafbee91162016-03-04 01:09:59 +0100316{
Alexander Graf1cd29f02016-03-24 01:37:37 +0100317 efi_status_t r;
318
319 EFI_ENTRY("%p", buffer);
Stefan Brüns42417bc2016-10-09 22:17:26 +0200320 r = efi_free_pool(buffer);
Alexander Graf1cd29f02016-03-24 01:37:37 +0100321 return EFI_EXIT(r);
Alexander Grafbee91162016-03-04 01:09:59 +0100322}
323
Heinrich Schuchardt3cc6e3f2017-08-27 00:51:09 +0200324static efi_status_t efi_create_handle(void **handle)
325{
326 struct efi_object *obj;
327 efi_status_t r;
328
329 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
330 sizeof(struct efi_object),
331 (void **)&obj);
332 if (r != EFI_SUCCESS)
333 return r;
334 memset(obj, 0, sizeof(struct efi_object));
335 obj->handle = obj;
336 list_add_tail(&obj->link, &efi_obj_list);
337 *handle = obj;
338 return r;
339}
340
Alexander Grafbee91162016-03-04 01:09:59 +0100341/*
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200342 * Our event capabilities are very limited. Only a small limited
343 * number of events is allowed to coexist.
Alexander Grafbee91162016-03-04 01:09:59 +0100344 */
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200345static struct efi_event efi_events[16];
Alexander Grafbee91162016-03-04 01:09:59 +0100346
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200347/*
348 * Create an event.
349 *
350 * This function is used inside U-Boot code to create an event.
351 *
352 * For the API function implementing the CreateEvent service see
353 * efi_create_event_ext.
354 *
355 * @type type of the event to create
356 * @notify_tpl task priority level of the event
357 * @notify_function notification function of the event
358 * @notify_context pointer passed to the notification function
359 * @event created event
360 * @return status code
361 */
xypron.glpk@gmx.deb521d292017-07-19 19:22:34 +0200362efi_status_t efi_create_event(uint32_t type, UINTN notify_tpl,
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200363 void (EFIAPI *notify_function) (
xypron.glpk@gmx.de2fd945f2017-07-18 20:17:17 +0200364 struct efi_event *event,
365 void *context),
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200366 void *notify_context, struct efi_event **event)
Alexander Grafbee91162016-03-04 01:09:59 +0100367{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200368 int i;
369
Jonathan Graya95343b2017-03-12 19:26:07 +1100370 if (event == NULL)
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200371 return EFI_INVALID_PARAMETER;
Jonathan Graya95343b2017-03-12 19:26:07 +1100372
373 if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200374 return EFI_INVALID_PARAMETER;
Jonathan Graya95343b2017-03-12 19:26:07 +1100375
376 if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
377 notify_function == NULL)
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200378 return EFI_INVALID_PARAMETER;
Jonathan Graya95343b2017-03-12 19:26:07 +1100379
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200380 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
381 if (efi_events[i].type)
382 continue;
383 efi_events[i].type = type;
384 efi_events[i].notify_tpl = notify_tpl;
385 efi_events[i].notify_function = notify_function;
386 efi_events[i].notify_context = notify_context;
387 /* Disable timers on bootup */
388 efi_events[i].trigger_next = -1ULL;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200389 efi_events[i].is_queued = false;
390 efi_events[i].is_signaled = false;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200391 *event = &efi_events[i];
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200392 return EFI_SUCCESS;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200393 }
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200394 return EFI_OUT_OF_RESOURCES;
Alexander Grafbee91162016-03-04 01:09:59 +0100395}
396
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200397/*
398 * Create an event.
399 *
400 * This function implements the CreateEvent service.
401 * See the Unified Extensible Firmware Interface (UEFI) specification
402 * for details.
403 *
404 * @type type of the event to create
405 * @notify_tpl task priority level of the event
406 * @notify_function notification function of the event
407 * @notify_context pointer passed to the notification function
408 * @event created event
409 * @return status code
410 */
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200411static efi_status_t EFIAPI efi_create_event_ext(
xypron.glpk@gmx.deb521d292017-07-19 19:22:34 +0200412 uint32_t type, UINTN notify_tpl,
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200413 void (EFIAPI *notify_function) (
414 struct efi_event *event,
415 void *context),
416 void *notify_context, struct efi_event **event)
417{
418 EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
419 notify_context);
420 return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
421 notify_context, event));
422}
423
424
Alexander Grafbee91162016-03-04 01:09:59 +0100425/*
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200426 * Check if a timer event has occurred or a queued notification function should
427 * be called.
428 *
Alexander Grafbee91162016-03-04 01:09:59 +0100429 * Our timers have to work without interrupts, so we check whenever keyboard
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200430 * input or disk accesses happen if enough time elapsed for them to fire.
Alexander Grafbee91162016-03-04 01:09:59 +0100431 */
432void efi_timer_check(void)
433{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200434 int i;
Alexander Grafbee91162016-03-04 01:09:59 +0100435 u64 now = timer_get_us();
436
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200437 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200438 if (!efi_events[i].type)
439 continue;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200440 if (efi_events[i].is_queued)
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200441 efi_signal_event(&efi_events[i]);
442 if (!(efi_events[i].type & EVT_TIMER) ||
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200443 now < efi_events[i].trigger_next)
444 continue;
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200445 switch (efi_events[i].trigger_type) {
446 case EFI_TIMER_RELATIVE:
447 efi_events[i].trigger_type = EFI_TIMER_STOP;
448 break;
449 case EFI_TIMER_PERIODIC:
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200450 efi_events[i].trigger_next +=
xypron.glpk@gmx.de8787b022017-07-18 20:17:23 +0200451 efi_events[i].trigger_time;
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200452 break;
453 default:
454 continue;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200455 }
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200456 efi_events[i].is_signaled = true;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200457 efi_signal_event(&efi_events[i]);
Alexander Grafbee91162016-03-04 01:09:59 +0100458 }
Alexander Grafbee91162016-03-04 01:09:59 +0100459 WATCHDOG_RESET();
460}
461
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200462/*
463 * Set the trigger time for a timer event or stop the event.
464 *
465 * This is the function for internal usage in U-Boot. For the API function
466 * implementing the SetTimer service see efi_set_timer_ext.
467 *
468 * @event event for which the timer is set
469 * @type type of the timer
470 * @trigger_time trigger period in multiples of 100ns
471 * @return status code
472 */
xypron.glpk@gmx.deb521d292017-07-19 19:22:34 +0200473efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +0200474 uint64_t trigger_time)
Alexander Grafbee91162016-03-04 01:09:59 +0100475{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200476 int i;
Alexander Grafbee91162016-03-04 01:09:59 +0100477
xypron.glpk@gmx.de8787b022017-07-18 20:17:23 +0200478 /*
479 * The parameter defines a multiple of 100ns.
480 * We use multiples of 1000ns. So divide by 10.
481 */
Heinrich Schuchardt7d963322017-10-05 16:14:14 +0200482 do_div(trigger_time, 10);
Alexander Grafbee91162016-03-04 01:09:59 +0100483
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200484 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
485 if (event != &efi_events[i])
486 continue;
Alexander Grafbee91162016-03-04 01:09:59 +0100487
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200488 if (!(event->type & EVT_TIMER))
489 break;
490 switch (type) {
491 case EFI_TIMER_STOP:
492 event->trigger_next = -1ULL;
493 break;
494 case EFI_TIMER_PERIODIC:
495 case EFI_TIMER_RELATIVE:
496 event->trigger_next =
xypron.glpk@gmx.de8787b022017-07-18 20:17:23 +0200497 timer_get_us() + trigger_time;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200498 break;
499 default:
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +0200500 return EFI_INVALID_PARAMETER;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200501 }
502 event->trigger_type = type;
503 event->trigger_time = trigger_time;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200504 event->is_signaled = false;
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +0200505 return EFI_SUCCESS;
Alexander Grafbee91162016-03-04 01:09:59 +0100506 }
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +0200507 return EFI_INVALID_PARAMETER;
508}
509
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200510/*
511 * Set the trigger time for a timer event or stop the event.
512 *
513 * This function implements the SetTimer service.
514 * See the Unified Extensible Firmware Interface (UEFI) specification
515 * for details.
516 *
517 * @event event for which the timer is set
518 * @type type of the timer
519 * @trigger_time trigger period in multiples of 100ns
520 * @return status code
521 */
xypron.glpk@gmx.deb521d292017-07-19 19:22:34 +0200522static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event,
523 enum efi_timer_delay type,
524 uint64_t trigger_time)
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +0200525{
526 EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
527 return EFI_EXIT(efi_set_timer(event, type, trigger_time));
Alexander Grafbee91162016-03-04 01:09:59 +0100528}
529
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200530/*
531 * Wait for events to be signaled.
532 *
533 * This function implements the WaitForEvent service.
534 * See the Unified Extensible Firmware Interface (UEFI) specification
535 * for details.
536 *
537 * @num_events number of events to be waited for
538 * @events events to be waited for
539 * @index index of the event that was signaled
540 * @return status code
541 */
Alexander Grafbee91162016-03-04 01:09:59 +0100542static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events,
xypron.glpk@gmx.de2fd945f2017-07-18 20:17:17 +0200543 struct efi_event **event,
Heinrich Schuchardtca379e12017-10-05 16:35:54 +0200544 size_t *index)
Alexander Grafbee91162016-03-04 01:09:59 +0100545{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200546 int i, j;
Alexander Grafbee91162016-03-04 01:09:59 +0100547
548 EFI_ENTRY("%ld, %p, %p", num_events, event, index);
549
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200550 /* Check parameters */
551 if (!num_events || !event)
552 return EFI_EXIT(EFI_INVALID_PARAMETER);
Heinrich Schuchardt32f4b2f2017-09-15 10:06:16 +0200553 /* Check TPL */
554 if (efi_tpl != TPL_APPLICATION)
555 return EFI_EXIT(EFI_UNSUPPORTED);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200556 for (i = 0; i < num_events; ++i) {
557 for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
558 if (event[i] == &efi_events[j])
559 goto known_event;
560 }
561 return EFI_EXIT(EFI_INVALID_PARAMETER);
562known_event:
563 if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
564 return EFI_EXIT(EFI_INVALID_PARAMETER);
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200565 if (!event[i]->is_signaled)
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200566 efi_signal_event(event[i]);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200567 }
568
569 /* Wait for signal */
570 for (;;) {
571 for (i = 0; i < num_events; ++i) {
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200572 if (event[i]->is_signaled)
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200573 goto out;
574 }
575 /* Allow events to occur. */
576 efi_timer_check();
577 }
578
579out:
580 /*
581 * Reset the signal which is passed to the caller to allow periodic
582 * events to occur.
583 */
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200584 event[i]->is_signaled = false;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200585 if (index)
586 *index = i;
Alexander Grafbee91162016-03-04 01:09:59 +0100587
588 return EFI_EXIT(EFI_SUCCESS);
589}
590
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200591/*
592 * Signal an EFI event.
593 *
594 * This function implements the SignalEvent service.
595 * See the Unified Extensible Firmware Interface (UEFI) specification
596 * for details.
597 *
598 * This functions sets the signaled state of the event and queues the
599 * notification function for execution.
600 *
601 * @event event to signal
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +0200602 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200603 */
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200604static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
Alexander Grafbee91162016-03-04 01:09:59 +0100605{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200606 int i;
607
Alexander Grafbee91162016-03-04 01:09:59 +0100608 EFI_ENTRY("%p", event);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200609 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
610 if (event != &efi_events[i])
611 continue;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200612 if (event->is_signaled)
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200613 break;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200614 event->is_signaled = true;
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200615 if (event->type & EVT_NOTIFY_SIGNAL)
616 efi_signal_event(event);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200617 break;
618 }
Alexander Grafbee91162016-03-04 01:09:59 +0100619 return EFI_EXIT(EFI_SUCCESS);
620}
621
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200622/*
623 * Close an EFI event.
624 *
625 * This function implements the CloseEvent service.
626 * See the Unified Extensible Firmware Interface (UEFI) specification
627 * for details.
628 *
629 * @event event to close
630 * @return status code
631 */
xypron.glpk@gmx.de2fd945f2017-07-18 20:17:17 +0200632static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
Alexander Grafbee91162016-03-04 01:09:59 +0100633{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200634 int i;
635
Alexander Grafbee91162016-03-04 01:09:59 +0100636 EFI_ENTRY("%p", event);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200637 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
638 if (event == &efi_events[i]) {
639 event->type = 0;
640 event->trigger_next = -1ULL;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200641 event->is_queued = false;
642 event->is_signaled = false;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200643 return EFI_EXIT(EFI_SUCCESS);
644 }
645 }
646 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafbee91162016-03-04 01:09:59 +0100647}
648
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200649/*
650 * Check if an event is signaled.
651 *
652 * This function implements the CheckEvent service.
653 * See the Unified Extensible Firmware Interface (UEFI) specification
654 * for details.
655 *
656 * If an event is not signaled yet the notification function is queued.
657 *
658 * @event event to check
659 * @return status code
660 */
xypron.glpk@gmx.de2fd945f2017-07-18 20:17:17 +0200661static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
Alexander Grafbee91162016-03-04 01:09:59 +0100662{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200663 int i;
664
Alexander Grafbee91162016-03-04 01:09:59 +0100665 EFI_ENTRY("%p", event);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200666 efi_timer_check();
667 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
668 if (event != &efi_events[i])
669 continue;
670 if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
671 break;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200672 if (!event->is_signaled)
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200673 efi_signal_event(event);
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200674 if (event->is_signaled)
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200675 return EFI_EXIT(EFI_SUCCESS);
676 return EFI_EXIT(EFI_NOT_READY);
677 }
678 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafbee91162016-03-04 01:09:59 +0100679}
680
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200681/*
Heinrich Schuchardt7b9f8ad2017-10-18 18:13:03 +0200682 * Find the internal EFI object for a handle.
683 *
684 * @handle handle to find
685 * @return EFI object
686 */
687static struct efi_object *efi_search_obj(void *handle)
688{
689 struct list_head *lhandle;
690
691 list_for_each(lhandle, &efi_obj_list) {
692 struct efi_object *efiobj;
693
694 efiobj = list_entry(lhandle, struct efi_object, link);
695 if (efiobj->handle == handle)
696 return efiobj;
697 }
698
699 return NULL;
700}
701
702/*
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200703 * Install protocol interface.
704 *
705 * This is the function for internal calls. For the API implementation of the
706 * InstallProtocolInterface service see function
707 * efi_install_protocol_interface_ext.
708 *
709 * @handle handle on which the protocol shall be installed
710 * @protocol GUID of the protocol to be installed
711 * @protocol_interface_type type of the interface to be installed,
712 * always EFI_NATIVE_INTERFACE
713 * @protocol_interface interface of the protocol implementation
714 * @return status code
715 */
Alexander Grafbee91162016-03-04 01:09:59 +0100716static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200717 const efi_guid_t *protocol, int protocol_interface_type,
Alexander Grafbee91162016-03-04 01:09:59 +0100718 void *protocol_interface)
719{
xypron.glpk@gmx.dee0549f82017-07-11 22:06:16 +0200720 struct list_head *lhandle;
721 int i;
722 efi_status_t r;
723
xypron.glpk@gmx.dee0549f82017-07-11 22:06:16 +0200724 if (!handle || !protocol ||
725 protocol_interface_type != EFI_NATIVE_INTERFACE) {
726 r = EFI_INVALID_PARAMETER;
727 goto out;
728 }
729
730 /* Create new handle if requested. */
731 if (!*handle) {
Heinrich Schuchardt3cc6e3f2017-08-27 00:51:09 +0200732 r = efi_create_handle(handle);
733 if (r != EFI_SUCCESS)
734 goto out;
xypron.glpk@gmx.dee0549f82017-07-11 22:06:16 +0200735 }
736 /* Find object. */
737 list_for_each(lhandle, &efi_obj_list) {
738 struct efi_object *efiobj;
739 efiobj = list_entry(lhandle, struct efi_object, link);
740
741 if (efiobj->handle != *handle)
742 continue;
743 /* Check if protocol is already installed on the handle. */
744 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
745 struct efi_handler *handler = &efiobj->protocols[i];
746
747 if (!handler->guid)
748 continue;
749 if (!guidcmp(handler->guid, protocol)) {
750 r = EFI_INVALID_PARAMETER;
751 goto out;
752 }
753 }
754 /* Install protocol in first empty slot. */
755 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
756 struct efi_handler *handler = &efiobj->protocols[i];
757
758 if (handler->guid)
759 continue;
760
761 handler->guid = protocol;
762 handler->protocol_interface = protocol_interface;
763 r = EFI_SUCCESS;
764 goto out;
765 }
766 r = EFI_OUT_OF_RESOURCES;
767 goto out;
768 }
769 r = EFI_INVALID_PARAMETER;
770out:
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +0200771 return r;
772}
773
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200774/*
775 * Install protocol interface.
776 *
777 * This function implements the InstallProtocolInterface service.
778 * See the Unified Extensible Firmware Interface (UEFI) specification
779 * for details.
780 *
781 * @handle handle on which the protocol shall be installed
782 * @protocol GUID of the protocol to be installed
783 * @protocol_interface_type type of the interface to be installed,
784 * always EFI_NATIVE_INTERFACE
785 * @protocol_interface interface of the protocol implementation
786 * @return status code
787 */
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +0200788static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200789 const efi_guid_t *protocol, int protocol_interface_type,
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +0200790 void *protocol_interface)
791{
Rob Clark778e6af2017-09-13 18:05:41 -0400792 EFI_ENTRY("%p, %pUl, %d, %p", handle, protocol, protocol_interface_type,
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +0200793 protocol_interface);
794
795 return EFI_EXIT(efi_install_protocol_interface(handle, protocol,
796 protocol_interface_type,
797 protocol_interface));
Alexander Grafbee91162016-03-04 01:09:59 +0100798}
xypron.glpk@gmx.dee0549f82017-07-11 22:06:16 +0200799
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200800/*
801 * Reinstall protocol interface.
802 *
803 * This function implements the ReinstallProtocolInterface service.
804 * See the Unified Extensible Firmware Interface (UEFI) specification
805 * for details.
806 *
807 * @handle handle on which the protocol shall be
808 * reinstalled
809 * @protocol GUID of the protocol to be installed
810 * @old_interface interface to be removed
811 * @new_interface interface to be installed
812 * @return status code
813 */
Alexander Grafbee91162016-03-04 01:09:59 +0100814static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200815 const efi_guid_t *protocol, void *old_interface,
Alexander Grafbee91162016-03-04 01:09:59 +0100816 void *new_interface)
817{
Rob Clark778e6af2017-09-13 18:05:41 -0400818 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, old_interface,
Alexander Grafbee91162016-03-04 01:09:59 +0100819 new_interface);
820 return EFI_EXIT(EFI_ACCESS_DENIED);
821}
822
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200823/*
824 * Uninstall protocol interface.
825 *
826 * This is the function for internal calls. For the API implementation of the
827 * UninstallProtocolInterface service see function
828 * efi_uninstall_protocol_interface_ext.
829 *
830 * @handle handle from which the protocol shall be removed
831 * @protocol GUID of the protocol to be removed
832 * @protocol_interface interface to be removed
833 * @return status code
834 */
Alexander Grafbee91162016-03-04 01:09:59 +0100835static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200836 const efi_guid_t *protocol, void *protocol_interface)
Alexander Grafbee91162016-03-04 01:09:59 +0100837{
xypron.glpk@gmx.de4b6ed0d2017-07-11 22:06:17 +0200838 struct list_head *lhandle;
839 int i;
840 efi_status_t r = EFI_NOT_FOUND;
841
xypron.glpk@gmx.de4b6ed0d2017-07-11 22:06:17 +0200842 if (!handle || !protocol) {
843 r = EFI_INVALID_PARAMETER;
844 goto out;
845 }
846
847 list_for_each(lhandle, &efi_obj_list) {
848 struct efi_object *efiobj;
849 efiobj = list_entry(lhandle, struct efi_object, link);
850
851 if (efiobj->handle != handle)
852 continue;
853
854 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
855 struct efi_handler *handler = &efiobj->protocols[i];
856 const efi_guid_t *hprotocol = handler->guid;
857
858 if (!hprotocol)
859 continue;
860 if (!guidcmp(hprotocol, protocol)) {
861 if (handler->protocol_interface) {
862 r = EFI_ACCESS_DENIED;
863 } else {
864 handler->guid = 0;
865 r = EFI_SUCCESS;
866 }
867 goto out;
868 }
869 }
870 }
871
872out:
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +0200873 return r;
874}
875
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200876/*
877 * Uninstall protocol interface.
878 *
879 * This function implements the UninstallProtocolInterface service.
880 * See the Unified Extensible Firmware Interface (UEFI) specification
881 * for details.
882 *
883 * @handle handle from which the protocol shall be removed
884 * @protocol GUID of the protocol to be removed
885 * @protocol_interface interface to be removed
886 * @return status code
887 */
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +0200888static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200889 const efi_guid_t *protocol, void *protocol_interface)
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +0200890{
Rob Clark778e6af2017-09-13 18:05:41 -0400891 EFI_ENTRY("%p, %pUl, %p", handle, protocol, protocol_interface);
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +0200892
893 return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol,
894 protocol_interface));
Alexander Grafbee91162016-03-04 01:09:59 +0100895}
896
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200897/*
898 * Register an event for notification when a protocol is installed.
899 *
900 * This function implements the RegisterProtocolNotify service.
901 * See the Unified Extensible Firmware Interface (UEFI) specification
902 * for details.
903 *
904 * @protocol GUID of the protocol whose installation shall be
905 * notified
906 * @event event to be signaled upon installation of the protocol
907 * @registration key for retrieving the registration information
908 * @return status code
909 */
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200910static efi_status_t EFIAPI efi_register_protocol_notify(
911 const efi_guid_t *protocol,
912 struct efi_event *event,
913 void **registration)
Alexander Grafbee91162016-03-04 01:09:59 +0100914{
Rob Clark778e6af2017-09-13 18:05:41 -0400915 EFI_ENTRY("%pUl, %p, %p", protocol, event, registration);
Alexander Grafbee91162016-03-04 01:09:59 +0100916 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
917}
918
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200919/*
920 * Determine if an EFI handle implements a protocol.
921 *
922 * See the documentation of the LocateHandle service in the UEFI specification.
923 *
924 * @search_type selection criterion
925 * @protocol GUID of the protocol
926 * @search_key registration key
927 * @efiobj handle
928 * @return 0 if the handle implements the protocol
929 */
Alexander Grafbee91162016-03-04 01:09:59 +0100930static int efi_search(enum efi_locate_search_type search_type,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200931 const efi_guid_t *protocol, void *search_key,
Alexander Grafbee91162016-03-04 01:09:59 +0100932 struct efi_object *efiobj)
933{
934 int i;
935
936 switch (search_type) {
937 case all_handles:
938 return 0;
939 case by_register_notify:
940 return -1;
941 case by_protocol:
942 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
943 const efi_guid_t *guid = efiobj->protocols[i].guid;
944 if (guid && !guidcmp(guid, protocol))
945 return 0;
946 }
947 return -1;
948 }
949
950 return -1;
951}
952
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200953/*
954 * Locate handles implementing a protocol.
955 *
956 * This function is meant for U-Boot internal calls. For the API implementation
957 * of the LocateHandle service see efi_locate_handle_ext.
958 *
959 * @search_type selection criterion
960 * @protocol GUID of the protocol
961 * @search_key registration key
962 * @buffer_size size of the buffer to receive the handles in bytes
963 * @buffer buffer to receive the relevant handles
964 * @return status code
965 */
xypron.glpk@gmx.deebf199b2017-08-09 20:55:00 +0200966static efi_status_t efi_locate_handle(
Alexander Grafbee91162016-03-04 01:09:59 +0100967 enum efi_locate_search_type search_type,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200968 const efi_guid_t *protocol, void *search_key,
Alexander Grafbee91162016-03-04 01:09:59 +0100969 unsigned long *buffer_size, efi_handle_t *buffer)
970{
971 struct list_head *lhandle;
972 unsigned long size = 0;
973
Alexander Grafbee91162016-03-04 01:09:59 +0100974 /* Count how much space we need */
975 list_for_each(lhandle, &efi_obj_list) {
976 struct efi_object *efiobj;
977 efiobj = list_entry(lhandle, struct efi_object, link);
978 if (!efi_search(search_type, protocol, search_key, efiobj)) {
979 size += sizeof(void*);
980 }
981 }
982
983 if (*buffer_size < size) {
984 *buffer_size = size;
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +0200985 return EFI_BUFFER_TOO_SMALL;
Alexander Grafbee91162016-03-04 01:09:59 +0100986 }
987
Rob Clark796a78c2017-08-06 14:10:07 -0400988 *buffer_size = size;
989 if (size == 0)
990 return EFI_NOT_FOUND;
991
Alexander Grafbee91162016-03-04 01:09:59 +0100992 /* Then fill the array */
993 list_for_each(lhandle, &efi_obj_list) {
994 struct efi_object *efiobj;
995 efiobj = list_entry(lhandle, struct efi_object, link);
996 if (!efi_search(search_type, protocol, search_key, efiobj)) {
997 *(buffer++) = efiobj->handle;
998 }
999 }
1000
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02001001 return EFI_SUCCESS;
1002}
1003
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001004/*
1005 * Locate handles implementing a protocol.
1006 *
1007 * This function implements the LocateHandle service.
1008 * See the Unified Extensible Firmware Interface (UEFI) specification
1009 * for details.
1010 *
1011 * @search_type selection criterion
1012 * @protocol GUID of the protocol
1013 * @search_key registration key
1014 * @buffer_size size of the buffer to receive the handles in bytes
1015 * @buffer buffer to receive the relevant handles
1016 * @return 0 if the handle implements the protocol
1017 */
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02001018static efi_status_t EFIAPI efi_locate_handle_ext(
1019 enum efi_locate_search_type search_type,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001020 const efi_guid_t *protocol, void *search_key,
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02001021 unsigned long *buffer_size, efi_handle_t *buffer)
1022{
Rob Clark778e6af2017-09-13 18:05:41 -04001023 EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02001024 buffer_size, buffer);
1025
1026 return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
1027 buffer_size, buffer));
Alexander Grafbee91162016-03-04 01:09:59 +01001028}
1029
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001030/*
1031 * Get the device path and handle of an device implementing a protocol.
1032 *
1033 * This function implements the LocateDevicePath service.
1034 * See the Unified Extensible Firmware Interface (UEFI) specification
1035 * for details.
1036 *
1037 * @protocol GUID of the protocol
1038 * @device_path device path
1039 * @device handle of the device
1040 * @return status code
1041 */
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001042static efi_status_t EFIAPI efi_locate_device_path(
1043 const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001044 struct efi_device_path **device_path,
1045 efi_handle_t *device)
1046{
Rob Clarkb66c60d2017-09-13 18:05:28 -04001047 struct efi_object *efiobj;
1048
1049 EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device);
1050
1051 efiobj = efi_dp_find_obj(*device_path, device_path);
1052 if (!efiobj)
1053 return EFI_EXIT(EFI_NOT_FOUND);
1054
1055 *device = efiobj->handle;
1056
1057 return EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +01001058}
1059
Alexander Grafd98cdf62017-07-26 13:41:04 +02001060/* Collapses configuration table entries, removing index i */
1061static void efi_remove_configuration_table(int i)
1062{
1063 struct efi_configuration_table *this = &efi_conf_table[i];
1064 struct efi_configuration_table *next = &efi_conf_table[i+1];
1065 struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables];
1066
1067 memmove(this, next, (ulong)end - (ulong)next);
1068 systab.nr_tables--;
1069}
1070
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001071/*
1072 * Adds, updates, or removes a configuration table.
1073 *
1074 * This function is used for internal calls. For the API implementation of the
1075 * InstallConfigurationTable service see efi_install_configuration_table_ext.
1076 *
1077 * @guid GUID of the installed table
1078 * @table table to be installed
1079 * @return status code
1080 */
Alexander Graf488bf122016-08-19 01:23:24 +02001081efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
Alexander Grafbee91162016-03-04 01:09:59 +01001082{
1083 int i;
1084
Alexander Grafbee91162016-03-04 01:09:59 +01001085 /* Check for guid override */
1086 for (i = 0; i < systab.nr_tables; i++) {
1087 if (!guidcmp(guid, &efi_conf_table[i].guid)) {
Alexander Grafd98cdf62017-07-26 13:41:04 +02001088 if (table)
1089 efi_conf_table[i].table = table;
1090 else
1091 efi_remove_configuration_table(i);
Alexander Graf488bf122016-08-19 01:23:24 +02001092 return EFI_SUCCESS;
Alexander Grafbee91162016-03-04 01:09:59 +01001093 }
1094 }
1095
Alexander Grafd98cdf62017-07-26 13:41:04 +02001096 if (!table)
1097 return EFI_NOT_FOUND;
1098
Alexander Grafbee91162016-03-04 01:09:59 +01001099 /* No override, check for overflow */
1100 if (i >= ARRAY_SIZE(efi_conf_table))
Alexander Graf488bf122016-08-19 01:23:24 +02001101 return EFI_OUT_OF_RESOURCES;
Alexander Grafbee91162016-03-04 01:09:59 +01001102
1103 /* Add a new entry */
1104 memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
1105 efi_conf_table[i].table = table;
Alexander Grafaba5e912016-08-19 01:23:30 +02001106 systab.nr_tables = i + 1;
Alexander Grafbee91162016-03-04 01:09:59 +01001107
Alexander Graf488bf122016-08-19 01:23:24 +02001108 return EFI_SUCCESS;
1109}
1110
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001111/*
1112 * Adds, updates, or removes a configuration table.
1113 *
1114 * This function implements the InstallConfigurationTable service.
1115 * See the Unified Extensible Firmware Interface (UEFI) specification
1116 * for details.
1117 *
1118 * @guid GUID of the installed table
1119 * @table table to be installed
1120 * @return status code
1121 */
Alexander Graf488bf122016-08-19 01:23:24 +02001122static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
1123 void *table)
1124{
Rob Clark778e6af2017-09-13 18:05:41 -04001125 EFI_ENTRY("%pUl, %p", guid, table);
Alexander Graf488bf122016-08-19 01:23:24 +02001126 return EFI_EXIT(efi_install_configuration_table(guid, table));
Alexander Grafbee91162016-03-04 01:09:59 +01001127}
1128
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001129/*
1130 * Initialize a loaded_image_info + loaded_image_info object with correct
Rob Clark95c55532017-09-13 18:05:33 -04001131 * protocols, boot-device, etc.
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001132 *
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001133 * @info loaded image info to be passed to the entry point of the
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001134 * image
1135 * @obj internal object associated with the loaded image
1136 * @device_path device path of the loaded image
1137 * @file_path file path of the loaded image
Rob Clark95c55532017-09-13 18:05:33 -04001138 */
1139void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *obj,
1140 struct efi_device_path *device_path,
1141 struct efi_device_path *file_path)
1142{
1143 obj->handle = info;
1144
1145 /*
1146 * When asking for the device path interface, return
1147 * bootefi_device_path
1148 */
1149 obj->protocols[0].guid = &efi_guid_device_path;
1150 obj->protocols[0].protocol_interface = device_path;
1151
1152 /*
1153 * When asking for the loaded_image interface, just
1154 * return handle which points to loaded_image_info
1155 */
1156 obj->protocols[1].guid = &efi_guid_loaded_image;
1157 obj->protocols[1].protocol_interface = info;
1158
1159 obj->protocols[2].guid = &efi_guid_console_control;
1160 obj->protocols[2].protocol_interface = (void *)&efi_console_control;
1161
1162 obj->protocols[3].guid = &efi_guid_device_path_to_text_protocol;
1163 obj->protocols[3].protocol_interface =
1164 (void *)&efi_device_path_to_text;
1165
1166 info->file_path = file_path;
Heinrich Schuchardt1a2c8d22017-10-08 06:57:26 +02001167 if (device_path)
1168 info->device_handle = efi_dp_find_obj(device_path, NULL);
Rob Clark95c55532017-09-13 18:05:33 -04001169
1170 list_add_tail(&obj->link, &efi_obj_list);
1171}
1172
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001173/*
1174 * Load an image using a file path.
1175 *
1176 * @file_path the path of the image to load
1177 * @buffer buffer containing the loaded image
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001178 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001179 */
Rob Clark9975fe92017-09-13 18:05:38 -04001180efi_status_t efi_load_image_from_path(struct efi_device_path *file_path,
1181 void **buffer)
Rob Clark838ee4b2017-09-13 18:05:35 -04001182{
1183 struct efi_file_info *info = NULL;
1184 struct efi_file_handle *f;
1185 static efi_status_t ret;
1186 uint64_t bs;
1187
1188 f = efi_file_from_path(file_path);
1189 if (!f)
1190 return EFI_DEVICE_ERROR;
1191
1192 bs = 0;
1193 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1194 &bs, info));
1195 if (ret == EFI_BUFFER_TOO_SMALL) {
1196 info = malloc(bs);
1197 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1198 &bs, info));
1199 }
1200 if (ret != EFI_SUCCESS)
1201 goto error;
1202
1203 ret = efi_allocate_pool(EFI_LOADER_DATA, info->file_size, buffer);
1204 if (ret)
1205 goto error;
1206
1207 EFI_CALL(ret = f->read(f, &info->file_size, *buffer));
1208
1209error:
1210 free(info);
1211 EFI_CALL(f->close(f));
1212
1213 if (ret != EFI_SUCCESS) {
1214 efi_free_pool(*buffer);
1215 *buffer = NULL;
1216 }
1217
1218 return ret;
1219}
1220
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001221/*
1222 * Load an EFI image into memory.
1223 *
1224 * This function implements the LoadImage service.
1225 * See the Unified Extensible Firmware Interface (UEFI) specification
1226 * for details.
1227 *
1228 * @boot_policy true for request originating from the boot manager
1229 * @parent_image the calles's image handle
1230 * @file_path the path of the image to load
1231 * @source_buffer memory location from which the image is installed
1232 * @source_size size of the memory area from which the image is
1233 * installed
1234 * @image_handle handle for the newly installed image
1235 * @return status code
1236 */
Alexander Grafbee91162016-03-04 01:09:59 +01001237static efi_status_t EFIAPI efi_load_image(bool boot_policy,
1238 efi_handle_t parent_image,
1239 struct efi_device_path *file_path,
1240 void *source_buffer,
1241 unsigned long source_size,
1242 efi_handle_t *image_handle)
1243{
Alexander Grafbee91162016-03-04 01:09:59 +01001244 struct efi_loaded_image *info;
1245 struct efi_object *obj;
1246
1247 EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
1248 file_path, source_buffer, source_size, image_handle);
Rob Clark838ee4b2017-09-13 18:05:35 -04001249
1250 info = calloc(1, sizeof(*info));
1251 obj = calloc(1, sizeof(*obj));
1252
1253 if (!source_buffer) {
1254 struct efi_device_path *dp, *fp;
1255 efi_status_t ret;
1256
Rob Clark9975fe92017-09-13 18:05:38 -04001257 ret = efi_load_image_from_path(file_path, &source_buffer);
Rob Clark838ee4b2017-09-13 18:05:35 -04001258 if (ret != EFI_SUCCESS) {
1259 free(info);
1260 free(obj);
1261 return EFI_EXIT(ret);
1262 }
1263
1264 /*
1265 * split file_path which contains both the device and
1266 * file parts:
1267 */
1268 efi_dp_split_file_path(file_path, &dp, &fp);
1269
1270 efi_setup_loaded_image(info, obj, dp, fp);
1271 } else {
1272 /* In this case, file_path is the "device" path, ie.
1273 * something like a HARDWARE_DEVICE:MEMORY_MAPPED
1274 */
1275 efi_setup_loaded_image(info, obj, file_path, NULL);
1276 }
1277
Alexander Grafbee91162016-03-04 01:09:59 +01001278 info->reserved = efi_load_pe(source_buffer, info);
1279 if (!info->reserved) {
1280 free(info);
1281 free(obj);
1282 return EFI_EXIT(EFI_UNSUPPORTED);
1283 }
1284
1285 *image_handle = info;
Alexander Grafbee91162016-03-04 01:09:59 +01001286
1287 return EFI_EXIT(EFI_SUCCESS);
1288}
1289
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001290/*
1291 * Call the entry point of an image.
1292 *
1293 * This function implements the StartImage service.
1294 * See the Unified Extensible Firmware Interface (UEFI) specification
1295 * for details.
1296 *
1297 * @image_handle handle of the image
1298 * @exit_data_size size of the buffer
1299 * @exit_data buffer to receive the exit data of the called image
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001300 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001301 */
Alexander Grafbee91162016-03-04 01:09:59 +01001302static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
1303 unsigned long *exit_data_size,
1304 s16 **exit_data)
1305{
1306 ulong (*entry)(void *image_handle, struct efi_system_table *st);
1307 struct efi_loaded_image *info = image_handle;
1308
1309 EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
1310 entry = info->reserved;
1311
1312 efi_is_direct_boot = false;
1313
1314 /* call the image! */
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001315 if (setjmp(&info->exit_jmp)) {
1316 /* We returned from the child image */
1317 return EFI_EXIT(info->exit_status);
1318 }
1319
Rob Clarkaf65db82017-07-27 08:04:19 -04001320 __efi_nesting_dec();
Rob Clarkc160d2f2017-07-27 08:04:18 -04001321 __efi_exit_check();
Alexander Grafbee91162016-03-04 01:09:59 +01001322 entry(image_handle, &systab);
Rob Clarkc160d2f2017-07-27 08:04:18 -04001323 __efi_entry_check();
Rob Clarkaf65db82017-07-27 08:04:19 -04001324 __efi_nesting_inc();
Alexander Grafbee91162016-03-04 01:09:59 +01001325
1326 /* Should usually never get here */
1327 return EFI_EXIT(EFI_SUCCESS);
1328}
1329
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001330/*
1331 * Leave an EFI application or driver.
1332 *
1333 * This function implements the Exit service.
1334 * See the Unified Extensible Firmware Interface (UEFI) specification
1335 * for details.
1336 *
1337 * @image_handle handle of the application or driver that is exiting
1338 * @exit_status status code
1339 * @exit_data_size size of the buffer in bytes
1340 * @exit_data buffer with data describing an error
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001341 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001342 */
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001343static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
1344 efi_status_t exit_status, unsigned long exit_data_size,
1345 int16_t *exit_data)
Alexander Grafbee91162016-03-04 01:09:59 +01001346{
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001347 struct efi_loaded_image *loaded_image_info = (void*)image_handle;
1348
Alexander Grafbee91162016-03-04 01:09:59 +01001349 EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
1350 exit_data_size, exit_data);
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001351
Alexander Grafa1489202017-09-03 14:14:17 +02001352 /* Make sure entry/exit counts for EFI world cross-overs match */
Heinrich Schuchardtda940732017-08-25 19:53:14 +02001353 __efi_exit_check();
1354
Alexander Grafa1489202017-09-03 14:14:17 +02001355 /*
1356 * But longjmp out with the U-Boot gd, not the application's, as
1357 * the other end is a setjmp call inside EFI context.
1358 */
1359 efi_restore_gd();
1360
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001361 loaded_image_info->exit_status = exit_status;
Alexander Graf692fcdd2016-09-27 09:30:32 +02001362 longjmp(&loaded_image_info->exit_jmp, 1);
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001363
1364 panic("EFI application exited");
Alexander Grafbee91162016-03-04 01:09:59 +01001365}
1366
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001367/*
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001368 * Unload an EFI image.
1369 *
1370 * This function implements the UnloadImage service.
1371 * See the Unified Extensible Firmware Interface (UEFI) specification
1372 * for details.
1373 *
1374 * @image_handle handle of the image to be unloaded
1375 * @return status code
1376 */
Alexander Grafbee91162016-03-04 01:09:59 +01001377static efi_status_t EFIAPI efi_unload_image(void *image_handle)
1378{
1379 struct efi_object *efiobj;
1380
1381 EFI_ENTRY("%p", image_handle);
1382 efiobj = efi_search_obj(image_handle);
1383 if (efiobj)
1384 list_del(&efiobj->link);
1385
1386 return EFI_EXIT(EFI_SUCCESS);
1387}
1388
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001389/*
1390 * Fix up caches for EFI payloads if necessary.
1391 */
Alexander Grafbee91162016-03-04 01:09:59 +01001392static void efi_exit_caches(void)
1393{
1394#if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
1395 /*
1396 * Grub on 32bit ARM needs to have caches disabled before jumping into
1397 * a zImage, but does not know of all cache layers. Give it a hand.
1398 */
1399 if (efi_is_direct_boot)
1400 cleanup_before_linux();
1401#endif
1402}
1403
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001404/*
1405 * Stop boot services.
1406 *
1407 * This function implements the ExitBootServices service.
1408 * See the Unified Extensible Firmware Interface (UEFI) specification
1409 * for details.
1410 *
1411 * @image_handle handle of the loaded image
1412 * @map_key key of the memory map
1413 * @return status code
1414 */
Alexander Grafbee91162016-03-04 01:09:59 +01001415static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
1416 unsigned long map_key)
1417{
Heinrich Schuchardt152a2632017-09-15 10:06:18 +02001418 int i;
1419
Alexander Grafbee91162016-03-04 01:09:59 +01001420 EFI_ENTRY("%p, %ld", image_handle, map_key);
1421
Heinrich Schuchardt152a2632017-09-15 10:06:18 +02001422 /* Notify that ExitBootServices is invoked. */
1423 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
1424 if (efi_events[i].type != EVT_SIGNAL_EXIT_BOOT_SERVICES)
1425 continue;
1426 efi_signal_event(&efi_events[i]);
1427 }
1428 /* Make sure that notification functions are not called anymore */
1429 efi_tpl = TPL_HIGH_LEVEL;
1430
Alexander Graf40583562017-10-19 23:23:50 +02001431 /* XXX Should persist EFI variables here */
Rob Clarkad644e72017-09-13 18:05:37 -04001432
Alexander Grafb7b84102016-11-17 01:02:57 +01001433 board_quiesce_devices();
1434
Alexander Grafbee91162016-03-04 01:09:59 +01001435 /* Fix up caches for EFI payloads if necessary */
1436 efi_exit_caches();
1437
1438 /* This stops all lingering devices */
1439 bootm_disable_interrupts();
1440
1441 /* Give the payload some time to boot */
Heinrich Schuchardtb3d60902017-10-18 18:13:04 +02001442 efi_set_watchdog(0);
Alexander Grafbee91162016-03-04 01:09:59 +01001443 WATCHDOG_RESET();
1444
1445 return EFI_EXIT(EFI_SUCCESS);
1446}
1447
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001448/*
1449 * Get next value of the counter.
1450 *
1451 * This function implements the NextMonotonicCount service.
1452 * See the Unified Extensible Firmware Interface (UEFI) specification
1453 * for details.
1454 *
1455 * @count returned value of the counter
1456 * @return status code
1457 */
Alexander Grafbee91162016-03-04 01:09:59 +01001458static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
1459{
1460 static uint64_t mono = 0;
1461 EFI_ENTRY("%p", count);
1462 *count = mono++;
1463 return EFI_EXIT(EFI_SUCCESS);
1464}
1465
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001466/*
1467 * Sleep.
1468 *
1469 * This function implements the Stall sercive.
1470 * See the Unified Extensible Firmware Interface (UEFI) specification
1471 * for details.
1472 *
1473 * @microseconds period to sleep in microseconds
1474 * @return status code
1475 */
Alexander Grafbee91162016-03-04 01:09:59 +01001476static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
1477{
1478 EFI_ENTRY("%ld", microseconds);
1479 udelay(microseconds);
1480 return EFI_EXIT(EFI_SUCCESS);
1481}
1482
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001483/*
1484 * Reset the watchdog timer.
1485 *
Heinrich Schuchardtb3d60902017-10-18 18:13:04 +02001486 * This function implements the SetWatchdogTimer service.
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001487 * See the Unified Extensible Firmware Interface (UEFI) specification
1488 * for details.
1489 *
1490 * @timeout seconds before reset by watchdog
1491 * @watchdog_code code to be logged when resetting
1492 * @data_size size of buffer in bytes
1493 * @watchdog_data buffer with data describing the reset reason
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001494 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001495 */
Alexander Grafbee91162016-03-04 01:09:59 +01001496static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
1497 uint64_t watchdog_code,
1498 unsigned long data_size,
1499 uint16_t *watchdog_data)
1500{
1501 EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
1502 data_size, watchdog_data);
Heinrich Schuchardtb3d60902017-10-18 18:13:04 +02001503 return EFI_EXIT(efi_set_watchdog(timeout));
Alexander Grafbee91162016-03-04 01:09:59 +01001504}
1505
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001506/*
1507 * Connect a controller to a driver.
1508 *
1509 * This function implements the ConnectController service.
1510 * See the Unified Extensible Firmware Interface (UEFI) specification
1511 * for details.
1512 *
1513 * @controller_handle handle of the controller
1514 * @driver_image_handle handle of the driver
1515 * @remain_device_path device path of a child controller
1516 * @recursive true to connect all child controllers
1517 * @return status code
1518 */
Alexander Grafbee91162016-03-04 01:09:59 +01001519static efi_status_t EFIAPI efi_connect_controller(
1520 efi_handle_t controller_handle,
1521 efi_handle_t *driver_image_handle,
1522 struct efi_device_path *remain_device_path,
1523 bool recursive)
1524{
1525 EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
1526 remain_device_path, recursive);
1527 return EFI_EXIT(EFI_NOT_FOUND);
1528}
1529
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001530/*
1531 * Disconnect a controller from a driver.
1532 *
1533 * This function implements the DisconnectController service.
1534 * See the Unified Extensible Firmware Interface (UEFI) specification
1535 * for details.
1536 *
1537 * @controller_handle handle of the controller
1538 * @driver_image_handle handle of the driver
1539 * @child_handle handle of the child to destroy
1540 * @return status code
1541 */
Alexander Grafbee91162016-03-04 01:09:59 +01001542static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
1543 void *driver_image_handle,
1544 void *child_handle)
1545{
1546 EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
1547 child_handle);
1548 return EFI_EXIT(EFI_INVALID_PARAMETER);
1549}
1550
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001551/*
1552 * Close a protocol.
1553 *
1554 * This function implements the CloseProtocol service.
1555 * See the Unified Extensible Firmware Interface (UEFI) specification
1556 * for details.
1557 *
1558 * @handle handle on which the protocol shall be closed
1559 * @protocol GUID of the protocol to close
1560 * @agent_handle handle of the driver
1561 * @controller_handle handle of the controller
1562 * @return status code
1563 */
Alexander Grafbee91162016-03-04 01:09:59 +01001564static efi_status_t EFIAPI efi_close_protocol(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001565 const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001566 void *agent_handle,
1567 void *controller_handle)
1568{
Rob Clark778e6af2017-09-13 18:05:41 -04001569 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, agent_handle,
Alexander Grafbee91162016-03-04 01:09:59 +01001570 controller_handle);
1571 return EFI_EXIT(EFI_NOT_FOUND);
1572}
1573
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001574/*
1575 * Provide information about then open status of a protocol on a handle
1576 *
1577 * This function implements the OpenProtocolInformation service.
1578 * See the Unified Extensible Firmware Interface (UEFI) specification
1579 * for details.
1580 *
1581 * @handle handle for which the information shall be retrieved
1582 * @protocol GUID of the protocol
1583 * @entry_buffer buffer to receive the open protocol information
1584 * @entry_count number of entries available in the buffer
1585 * @return status code
1586 */
Alexander Grafbee91162016-03-04 01:09:59 +01001587static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001588 const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001589 struct efi_open_protocol_info_entry **entry_buffer,
1590 unsigned long *entry_count)
1591{
Rob Clark778e6af2017-09-13 18:05:41 -04001592 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, entry_buffer,
Alexander Grafbee91162016-03-04 01:09:59 +01001593 entry_count);
1594 return EFI_EXIT(EFI_NOT_FOUND);
1595}
1596
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001597/*
1598 * Get protocols installed on a handle.
1599 *
1600 * This function implements the ProtocolsPerHandleService.
1601 * See the Unified Extensible Firmware Interface (UEFI) specification
1602 * for details.
1603 *
1604 * @handle handle for which the information is retrieved
1605 * @protocol_buffer buffer with protocol GUIDs
1606 * @protocol_buffer_count number of entries in the buffer
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001607 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001608 */
Alexander Grafbee91162016-03-04 01:09:59 +01001609static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
1610 efi_guid_t ***protocol_buffer,
1611 unsigned long *protocol_buffer_count)
1612{
xypron.glpk@gmx.dec0ebfc82017-07-13 23:24:32 +02001613 unsigned long buffer_size;
1614 struct efi_object *efiobj;
1615 unsigned long i, j;
1616 struct list_head *lhandle;
1617 efi_status_t r;
1618
Alexander Grafbee91162016-03-04 01:09:59 +01001619 EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
1620 protocol_buffer_count);
xypron.glpk@gmx.dec0ebfc82017-07-13 23:24:32 +02001621
1622 if (!handle || !protocol_buffer || !protocol_buffer_count)
1623 return EFI_EXIT(EFI_INVALID_PARAMETER);
1624
1625 *protocol_buffer = NULL;
Rob Clark661c8322017-07-20 07:59:39 -04001626 *protocol_buffer_count = 0;
xypron.glpk@gmx.dec0ebfc82017-07-13 23:24:32 +02001627 list_for_each(lhandle, &efi_obj_list) {
1628 efiobj = list_entry(lhandle, struct efi_object, link);
1629
1630 if (efiobj->handle != handle)
1631 continue;
1632
1633 /* Count protocols */
1634 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1635 if (efiobj->protocols[i].guid)
1636 ++*protocol_buffer_count;
1637 }
1638 /* Copy guids */
1639 if (*protocol_buffer_count) {
1640 buffer_size = sizeof(efi_guid_t *) *
1641 *protocol_buffer_count;
1642 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
1643 buffer_size,
1644 (void **)protocol_buffer);
1645 if (r != EFI_SUCCESS)
1646 return EFI_EXIT(r);
1647 j = 0;
1648 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); ++i) {
1649 if (efiobj->protocols[i].guid) {
1650 (*protocol_buffer)[j] = (void *)
1651 efiobj->protocols[i].guid;
1652 ++j;
1653 }
1654 }
1655 }
1656 break;
1657 }
1658
1659 return EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +01001660}
1661
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001662/*
1663 * Locate handles implementing a protocol.
1664 *
1665 * This function implements the LocateHandleBuffer service.
1666 * See the Unified Extensible Firmware Interface (UEFI) specification
1667 * for details.
1668 *
1669 * @search_type selection criterion
1670 * @protocol GUID of the protocol
1671 * @search_key registration key
1672 * @no_handles number of returned handles
1673 * @buffer buffer with the returned handles
1674 * @return status code
1675 */
Alexander Grafbee91162016-03-04 01:09:59 +01001676static efi_status_t EFIAPI efi_locate_handle_buffer(
1677 enum efi_locate_search_type search_type,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001678 const efi_guid_t *protocol, void *search_key,
Alexander Grafbee91162016-03-04 01:09:59 +01001679 unsigned long *no_handles, efi_handle_t **buffer)
1680{
xypron.glpk@gmx.dec2e703f2017-07-11 22:06:22 +02001681 efi_status_t r;
1682 unsigned long buffer_size = 0;
1683
Rob Clark778e6af2017-09-13 18:05:41 -04001684 EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
Alexander Grafbee91162016-03-04 01:09:59 +01001685 no_handles, buffer);
xypron.glpk@gmx.dec2e703f2017-07-11 22:06:22 +02001686
1687 if (!no_handles || !buffer) {
1688 r = EFI_INVALID_PARAMETER;
1689 goto out;
1690 }
1691 *no_handles = 0;
1692 *buffer = NULL;
1693 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
1694 *buffer);
1695 if (r != EFI_BUFFER_TOO_SMALL)
1696 goto out;
1697 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
1698 (void **)buffer);
1699 if (r != EFI_SUCCESS)
1700 goto out;
1701 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
1702 *buffer);
1703 if (r == EFI_SUCCESS)
1704 *no_handles = buffer_size / sizeof(void *);
1705out:
1706 return EFI_EXIT(r);
Alexander Grafbee91162016-03-04 01:09:59 +01001707}
1708
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001709/*
1710 * Find an interface implementing a protocol.
1711 *
1712 * This function implements the LocateProtocol service.
1713 * See the Unified Extensible Firmware Interface (UEFI) specification
1714 * for details.
1715 *
1716 * @protocol GUID of the protocol
1717 * @registration registration key passed to the notification function
1718 * @protocol_interface interface implementing the protocol
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001719 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001720 */
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001721static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001722 void *registration,
1723 void **protocol_interface)
1724{
xypron.glpk@gmx.de88adae52017-07-11 22:06:24 +02001725 struct list_head *lhandle;
Alexander Grafbee91162016-03-04 01:09:59 +01001726 int i;
1727
Rob Clark778e6af2017-09-13 18:05:41 -04001728 EFI_ENTRY("%pUl, %p, %p", protocol, registration, protocol_interface);
xypron.glpk@gmx.de88adae52017-07-11 22:06:24 +02001729
1730 if (!protocol || !protocol_interface)
1731 return EFI_EXIT(EFI_INVALID_PARAMETER);
1732
Heinrich Schuchardtae0bd3a2017-08-18 17:45:16 +02001733 EFI_PRINT_GUID("protocol", protocol);
1734
xypron.glpk@gmx.de88adae52017-07-11 22:06:24 +02001735 list_for_each(lhandle, &efi_obj_list) {
1736 struct efi_object *efiobj;
1737
1738 efiobj = list_entry(lhandle, struct efi_object, link);
1739 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1740 struct efi_handler *handler = &efiobj->protocols[i];
1741
1742 if (!handler->guid)
1743 continue;
1744 if (!guidcmp(handler->guid, protocol)) {
1745 *protocol_interface =
1746 handler->protocol_interface;
1747 return EFI_EXIT(EFI_SUCCESS);
1748 }
Alexander Grafbee91162016-03-04 01:09:59 +01001749 }
1750 }
xypron.glpk@gmx.de88adae52017-07-11 22:06:24 +02001751 *protocol_interface = NULL;
Alexander Grafbee91162016-03-04 01:09:59 +01001752
1753 return EFI_EXIT(EFI_NOT_FOUND);
1754}
1755
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001756/*
1757 * Install multiple protocol interfaces.
1758 *
1759 * This function implements the MultipleProtocolInterfaces service.
1760 * See the Unified Extensible Firmware Interface (UEFI) specification
1761 * for details.
1762 *
1763 * @handle handle on which the protocol interfaces shall be installed
1764 * @... NULL terminated argument list with pairs of protocol GUIDS and
1765 * interfaces
1766 * @return status code
1767 */
Alexander Grafbee91162016-03-04 01:09:59 +01001768static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
1769 void **handle, ...)
1770{
1771 EFI_ENTRY("%p", handle);
xypron.glpk@gmx.de58b83582017-07-11 22:06:20 +02001772
1773 va_list argptr;
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001774 const efi_guid_t *protocol;
xypron.glpk@gmx.de58b83582017-07-11 22:06:20 +02001775 void *protocol_interface;
1776 efi_status_t r = EFI_SUCCESS;
1777 int i = 0;
1778
1779 if (!handle)
1780 return EFI_EXIT(EFI_INVALID_PARAMETER);
1781
1782 va_start(argptr, handle);
1783 for (;;) {
1784 protocol = va_arg(argptr, efi_guid_t*);
1785 if (!protocol)
1786 break;
1787 protocol_interface = va_arg(argptr, void*);
1788 r = efi_install_protocol_interface(handle, protocol,
1789 EFI_NATIVE_INTERFACE,
1790 protocol_interface);
1791 if (r != EFI_SUCCESS)
1792 break;
1793 i++;
1794 }
1795 va_end(argptr);
1796 if (r == EFI_SUCCESS)
1797 return EFI_EXIT(r);
1798
1799 /* If an error occured undo all changes. */
1800 va_start(argptr, handle);
1801 for (; i; --i) {
1802 protocol = va_arg(argptr, efi_guid_t*);
1803 protocol_interface = va_arg(argptr, void*);
1804 efi_uninstall_protocol_interface(handle, protocol,
1805 protocol_interface);
1806 }
1807 va_end(argptr);
1808
1809 return EFI_EXIT(r);
Alexander Grafbee91162016-03-04 01:09:59 +01001810}
1811
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001812/*
1813 * Uninstall multiple protocol interfaces.
1814 *
1815 * This function implements the UninstallMultipleProtocolInterfaces service.
1816 * See the Unified Extensible Firmware Interface (UEFI) specification
1817 * for details.
1818 *
1819 * @handle handle from which the protocol interfaces shall be removed
1820 * @... NULL terminated argument list with pairs of protocol GUIDS and
1821 * interfaces
1822 * @return status code
1823 */
Alexander Grafbee91162016-03-04 01:09:59 +01001824static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
1825 void *handle, ...)
1826{
1827 EFI_ENTRY("%p", handle);
1828 return EFI_EXIT(EFI_INVALID_PARAMETER);
1829}
1830
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001831/*
1832 * Calculate cyclic redundancy code.
1833 *
1834 * This function implements the CalculateCrc32 service.
1835 * See the Unified Extensible Firmware Interface (UEFI) specification
1836 * for details.
1837 *
1838 * @data buffer with data
1839 * @data_size size of buffer in bytes
1840 * @crc32_p cyclic redundancy code
1841 * @return status code
1842 */
Alexander Grafbee91162016-03-04 01:09:59 +01001843static efi_status_t EFIAPI efi_calculate_crc32(void *data,
1844 unsigned long data_size,
1845 uint32_t *crc32_p)
1846{
1847 EFI_ENTRY("%p, %ld", data, data_size);
1848 *crc32_p = crc32(0, data, data_size);
1849 return EFI_EXIT(EFI_SUCCESS);
1850}
1851
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001852/*
1853 * Copy memory.
1854 *
1855 * This function implements the CopyMem service.
1856 * See the Unified Extensible Firmware Interface (UEFI) specification
1857 * for details.
1858 *
1859 * @destination destination of the copy operation
1860 * @source source of the copy operation
1861 * @length number of bytes to copy
1862 */
Heinrich Schuchardtfc05a952017-10-05 16:35:52 +02001863static void EFIAPI efi_copy_mem(void *destination, const void *source,
1864 size_t length)
Alexander Grafbee91162016-03-04 01:09:59 +01001865{
Heinrich Schuchardtfc05a952017-10-05 16:35:52 +02001866 EFI_ENTRY("%p, %p, %ld", destination, source, (unsigned long)length);
Alexander Grafbee91162016-03-04 01:09:59 +01001867 memcpy(destination, source, length);
Heinrich Schuchardtf7c78172017-10-05 16:35:51 +02001868 EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +01001869}
1870
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001871/*
1872 * Fill memory with a byte value.
1873 *
1874 * This function implements the SetMem service.
1875 * See the Unified Extensible Firmware Interface (UEFI) specification
1876 * for details.
1877 *
1878 * @buffer buffer to fill
1879 * @size size of buffer in bytes
1880 * @value byte to copy to the buffer
1881 */
Heinrich Schuchardtfc05a952017-10-05 16:35:52 +02001882static void EFIAPI efi_set_mem(void *buffer, size_t size, uint8_t value)
Alexander Grafbee91162016-03-04 01:09:59 +01001883{
Heinrich Schuchardtfc05a952017-10-05 16:35:52 +02001884 EFI_ENTRY("%p, %ld, 0x%x", buffer, (unsigned long)size, value);
Alexander Grafbee91162016-03-04 01:09:59 +01001885 memset(buffer, value, size);
Heinrich Schuchardtf7c78172017-10-05 16:35:51 +02001886 EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +01001887}
1888
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001889/*
1890 * Open protocol interface on a handle.
1891 *
1892 * This function implements the OpenProtocol interface.
1893 * See the Unified Extensible Firmware Interface (UEFI) specification
1894 * for details.
1895 *
1896 * @handle handle on which the protocol shall be opened
1897 * @protocol GUID of the protocol
1898 * @protocol_interface interface implementing the protocol
1899 * @agent_handle handle of the driver
1900 * @controller_handle handle of the controller
1901 * @attributes attributes indicating how to open the protocol
1902 * @return status code
1903 */
Alexander Grafbee91162016-03-04 01:09:59 +01001904static efi_status_t EFIAPI efi_open_protocol(
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001905 void *handle, const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001906 void **protocol_interface, void *agent_handle,
1907 void *controller_handle, uint32_t attributes)
1908{
1909 struct list_head *lhandle;
1910 int i;
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001911 efi_status_t r = EFI_INVALID_PARAMETER;
Alexander Grafbee91162016-03-04 01:09:59 +01001912
Rob Clark778e6af2017-09-13 18:05:41 -04001913 EFI_ENTRY("%p, %pUl, %p, %p, %p, 0x%x", handle, protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001914 protocol_interface, agent_handle, controller_handle,
1915 attributes);
xypron.glpk@gmx.deb5349f72017-07-11 22:06:14 +02001916
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001917 if (!handle || !protocol ||
1918 (!protocol_interface && attributes !=
1919 EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
1920 goto out;
1921 }
1922
Heinrich Schuchardtae0bd3a2017-08-18 17:45:16 +02001923 EFI_PRINT_GUID("protocol", protocol);
1924
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001925 switch (attributes) {
1926 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
1927 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
1928 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
1929 break;
1930 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
1931 if (controller_handle == handle)
1932 goto out;
1933 case EFI_OPEN_PROTOCOL_BY_DRIVER:
1934 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
1935 if (controller_handle == NULL)
1936 goto out;
1937 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
1938 if (agent_handle == NULL)
1939 goto out;
1940 break;
1941 default:
xypron.glpk@gmx.deb5349f72017-07-11 22:06:14 +02001942 goto out;
1943 }
1944
Alexander Grafbee91162016-03-04 01:09:59 +01001945 list_for_each(lhandle, &efi_obj_list) {
1946 struct efi_object *efiobj;
1947 efiobj = list_entry(lhandle, struct efi_object, link);
1948
1949 if (efiobj->handle != handle)
1950 continue;
1951
1952 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1953 struct efi_handler *handler = &efiobj->protocols[i];
1954 const efi_guid_t *hprotocol = handler->guid;
1955 if (!hprotocol)
xypron.glpk@gmx.de4b6ed0d2017-07-11 22:06:17 +02001956 continue;
Alexander Grafbee91162016-03-04 01:09:59 +01001957 if (!guidcmp(hprotocol, protocol)) {
xypron.glpk@gmx.deb5349f72017-07-11 22:06:14 +02001958 if (attributes !=
1959 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
1960 *protocol_interface =
1961 handler->protocol_interface;
1962 }
1963 r = EFI_SUCCESS;
Alexander Grafbee91162016-03-04 01:09:59 +01001964 goto out;
1965 }
1966 }
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001967 goto unsupported;
Alexander Grafbee91162016-03-04 01:09:59 +01001968 }
1969
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001970unsupported:
1971 r = EFI_UNSUPPORTED;
Alexander Grafbee91162016-03-04 01:09:59 +01001972out:
1973 return EFI_EXIT(r);
1974}
1975
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001976/*
1977 * Get interface of a protocol on a handle.
1978 *
1979 * This function implements the HandleProtocol service.
1980 * See the Unified Extensible Firmware Interface (UEFI) specification
1981 * for details.
1982 *
1983 * @handle handle on which the protocol shall be opened
1984 * @protocol GUID of the protocol
1985 * @protocol_interface interface implementing the protocol
1986 * @return status code
1987 */
Alexander Grafbee91162016-03-04 01:09:59 +01001988static efi_status_t EFIAPI efi_handle_protocol(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001989 const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001990 void **protocol_interface)
1991{
xypron.glpk@gmx.de8e1d3292017-06-29 21:16:19 +02001992 return efi_open_protocol(handle, protocol, protocol_interface, NULL,
1993 NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
Alexander Grafbee91162016-03-04 01:09:59 +01001994}
1995
1996static const struct efi_boot_services efi_boot_services = {
1997 .hdr = {
1998 .headersize = sizeof(struct efi_table_hdr),
1999 },
2000 .raise_tpl = efi_raise_tpl,
2001 .restore_tpl = efi_restore_tpl,
2002 .allocate_pages = efi_allocate_pages_ext,
2003 .free_pages = efi_free_pages_ext,
2004 .get_memory_map = efi_get_memory_map_ext,
Stefan Brünsead12742016-10-09 22:17:18 +02002005 .allocate_pool = efi_allocate_pool_ext,
Stefan Brüns42417bc2016-10-09 22:17:26 +02002006 .free_pool = efi_free_pool_ext,
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +02002007 .create_event = efi_create_event_ext,
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +02002008 .set_timer = efi_set_timer_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002009 .wait_for_event = efi_wait_for_event,
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +02002010 .signal_event = efi_signal_event_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002011 .close_event = efi_close_event,
2012 .check_event = efi_check_event,
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +02002013 .install_protocol_interface = efi_install_protocol_interface_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002014 .reinstall_protocol_interface = efi_reinstall_protocol_interface,
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +02002015 .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002016 .handle_protocol = efi_handle_protocol,
2017 .reserved = NULL,
2018 .register_protocol_notify = efi_register_protocol_notify,
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02002019 .locate_handle = efi_locate_handle_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002020 .locate_device_path = efi_locate_device_path,
Alexander Graf488bf122016-08-19 01:23:24 +02002021 .install_configuration_table = efi_install_configuration_table_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002022 .load_image = efi_load_image,
2023 .start_image = efi_start_image,
Alexander Grafa86aeaf2016-05-20 23:28:23 +02002024 .exit = efi_exit,
Alexander Grafbee91162016-03-04 01:09:59 +01002025 .unload_image = efi_unload_image,
2026 .exit_boot_services = efi_exit_boot_services,
2027 .get_next_monotonic_count = efi_get_next_monotonic_count,
2028 .stall = efi_stall,
2029 .set_watchdog_timer = efi_set_watchdog_timer,
2030 .connect_controller = efi_connect_controller,
2031 .disconnect_controller = efi_disconnect_controller,
2032 .open_protocol = efi_open_protocol,
2033 .close_protocol = efi_close_protocol,
2034 .open_protocol_information = efi_open_protocol_information,
2035 .protocols_per_handle = efi_protocols_per_handle,
2036 .locate_handle_buffer = efi_locate_handle_buffer,
2037 .locate_protocol = efi_locate_protocol,
2038 .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
2039 .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
2040 .calculate_crc32 = efi_calculate_crc32,
2041 .copy_mem = efi_copy_mem,
2042 .set_mem = efi_set_mem,
2043};
2044
2045
Alexander Graf3c63db92016-10-14 13:45:30 +02002046static uint16_t __efi_runtime_data firmware_vendor[] =
Alexander Grafbee91162016-03-04 01:09:59 +01002047 { 'D','a','s',' ','U','-','b','o','o','t',0 };
2048
Alexander Graf3c63db92016-10-14 13:45:30 +02002049struct efi_system_table __efi_runtime_data systab = {
Alexander Grafbee91162016-03-04 01:09:59 +01002050 .hdr = {
2051 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
2052 .revision = 0x20005, /* 2.5 */
2053 .headersize = sizeof(struct efi_table_hdr),
2054 },
2055 .fw_vendor = (long)firmware_vendor,
2056 .con_in = (void*)&efi_con_in,
2057 .con_out = (void*)&efi_con_out,
2058 .std_err = (void*)&efi_con_out,
2059 .runtime = (void*)&efi_runtime_services,
2060 .boottime = (void*)&efi_boot_services,
2061 .nr_tables = 0,
2062 .tables = (void*)efi_conf_table,
2063};