blob: e5adc17faba94d9a09721d0b6d625d5d7f839592 [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/*
159 * Write a debug message for an EPI API service that is not implemented yet.
160 *
161 * @funcname function that is not yet implemented
162 * @return EFI_UNSUPPORTED
163 */
Alexander Grafbee91162016-03-04 01:09:59 +0100164static efi_status_t efi_unsupported(const char *funcname)
165{
Alexander Grafedcef3b2016-06-02 11:38:27 +0200166 debug("EFI: App called into unimplemented function %s\n", funcname);
Alexander Grafbee91162016-03-04 01:09:59 +0100167 return EFI_EXIT(EFI_UNSUPPORTED);
168}
169
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200170/*
171 * Raise the task priority level.
172 *
173 * This function implements the RaiseTpl service.
174 * See the Unified Extensible Firmware Interface (UEFI) specification
175 * for details.
176 *
177 * @new_tpl new value of the task priority level
178 * @return old value of the task priority level
179 */
xypron.glpk@gmx.de503f2692017-07-18 20:17:19 +0200180static unsigned long EFIAPI efi_raise_tpl(UINTN new_tpl)
Alexander Grafbee91162016-03-04 01:09:59 +0100181{
Heinrich Schuchardt32f4b2f2017-09-15 10:06:16 +0200182 UINTN old_tpl = efi_tpl;
183
xypron.glpk@gmx.de503f2692017-07-18 20:17:19 +0200184 EFI_ENTRY("0x%zx", new_tpl);
Heinrich Schuchardt32f4b2f2017-09-15 10:06:16 +0200185
186 if (new_tpl < efi_tpl)
187 debug("WARNING: new_tpl < current_tpl in %s\n", __func__);
188 efi_tpl = new_tpl;
189 if (efi_tpl > TPL_HIGH_LEVEL)
190 efi_tpl = TPL_HIGH_LEVEL;
191
192 EFI_EXIT(EFI_SUCCESS);
193 return old_tpl;
Alexander Grafbee91162016-03-04 01:09:59 +0100194}
195
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200196/*
197 * Lower the task priority level.
198 *
199 * This function implements the RestoreTpl service.
200 * See the Unified Extensible Firmware Interface (UEFI) specification
201 * for details.
202 *
203 * @old_tpl value of the task priority level to be restored
204 */
xypron.glpk@gmx.de503f2692017-07-18 20:17:19 +0200205static void EFIAPI efi_restore_tpl(UINTN old_tpl)
Alexander Grafbee91162016-03-04 01:09:59 +0100206{
xypron.glpk@gmx.de503f2692017-07-18 20:17:19 +0200207 EFI_ENTRY("0x%zx", old_tpl);
Heinrich Schuchardt32f4b2f2017-09-15 10:06:16 +0200208
209 if (old_tpl > efi_tpl)
210 debug("WARNING: old_tpl > current_tpl in %s\n", __func__);
211 efi_tpl = old_tpl;
212 if (efi_tpl > TPL_HIGH_LEVEL)
213 efi_tpl = TPL_HIGH_LEVEL;
214
215 EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +0100216}
217
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200218/*
219 * Allocate memory pages.
220 *
221 * This function implements the AllocatePages service.
222 * See the Unified Extensible Firmware Interface (UEFI) specification
223 * for details.
224 *
225 * @type type of allocation to be performed
226 * @memory_type usage type of the allocated memory
227 * @pages number of pages to be allocated
228 * @memory allocated memory
229 * @return status code
230 */
Masahiro Yamada6e0bf8d2017-06-22 17:49:03 +0900231static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
232 unsigned long pages,
233 uint64_t *memory)
Alexander Grafbee91162016-03-04 01:09:59 +0100234{
235 efi_status_t r;
236
237 EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory);
238 r = efi_allocate_pages(type, memory_type, pages, memory);
239 return EFI_EXIT(r);
240}
241
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200242/*
243 * Free memory pages.
244 *
245 * This function implements the FreePages service.
246 * See the Unified Extensible Firmware Interface (UEFI) specification
247 * for details.
248 *
249 * @memory start of the memory area to be freed
250 * @pages number of pages to be freed
251 * @return status code
252 */
Masahiro Yamada6e0bf8d2017-06-22 17:49:03 +0900253static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
254 unsigned long pages)
Alexander Grafbee91162016-03-04 01:09:59 +0100255{
256 efi_status_t r;
257
258 EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages);
259 r = efi_free_pages(memory, pages);
260 return EFI_EXIT(r);
261}
262
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200263/*
264 * Get map describing memory usage.
265 *
266 * This function implements the GetMemoryMap service.
267 * See the Unified Extensible Firmware Interface (UEFI) specification
268 * for details.
269 *
270 * @memory_map_size on entry the size, in bytes, of the memory map buffer,
271 * on exit the size of the copied memory map
272 * @memory_map buffer to which the memory map is written
273 * @map_key key for the memory map
274 * @descriptor_size size of an individual memory descriptor
275 * @descriptor_version version number of the memory descriptor structure
276 * @return status code
277 */
Masahiro Yamada6e0bf8d2017-06-22 17:49:03 +0900278static efi_status_t EFIAPI efi_get_memory_map_ext(
279 unsigned long *memory_map_size,
280 struct efi_mem_desc *memory_map,
281 unsigned long *map_key,
282 unsigned long *descriptor_size,
283 uint32_t *descriptor_version)
Alexander Grafbee91162016-03-04 01:09:59 +0100284{
285 efi_status_t r;
286
287 EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map,
288 map_key, descriptor_size, descriptor_version);
289 r = efi_get_memory_map(memory_map_size, memory_map, map_key,
290 descriptor_size, descriptor_version);
291 return EFI_EXIT(r);
292}
293
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200294/*
295 * Allocate memory from pool.
296 *
297 * This function implements the AllocatePool service.
298 * See the Unified Extensible Firmware Interface (UEFI) specification
299 * for details.
300 *
301 * @pool_type type of the pool from which memory is to be allocated
302 * @size number of bytes to be allocated
303 * @buffer allocated memory
304 * @return status code
305 */
Stefan Brünsead12742016-10-09 22:17:18 +0200306static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
307 unsigned long size,
308 void **buffer)
Alexander Grafbee91162016-03-04 01:09:59 +0100309{
Alexander Graf1cd29f02016-03-24 01:37:37 +0100310 efi_status_t r;
311
312 EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer);
Stefan Brünsead12742016-10-09 22:17:18 +0200313 r = efi_allocate_pool(pool_type, size, buffer);
Alexander Graf1cd29f02016-03-24 01:37:37 +0100314 return EFI_EXIT(r);
Alexander Grafbee91162016-03-04 01:09:59 +0100315}
316
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200317/*
318 * Free memory from pool.
319 *
320 * This function implements the FreePool service.
321 * See the Unified Extensible Firmware Interface (UEFI) specification
322 * for details.
323 *
324 * @buffer start of memory to be freed
325 * @return status code
326 */
Stefan Brüns42417bc2016-10-09 22:17:26 +0200327static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
Alexander Grafbee91162016-03-04 01:09:59 +0100328{
Alexander Graf1cd29f02016-03-24 01:37:37 +0100329 efi_status_t r;
330
331 EFI_ENTRY("%p", buffer);
Stefan Brüns42417bc2016-10-09 22:17:26 +0200332 r = efi_free_pool(buffer);
Alexander Graf1cd29f02016-03-24 01:37:37 +0100333 return EFI_EXIT(r);
Alexander Grafbee91162016-03-04 01:09:59 +0100334}
335
Heinrich Schuchardt3cc6e3f2017-08-27 00:51:09 +0200336static efi_status_t efi_create_handle(void **handle)
337{
338 struct efi_object *obj;
339 efi_status_t r;
340
341 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
342 sizeof(struct efi_object),
343 (void **)&obj);
344 if (r != EFI_SUCCESS)
345 return r;
346 memset(obj, 0, sizeof(struct efi_object));
347 obj->handle = obj;
348 list_add_tail(&obj->link, &efi_obj_list);
349 *handle = obj;
350 return r;
351}
352
Alexander Grafbee91162016-03-04 01:09:59 +0100353/*
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200354 * Our event capabilities are very limited. Only a small limited
355 * number of events is allowed to coexist.
Alexander Grafbee91162016-03-04 01:09:59 +0100356 */
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200357static struct efi_event efi_events[16];
Alexander Grafbee91162016-03-04 01:09:59 +0100358
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200359/*
360 * Create an event.
361 *
362 * This function is used inside U-Boot code to create an event.
363 *
364 * For the API function implementing the CreateEvent service see
365 * efi_create_event_ext.
366 *
367 * @type type of the event to create
368 * @notify_tpl task priority level of the event
369 * @notify_function notification function of the event
370 * @notify_context pointer passed to the notification function
371 * @event created event
372 * @return status code
373 */
xypron.glpk@gmx.deb521d292017-07-19 19:22:34 +0200374efi_status_t efi_create_event(uint32_t type, UINTN notify_tpl,
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200375 void (EFIAPI *notify_function) (
xypron.glpk@gmx.de2fd945f2017-07-18 20:17:17 +0200376 struct efi_event *event,
377 void *context),
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200378 void *notify_context, struct efi_event **event)
Alexander Grafbee91162016-03-04 01:09:59 +0100379{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200380 int i;
381
Jonathan Graya95343b2017-03-12 19:26:07 +1100382 if (event == NULL)
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200383 return EFI_INVALID_PARAMETER;
Jonathan Graya95343b2017-03-12 19:26:07 +1100384
385 if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200386 return EFI_INVALID_PARAMETER;
Jonathan Graya95343b2017-03-12 19:26:07 +1100387
388 if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
389 notify_function == NULL)
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200390 return EFI_INVALID_PARAMETER;
Jonathan Graya95343b2017-03-12 19:26:07 +1100391
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200392 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
393 if (efi_events[i].type)
394 continue;
395 efi_events[i].type = type;
396 efi_events[i].notify_tpl = notify_tpl;
397 efi_events[i].notify_function = notify_function;
398 efi_events[i].notify_context = notify_context;
399 /* Disable timers on bootup */
400 efi_events[i].trigger_next = -1ULL;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200401 efi_events[i].is_queued = false;
402 efi_events[i].is_signaled = false;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200403 *event = &efi_events[i];
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200404 return EFI_SUCCESS;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200405 }
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200406 return EFI_OUT_OF_RESOURCES;
Alexander Grafbee91162016-03-04 01:09:59 +0100407}
408
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200409/*
410 * Create an event.
411 *
412 * This function implements the CreateEvent service.
413 * See the Unified Extensible Firmware Interface (UEFI) specification
414 * for details.
415 *
416 * @type type of the event to create
417 * @notify_tpl task priority level of the event
418 * @notify_function notification function of the event
419 * @notify_context pointer passed to the notification function
420 * @event created event
421 * @return status code
422 */
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200423static efi_status_t EFIAPI efi_create_event_ext(
xypron.glpk@gmx.deb521d292017-07-19 19:22:34 +0200424 uint32_t type, UINTN notify_tpl,
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +0200425 void (EFIAPI *notify_function) (
426 struct efi_event *event,
427 void *context),
428 void *notify_context, struct efi_event **event)
429{
430 EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
431 notify_context);
432 return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
433 notify_context, event));
434}
435
436
Alexander Grafbee91162016-03-04 01:09:59 +0100437/*
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200438 * Check if a timer event has occurred or a queued notification function should
439 * be called.
440 *
Alexander Grafbee91162016-03-04 01:09:59 +0100441 * Our timers have to work without interrupts, so we check whenever keyboard
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200442 * input or disk accesses happen if enough time elapsed for them to fire.
Alexander Grafbee91162016-03-04 01:09:59 +0100443 */
444void efi_timer_check(void)
445{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200446 int i;
Alexander Grafbee91162016-03-04 01:09:59 +0100447 u64 now = timer_get_us();
448
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200449 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200450 if (!efi_events[i].type)
451 continue;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200452 if (efi_events[i].is_queued)
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200453 efi_signal_event(&efi_events[i]);
454 if (!(efi_events[i].type & EVT_TIMER) ||
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200455 now < efi_events[i].trigger_next)
456 continue;
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200457 switch (efi_events[i].trigger_type) {
458 case EFI_TIMER_RELATIVE:
459 efi_events[i].trigger_type = EFI_TIMER_STOP;
460 break;
461 case EFI_TIMER_PERIODIC:
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200462 efi_events[i].trigger_next +=
xypron.glpk@gmx.de8787b022017-07-18 20:17:23 +0200463 efi_events[i].trigger_time;
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200464 break;
465 default:
466 continue;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200467 }
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200468 efi_events[i].is_signaled = true;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200469 efi_signal_event(&efi_events[i]);
Alexander Grafbee91162016-03-04 01:09:59 +0100470 }
Alexander Grafbee91162016-03-04 01:09:59 +0100471 WATCHDOG_RESET();
472}
473
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200474/*
475 * Set the trigger time for a timer event or stop the event.
476 *
477 * This is the function for internal usage in U-Boot. For the API function
478 * implementing the SetTimer service see efi_set_timer_ext.
479 *
480 * @event event for which the timer is set
481 * @type type of the timer
482 * @trigger_time trigger period in multiples of 100ns
483 * @return status code
484 */
xypron.glpk@gmx.deb521d292017-07-19 19:22:34 +0200485efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +0200486 uint64_t trigger_time)
Alexander Grafbee91162016-03-04 01:09:59 +0100487{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200488 int i;
Alexander Grafbee91162016-03-04 01:09:59 +0100489
xypron.glpk@gmx.de8787b022017-07-18 20:17:23 +0200490 /*
491 * The parameter defines a multiple of 100ns.
492 * We use multiples of 1000ns. So divide by 10.
493 */
Heinrich Schuchardt7d963322017-10-05 16:14:14 +0200494 do_div(trigger_time, 10);
Alexander Grafbee91162016-03-04 01:09:59 +0100495
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200496 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
497 if (event != &efi_events[i])
498 continue;
Alexander Grafbee91162016-03-04 01:09:59 +0100499
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200500 if (!(event->type & EVT_TIMER))
501 break;
502 switch (type) {
503 case EFI_TIMER_STOP:
504 event->trigger_next = -1ULL;
505 break;
506 case EFI_TIMER_PERIODIC:
507 case EFI_TIMER_RELATIVE:
508 event->trigger_next =
xypron.glpk@gmx.de8787b022017-07-18 20:17:23 +0200509 timer_get_us() + trigger_time;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200510 break;
511 default:
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +0200512 return EFI_INVALID_PARAMETER;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200513 }
514 event->trigger_type = type;
515 event->trigger_time = trigger_time;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200516 event->is_signaled = false;
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +0200517 return EFI_SUCCESS;
Alexander Grafbee91162016-03-04 01:09:59 +0100518 }
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +0200519 return EFI_INVALID_PARAMETER;
520}
521
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200522/*
523 * Set the trigger time for a timer event or stop the event.
524 *
525 * This function implements the SetTimer service.
526 * See the Unified Extensible Firmware Interface (UEFI) specification
527 * for details.
528 *
529 * @event event for which the timer is set
530 * @type type of the timer
531 * @trigger_time trigger period in multiples of 100ns
532 * @return status code
533 */
xypron.glpk@gmx.deb521d292017-07-19 19:22:34 +0200534static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event,
535 enum efi_timer_delay type,
536 uint64_t trigger_time)
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +0200537{
538 EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
539 return EFI_EXIT(efi_set_timer(event, type, trigger_time));
Alexander Grafbee91162016-03-04 01:09:59 +0100540}
541
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200542/*
543 * Wait for events to be signaled.
544 *
545 * This function implements the WaitForEvent service.
546 * See the Unified Extensible Firmware Interface (UEFI) specification
547 * for details.
548 *
549 * @num_events number of events to be waited for
550 * @events events to be waited for
551 * @index index of the event that was signaled
552 * @return status code
553 */
Alexander Grafbee91162016-03-04 01:09:59 +0100554static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events,
xypron.glpk@gmx.de2fd945f2017-07-18 20:17:17 +0200555 struct efi_event **event,
556 unsigned long *index)
Alexander Grafbee91162016-03-04 01:09:59 +0100557{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200558 int i, j;
Alexander Grafbee91162016-03-04 01:09:59 +0100559
560 EFI_ENTRY("%ld, %p, %p", num_events, event, index);
561
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200562 /* Check parameters */
563 if (!num_events || !event)
564 return EFI_EXIT(EFI_INVALID_PARAMETER);
Heinrich Schuchardt32f4b2f2017-09-15 10:06:16 +0200565 /* Check TPL */
566 if (efi_tpl != TPL_APPLICATION)
567 return EFI_EXIT(EFI_UNSUPPORTED);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200568 for (i = 0; i < num_events; ++i) {
569 for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
570 if (event[i] == &efi_events[j])
571 goto known_event;
572 }
573 return EFI_EXIT(EFI_INVALID_PARAMETER);
574known_event:
575 if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
576 return EFI_EXIT(EFI_INVALID_PARAMETER);
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200577 if (!event[i]->is_signaled)
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200578 efi_signal_event(event[i]);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200579 }
580
581 /* Wait for signal */
582 for (;;) {
583 for (i = 0; i < num_events; ++i) {
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200584 if (event[i]->is_signaled)
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200585 goto out;
586 }
587 /* Allow events to occur. */
588 efi_timer_check();
589 }
590
591out:
592 /*
593 * Reset the signal which is passed to the caller to allow periodic
594 * events to occur.
595 */
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200596 event[i]->is_signaled = false;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200597 if (index)
598 *index = i;
Alexander Grafbee91162016-03-04 01:09:59 +0100599
600 return EFI_EXIT(EFI_SUCCESS);
601}
602
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200603/*
604 * Signal an EFI event.
605 *
606 * This function implements the SignalEvent service.
607 * See the Unified Extensible Firmware Interface (UEFI) specification
608 * for details.
609 *
610 * This functions sets the signaled state of the event and queues the
611 * notification function for execution.
612 *
613 * @event event to signal
614 */
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200615static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
Alexander Grafbee91162016-03-04 01:09:59 +0100616{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200617 int i;
618
Alexander Grafbee91162016-03-04 01:09:59 +0100619 EFI_ENTRY("%p", event);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200620 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
621 if (event != &efi_events[i])
622 continue;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200623 if (event->is_signaled)
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200624 break;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200625 event->is_signaled = true;
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200626 if (event->type & EVT_NOTIFY_SIGNAL)
627 efi_signal_event(event);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200628 break;
629 }
Alexander Grafbee91162016-03-04 01:09:59 +0100630 return EFI_EXIT(EFI_SUCCESS);
631}
632
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200633/*
634 * Close an EFI event.
635 *
636 * This function implements the CloseEvent service.
637 * See the Unified Extensible Firmware Interface (UEFI) specification
638 * for details.
639 *
640 * @event event to close
641 * @return status code
642 */
xypron.glpk@gmx.de2fd945f2017-07-18 20:17:17 +0200643static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
Alexander Grafbee91162016-03-04 01:09:59 +0100644{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200645 int i;
646
Alexander Grafbee91162016-03-04 01:09:59 +0100647 EFI_ENTRY("%p", event);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200648 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
649 if (event == &efi_events[i]) {
650 event->type = 0;
651 event->trigger_next = -1ULL;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200652 event->is_queued = false;
653 event->is_signaled = false;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200654 return EFI_EXIT(EFI_SUCCESS);
655 }
656 }
657 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafbee91162016-03-04 01:09:59 +0100658}
659
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200660/*
661 * Check if an event is signaled.
662 *
663 * This function implements the CheckEvent service.
664 * See the Unified Extensible Firmware Interface (UEFI) specification
665 * for details.
666 *
667 * If an event is not signaled yet the notification function is queued.
668 *
669 * @event event to check
670 * @return status code
671 */
xypron.glpk@gmx.de2fd945f2017-07-18 20:17:17 +0200672static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
Alexander Grafbee91162016-03-04 01:09:59 +0100673{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200674 int i;
675
Alexander Grafbee91162016-03-04 01:09:59 +0100676 EFI_ENTRY("%p", event);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200677 efi_timer_check();
678 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
679 if (event != &efi_events[i])
680 continue;
681 if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
682 break;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200683 if (!event->is_signaled)
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200684 efi_signal_event(event);
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200685 if (event->is_signaled)
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200686 return EFI_EXIT(EFI_SUCCESS);
687 return EFI_EXIT(EFI_NOT_READY);
688 }
689 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafbee91162016-03-04 01:09:59 +0100690}
691
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200692/*
693 * Install protocol interface.
694 *
695 * This is the function for internal calls. For the API implementation of the
696 * InstallProtocolInterface service see function
697 * efi_install_protocol_interface_ext.
698 *
699 * @handle handle on which the protocol shall be installed
700 * @protocol GUID of the protocol to be installed
701 * @protocol_interface_type type of the interface to be installed,
702 * always EFI_NATIVE_INTERFACE
703 * @protocol_interface interface of the protocol implementation
704 * @return status code
705 */
Alexander Grafbee91162016-03-04 01:09:59 +0100706static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200707 const efi_guid_t *protocol, int protocol_interface_type,
Alexander Grafbee91162016-03-04 01:09:59 +0100708 void *protocol_interface)
709{
xypron.glpk@gmx.dee0549f82017-07-11 22:06:16 +0200710 struct list_head *lhandle;
711 int i;
712 efi_status_t r;
713
xypron.glpk@gmx.dee0549f82017-07-11 22:06:16 +0200714 if (!handle || !protocol ||
715 protocol_interface_type != EFI_NATIVE_INTERFACE) {
716 r = EFI_INVALID_PARAMETER;
717 goto out;
718 }
719
720 /* Create new handle if requested. */
721 if (!*handle) {
Heinrich Schuchardt3cc6e3f2017-08-27 00:51:09 +0200722 r = efi_create_handle(handle);
723 if (r != EFI_SUCCESS)
724 goto out;
xypron.glpk@gmx.dee0549f82017-07-11 22:06:16 +0200725 }
726 /* Find object. */
727 list_for_each(lhandle, &efi_obj_list) {
728 struct efi_object *efiobj;
729 efiobj = list_entry(lhandle, struct efi_object, link);
730
731 if (efiobj->handle != *handle)
732 continue;
733 /* Check if protocol is already installed on the handle. */
734 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
735 struct efi_handler *handler = &efiobj->protocols[i];
736
737 if (!handler->guid)
738 continue;
739 if (!guidcmp(handler->guid, protocol)) {
740 r = EFI_INVALID_PARAMETER;
741 goto out;
742 }
743 }
744 /* Install protocol in first empty slot. */
745 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
746 struct efi_handler *handler = &efiobj->protocols[i];
747
748 if (handler->guid)
749 continue;
750
751 handler->guid = protocol;
752 handler->protocol_interface = protocol_interface;
753 r = EFI_SUCCESS;
754 goto out;
755 }
756 r = EFI_OUT_OF_RESOURCES;
757 goto out;
758 }
759 r = EFI_INVALID_PARAMETER;
760out:
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +0200761 return r;
762}
763
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200764/*
765 * Install protocol interface.
766 *
767 * This function implements the InstallProtocolInterface service.
768 * See the Unified Extensible Firmware Interface (UEFI) specification
769 * for details.
770 *
771 * @handle handle on which the protocol shall be installed
772 * @protocol GUID of the protocol to be installed
773 * @protocol_interface_type type of the interface to be installed,
774 * always EFI_NATIVE_INTERFACE
775 * @protocol_interface interface of the protocol implementation
776 * @return status code
777 */
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +0200778static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200779 const efi_guid_t *protocol, int protocol_interface_type,
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +0200780 void *protocol_interface)
781{
Rob Clark778e6af2017-09-13 18:05:41 -0400782 EFI_ENTRY("%p, %pUl, %d, %p", handle, protocol, protocol_interface_type,
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +0200783 protocol_interface);
784
785 return EFI_EXIT(efi_install_protocol_interface(handle, protocol,
786 protocol_interface_type,
787 protocol_interface));
Alexander Grafbee91162016-03-04 01:09:59 +0100788}
xypron.glpk@gmx.dee0549f82017-07-11 22:06:16 +0200789
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200790/*
791 * Reinstall protocol interface.
792 *
793 * This function implements the ReinstallProtocolInterface service.
794 * See the Unified Extensible Firmware Interface (UEFI) specification
795 * for details.
796 *
797 * @handle handle on which the protocol shall be
798 * reinstalled
799 * @protocol GUID of the protocol to be installed
800 * @old_interface interface to be removed
801 * @new_interface interface to be installed
802 * @return status code
803 */
Alexander Grafbee91162016-03-04 01:09:59 +0100804static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200805 const efi_guid_t *protocol, void *old_interface,
Alexander Grafbee91162016-03-04 01:09:59 +0100806 void *new_interface)
807{
Rob Clark778e6af2017-09-13 18:05:41 -0400808 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, old_interface,
Alexander Grafbee91162016-03-04 01:09:59 +0100809 new_interface);
810 return EFI_EXIT(EFI_ACCESS_DENIED);
811}
812
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200813/*
814 * Uninstall protocol interface.
815 *
816 * This is the function for internal calls. For the API implementation of the
817 * UninstallProtocolInterface service see function
818 * efi_uninstall_protocol_interface_ext.
819 *
820 * @handle handle from which the protocol shall be removed
821 * @protocol GUID of the protocol to be removed
822 * @protocol_interface interface to be removed
823 * @return status code
824 */
Alexander Grafbee91162016-03-04 01:09:59 +0100825static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200826 const efi_guid_t *protocol, void *protocol_interface)
Alexander Grafbee91162016-03-04 01:09:59 +0100827{
xypron.glpk@gmx.de4b6ed0d2017-07-11 22:06:17 +0200828 struct list_head *lhandle;
829 int i;
830 efi_status_t r = EFI_NOT_FOUND;
831
xypron.glpk@gmx.de4b6ed0d2017-07-11 22:06:17 +0200832 if (!handle || !protocol) {
833 r = EFI_INVALID_PARAMETER;
834 goto out;
835 }
836
837 list_for_each(lhandle, &efi_obj_list) {
838 struct efi_object *efiobj;
839 efiobj = list_entry(lhandle, struct efi_object, link);
840
841 if (efiobj->handle != handle)
842 continue;
843
844 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
845 struct efi_handler *handler = &efiobj->protocols[i];
846 const efi_guid_t *hprotocol = handler->guid;
847
848 if (!hprotocol)
849 continue;
850 if (!guidcmp(hprotocol, protocol)) {
851 if (handler->protocol_interface) {
852 r = EFI_ACCESS_DENIED;
853 } else {
854 handler->guid = 0;
855 r = EFI_SUCCESS;
856 }
857 goto out;
858 }
859 }
860 }
861
862out:
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +0200863 return r;
864}
865
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200866/*
867 * Uninstall protocol interface.
868 *
869 * This function implements the UninstallProtocolInterface service.
870 * See the Unified Extensible Firmware Interface (UEFI) specification
871 * for details.
872 *
873 * @handle handle from which the protocol shall be removed
874 * @protocol GUID of the protocol to be removed
875 * @protocol_interface interface to be removed
876 * @return status code
877 */
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +0200878static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200879 const efi_guid_t *protocol, void *protocol_interface)
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +0200880{
Rob Clark778e6af2017-09-13 18:05:41 -0400881 EFI_ENTRY("%p, %pUl, %p", handle, protocol, protocol_interface);
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +0200882
883 return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol,
884 protocol_interface));
Alexander Grafbee91162016-03-04 01:09:59 +0100885}
886
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200887/*
888 * Register an event for notification when a protocol is installed.
889 *
890 * This function implements the RegisterProtocolNotify service.
891 * See the Unified Extensible Firmware Interface (UEFI) specification
892 * for details.
893 *
894 * @protocol GUID of the protocol whose installation shall be
895 * notified
896 * @event event to be signaled upon installation of the protocol
897 * @registration key for retrieving the registration information
898 * @return status code
899 */
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200900static efi_status_t EFIAPI efi_register_protocol_notify(
901 const efi_guid_t *protocol,
902 struct efi_event *event,
903 void **registration)
Alexander Grafbee91162016-03-04 01:09:59 +0100904{
Rob Clark778e6af2017-09-13 18:05:41 -0400905 EFI_ENTRY("%pUl, %p, %p", protocol, event, registration);
Alexander Grafbee91162016-03-04 01:09:59 +0100906 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
907}
908
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200909/*
910 * Determine if an EFI handle implements a protocol.
911 *
912 * See the documentation of the LocateHandle service in the UEFI specification.
913 *
914 * @search_type selection criterion
915 * @protocol GUID of the protocol
916 * @search_key registration key
917 * @efiobj handle
918 * @return 0 if the handle implements the protocol
919 */
Alexander Grafbee91162016-03-04 01:09:59 +0100920static int efi_search(enum efi_locate_search_type search_type,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200921 const efi_guid_t *protocol, void *search_key,
Alexander Grafbee91162016-03-04 01:09:59 +0100922 struct efi_object *efiobj)
923{
924 int i;
925
926 switch (search_type) {
927 case all_handles:
928 return 0;
929 case by_register_notify:
930 return -1;
931 case by_protocol:
932 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
933 const efi_guid_t *guid = efiobj->protocols[i].guid;
934 if (guid && !guidcmp(guid, protocol))
935 return 0;
936 }
937 return -1;
938 }
939
940 return -1;
941}
942
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200943/*
944 * Locate handles implementing a protocol.
945 *
946 * This function is meant for U-Boot internal calls. For the API implementation
947 * of the LocateHandle service see efi_locate_handle_ext.
948 *
949 * @search_type selection criterion
950 * @protocol GUID of the protocol
951 * @search_key registration key
952 * @buffer_size size of the buffer to receive the handles in bytes
953 * @buffer buffer to receive the relevant handles
954 * @return status code
955 */
xypron.glpk@gmx.deebf199b2017-08-09 20:55:00 +0200956static efi_status_t efi_locate_handle(
Alexander Grafbee91162016-03-04 01:09:59 +0100957 enum efi_locate_search_type search_type,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200958 const efi_guid_t *protocol, void *search_key,
Alexander Grafbee91162016-03-04 01:09:59 +0100959 unsigned long *buffer_size, efi_handle_t *buffer)
960{
961 struct list_head *lhandle;
962 unsigned long size = 0;
963
Alexander Grafbee91162016-03-04 01:09:59 +0100964 /* Count how much space we need */
965 list_for_each(lhandle, &efi_obj_list) {
966 struct efi_object *efiobj;
967 efiobj = list_entry(lhandle, struct efi_object, link);
968 if (!efi_search(search_type, protocol, search_key, efiobj)) {
969 size += sizeof(void*);
970 }
971 }
972
973 if (*buffer_size < size) {
974 *buffer_size = size;
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +0200975 return EFI_BUFFER_TOO_SMALL;
Alexander Grafbee91162016-03-04 01:09:59 +0100976 }
977
Rob Clark796a78c2017-08-06 14:10:07 -0400978 *buffer_size = size;
979 if (size == 0)
980 return EFI_NOT_FOUND;
981
Alexander Grafbee91162016-03-04 01:09:59 +0100982 /* Then fill the array */
983 list_for_each(lhandle, &efi_obj_list) {
984 struct efi_object *efiobj;
985 efiobj = list_entry(lhandle, struct efi_object, link);
986 if (!efi_search(search_type, protocol, search_key, efiobj)) {
987 *(buffer++) = efiobj->handle;
988 }
989 }
990
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +0200991 return EFI_SUCCESS;
992}
993
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200994/*
995 * Locate handles implementing a protocol.
996 *
997 * This function implements the LocateHandle service.
998 * See the Unified Extensible Firmware Interface (UEFI) specification
999 * for details.
1000 *
1001 * @search_type selection criterion
1002 * @protocol GUID of the protocol
1003 * @search_key registration key
1004 * @buffer_size size of the buffer to receive the handles in bytes
1005 * @buffer buffer to receive the relevant handles
1006 * @return 0 if the handle implements the protocol
1007 */
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02001008static efi_status_t EFIAPI efi_locate_handle_ext(
1009 enum efi_locate_search_type search_type,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001010 const efi_guid_t *protocol, void *search_key,
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02001011 unsigned long *buffer_size, efi_handle_t *buffer)
1012{
Rob Clark778e6af2017-09-13 18:05:41 -04001013 EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02001014 buffer_size, buffer);
1015
1016 return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
1017 buffer_size, buffer));
Alexander Grafbee91162016-03-04 01:09:59 +01001018}
1019
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001020/*
1021 * Get the device path and handle of an device implementing a protocol.
1022 *
1023 * This function implements the LocateDevicePath service.
1024 * See the Unified Extensible Firmware Interface (UEFI) specification
1025 * for details.
1026 *
1027 * @protocol GUID of the protocol
1028 * @device_path device path
1029 * @device handle of the device
1030 * @return status code
1031 */
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001032static efi_status_t EFIAPI efi_locate_device_path(
1033 const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001034 struct efi_device_path **device_path,
1035 efi_handle_t *device)
1036{
Rob Clarkb66c60d2017-09-13 18:05:28 -04001037 struct efi_object *efiobj;
1038
1039 EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device);
1040
1041 efiobj = efi_dp_find_obj(*device_path, device_path);
1042 if (!efiobj)
1043 return EFI_EXIT(EFI_NOT_FOUND);
1044
1045 *device = efiobj->handle;
1046
1047 return EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +01001048}
1049
Alexander Grafd98cdf62017-07-26 13:41:04 +02001050/* Collapses configuration table entries, removing index i */
1051static void efi_remove_configuration_table(int i)
1052{
1053 struct efi_configuration_table *this = &efi_conf_table[i];
1054 struct efi_configuration_table *next = &efi_conf_table[i+1];
1055 struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables];
1056
1057 memmove(this, next, (ulong)end - (ulong)next);
1058 systab.nr_tables--;
1059}
1060
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001061/*
1062 * Adds, updates, or removes a configuration table.
1063 *
1064 * This function is used for internal calls. For the API implementation of the
1065 * InstallConfigurationTable service see efi_install_configuration_table_ext.
1066 *
1067 * @guid GUID of the installed table
1068 * @table table to be installed
1069 * @return status code
1070 */
Alexander Graf488bf122016-08-19 01:23:24 +02001071efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
Alexander Grafbee91162016-03-04 01:09:59 +01001072{
1073 int i;
1074
Alexander Grafbee91162016-03-04 01:09:59 +01001075 /* Check for guid override */
1076 for (i = 0; i < systab.nr_tables; i++) {
1077 if (!guidcmp(guid, &efi_conf_table[i].guid)) {
Alexander Grafd98cdf62017-07-26 13:41:04 +02001078 if (table)
1079 efi_conf_table[i].table = table;
1080 else
1081 efi_remove_configuration_table(i);
Alexander Graf488bf122016-08-19 01:23:24 +02001082 return EFI_SUCCESS;
Alexander Grafbee91162016-03-04 01:09:59 +01001083 }
1084 }
1085
Alexander Grafd98cdf62017-07-26 13:41:04 +02001086 if (!table)
1087 return EFI_NOT_FOUND;
1088
Alexander Grafbee91162016-03-04 01:09:59 +01001089 /* No override, check for overflow */
1090 if (i >= ARRAY_SIZE(efi_conf_table))
Alexander Graf488bf122016-08-19 01:23:24 +02001091 return EFI_OUT_OF_RESOURCES;
Alexander Grafbee91162016-03-04 01:09:59 +01001092
1093 /* Add a new entry */
1094 memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
1095 efi_conf_table[i].table = table;
Alexander Grafaba5e912016-08-19 01:23:30 +02001096 systab.nr_tables = i + 1;
Alexander Grafbee91162016-03-04 01:09:59 +01001097
Alexander Graf488bf122016-08-19 01:23:24 +02001098 return EFI_SUCCESS;
1099}
1100
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001101/*
1102 * Adds, updates, or removes a configuration table.
1103 *
1104 * This function implements the InstallConfigurationTable service.
1105 * See the Unified Extensible Firmware Interface (UEFI) specification
1106 * for details.
1107 *
1108 * @guid GUID of the installed table
1109 * @table table to be installed
1110 * @return status code
1111 */
Alexander Graf488bf122016-08-19 01:23:24 +02001112static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
1113 void *table)
1114{
Rob Clark778e6af2017-09-13 18:05:41 -04001115 EFI_ENTRY("%pUl, %p", guid, table);
Alexander Graf488bf122016-08-19 01:23:24 +02001116 return EFI_EXIT(efi_install_configuration_table(guid, table));
Alexander Grafbee91162016-03-04 01:09:59 +01001117}
1118
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001119/*
1120 * Initialize a loaded_image_info + loaded_image_info object with correct
Rob Clark95c55532017-09-13 18:05:33 -04001121 * protocols, boot-device, etc.
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001122 *
1123 * @info loaded image info to be passed to the enty point of the
1124 * image
1125 * @obj internal object associated with the loaded image
1126 * @device_path device path of the loaded image
1127 * @file_path file path of the loaded image
Rob Clark95c55532017-09-13 18:05:33 -04001128 */
1129void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *obj,
1130 struct efi_device_path *device_path,
1131 struct efi_device_path *file_path)
1132{
1133 obj->handle = info;
1134
1135 /*
1136 * When asking for the device path interface, return
1137 * bootefi_device_path
1138 */
1139 obj->protocols[0].guid = &efi_guid_device_path;
1140 obj->protocols[0].protocol_interface = device_path;
1141
1142 /*
1143 * When asking for the loaded_image interface, just
1144 * return handle which points to loaded_image_info
1145 */
1146 obj->protocols[1].guid = &efi_guid_loaded_image;
1147 obj->protocols[1].protocol_interface = info;
1148
1149 obj->protocols[2].guid = &efi_guid_console_control;
1150 obj->protocols[2].protocol_interface = (void *)&efi_console_control;
1151
1152 obj->protocols[3].guid = &efi_guid_device_path_to_text_protocol;
1153 obj->protocols[3].protocol_interface =
1154 (void *)&efi_device_path_to_text;
1155
1156 info->file_path = file_path;
1157 info->device_handle = efi_dp_find_obj(device_path, NULL);
1158
1159 list_add_tail(&obj->link, &efi_obj_list);
1160}
1161
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001162/*
1163 * Load an image using a file path.
1164 *
1165 * @file_path the path of the image to load
1166 * @buffer buffer containing the loaded image
1167 */
Rob Clark9975fe92017-09-13 18:05:38 -04001168efi_status_t efi_load_image_from_path(struct efi_device_path *file_path,
1169 void **buffer)
Rob Clark838ee4b2017-09-13 18:05:35 -04001170{
1171 struct efi_file_info *info = NULL;
1172 struct efi_file_handle *f;
1173 static efi_status_t ret;
1174 uint64_t bs;
1175
1176 f = efi_file_from_path(file_path);
1177 if (!f)
1178 return EFI_DEVICE_ERROR;
1179
1180 bs = 0;
1181 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1182 &bs, info));
1183 if (ret == EFI_BUFFER_TOO_SMALL) {
1184 info = malloc(bs);
1185 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1186 &bs, info));
1187 }
1188 if (ret != EFI_SUCCESS)
1189 goto error;
1190
1191 ret = efi_allocate_pool(EFI_LOADER_DATA, info->file_size, buffer);
1192 if (ret)
1193 goto error;
1194
1195 EFI_CALL(ret = f->read(f, &info->file_size, *buffer));
1196
1197error:
1198 free(info);
1199 EFI_CALL(f->close(f));
1200
1201 if (ret != EFI_SUCCESS) {
1202 efi_free_pool(*buffer);
1203 *buffer = NULL;
1204 }
1205
1206 return ret;
1207}
1208
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001209/*
1210 * Load an EFI image into memory.
1211 *
1212 * This function implements the LoadImage service.
1213 * See the Unified Extensible Firmware Interface (UEFI) specification
1214 * for details.
1215 *
1216 * @boot_policy true for request originating from the boot manager
1217 * @parent_image the calles's image handle
1218 * @file_path the path of the image to load
1219 * @source_buffer memory location from which the image is installed
1220 * @source_size size of the memory area from which the image is
1221 * installed
1222 * @image_handle handle for the newly installed image
1223 * @return status code
1224 */
Alexander Grafbee91162016-03-04 01:09:59 +01001225static efi_status_t EFIAPI efi_load_image(bool boot_policy,
1226 efi_handle_t parent_image,
1227 struct efi_device_path *file_path,
1228 void *source_buffer,
1229 unsigned long source_size,
1230 efi_handle_t *image_handle)
1231{
Alexander Grafbee91162016-03-04 01:09:59 +01001232 struct efi_loaded_image *info;
1233 struct efi_object *obj;
1234
1235 EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
1236 file_path, source_buffer, source_size, image_handle);
Rob Clark838ee4b2017-09-13 18:05:35 -04001237
1238 info = calloc(1, sizeof(*info));
1239 obj = calloc(1, sizeof(*obj));
1240
1241 if (!source_buffer) {
1242 struct efi_device_path *dp, *fp;
1243 efi_status_t ret;
1244
Rob Clark9975fe92017-09-13 18:05:38 -04001245 ret = efi_load_image_from_path(file_path, &source_buffer);
Rob Clark838ee4b2017-09-13 18:05:35 -04001246 if (ret != EFI_SUCCESS) {
1247 free(info);
1248 free(obj);
1249 return EFI_EXIT(ret);
1250 }
1251
1252 /*
1253 * split file_path which contains both the device and
1254 * file parts:
1255 */
1256 efi_dp_split_file_path(file_path, &dp, &fp);
1257
1258 efi_setup_loaded_image(info, obj, dp, fp);
1259 } else {
1260 /* In this case, file_path is the "device" path, ie.
1261 * something like a HARDWARE_DEVICE:MEMORY_MAPPED
1262 */
1263 efi_setup_loaded_image(info, obj, file_path, NULL);
1264 }
1265
Alexander Grafbee91162016-03-04 01:09:59 +01001266 info->reserved = efi_load_pe(source_buffer, info);
1267 if (!info->reserved) {
1268 free(info);
1269 free(obj);
1270 return EFI_EXIT(EFI_UNSUPPORTED);
1271 }
1272
1273 *image_handle = info;
Alexander Grafbee91162016-03-04 01:09:59 +01001274
1275 return EFI_EXIT(EFI_SUCCESS);
1276}
1277
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001278/*
1279 * Call the entry point of an image.
1280 *
1281 * This function implements the StartImage service.
1282 * See the Unified Extensible Firmware Interface (UEFI) specification
1283 * for details.
1284 *
1285 * @image_handle handle of the image
1286 * @exit_data_size size of the buffer
1287 * @exit_data buffer to receive the exit data of the called image
1288 */
Alexander Grafbee91162016-03-04 01:09:59 +01001289static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
1290 unsigned long *exit_data_size,
1291 s16 **exit_data)
1292{
1293 ulong (*entry)(void *image_handle, struct efi_system_table *st);
1294 struct efi_loaded_image *info = image_handle;
1295
1296 EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
1297 entry = info->reserved;
1298
1299 efi_is_direct_boot = false;
1300
1301 /* call the image! */
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001302 if (setjmp(&info->exit_jmp)) {
1303 /* We returned from the child image */
1304 return EFI_EXIT(info->exit_status);
1305 }
1306
Rob Clarkaf65db82017-07-27 08:04:19 -04001307 __efi_nesting_dec();
Rob Clarkc160d2f2017-07-27 08:04:18 -04001308 __efi_exit_check();
Alexander Grafbee91162016-03-04 01:09:59 +01001309 entry(image_handle, &systab);
Rob Clarkc160d2f2017-07-27 08:04:18 -04001310 __efi_entry_check();
Rob Clarkaf65db82017-07-27 08:04:19 -04001311 __efi_nesting_inc();
Alexander Grafbee91162016-03-04 01:09:59 +01001312
1313 /* Should usually never get here */
1314 return EFI_EXIT(EFI_SUCCESS);
1315}
1316
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001317/*
1318 * Leave an EFI application or driver.
1319 *
1320 * This function implements the Exit service.
1321 * See the Unified Extensible Firmware Interface (UEFI) specification
1322 * for details.
1323 *
1324 * @image_handle handle of the application or driver that is exiting
1325 * @exit_status status code
1326 * @exit_data_size size of the buffer in bytes
1327 * @exit_data buffer with data describing an error
1328 */
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001329static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
1330 efi_status_t exit_status, unsigned long exit_data_size,
1331 int16_t *exit_data)
Alexander Grafbee91162016-03-04 01:09:59 +01001332{
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001333 struct efi_loaded_image *loaded_image_info = (void*)image_handle;
1334
Alexander Grafbee91162016-03-04 01:09:59 +01001335 EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
1336 exit_data_size, exit_data);
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001337
Alexander Grafa1489202017-09-03 14:14:17 +02001338 /* Make sure entry/exit counts for EFI world cross-overs match */
Heinrich Schuchardtda940732017-08-25 19:53:14 +02001339 __efi_exit_check();
1340
Alexander Grafa1489202017-09-03 14:14:17 +02001341 /*
1342 * But longjmp out with the U-Boot gd, not the application's, as
1343 * the other end is a setjmp call inside EFI context.
1344 */
1345 efi_restore_gd();
1346
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001347 loaded_image_info->exit_status = exit_status;
Alexander Graf692fcdd2016-09-27 09:30:32 +02001348 longjmp(&loaded_image_info->exit_jmp, 1);
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001349
1350 panic("EFI application exited");
Alexander Grafbee91162016-03-04 01:09:59 +01001351}
1352
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001353/*
1354 * Find the internal EFI object for a handle.
1355 *
1356 * @handle handle to find
1357 * @return EFI object
1358 */
Alexander Grafbee91162016-03-04 01:09:59 +01001359static struct efi_object *efi_search_obj(void *handle)
1360{
1361 struct list_head *lhandle;
1362
1363 list_for_each(lhandle, &efi_obj_list) {
1364 struct efi_object *efiobj;
1365 efiobj = list_entry(lhandle, struct efi_object, link);
1366 if (efiobj->handle == handle)
1367 return efiobj;
1368 }
1369
1370 return NULL;
1371}
1372
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001373/*
1374 * Unload an EFI image.
1375 *
1376 * This function implements the UnloadImage service.
1377 * See the Unified Extensible Firmware Interface (UEFI) specification
1378 * for details.
1379 *
1380 * @image_handle handle of the image to be unloaded
1381 * @return status code
1382 */
Alexander Grafbee91162016-03-04 01:09:59 +01001383static efi_status_t EFIAPI efi_unload_image(void *image_handle)
1384{
1385 struct efi_object *efiobj;
1386
1387 EFI_ENTRY("%p", image_handle);
1388 efiobj = efi_search_obj(image_handle);
1389 if (efiobj)
1390 list_del(&efiobj->link);
1391
1392 return EFI_EXIT(EFI_SUCCESS);
1393}
1394
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001395/*
1396 * Fix up caches for EFI payloads if necessary.
1397 */
Alexander Grafbee91162016-03-04 01:09:59 +01001398static void efi_exit_caches(void)
1399{
1400#if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
1401 /*
1402 * Grub on 32bit ARM needs to have caches disabled before jumping into
1403 * a zImage, but does not know of all cache layers. Give it a hand.
1404 */
1405 if (efi_is_direct_boot)
1406 cleanup_before_linux();
1407#endif
1408}
1409
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001410/*
1411 * Stop boot services.
1412 *
1413 * This function implements the ExitBootServices service.
1414 * See the Unified Extensible Firmware Interface (UEFI) specification
1415 * for details.
1416 *
1417 * @image_handle handle of the loaded image
1418 * @map_key key of the memory map
1419 * @return status code
1420 */
Alexander Grafbee91162016-03-04 01:09:59 +01001421static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
1422 unsigned long map_key)
1423{
Heinrich Schuchardt152a2632017-09-15 10:06:18 +02001424 int i;
1425
Alexander Grafbee91162016-03-04 01:09:59 +01001426 EFI_ENTRY("%p, %ld", image_handle, map_key);
1427
Heinrich Schuchardt152a2632017-09-15 10:06:18 +02001428 /* Notify that ExitBootServices is invoked. */
1429 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
1430 if (efi_events[i].type != EVT_SIGNAL_EXIT_BOOT_SERVICES)
1431 continue;
1432 efi_signal_event(&efi_events[i]);
1433 }
1434 /* Make sure that notification functions are not called anymore */
1435 efi_tpl = TPL_HIGH_LEVEL;
1436
Rob Clarkad644e72017-09-13 18:05:37 -04001437#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1438 /* save any EFI variables that have been written: */
1439 env_save();
1440#endif
1441
Alexander Grafb7b84102016-11-17 01:02:57 +01001442 board_quiesce_devices();
1443
Alexander Grafbee91162016-03-04 01:09:59 +01001444 /* Fix up caches for EFI payloads if necessary */
1445 efi_exit_caches();
1446
1447 /* This stops all lingering devices */
1448 bootm_disable_interrupts();
1449
1450 /* Give the payload some time to boot */
1451 WATCHDOG_RESET();
1452
1453 return EFI_EXIT(EFI_SUCCESS);
1454}
1455
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001456/*
1457 * Get next value of the counter.
1458 *
1459 * This function implements the NextMonotonicCount service.
1460 * See the Unified Extensible Firmware Interface (UEFI) specification
1461 * for details.
1462 *
1463 * @count returned value of the counter
1464 * @return status code
1465 */
Alexander Grafbee91162016-03-04 01:09:59 +01001466static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
1467{
1468 static uint64_t mono = 0;
1469 EFI_ENTRY("%p", count);
1470 *count = mono++;
1471 return EFI_EXIT(EFI_SUCCESS);
1472}
1473
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001474/*
1475 * Sleep.
1476 *
1477 * This function implements the Stall sercive.
1478 * See the Unified Extensible Firmware Interface (UEFI) specification
1479 * for details.
1480 *
1481 * @microseconds period to sleep in microseconds
1482 * @return status code
1483 */
Alexander Grafbee91162016-03-04 01:09:59 +01001484static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
1485{
1486 EFI_ENTRY("%ld", microseconds);
1487 udelay(microseconds);
1488 return EFI_EXIT(EFI_SUCCESS);
1489}
1490
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001491/*
1492 * Reset the watchdog timer.
1493 *
1494 * This function implements the WatchdogTimer service.
1495 * See the Unified Extensible Firmware Interface (UEFI) specification
1496 * for details.
1497 *
1498 * @timeout seconds before reset by watchdog
1499 * @watchdog_code code to be logged when resetting
1500 * @data_size size of buffer in bytes
1501 * @watchdog_data buffer with data describing the reset reason
1502 */
Alexander Grafbee91162016-03-04 01:09:59 +01001503static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
1504 uint64_t watchdog_code,
1505 unsigned long data_size,
1506 uint16_t *watchdog_data)
1507{
1508 EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
1509 data_size, watchdog_data);
Rob Clarkb5104822017-07-25 20:17:59 -04001510 return efi_unsupported(__func__);
Alexander Grafbee91162016-03-04 01:09:59 +01001511}
1512
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001513/*
1514 * Connect a controller to a driver.
1515 *
1516 * This function implements the ConnectController service.
1517 * See the Unified Extensible Firmware Interface (UEFI) specification
1518 * for details.
1519 *
1520 * @controller_handle handle of the controller
1521 * @driver_image_handle handle of the driver
1522 * @remain_device_path device path of a child controller
1523 * @recursive true to connect all child controllers
1524 * @return status code
1525 */
Alexander Grafbee91162016-03-04 01:09:59 +01001526static efi_status_t EFIAPI efi_connect_controller(
1527 efi_handle_t controller_handle,
1528 efi_handle_t *driver_image_handle,
1529 struct efi_device_path *remain_device_path,
1530 bool recursive)
1531{
1532 EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
1533 remain_device_path, recursive);
1534 return EFI_EXIT(EFI_NOT_FOUND);
1535}
1536
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001537/*
1538 * Disconnect a controller from a driver.
1539 *
1540 * This function implements the DisconnectController service.
1541 * See the Unified Extensible Firmware Interface (UEFI) specification
1542 * for details.
1543 *
1544 * @controller_handle handle of the controller
1545 * @driver_image_handle handle of the driver
1546 * @child_handle handle of the child to destroy
1547 * @return status code
1548 */
Alexander Grafbee91162016-03-04 01:09:59 +01001549static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
1550 void *driver_image_handle,
1551 void *child_handle)
1552{
1553 EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
1554 child_handle);
1555 return EFI_EXIT(EFI_INVALID_PARAMETER);
1556}
1557
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001558/*
1559 * Close a protocol.
1560 *
1561 * This function implements the CloseProtocol service.
1562 * See the Unified Extensible Firmware Interface (UEFI) specification
1563 * for details.
1564 *
1565 * @handle handle on which the protocol shall be closed
1566 * @protocol GUID of the protocol to close
1567 * @agent_handle handle of the driver
1568 * @controller_handle handle of the controller
1569 * @return status code
1570 */
Alexander Grafbee91162016-03-04 01:09:59 +01001571static efi_status_t EFIAPI efi_close_protocol(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001572 const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001573 void *agent_handle,
1574 void *controller_handle)
1575{
Rob Clark778e6af2017-09-13 18:05:41 -04001576 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, agent_handle,
Alexander Grafbee91162016-03-04 01:09:59 +01001577 controller_handle);
1578 return EFI_EXIT(EFI_NOT_FOUND);
1579}
1580
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001581/*
1582 * Provide information about then open status of a protocol on a handle
1583 *
1584 * This function implements the OpenProtocolInformation service.
1585 * See the Unified Extensible Firmware Interface (UEFI) specification
1586 * for details.
1587 *
1588 * @handle handle for which the information shall be retrieved
1589 * @protocol GUID of the protocol
1590 * @entry_buffer buffer to receive the open protocol information
1591 * @entry_count number of entries available in the buffer
1592 * @return status code
1593 */
Alexander Grafbee91162016-03-04 01:09:59 +01001594static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001595 const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001596 struct efi_open_protocol_info_entry **entry_buffer,
1597 unsigned long *entry_count)
1598{
Rob Clark778e6af2017-09-13 18:05:41 -04001599 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, entry_buffer,
Alexander Grafbee91162016-03-04 01:09:59 +01001600 entry_count);
1601 return EFI_EXIT(EFI_NOT_FOUND);
1602}
1603
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001604/*
1605 * Get protocols installed on a handle.
1606 *
1607 * This function implements the ProtocolsPerHandleService.
1608 * See the Unified Extensible Firmware Interface (UEFI) specification
1609 * for details.
1610 *
1611 * @handle handle for which the information is retrieved
1612 * @protocol_buffer buffer with protocol GUIDs
1613 * @protocol_buffer_count number of entries in the buffer
1614 */
Alexander Grafbee91162016-03-04 01:09:59 +01001615static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
1616 efi_guid_t ***protocol_buffer,
1617 unsigned long *protocol_buffer_count)
1618{
xypron.glpk@gmx.dec0ebfc82017-07-13 23:24:32 +02001619 unsigned long buffer_size;
1620 struct efi_object *efiobj;
1621 unsigned long i, j;
1622 struct list_head *lhandle;
1623 efi_status_t r;
1624
Alexander Grafbee91162016-03-04 01:09:59 +01001625 EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
1626 protocol_buffer_count);
xypron.glpk@gmx.dec0ebfc82017-07-13 23:24:32 +02001627
1628 if (!handle || !protocol_buffer || !protocol_buffer_count)
1629 return EFI_EXIT(EFI_INVALID_PARAMETER);
1630
1631 *protocol_buffer = NULL;
Rob Clark661c8322017-07-20 07:59:39 -04001632 *protocol_buffer_count = 0;
xypron.glpk@gmx.dec0ebfc82017-07-13 23:24:32 +02001633 list_for_each(lhandle, &efi_obj_list) {
1634 efiobj = list_entry(lhandle, struct efi_object, link);
1635
1636 if (efiobj->handle != handle)
1637 continue;
1638
1639 /* Count protocols */
1640 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1641 if (efiobj->protocols[i].guid)
1642 ++*protocol_buffer_count;
1643 }
1644 /* Copy guids */
1645 if (*protocol_buffer_count) {
1646 buffer_size = sizeof(efi_guid_t *) *
1647 *protocol_buffer_count;
1648 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
1649 buffer_size,
1650 (void **)protocol_buffer);
1651 if (r != EFI_SUCCESS)
1652 return EFI_EXIT(r);
1653 j = 0;
1654 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); ++i) {
1655 if (efiobj->protocols[i].guid) {
1656 (*protocol_buffer)[j] = (void *)
1657 efiobj->protocols[i].guid;
1658 ++j;
1659 }
1660 }
1661 }
1662 break;
1663 }
1664
1665 return EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +01001666}
1667
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001668/*
1669 * Locate handles implementing a protocol.
1670 *
1671 * This function implements the LocateHandleBuffer service.
1672 * See the Unified Extensible Firmware Interface (UEFI) specification
1673 * for details.
1674 *
1675 * @search_type selection criterion
1676 * @protocol GUID of the protocol
1677 * @search_key registration key
1678 * @no_handles number of returned handles
1679 * @buffer buffer with the returned handles
1680 * @return status code
1681 */
Alexander Grafbee91162016-03-04 01:09:59 +01001682static efi_status_t EFIAPI efi_locate_handle_buffer(
1683 enum efi_locate_search_type search_type,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001684 const efi_guid_t *protocol, void *search_key,
Alexander Grafbee91162016-03-04 01:09:59 +01001685 unsigned long *no_handles, efi_handle_t **buffer)
1686{
xypron.glpk@gmx.dec2e703f2017-07-11 22:06:22 +02001687 efi_status_t r;
1688 unsigned long buffer_size = 0;
1689
Rob Clark778e6af2017-09-13 18:05:41 -04001690 EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
Alexander Grafbee91162016-03-04 01:09:59 +01001691 no_handles, buffer);
xypron.glpk@gmx.dec2e703f2017-07-11 22:06:22 +02001692
1693 if (!no_handles || !buffer) {
1694 r = EFI_INVALID_PARAMETER;
1695 goto out;
1696 }
1697 *no_handles = 0;
1698 *buffer = NULL;
1699 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
1700 *buffer);
1701 if (r != EFI_BUFFER_TOO_SMALL)
1702 goto out;
1703 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
1704 (void **)buffer);
1705 if (r != EFI_SUCCESS)
1706 goto out;
1707 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
1708 *buffer);
1709 if (r == EFI_SUCCESS)
1710 *no_handles = buffer_size / sizeof(void *);
1711out:
1712 return EFI_EXIT(r);
Alexander Grafbee91162016-03-04 01:09:59 +01001713}
1714
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001715/*
1716 * Find an interface implementing a protocol.
1717 *
1718 * This function implements the LocateProtocol service.
1719 * See the Unified Extensible Firmware Interface (UEFI) specification
1720 * for details.
1721 *
1722 * @protocol GUID of the protocol
1723 * @registration registration key passed to the notification function
1724 * @protocol_interface interface implementing the protocol
1725 */
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001726static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001727 void *registration,
1728 void **protocol_interface)
1729{
xypron.glpk@gmx.de88adae52017-07-11 22:06:24 +02001730 struct list_head *lhandle;
Alexander Grafbee91162016-03-04 01:09:59 +01001731 int i;
1732
Rob Clark778e6af2017-09-13 18:05:41 -04001733 EFI_ENTRY("%pUl, %p, %p", protocol, registration, protocol_interface);
xypron.glpk@gmx.de88adae52017-07-11 22:06:24 +02001734
1735 if (!protocol || !protocol_interface)
1736 return EFI_EXIT(EFI_INVALID_PARAMETER);
1737
Heinrich Schuchardtae0bd3a2017-08-18 17:45:16 +02001738 EFI_PRINT_GUID("protocol", protocol);
1739
xypron.glpk@gmx.de88adae52017-07-11 22:06:24 +02001740 list_for_each(lhandle, &efi_obj_list) {
1741 struct efi_object *efiobj;
1742
1743 efiobj = list_entry(lhandle, struct efi_object, link);
1744 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1745 struct efi_handler *handler = &efiobj->protocols[i];
1746
1747 if (!handler->guid)
1748 continue;
1749 if (!guidcmp(handler->guid, protocol)) {
1750 *protocol_interface =
1751 handler->protocol_interface;
1752 return EFI_EXIT(EFI_SUCCESS);
1753 }
Alexander Grafbee91162016-03-04 01:09:59 +01001754 }
1755 }
xypron.glpk@gmx.de88adae52017-07-11 22:06:24 +02001756 *protocol_interface = NULL;
Alexander Grafbee91162016-03-04 01:09:59 +01001757
1758 return EFI_EXIT(EFI_NOT_FOUND);
1759}
1760
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001761/*
1762 * Install multiple protocol interfaces.
1763 *
1764 * This function implements the MultipleProtocolInterfaces service.
1765 * See the Unified Extensible Firmware Interface (UEFI) specification
1766 * for details.
1767 *
1768 * @handle handle on which the protocol interfaces shall be installed
1769 * @... NULL terminated argument list with pairs of protocol GUIDS and
1770 * interfaces
1771 * @return status code
1772 */
Alexander Grafbee91162016-03-04 01:09:59 +01001773static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
1774 void **handle, ...)
1775{
1776 EFI_ENTRY("%p", handle);
xypron.glpk@gmx.de58b83582017-07-11 22:06:20 +02001777
1778 va_list argptr;
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001779 const efi_guid_t *protocol;
xypron.glpk@gmx.de58b83582017-07-11 22:06:20 +02001780 void *protocol_interface;
1781 efi_status_t r = EFI_SUCCESS;
1782 int i = 0;
1783
1784 if (!handle)
1785 return EFI_EXIT(EFI_INVALID_PARAMETER);
1786
1787 va_start(argptr, handle);
1788 for (;;) {
1789 protocol = va_arg(argptr, efi_guid_t*);
1790 if (!protocol)
1791 break;
1792 protocol_interface = va_arg(argptr, void*);
1793 r = efi_install_protocol_interface(handle, protocol,
1794 EFI_NATIVE_INTERFACE,
1795 protocol_interface);
1796 if (r != EFI_SUCCESS)
1797 break;
1798 i++;
1799 }
1800 va_end(argptr);
1801 if (r == EFI_SUCCESS)
1802 return EFI_EXIT(r);
1803
1804 /* If an error occured undo all changes. */
1805 va_start(argptr, handle);
1806 for (; i; --i) {
1807 protocol = va_arg(argptr, efi_guid_t*);
1808 protocol_interface = va_arg(argptr, void*);
1809 efi_uninstall_protocol_interface(handle, protocol,
1810 protocol_interface);
1811 }
1812 va_end(argptr);
1813
1814 return EFI_EXIT(r);
Alexander Grafbee91162016-03-04 01:09:59 +01001815}
1816
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001817/*
1818 * Uninstall multiple protocol interfaces.
1819 *
1820 * This function implements the UninstallMultipleProtocolInterfaces service.
1821 * See the Unified Extensible Firmware Interface (UEFI) specification
1822 * for details.
1823 *
1824 * @handle handle from which the protocol interfaces shall be removed
1825 * @... NULL terminated argument list with pairs of protocol GUIDS and
1826 * interfaces
1827 * @return status code
1828 */
Alexander Grafbee91162016-03-04 01:09:59 +01001829static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
1830 void *handle, ...)
1831{
1832 EFI_ENTRY("%p", handle);
1833 return EFI_EXIT(EFI_INVALID_PARAMETER);
1834}
1835
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001836/*
1837 * Calculate cyclic redundancy code.
1838 *
1839 * This function implements the CalculateCrc32 service.
1840 * See the Unified Extensible Firmware Interface (UEFI) specification
1841 * for details.
1842 *
1843 * @data buffer with data
1844 * @data_size size of buffer in bytes
1845 * @crc32_p cyclic redundancy code
1846 * @return status code
1847 */
Alexander Grafbee91162016-03-04 01:09:59 +01001848static efi_status_t EFIAPI efi_calculate_crc32(void *data,
1849 unsigned long data_size,
1850 uint32_t *crc32_p)
1851{
1852 EFI_ENTRY("%p, %ld", data, data_size);
1853 *crc32_p = crc32(0, data, data_size);
1854 return EFI_EXIT(EFI_SUCCESS);
1855}
1856
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001857/*
1858 * Copy memory.
1859 *
1860 * This function implements the CopyMem service.
1861 * See the Unified Extensible Firmware Interface (UEFI) specification
1862 * for details.
1863 *
1864 * @destination destination of the copy operation
1865 * @source source of the copy operation
1866 * @length number of bytes to copy
1867 */
Heinrich Schuchardtfc05a952017-10-05 16:35:52 +02001868static void EFIAPI efi_copy_mem(void *destination, const void *source,
1869 size_t length)
Alexander Grafbee91162016-03-04 01:09:59 +01001870{
Heinrich Schuchardtfc05a952017-10-05 16:35:52 +02001871 EFI_ENTRY("%p, %p, %ld", destination, source, (unsigned long)length);
Alexander Grafbee91162016-03-04 01:09:59 +01001872 memcpy(destination, source, length);
Heinrich Schuchardtf7c78172017-10-05 16:35:51 +02001873 EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +01001874}
1875
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001876/*
1877 * Fill memory with a byte value.
1878 *
1879 * This function implements the SetMem service.
1880 * See the Unified Extensible Firmware Interface (UEFI) specification
1881 * for details.
1882 *
1883 * @buffer buffer to fill
1884 * @size size of buffer in bytes
1885 * @value byte to copy to the buffer
1886 */
Heinrich Schuchardtfc05a952017-10-05 16:35:52 +02001887static void EFIAPI efi_set_mem(void *buffer, size_t size, uint8_t value)
Alexander Grafbee91162016-03-04 01:09:59 +01001888{
Heinrich Schuchardtfc05a952017-10-05 16:35:52 +02001889 EFI_ENTRY("%p, %ld, 0x%x", buffer, (unsigned long)size, value);
Alexander Grafbee91162016-03-04 01:09:59 +01001890 memset(buffer, value, size);
Heinrich Schuchardtf7c78172017-10-05 16:35:51 +02001891 EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +01001892}
1893
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001894/*
1895 * Open protocol interface on a handle.
1896 *
1897 * This function implements the OpenProtocol interface.
1898 * See the Unified Extensible Firmware Interface (UEFI) specification
1899 * for details.
1900 *
1901 * @handle handle on which the protocol shall be opened
1902 * @protocol GUID of the protocol
1903 * @protocol_interface interface implementing the protocol
1904 * @agent_handle handle of the driver
1905 * @controller_handle handle of the controller
1906 * @attributes attributes indicating how to open the protocol
1907 * @return status code
1908 */
Alexander Grafbee91162016-03-04 01:09:59 +01001909static efi_status_t EFIAPI efi_open_protocol(
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001910 void *handle, const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001911 void **protocol_interface, void *agent_handle,
1912 void *controller_handle, uint32_t attributes)
1913{
1914 struct list_head *lhandle;
1915 int i;
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001916 efi_status_t r = EFI_INVALID_PARAMETER;
Alexander Grafbee91162016-03-04 01:09:59 +01001917
Rob Clark778e6af2017-09-13 18:05:41 -04001918 EFI_ENTRY("%p, %pUl, %p, %p, %p, 0x%x", handle, protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001919 protocol_interface, agent_handle, controller_handle,
1920 attributes);
xypron.glpk@gmx.deb5349f72017-07-11 22:06:14 +02001921
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001922 if (!handle || !protocol ||
1923 (!protocol_interface && attributes !=
1924 EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
1925 goto out;
1926 }
1927
Heinrich Schuchardtae0bd3a2017-08-18 17:45:16 +02001928 EFI_PRINT_GUID("protocol", protocol);
1929
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001930 switch (attributes) {
1931 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
1932 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
1933 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
1934 break;
1935 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
1936 if (controller_handle == handle)
1937 goto out;
1938 case EFI_OPEN_PROTOCOL_BY_DRIVER:
1939 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
1940 if (controller_handle == NULL)
1941 goto out;
1942 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
1943 if (agent_handle == NULL)
1944 goto out;
1945 break;
1946 default:
xypron.glpk@gmx.deb5349f72017-07-11 22:06:14 +02001947 goto out;
1948 }
1949
Alexander Grafbee91162016-03-04 01:09:59 +01001950 list_for_each(lhandle, &efi_obj_list) {
1951 struct efi_object *efiobj;
1952 efiobj = list_entry(lhandle, struct efi_object, link);
1953
1954 if (efiobj->handle != handle)
1955 continue;
1956
1957 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1958 struct efi_handler *handler = &efiobj->protocols[i];
1959 const efi_guid_t *hprotocol = handler->guid;
1960 if (!hprotocol)
xypron.glpk@gmx.de4b6ed0d2017-07-11 22:06:17 +02001961 continue;
Alexander Grafbee91162016-03-04 01:09:59 +01001962 if (!guidcmp(hprotocol, protocol)) {
xypron.glpk@gmx.deb5349f72017-07-11 22:06:14 +02001963 if (attributes !=
1964 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
1965 *protocol_interface =
1966 handler->protocol_interface;
1967 }
1968 r = EFI_SUCCESS;
Alexander Grafbee91162016-03-04 01:09:59 +01001969 goto out;
1970 }
1971 }
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001972 goto unsupported;
Alexander Grafbee91162016-03-04 01:09:59 +01001973 }
1974
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001975unsupported:
1976 r = EFI_UNSUPPORTED;
Alexander Grafbee91162016-03-04 01:09:59 +01001977out:
1978 return EFI_EXIT(r);
1979}
1980
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001981/*
1982 * Get interface of a protocol on a handle.
1983 *
1984 * This function implements the HandleProtocol service.
1985 * See the Unified Extensible Firmware Interface (UEFI) specification
1986 * for details.
1987 *
1988 * @handle handle on which the protocol shall be opened
1989 * @protocol GUID of the protocol
1990 * @protocol_interface interface implementing the protocol
1991 * @return status code
1992 */
Alexander Grafbee91162016-03-04 01:09:59 +01001993static efi_status_t EFIAPI efi_handle_protocol(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001994 const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001995 void **protocol_interface)
1996{
xypron.glpk@gmx.de8e1d3292017-06-29 21:16:19 +02001997 return efi_open_protocol(handle, protocol, protocol_interface, NULL,
1998 NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
Alexander Grafbee91162016-03-04 01:09:59 +01001999}
2000
2001static const struct efi_boot_services efi_boot_services = {
2002 .hdr = {
2003 .headersize = sizeof(struct efi_table_hdr),
2004 },
2005 .raise_tpl = efi_raise_tpl,
2006 .restore_tpl = efi_restore_tpl,
2007 .allocate_pages = efi_allocate_pages_ext,
2008 .free_pages = efi_free_pages_ext,
2009 .get_memory_map = efi_get_memory_map_ext,
Stefan Brünsead12742016-10-09 22:17:18 +02002010 .allocate_pool = efi_allocate_pool_ext,
Stefan Brüns42417bc2016-10-09 22:17:26 +02002011 .free_pool = efi_free_pool_ext,
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +02002012 .create_event = efi_create_event_ext,
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +02002013 .set_timer = efi_set_timer_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002014 .wait_for_event = efi_wait_for_event,
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +02002015 .signal_event = efi_signal_event_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002016 .close_event = efi_close_event,
2017 .check_event = efi_check_event,
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +02002018 .install_protocol_interface = efi_install_protocol_interface_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002019 .reinstall_protocol_interface = efi_reinstall_protocol_interface,
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +02002020 .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002021 .handle_protocol = efi_handle_protocol,
2022 .reserved = NULL,
2023 .register_protocol_notify = efi_register_protocol_notify,
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02002024 .locate_handle = efi_locate_handle_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002025 .locate_device_path = efi_locate_device_path,
Alexander Graf488bf122016-08-19 01:23:24 +02002026 .install_configuration_table = efi_install_configuration_table_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002027 .load_image = efi_load_image,
2028 .start_image = efi_start_image,
Alexander Grafa86aeaf2016-05-20 23:28:23 +02002029 .exit = efi_exit,
Alexander Grafbee91162016-03-04 01:09:59 +01002030 .unload_image = efi_unload_image,
2031 .exit_boot_services = efi_exit_boot_services,
2032 .get_next_monotonic_count = efi_get_next_monotonic_count,
2033 .stall = efi_stall,
2034 .set_watchdog_timer = efi_set_watchdog_timer,
2035 .connect_controller = efi_connect_controller,
2036 .disconnect_controller = efi_disconnect_controller,
2037 .open_protocol = efi_open_protocol,
2038 .close_protocol = efi_close_protocol,
2039 .open_protocol_information = efi_open_protocol_information,
2040 .protocols_per_handle = efi_protocols_per_handle,
2041 .locate_handle_buffer = efi_locate_handle_buffer,
2042 .locate_protocol = efi_locate_protocol,
2043 .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
2044 .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
2045 .calculate_crc32 = efi_calculate_crc32,
2046 .copy_mem = efi_copy_mem,
2047 .set_mem = efi_set_mem,
2048};
2049
2050
Alexander Graf3c63db92016-10-14 13:45:30 +02002051static uint16_t __efi_runtime_data firmware_vendor[] =
Alexander Grafbee91162016-03-04 01:09:59 +01002052 { 'D','a','s',' ','U','-','b','o','o','t',0 };
2053
Alexander Graf3c63db92016-10-14 13:45:30 +02002054struct efi_system_table __efi_runtime_data systab = {
Alexander Grafbee91162016-03-04 01:09:59 +01002055 .hdr = {
2056 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
2057 .revision = 0x20005, /* 2.5 */
2058 .headersize = sizeof(struct efi_table_hdr),
2059 },
2060 .fw_vendor = (long)firmware_vendor,
2061 .con_in = (void*)&efi_con_in,
2062 .con_out = (void*)&efi_con_out,
2063 .std_err = (void*)&efi_con_out,
2064 .runtime = (void*)&efi_runtime_services,
2065 .boottime = (void*)&efi_boot_services,
2066 .nr_tables = 0,
2067 .tables = (void*)efi_conf_table,
2068};