blob: f627340de44c34997c72ee447527a6248496d7b6 [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,
Heinrich Schuchardtca379e12017-10-05 16:35:54 +0200556 size_t *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
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +0200614 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200615 */
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200616static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
Alexander Grafbee91162016-03-04 01:09:59 +0100617{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200618 int i;
619
Alexander Grafbee91162016-03-04 01:09:59 +0100620 EFI_ENTRY("%p", event);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200621 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
622 if (event != &efi_events[i])
623 continue;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200624 if (event->is_signaled)
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200625 break;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200626 event->is_signaled = true;
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200627 if (event->type & EVT_NOTIFY_SIGNAL)
628 efi_signal_event(event);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200629 break;
630 }
Alexander Grafbee91162016-03-04 01:09:59 +0100631 return EFI_EXIT(EFI_SUCCESS);
632}
633
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200634/*
635 * Close an EFI event.
636 *
637 * This function implements the CloseEvent service.
638 * See the Unified Extensible Firmware Interface (UEFI) specification
639 * for details.
640 *
641 * @event event to close
642 * @return status code
643 */
xypron.glpk@gmx.de2fd945f2017-07-18 20:17:17 +0200644static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
Alexander Grafbee91162016-03-04 01:09:59 +0100645{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200646 int i;
647
Alexander Grafbee91162016-03-04 01:09:59 +0100648 EFI_ENTRY("%p", event);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200649 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
650 if (event == &efi_events[i]) {
651 event->type = 0;
652 event->trigger_next = -1ULL;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200653 event->is_queued = false;
654 event->is_signaled = false;
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200655 return EFI_EXIT(EFI_SUCCESS);
656 }
657 }
658 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafbee91162016-03-04 01:09:59 +0100659}
660
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200661/*
662 * Check if an event is signaled.
663 *
664 * This function implements the CheckEvent service.
665 * See the Unified Extensible Firmware Interface (UEFI) specification
666 * for details.
667 *
668 * If an event is not signaled yet the notification function is queued.
669 *
670 * @event event to check
671 * @return status code
672 */
xypron.glpk@gmx.de2fd945f2017-07-18 20:17:17 +0200673static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
Alexander Grafbee91162016-03-04 01:09:59 +0100674{
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200675 int i;
676
Alexander Grafbee91162016-03-04 01:09:59 +0100677 EFI_ENTRY("%p", event);
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200678 efi_timer_check();
679 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
680 if (event != &efi_events[i])
681 continue;
682 if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
683 break;
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200684 if (!event->is_signaled)
Heinrich Schuchardtca62a4f2017-09-15 10:06:13 +0200685 efi_signal_event(event);
Heinrich Schuchardte190e892017-10-04 15:03:24 +0200686 if (event->is_signaled)
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +0200687 return EFI_EXIT(EFI_SUCCESS);
688 return EFI_EXIT(EFI_NOT_READY);
689 }
690 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafbee91162016-03-04 01:09:59 +0100691}
692
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200693/*
694 * Install protocol interface.
695 *
696 * This is the function for internal calls. For the API implementation of the
697 * InstallProtocolInterface service see function
698 * efi_install_protocol_interface_ext.
699 *
700 * @handle handle on which the protocol shall be installed
701 * @protocol GUID of the protocol to be installed
702 * @protocol_interface_type type of the interface to be installed,
703 * always EFI_NATIVE_INTERFACE
704 * @protocol_interface interface of the protocol implementation
705 * @return status code
706 */
Alexander Grafbee91162016-03-04 01:09:59 +0100707static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200708 const efi_guid_t *protocol, int protocol_interface_type,
Alexander Grafbee91162016-03-04 01:09:59 +0100709 void *protocol_interface)
710{
xypron.glpk@gmx.dee0549f82017-07-11 22:06:16 +0200711 struct list_head *lhandle;
712 int i;
713 efi_status_t r;
714
xypron.glpk@gmx.dee0549f82017-07-11 22:06:16 +0200715 if (!handle || !protocol ||
716 protocol_interface_type != EFI_NATIVE_INTERFACE) {
717 r = EFI_INVALID_PARAMETER;
718 goto out;
719 }
720
721 /* Create new handle if requested. */
722 if (!*handle) {
Heinrich Schuchardt3cc6e3f2017-08-27 00:51:09 +0200723 r = efi_create_handle(handle);
724 if (r != EFI_SUCCESS)
725 goto out;
xypron.glpk@gmx.dee0549f82017-07-11 22:06:16 +0200726 }
727 /* Find object. */
728 list_for_each(lhandle, &efi_obj_list) {
729 struct efi_object *efiobj;
730 efiobj = list_entry(lhandle, struct efi_object, link);
731
732 if (efiobj->handle != *handle)
733 continue;
734 /* Check if protocol is already installed on the handle. */
735 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
736 struct efi_handler *handler = &efiobj->protocols[i];
737
738 if (!handler->guid)
739 continue;
740 if (!guidcmp(handler->guid, protocol)) {
741 r = EFI_INVALID_PARAMETER;
742 goto out;
743 }
744 }
745 /* Install protocol in first empty slot. */
746 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
747 struct efi_handler *handler = &efiobj->protocols[i];
748
749 if (handler->guid)
750 continue;
751
752 handler->guid = protocol;
753 handler->protocol_interface = protocol_interface;
754 r = EFI_SUCCESS;
755 goto out;
756 }
757 r = EFI_OUT_OF_RESOURCES;
758 goto out;
759 }
760 r = EFI_INVALID_PARAMETER;
761out:
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +0200762 return r;
763}
764
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200765/*
766 * Install protocol interface.
767 *
768 * This function implements the InstallProtocolInterface service.
769 * See the Unified Extensible Firmware Interface (UEFI) specification
770 * for details.
771 *
772 * @handle handle on which the protocol shall be installed
773 * @protocol GUID of the protocol to be installed
774 * @protocol_interface_type type of the interface to be installed,
775 * always EFI_NATIVE_INTERFACE
776 * @protocol_interface interface of the protocol implementation
777 * @return status code
778 */
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +0200779static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200780 const efi_guid_t *protocol, int protocol_interface_type,
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +0200781 void *protocol_interface)
782{
Rob Clark778e6af2017-09-13 18:05:41 -0400783 EFI_ENTRY("%p, %pUl, %d, %p", handle, protocol, protocol_interface_type,
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +0200784 protocol_interface);
785
786 return EFI_EXIT(efi_install_protocol_interface(handle, protocol,
787 protocol_interface_type,
788 protocol_interface));
Alexander Grafbee91162016-03-04 01:09:59 +0100789}
xypron.glpk@gmx.dee0549f82017-07-11 22:06:16 +0200790
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200791/*
792 * Reinstall protocol interface.
793 *
794 * This function implements the ReinstallProtocolInterface service.
795 * See the Unified Extensible Firmware Interface (UEFI) specification
796 * for details.
797 *
798 * @handle handle on which the protocol shall be
799 * reinstalled
800 * @protocol GUID of the protocol to be installed
801 * @old_interface interface to be removed
802 * @new_interface interface to be installed
803 * @return status code
804 */
Alexander Grafbee91162016-03-04 01:09:59 +0100805static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200806 const efi_guid_t *protocol, void *old_interface,
Alexander Grafbee91162016-03-04 01:09:59 +0100807 void *new_interface)
808{
Rob Clark778e6af2017-09-13 18:05:41 -0400809 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, old_interface,
Alexander Grafbee91162016-03-04 01:09:59 +0100810 new_interface);
811 return EFI_EXIT(EFI_ACCESS_DENIED);
812}
813
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200814/*
815 * Uninstall protocol interface.
816 *
817 * This is the function for internal calls. For the API implementation of the
818 * UninstallProtocolInterface service see function
819 * efi_uninstall_protocol_interface_ext.
820 *
821 * @handle handle from which the protocol shall be removed
822 * @protocol GUID of the protocol to be removed
823 * @protocol_interface interface to be removed
824 * @return status code
825 */
Alexander Grafbee91162016-03-04 01:09:59 +0100826static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200827 const efi_guid_t *protocol, void *protocol_interface)
Alexander Grafbee91162016-03-04 01:09:59 +0100828{
xypron.glpk@gmx.de4b6ed0d2017-07-11 22:06:17 +0200829 struct list_head *lhandle;
830 int i;
831 efi_status_t r = EFI_NOT_FOUND;
832
xypron.glpk@gmx.de4b6ed0d2017-07-11 22:06:17 +0200833 if (!handle || !protocol) {
834 r = EFI_INVALID_PARAMETER;
835 goto out;
836 }
837
838 list_for_each(lhandle, &efi_obj_list) {
839 struct efi_object *efiobj;
840 efiobj = list_entry(lhandle, struct efi_object, link);
841
842 if (efiobj->handle != handle)
843 continue;
844
845 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
846 struct efi_handler *handler = &efiobj->protocols[i];
847 const efi_guid_t *hprotocol = handler->guid;
848
849 if (!hprotocol)
850 continue;
851 if (!guidcmp(hprotocol, protocol)) {
852 if (handler->protocol_interface) {
853 r = EFI_ACCESS_DENIED;
854 } else {
855 handler->guid = 0;
856 r = EFI_SUCCESS;
857 }
858 goto out;
859 }
860 }
861 }
862
863out:
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +0200864 return r;
865}
866
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200867/*
868 * Uninstall protocol interface.
869 *
870 * This function implements the UninstallProtocolInterface service.
871 * See the Unified Extensible Firmware Interface (UEFI) specification
872 * for details.
873 *
874 * @handle handle from which the protocol shall be removed
875 * @protocol GUID of the protocol to be removed
876 * @protocol_interface interface to be removed
877 * @return status code
878 */
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +0200879static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200880 const efi_guid_t *protocol, void *protocol_interface)
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +0200881{
Rob Clark778e6af2017-09-13 18:05:41 -0400882 EFI_ENTRY("%p, %pUl, %p", handle, protocol, protocol_interface);
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +0200883
884 return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol,
885 protocol_interface));
Alexander Grafbee91162016-03-04 01:09:59 +0100886}
887
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200888/*
889 * Register an event for notification when a protocol is installed.
890 *
891 * This function implements the RegisterProtocolNotify service.
892 * See the Unified Extensible Firmware Interface (UEFI) specification
893 * for details.
894 *
895 * @protocol GUID of the protocol whose installation shall be
896 * notified
897 * @event event to be signaled upon installation of the protocol
898 * @registration key for retrieving the registration information
899 * @return status code
900 */
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200901static efi_status_t EFIAPI efi_register_protocol_notify(
902 const efi_guid_t *protocol,
903 struct efi_event *event,
904 void **registration)
Alexander Grafbee91162016-03-04 01:09:59 +0100905{
Rob Clark778e6af2017-09-13 18:05:41 -0400906 EFI_ENTRY("%pUl, %p, %p", protocol, event, registration);
Alexander Grafbee91162016-03-04 01:09:59 +0100907 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
908}
909
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200910/*
911 * Determine if an EFI handle implements a protocol.
912 *
913 * See the documentation of the LocateHandle service in the UEFI specification.
914 *
915 * @search_type selection criterion
916 * @protocol GUID of the protocol
917 * @search_key registration key
918 * @efiobj handle
919 * @return 0 if the handle implements the protocol
920 */
Alexander Grafbee91162016-03-04 01:09:59 +0100921static int efi_search(enum efi_locate_search_type search_type,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200922 const efi_guid_t *protocol, void *search_key,
Alexander Grafbee91162016-03-04 01:09:59 +0100923 struct efi_object *efiobj)
924{
925 int i;
926
927 switch (search_type) {
928 case all_handles:
929 return 0;
930 case by_register_notify:
931 return -1;
932 case by_protocol:
933 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
934 const efi_guid_t *guid = efiobj->protocols[i].guid;
935 if (guid && !guidcmp(guid, protocol))
936 return 0;
937 }
938 return -1;
939 }
940
941 return -1;
942}
943
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200944/*
945 * Locate handles implementing a protocol.
946 *
947 * This function is meant for U-Boot internal calls. For the API implementation
948 * of the LocateHandle service see efi_locate_handle_ext.
949 *
950 * @search_type selection criterion
951 * @protocol GUID of the protocol
952 * @search_key registration key
953 * @buffer_size size of the buffer to receive the handles in bytes
954 * @buffer buffer to receive the relevant handles
955 * @return status code
956 */
xypron.glpk@gmx.deebf199b2017-08-09 20:55:00 +0200957static efi_status_t efi_locate_handle(
Alexander Grafbee91162016-03-04 01:09:59 +0100958 enum efi_locate_search_type search_type,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +0200959 const efi_guid_t *protocol, void *search_key,
Alexander Grafbee91162016-03-04 01:09:59 +0100960 unsigned long *buffer_size, efi_handle_t *buffer)
961{
962 struct list_head *lhandle;
963 unsigned long size = 0;
964
Alexander Grafbee91162016-03-04 01:09:59 +0100965 /* Count how much space we need */
966 list_for_each(lhandle, &efi_obj_list) {
967 struct efi_object *efiobj;
968 efiobj = list_entry(lhandle, struct efi_object, link);
969 if (!efi_search(search_type, protocol, search_key, efiobj)) {
970 size += sizeof(void*);
971 }
972 }
973
974 if (*buffer_size < size) {
975 *buffer_size = size;
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +0200976 return EFI_BUFFER_TOO_SMALL;
Alexander Grafbee91162016-03-04 01:09:59 +0100977 }
978
Rob Clark796a78c2017-08-06 14:10:07 -0400979 *buffer_size = size;
980 if (size == 0)
981 return EFI_NOT_FOUND;
982
Alexander Grafbee91162016-03-04 01:09:59 +0100983 /* Then fill the array */
984 list_for_each(lhandle, &efi_obj_list) {
985 struct efi_object *efiobj;
986 efiobj = list_entry(lhandle, struct efi_object, link);
987 if (!efi_search(search_type, protocol, search_key, efiobj)) {
988 *(buffer++) = efiobj->handle;
989 }
990 }
991
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +0200992 return EFI_SUCCESS;
993}
994
Heinrich Schuchardt332468f2017-09-21 18:30:11 +0200995/*
996 * Locate handles implementing a protocol.
997 *
998 * This function implements the LocateHandle service.
999 * See the Unified Extensible Firmware Interface (UEFI) specification
1000 * for details.
1001 *
1002 * @search_type selection criterion
1003 * @protocol GUID of the protocol
1004 * @search_key registration key
1005 * @buffer_size size of the buffer to receive the handles in bytes
1006 * @buffer buffer to receive the relevant handles
1007 * @return 0 if the handle implements the protocol
1008 */
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02001009static efi_status_t EFIAPI efi_locate_handle_ext(
1010 enum efi_locate_search_type search_type,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001011 const efi_guid_t *protocol, void *search_key,
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02001012 unsigned long *buffer_size, efi_handle_t *buffer)
1013{
Rob Clark778e6af2017-09-13 18:05:41 -04001014 EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02001015 buffer_size, buffer);
1016
1017 return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
1018 buffer_size, buffer));
Alexander Grafbee91162016-03-04 01:09:59 +01001019}
1020
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001021/*
1022 * Get the device path and handle of an device implementing a protocol.
1023 *
1024 * This function implements the LocateDevicePath service.
1025 * See the Unified Extensible Firmware Interface (UEFI) specification
1026 * for details.
1027 *
1028 * @protocol GUID of the protocol
1029 * @device_path device path
1030 * @device handle of the device
1031 * @return status code
1032 */
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001033static efi_status_t EFIAPI efi_locate_device_path(
1034 const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001035 struct efi_device_path **device_path,
1036 efi_handle_t *device)
1037{
Rob Clarkb66c60d2017-09-13 18:05:28 -04001038 struct efi_object *efiobj;
1039
1040 EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device);
1041
1042 efiobj = efi_dp_find_obj(*device_path, device_path);
1043 if (!efiobj)
1044 return EFI_EXIT(EFI_NOT_FOUND);
1045
1046 *device = efiobj->handle;
1047
1048 return EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +01001049}
1050
Alexander Grafd98cdf62017-07-26 13:41:04 +02001051/* Collapses configuration table entries, removing index i */
1052static void efi_remove_configuration_table(int i)
1053{
1054 struct efi_configuration_table *this = &efi_conf_table[i];
1055 struct efi_configuration_table *next = &efi_conf_table[i+1];
1056 struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables];
1057
1058 memmove(this, next, (ulong)end - (ulong)next);
1059 systab.nr_tables--;
1060}
1061
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001062/*
1063 * Adds, updates, or removes a configuration table.
1064 *
1065 * This function is used for internal calls. For the API implementation of the
1066 * InstallConfigurationTable service see efi_install_configuration_table_ext.
1067 *
1068 * @guid GUID of the installed table
1069 * @table table to be installed
1070 * @return status code
1071 */
Alexander Graf488bf122016-08-19 01:23:24 +02001072efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
Alexander Grafbee91162016-03-04 01:09:59 +01001073{
1074 int i;
1075
Alexander Grafbee91162016-03-04 01:09:59 +01001076 /* Check for guid override */
1077 for (i = 0; i < systab.nr_tables; i++) {
1078 if (!guidcmp(guid, &efi_conf_table[i].guid)) {
Alexander Grafd98cdf62017-07-26 13:41:04 +02001079 if (table)
1080 efi_conf_table[i].table = table;
1081 else
1082 efi_remove_configuration_table(i);
Alexander Graf488bf122016-08-19 01:23:24 +02001083 return EFI_SUCCESS;
Alexander Grafbee91162016-03-04 01:09:59 +01001084 }
1085 }
1086
Alexander Grafd98cdf62017-07-26 13:41:04 +02001087 if (!table)
1088 return EFI_NOT_FOUND;
1089
Alexander Grafbee91162016-03-04 01:09:59 +01001090 /* No override, check for overflow */
1091 if (i >= ARRAY_SIZE(efi_conf_table))
Alexander Graf488bf122016-08-19 01:23:24 +02001092 return EFI_OUT_OF_RESOURCES;
Alexander Grafbee91162016-03-04 01:09:59 +01001093
1094 /* Add a new entry */
1095 memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
1096 efi_conf_table[i].table = table;
Alexander Grafaba5e912016-08-19 01:23:30 +02001097 systab.nr_tables = i + 1;
Alexander Grafbee91162016-03-04 01:09:59 +01001098
Alexander Graf488bf122016-08-19 01:23:24 +02001099 return EFI_SUCCESS;
1100}
1101
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001102/*
1103 * Adds, updates, or removes a configuration table.
1104 *
1105 * This function implements the InstallConfigurationTable service.
1106 * See the Unified Extensible Firmware Interface (UEFI) specification
1107 * for details.
1108 *
1109 * @guid GUID of the installed table
1110 * @table table to be installed
1111 * @return status code
1112 */
Alexander Graf488bf122016-08-19 01:23:24 +02001113static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
1114 void *table)
1115{
Rob Clark778e6af2017-09-13 18:05:41 -04001116 EFI_ENTRY("%pUl, %p", guid, table);
Alexander Graf488bf122016-08-19 01:23:24 +02001117 return EFI_EXIT(efi_install_configuration_table(guid, table));
Alexander Grafbee91162016-03-04 01:09:59 +01001118}
1119
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001120/*
1121 * Initialize a loaded_image_info + loaded_image_info object with correct
Rob Clark95c55532017-09-13 18:05:33 -04001122 * protocols, boot-device, etc.
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001123 *
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001124 * @info loaded image info to be passed to the entry point of the
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001125 * image
1126 * @obj internal object associated with the loaded image
1127 * @device_path device path of the loaded image
1128 * @file_path file path of the loaded image
Rob Clark95c55532017-09-13 18:05:33 -04001129 */
1130void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *obj,
1131 struct efi_device_path *device_path,
1132 struct efi_device_path *file_path)
1133{
1134 obj->handle = info;
1135
1136 /*
1137 * When asking for the device path interface, return
1138 * bootefi_device_path
1139 */
1140 obj->protocols[0].guid = &efi_guid_device_path;
1141 obj->protocols[0].protocol_interface = device_path;
1142
1143 /*
1144 * When asking for the loaded_image interface, just
1145 * return handle which points to loaded_image_info
1146 */
1147 obj->protocols[1].guid = &efi_guid_loaded_image;
1148 obj->protocols[1].protocol_interface = info;
1149
1150 obj->protocols[2].guid = &efi_guid_console_control;
1151 obj->protocols[2].protocol_interface = (void *)&efi_console_control;
1152
1153 obj->protocols[3].guid = &efi_guid_device_path_to_text_protocol;
1154 obj->protocols[3].protocol_interface =
1155 (void *)&efi_device_path_to_text;
1156
1157 info->file_path = file_path;
Heinrich Schuchardt1a2c8d22017-10-08 06:57:26 +02001158 if (device_path)
1159 info->device_handle = efi_dp_find_obj(device_path, NULL);
Rob Clark95c55532017-09-13 18:05:33 -04001160
1161 list_add_tail(&obj->link, &efi_obj_list);
1162}
1163
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001164/*
1165 * Load an image using a file path.
1166 *
1167 * @file_path the path of the image to load
1168 * @buffer buffer containing the loaded image
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001169 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001170 */
Rob Clark9975fe92017-09-13 18:05:38 -04001171efi_status_t efi_load_image_from_path(struct efi_device_path *file_path,
1172 void **buffer)
Rob Clark838ee4b2017-09-13 18:05:35 -04001173{
1174 struct efi_file_info *info = NULL;
1175 struct efi_file_handle *f;
1176 static efi_status_t ret;
1177 uint64_t bs;
1178
1179 f = efi_file_from_path(file_path);
1180 if (!f)
1181 return EFI_DEVICE_ERROR;
1182
1183 bs = 0;
1184 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1185 &bs, info));
1186 if (ret == EFI_BUFFER_TOO_SMALL) {
1187 info = malloc(bs);
1188 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1189 &bs, info));
1190 }
1191 if (ret != EFI_SUCCESS)
1192 goto error;
1193
1194 ret = efi_allocate_pool(EFI_LOADER_DATA, info->file_size, buffer);
1195 if (ret)
1196 goto error;
1197
1198 EFI_CALL(ret = f->read(f, &info->file_size, *buffer));
1199
1200error:
1201 free(info);
1202 EFI_CALL(f->close(f));
1203
1204 if (ret != EFI_SUCCESS) {
1205 efi_free_pool(*buffer);
1206 *buffer = NULL;
1207 }
1208
1209 return ret;
1210}
1211
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001212/*
1213 * Load an EFI image into memory.
1214 *
1215 * This function implements the LoadImage service.
1216 * See the Unified Extensible Firmware Interface (UEFI) specification
1217 * for details.
1218 *
1219 * @boot_policy true for request originating from the boot manager
1220 * @parent_image the calles's image handle
1221 * @file_path the path of the image to load
1222 * @source_buffer memory location from which the image is installed
1223 * @source_size size of the memory area from which the image is
1224 * installed
1225 * @image_handle handle for the newly installed image
1226 * @return status code
1227 */
Alexander Grafbee91162016-03-04 01:09:59 +01001228static efi_status_t EFIAPI efi_load_image(bool boot_policy,
1229 efi_handle_t parent_image,
1230 struct efi_device_path *file_path,
1231 void *source_buffer,
1232 unsigned long source_size,
1233 efi_handle_t *image_handle)
1234{
Alexander Grafbee91162016-03-04 01:09:59 +01001235 struct efi_loaded_image *info;
1236 struct efi_object *obj;
1237
1238 EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
1239 file_path, source_buffer, source_size, image_handle);
Rob Clark838ee4b2017-09-13 18:05:35 -04001240
1241 info = calloc(1, sizeof(*info));
1242 obj = calloc(1, sizeof(*obj));
1243
1244 if (!source_buffer) {
1245 struct efi_device_path *dp, *fp;
1246 efi_status_t ret;
1247
Rob Clark9975fe92017-09-13 18:05:38 -04001248 ret = efi_load_image_from_path(file_path, &source_buffer);
Rob Clark838ee4b2017-09-13 18:05:35 -04001249 if (ret != EFI_SUCCESS) {
1250 free(info);
1251 free(obj);
1252 return EFI_EXIT(ret);
1253 }
1254
1255 /*
1256 * split file_path which contains both the device and
1257 * file parts:
1258 */
1259 efi_dp_split_file_path(file_path, &dp, &fp);
1260
1261 efi_setup_loaded_image(info, obj, dp, fp);
1262 } else {
1263 /* In this case, file_path is the "device" path, ie.
1264 * something like a HARDWARE_DEVICE:MEMORY_MAPPED
1265 */
1266 efi_setup_loaded_image(info, obj, file_path, NULL);
1267 }
1268
Alexander Grafbee91162016-03-04 01:09:59 +01001269 info->reserved = efi_load_pe(source_buffer, info);
1270 if (!info->reserved) {
1271 free(info);
1272 free(obj);
1273 return EFI_EXIT(EFI_UNSUPPORTED);
1274 }
1275
1276 *image_handle = info;
Alexander Grafbee91162016-03-04 01:09:59 +01001277
1278 return EFI_EXIT(EFI_SUCCESS);
1279}
1280
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001281/*
1282 * Call the entry point of an image.
1283 *
1284 * This function implements the StartImage service.
1285 * See the Unified Extensible Firmware Interface (UEFI) specification
1286 * for details.
1287 *
1288 * @image_handle handle of the image
1289 * @exit_data_size size of the buffer
1290 * @exit_data buffer to receive the exit data of the called image
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001291 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001292 */
Alexander Grafbee91162016-03-04 01:09:59 +01001293static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
1294 unsigned long *exit_data_size,
1295 s16 **exit_data)
1296{
1297 ulong (*entry)(void *image_handle, struct efi_system_table *st);
1298 struct efi_loaded_image *info = image_handle;
1299
1300 EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
1301 entry = info->reserved;
1302
1303 efi_is_direct_boot = false;
1304
1305 /* call the image! */
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001306 if (setjmp(&info->exit_jmp)) {
1307 /* We returned from the child image */
1308 return EFI_EXIT(info->exit_status);
1309 }
1310
Rob Clarkaf65db82017-07-27 08:04:19 -04001311 __efi_nesting_dec();
Rob Clarkc160d2f2017-07-27 08:04:18 -04001312 __efi_exit_check();
Alexander Grafbee91162016-03-04 01:09:59 +01001313 entry(image_handle, &systab);
Rob Clarkc160d2f2017-07-27 08:04:18 -04001314 __efi_entry_check();
Rob Clarkaf65db82017-07-27 08:04:19 -04001315 __efi_nesting_inc();
Alexander Grafbee91162016-03-04 01:09:59 +01001316
1317 /* Should usually never get here */
1318 return EFI_EXIT(EFI_SUCCESS);
1319}
1320
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001321/*
1322 * Leave an EFI application or driver.
1323 *
1324 * This function implements the Exit service.
1325 * See the Unified Extensible Firmware Interface (UEFI) specification
1326 * for details.
1327 *
1328 * @image_handle handle of the application or driver that is exiting
1329 * @exit_status status code
1330 * @exit_data_size size of the buffer in bytes
1331 * @exit_data buffer with data describing an error
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001332 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001333 */
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001334static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
1335 efi_status_t exit_status, unsigned long exit_data_size,
1336 int16_t *exit_data)
Alexander Grafbee91162016-03-04 01:09:59 +01001337{
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001338 struct efi_loaded_image *loaded_image_info = (void*)image_handle;
1339
Alexander Grafbee91162016-03-04 01:09:59 +01001340 EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
1341 exit_data_size, exit_data);
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001342
Alexander Grafa1489202017-09-03 14:14:17 +02001343 /* Make sure entry/exit counts for EFI world cross-overs match */
Heinrich Schuchardtda940732017-08-25 19:53:14 +02001344 __efi_exit_check();
1345
Alexander Grafa1489202017-09-03 14:14:17 +02001346 /*
1347 * But longjmp out with the U-Boot gd, not the application's, as
1348 * the other end is a setjmp call inside EFI context.
1349 */
1350 efi_restore_gd();
1351
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001352 loaded_image_info->exit_status = exit_status;
Alexander Graf692fcdd2016-09-27 09:30:32 +02001353 longjmp(&loaded_image_info->exit_jmp, 1);
Alexander Grafa86aeaf2016-05-20 23:28:23 +02001354
1355 panic("EFI application exited");
Alexander Grafbee91162016-03-04 01:09:59 +01001356}
1357
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001358/*
1359 * Find the internal EFI object for a handle.
1360 *
1361 * @handle handle to find
1362 * @return EFI object
1363 */
Alexander Grafbee91162016-03-04 01:09:59 +01001364static struct efi_object *efi_search_obj(void *handle)
1365{
1366 struct list_head *lhandle;
1367
1368 list_for_each(lhandle, &efi_obj_list) {
1369 struct efi_object *efiobj;
1370 efiobj = list_entry(lhandle, struct efi_object, link);
1371 if (efiobj->handle == handle)
1372 return efiobj;
1373 }
1374
1375 return NULL;
1376}
1377
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001378/*
1379 * Unload an EFI image.
1380 *
1381 * This function implements the UnloadImage service.
1382 * See the Unified Extensible Firmware Interface (UEFI) specification
1383 * for details.
1384 *
1385 * @image_handle handle of the image to be unloaded
1386 * @return status code
1387 */
Alexander Grafbee91162016-03-04 01:09:59 +01001388static efi_status_t EFIAPI efi_unload_image(void *image_handle)
1389{
1390 struct efi_object *efiobj;
1391
1392 EFI_ENTRY("%p", image_handle);
1393 efiobj = efi_search_obj(image_handle);
1394 if (efiobj)
1395 list_del(&efiobj->link);
1396
1397 return EFI_EXIT(EFI_SUCCESS);
1398}
1399
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001400/*
1401 * Fix up caches for EFI payloads if necessary.
1402 */
Alexander Grafbee91162016-03-04 01:09:59 +01001403static void efi_exit_caches(void)
1404{
1405#if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
1406 /*
1407 * Grub on 32bit ARM needs to have caches disabled before jumping into
1408 * a zImage, but does not know of all cache layers. Give it a hand.
1409 */
1410 if (efi_is_direct_boot)
1411 cleanup_before_linux();
1412#endif
1413}
1414
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001415/*
1416 * Stop boot services.
1417 *
1418 * This function implements the ExitBootServices service.
1419 * See the Unified Extensible Firmware Interface (UEFI) specification
1420 * for details.
1421 *
1422 * @image_handle handle of the loaded image
1423 * @map_key key of the memory map
1424 * @return status code
1425 */
Alexander Grafbee91162016-03-04 01:09:59 +01001426static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
1427 unsigned long map_key)
1428{
Heinrich Schuchardt152a2632017-09-15 10:06:18 +02001429 int i;
1430
Alexander Grafbee91162016-03-04 01:09:59 +01001431 EFI_ENTRY("%p, %ld", image_handle, map_key);
1432
Heinrich Schuchardt152a2632017-09-15 10:06:18 +02001433 /* Notify that ExitBootServices is invoked. */
1434 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
1435 if (efi_events[i].type != EVT_SIGNAL_EXIT_BOOT_SERVICES)
1436 continue;
1437 efi_signal_event(&efi_events[i]);
1438 }
1439 /* Make sure that notification functions are not called anymore */
1440 efi_tpl = TPL_HIGH_LEVEL;
1441
Rob Clarkad644e72017-09-13 18:05:37 -04001442#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1443 /* save any EFI variables that have been written: */
1444 env_save();
1445#endif
1446
Alexander Grafb7b84102016-11-17 01:02:57 +01001447 board_quiesce_devices();
1448
Alexander Grafbee91162016-03-04 01:09:59 +01001449 /* Fix up caches for EFI payloads if necessary */
1450 efi_exit_caches();
1451
1452 /* This stops all lingering devices */
1453 bootm_disable_interrupts();
1454
1455 /* Give the payload some time to boot */
1456 WATCHDOG_RESET();
1457
1458 return EFI_EXIT(EFI_SUCCESS);
1459}
1460
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001461/*
1462 * Get next value of the counter.
1463 *
1464 * This function implements the NextMonotonicCount service.
1465 * See the Unified Extensible Firmware Interface (UEFI) specification
1466 * for details.
1467 *
1468 * @count returned value of the counter
1469 * @return status code
1470 */
Alexander Grafbee91162016-03-04 01:09:59 +01001471static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
1472{
1473 static uint64_t mono = 0;
1474 EFI_ENTRY("%p", count);
1475 *count = mono++;
1476 return EFI_EXIT(EFI_SUCCESS);
1477}
1478
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001479/*
1480 * Sleep.
1481 *
1482 * This function implements the Stall sercive.
1483 * See the Unified Extensible Firmware Interface (UEFI) specification
1484 * for details.
1485 *
1486 * @microseconds period to sleep in microseconds
1487 * @return status code
1488 */
Alexander Grafbee91162016-03-04 01:09:59 +01001489static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
1490{
1491 EFI_ENTRY("%ld", microseconds);
1492 udelay(microseconds);
1493 return EFI_EXIT(EFI_SUCCESS);
1494}
1495
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001496/*
1497 * Reset the watchdog timer.
1498 *
1499 * This function implements the WatchdogTimer service.
1500 * See the Unified Extensible Firmware Interface (UEFI) specification
1501 * for details.
1502 *
1503 * @timeout seconds before reset by watchdog
1504 * @watchdog_code code to be logged when resetting
1505 * @data_size size of buffer in bytes
1506 * @watchdog_data buffer with data describing the reset reason
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001507 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001508 */
Alexander Grafbee91162016-03-04 01:09:59 +01001509static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
1510 uint64_t watchdog_code,
1511 unsigned long data_size,
1512 uint16_t *watchdog_data)
1513{
1514 EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
1515 data_size, watchdog_data);
Rob Clarkb5104822017-07-25 20:17:59 -04001516 return efi_unsupported(__func__);
Alexander Grafbee91162016-03-04 01:09:59 +01001517}
1518
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001519/*
1520 * Connect a controller to a driver.
1521 *
1522 * This function implements the ConnectController service.
1523 * See the Unified Extensible Firmware Interface (UEFI) specification
1524 * for details.
1525 *
1526 * @controller_handle handle of the controller
1527 * @driver_image_handle handle of the driver
1528 * @remain_device_path device path of a child controller
1529 * @recursive true to connect all child controllers
1530 * @return status code
1531 */
Alexander Grafbee91162016-03-04 01:09:59 +01001532static efi_status_t EFIAPI efi_connect_controller(
1533 efi_handle_t controller_handle,
1534 efi_handle_t *driver_image_handle,
1535 struct efi_device_path *remain_device_path,
1536 bool recursive)
1537{
1538 EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
1539 remain_device_path, recursive);
1540 return EFI_EXIT(EFI_NOT_FOUND);
1541}
1542
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001543/*
1544 * Disconnect a controller from a driver.
1545 *
1546 * This function implements the DisconnectController service.
1547 * See the Unified Extensible Firmware Interface (UEFI) specification
1548 * for details.
1549 *
1550 * @controller_handle handle of the controller
1551 * @driver_image_handle handle of the driver
1552 * @child_handle handle of the child to destroy
1553 * @return status code
1554 */
Alexander Grafbee91162016-03-04 01:09:59 +01001555static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
1556 void *driver_image_handle,
1557 void *child_handle)
1558{
1559 EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
1560 child_handle);
1561 return EFI_EXIT(EFI_INVALID_PARAMETER);
1562}
1563
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001564/*
1565 * Close a protocol.
1566 *
1567 * This function implements the CloseProtocol service.
1568 * See the Unified Extensible Firmware Interface (UEFI) specification
1569 * for details.
1570 *
1571 * @handle handle on which the protocol shall be closed
1572 * @protocol GUID of the protocol to close
1573 * @agent_handle handle of the driver
1574 * @controller_handle handle of the controller
1575 * @return status code
1576 */
Alexander Grafbee91162016-03-04 01:09:59 +01001577static efi_status_t EFIAPI efi_close_protocol(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001578 const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001579 void *agent_handle,
1580 void *controller_handle)
1581{
Rob Clark778e6af2017-09-13 18:05:41 -04001582 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, agent_handle,
Alexander Grafbee91162016-03-04 01:09:59 +01001583 controller_handle);
1584 return EFI_EXIT(EFI_NOT_FOUND);
1585}
1586
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001587/*
1588 * Provide information about then open status of a protocol on a handle
1589 *
1590 * This function implements the OpenProtocolInformation service.
1591 * See the Unified Extensible Firmware Interface (UEFI) specification
1592 * for details.
1593 *
1594 * @handle handle for which the information shall be retrieved
1595 * @protocol GUID of the protocol
1596 * @entry_buffer buffer to receive the open protocol information
1597 * @entry_count number of entries available in the buffer
1598 * @return status code
1599 */
Alexander Grafbee91162016-03-04 01:09:59 +01001600static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001601 const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001602 struct efi_open_protocol_info_entry **entry_buffer,
1603 unsigned long *entry_count)
1604{
Rob Clark778e6af2017-09-13 18:05:41 -04001605 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, entry_buffer,
Alexander Grafbee91162016-03-04 01:09:59 +01001606 entry_count);
1607 return EFI_EXIT(EFI_NOT_FOUND);
1608}
1609
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001610/*
1611 * Get protocols installed on a handle.
1612 *
1613 * This function implements the ProtocolsPerHandleService.
1614 * See the Unified Extensible Firmware Interface (UEFI) specification
1615 * for details.
1616 *
1617 * @handle handle for which the information is retrieved
1618 * @protocol_buffer buffer with protocol GUIDs
1619 * @protocol_buffer_count number of entries in the buffer
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001620 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001621 */
Alexander Grafbee91162016-03-04 01:09:59 +01001622static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
1623 efi_guid_t ***protocol_buffer,
1624 unsigned long *protocol_buffer_count)
1625{
xypron.glpk@gmx.dec0ebfc82017-07-13 23:24:32 +02001626 unsigned long buffer_size;
1627 struct efi_object *efiobj;
1628 unsigned long i, j;
1629 struct list_head *lhandle;
1630 efi_status_t r;
1631
Alexander Grafbee91162016-03-04 01:09:59 +01001632 EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
1633 protocol_buffer_count);
xypron.glpk@gmx.dec0ebfc82017-07-13 23:24:32 +02001634
1635 if (!handle || !protocol_buffer || !protocol_buffer_count)
1636 return EFI_EXIT(EFI_INVALID_PARAMETER);
1637
1638 *protocol_buffer = NULL;
Rob Clark661c8322017-07-20 07:59:39 -04001639 *protocol_buffer_count = 0;
xypron.glpk@gmx.dec0ebfc82017-07-13 23:24:32 +02001640 list_for_each(lhandle, &efi_obj_list) {
1641 efiobj = list_entry(lhandle, struct efi_object, link);
1642
1643 if (efiobj->handle != handle)
1644 continue;
1645
1646 /* Count protocols */
1647 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1648 if (efiobj->protocols[i].guid)
1649 ++*protocol_buffer_count;
1650 }
1651 /* Copy guids */
1652 if (*protocol_buffer_count) {
1653 buffer_size = sizeof(efi_guid_t *) *
1654 *protocol_buffer_count;
1655 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
1656 buffer_size,
1657 (void **)protocol_buffer);
1658 if (r != EFI_SUCCESS)
1659 return EFI_EXIT(r);
1660 j = 0;
1661 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); ++i) {
1662 if (efiobj->protocols[i].guid) {
1663 (*protocol_buffer)[j] = (void *)
1664 efiobj->protocols[i].guid;
1665 ++j;
1666 }
1667 }
1668 }
1669 break;
1670 }
1671
1672 return EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +01001673}
1674
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001675/*
1676 * Locate handles implementing a protocol.
1677 *
1678 * This function implements the LocateHandleBuffer service.
1679 * See the Unified Extensible Firmware Interface (UEFI) specification
1680 * for details.
1681 *
1682 * @search_type selection criterion
1683 * @protocol GUID of the protocol
1684 * @search_key registration key
1685 * @no_handles number of returned handles
1686 * @buffer buffer with the returned handles
1687 * @return status code
1688 */
Alexander Grafbee91162016-03-04 01:09:59 +01001689static efi_status_t EFIAPI efi_locate_handle_buffer(
1690 enum efi_locate_search_type search_type,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001691 const efi_guid_t *protocol, void *search_key,
Alexander Grafbee91162016-03-04 01:09:59 +01001692 unsigned long *no_handles, efi_handle_t **buffer)
1693{
xypron.glpk@gmx.dec2e703f2017-07-11 22:06:22 +02001694 efi_status_t r;
1695 unsigned long buffer_size = 0;
1696
Rob Clark778e6af2017-09-13 18:05:41 -04001697 EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
Alexander Grafbee91162016-03-04 01:09:59 +01001698 no_handles, buffer);
xypron.glpk@gmx.dec2e703f2017-07-11 22:06:22 +02001699
1700 if (!no_handles || !buffer) {
1701 r = EFI_INVALID_PARAMETER;
1702 goto out;
1703 }
1704 *no_handles = 0;
1705 *buffer = NULL;
1706 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
1707 *buffer);
1708 if (r != EFI_BUFFER_TOO_SMALL)
1709 goto out;
1710 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
1711 (void **)buffer);
1712 if (r != EFI_SUCCESS)
1713 goto out;
1714 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
1715 *buffer);
1716 if (r == EFI_SUCCESS)
1717 *no_handles = buffer_size / sizeof(void *);
1718out:
1719 return EFI_EXIT(r);
Alexander Grafbee91162016-03-04 01:09:59 +01001720}
1721
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001722/*
1723 * Find an interface implementing a protocol.
1724 *
1725 * This function implements the LocateProtocol service.
1726 * See the Unified Extensible Firmware Interface (UEFI) specification
1727 * for details.
1728 *
1729 * @protocol GUID of the protocol
1730 * @registration registration key passed to the notification function
1731 * @protocol_interface interface implementing the protocol
Heinrich Schuchardt10a08c42017-10-08 06:57:27 +02001732 * @return status code
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001733 */
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001734static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001735 void *registration,
1736 void **protocol_interface)
1737{
xypron.glpk@gmx.de88adae52017-07-11 22:06:24 +02001738 struct list_head *lhandle;
Alexander Grafbee91162016-03-04 01:09:59 +01001739 int i;
1740
Rob Clark778e6af2017-09-13 18:05:41 -04001741 EFI_ENTRY("%pUl, %p, %p", protocol, registration, protocol_interface);
xypron.glpk@gmx.de88adae52017-07-11 22:06:24 +02001742
1743 if (!protocol || !protocol_interface)
1744 return EFI_EXIT(EFI_INVALID_PARAMETER);
1745
Heinrich Schuchardtae0bd3a2017-08-18 17:45:16 +02001746 EFI_PRINT_GUID("protocol", protocol);
1747
xypron.glpk@gmx.de88adae52017-07-11 22:06:24 +02001748 list_for_each(lhandle, &efi_obj_list) {
1749 struct efi_object *efiobj;
1750
1751 efiobj = list_entry(lhandle, struct efi_object, link);
1752 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1753 struct efi_handler *handler = &efiobj->protocols[i];
1754
1755 if (!handler->guid)
1756 continue;
1757 if (!guidcmp(handler->guid, protocol)) {
1758 *protocol_interface =
1759 handler->protocol_interface;
1760 return EFI_EXIT(EFI_SUCCESS);
1761 }
Alexander Grafbee91162016-03-04 01:09:59 +01001762 }
1763 }
xypron.glpk@gmx.de88adae52017-07-11 22:06:24 +02001764 *protocol_interface = NULL;
Alexander Grafbee91162016-03-04 01:09:59 +01001765
1766 return EFI_EXIT(EFI_NOT_FOUND);
1767}
1768
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001769/*
1770 * Install multiple protocol interfaces.
1771 *
1772 * This function implements the MultipleProtocolInterfaces service.
1773 * See the Unified Extensible Firmware Interface (UEFI) specification
1774 * for details.
1775 *
1776 * @handle handle on which the protocol interfaces shall be installed
1777 * @... NULL terminated argument list with pairs of protocol GUIDS and
1778 * interfaces
1779 * @return status code
1780 */
Alexander Grafbee91162016-03-04 01:09:59 +01001781static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
1782 void **handle, ...)
1783{
1784 EFI_ENTRY("%p", handle);
xypron.glpk@gmx.de58b83582017-07-11 22:06:20 +02001785
1786 va_list argptr;
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001787 const efi_guid_t *protocol;
xypron.glpk@gmx.de58b83582017-07-11 22:06:20 +02001788 void *protocol_interface;
1789 efi_status_t r = EFI_SUCCESS;
1790 int i = 0;
1791
1792 if (!handle)
1793 return EFI_EXIT(EFI_INVALID_PARAMETER);
1794
1795 va_start(argptr, handle);
1796 for (;;) {
1797 protocol = va_arg(argptr, efi_guid_t*);
1798 if (!protocol)
1799 break;
1800 protocol_interface = va_arg(argptr, void*);
1801 r = efi_install_protocol_interface(handle, protocol,
1802 EFI_NATIVE_INTERFACE,
1803 protocol_interface);
1804 if (r != EFI_SUCCESS)
1805 break;
1806 i++;
1807 }
1808 va_end(argptr);
1809 if (r == EFI_SUCCESS)
1810 return EFI_EXIT(r);
1811
1812 /* If an error occured undo all changes. */
1813 va_start(argptr, handle);
1814 for (; i; --i) {
1815 protocol = va_arg(argptr, efi_guid_t*);
1816 protocol_interface = va_arg(argptr, void*);
1817 efi_uninstall_protocol_interface(handle, protocol,
1818 protocol_interface);
1819 }
1820 va_end(argptr);
1821
1822 return EFI_EXIT(r);
Alexander Grafbee91162016-03-04 01:09:59 +01001823}
1824
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001825/*
1826 * Uninstall multiple protocol interfaces.
1827 *
1828 * This function implements the UninstallMultipleProtocolInterfaces service.
1829 * See the Unified Extensible Firmware Interface (UEFI) specification
1830 * for details.
1831 *
1832 * @handle handle from which the protocol interfaces shall be removed
1833 * @... NULL terminated argument list with pairs of protocol GUIDS and
1834 * interfaces
1835 * @return status code
1836 */
Alexander Grafbee91162016-03-04 01:09:59 +01001837static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
1838 void *handle, ...)
1839{
1840 EFI_ENTRY("%p", handle);
1841 return EFI_EXIT(EFI_INVALID_PARAMETER);
1842}
1843
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001844/*
1845 * Calculate cyclic redundancy code.
1846 *
1847 * This function implements the CalculateCrc32 service.
1848 * See the Unified Extensible Firmware Interface (UEFI) specification
1849 * for details.
1850 *
1851 * @data buffer with data
1852 * @data_size size of buffer in bytes
1853 * @crc32_p cyclic redundancy code
1854 * @return status code
1855 */
Alexander Grafbee91162016-03-04 01:09:59 +01001856static efi_status_t EFIAPI efi_calculate_crc32(void *data,
1857 unsigned long data_size,
1858 uint32_t *crc32_p)
1859{
1860 EFI_ENTRY("%p, %ld", data, data_size);
1861 *crc32_p = crc32(0, data, data_size);
1862 return EFI_EXIT(EFI_SUCCESS);
1863}
1864
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001865/*
1866 * Copy memory.
1867 *
1868 * This function implements the CopyMem service.
1869 * See the Unified Extensible Firmware Interface (UEFI) specification
1870 * for details.
1871 *
1872 * @destination destination of the copy operation
1873 * @source source of the copy operation
1874 * @length number of bytes to copy
1875 */
Heinrich Schuchardtfc05a952017-10-05 16:35:52 +02001876static void EFIAPI efi_copy_mem(void *destination, const void *source,
1877 size_t length)
Alexander Grafbee91162016-03-04 01:09:59 +01001878{
Heinrich Schuchardtfc05a952017-10-05 16:35:52 +02001879 EFI_ENTRY("%p, %p, %ld", destination, source, (unsigned long)length);
Alexander Grafbee91162016-03-04 01:09:59 +01001880 memcpy(destination, source, length);
Heinrich Schuchardtf7c78172017-10-05 16:35:51 +02001881 EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +01001882}
1883
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001884/*
1885 * Fill memory with a byte value.
1886 *
1887 * This function implements the SetMem service.
1888 * See the Unified Extensible Firmware Interface (UEFI) specification
1889 * for details.
1890 *
1891 * @buffer buffer to fill
1892 * @size size of buffer in bytes
1893 * @value byte to copy to the buffer
1894 */
Heinrich Schuchardtfc05a952017-10-05 16:35:52 +02001895static void EFIAPI efi_set_mem(void *buffer, size_t size, uint8_t value)
Alexander Grafbee91162016-03-04 01:09:59 +01001896{
Heinrich Schuchardtfc05a952017-10-05 16:35:52 +02001897 EFI_ENTRY("%p, %ld, 0x%x", buffer, (unsigned long)size, value);
Alexander Grafbee91162016-03-04 01:09:59 +01001898 memset(buffer, value, size);
Heinrich Schuchardtf7c78172017-10-05 16:35:51 +02001899 EFI_EXIT(EFI_SUCCESS);
Alexander Grafbee91162016-03-04 01:09:59 +01001900}
1901
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001902/*
1903 * Open protocol interface on a handle.
1904 *
1905 * This function implements the OpenProtocol interface.
1906 * See the Unified Extensible Firmware Interface (UEFI) specification
1907 * for details.
1908 *
1909 * @handle handle on which the protocol shall be opened
1910 * @protocol GUID of the protocol
1911 * @protocol_interface interface implementing the protocol
1912 * @agent_handle handle of the driver
1913 * @controller_handle handle of the controller
1914 * @attributes attributes indicating how to open the protocol
1915 * @return status code
1916 */
Alexander Grafbee91162016-03-04 01:09:59 +01001917static efi_status_t EFIAPI efi_open_protocol(
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02001918 void *handle, const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001919 void **protocol_interface, void *agent_handle,
1920 void *controller_handle, uint32_t attributes)
1921{
1922 struct list_head *lhandle;
1923 int i;
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001924 efi_status_t r = EFI_INVALID_PARAMETER;
Alexander Grafbee91162016-03-04 01:09:59 +01001925
Rob Clark778e6af2017-09-13 18:05:41 -04001926 EFI_ENTRY("%p, %pUl, %p, %p, %p, 0x%x", handle, protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01001927 protocol_interface, agent_handle, controller_handle,
1928 attributes);
xypron.glpk@gmx.deb5349f72017-07-11 22:06:14 +02001929
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001930 if (!handle || !protocol ||
1931 (!protocol_interface && attributes !=
1932 EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
1933 goto out;
1934 }
1935
Heinrich Schuchardtae0bd3a2017-08-18 17:45:16 +02001936 EFI_PRINT_GUID("protocol", protocol);
1937
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001938 switch (attributes) {
1939 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
1940 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
1941 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
1942 break;
1943 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
1944 if (controller_handle == handle)
1945 goto out;
1946 case EFI_OPEN_PROTOCOL_BY_DRIVER:
1947 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
1948 if (controller_handle == NULL)
1949 goto out;
1950 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
1951 if (agent_handle == NULL)
1952 goto out;
1953 break;
1954 default:
xypron.glpk@gmx.deb5349f72017-07-11 22:06:14 +02001955 goto out;
1956 }
1957
Alexander Grafbee91162016-03-04 01:09:59 +01001958 list_for_each(lhandle, &efi_obj_list) {
1959 struct efi_object *efiobj;
1960 efiobj = list_entry(lhandle, struct efi_object, link);
1961
1962 if (efiobj->handle != handle)
1963 continue;
1964
1965 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1966 struct efi_handler *handler = &efiobj->protocols[i];
1967 const efi_guid_t *hprotocol = handler->guid;
1968 if (!hprotocol)
xypron.glpk@gmx.de4b6ed0d2017-07-11 22:06:17 +02001969 continue;
Alexander Grafbee91162016-03-04 01:09:59 +01001970 if (!guidcmp(hprotocol, protocol)) {
xypron.glpk@gmx.deb5349f72017-07-11 22:06:14 +02001971 if (attributes !=
1972 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
1973 *protocol_interface =
1974 handler->protocol_interface;
1975 }
1976 r = EFI_SUCCESS;
Alexander Grafbee91162016-03-04 01:09:59 +01001977 goto out;
1978 }
1979 }
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001980 goto unsupported;
Alexander Grafbee91162016-03-04 01:09:59 +01001981 }
1982
xypron.glpk@gmx.de69baec62017-07-11 22:06:15 +02001983unsupported:
1984 r = EFI_UNSUPPORTED;
Alexander Grafbee91162016-03-04 01:09:59 +01001985out:
1986 return EFI_EXIT(r);
1987}
1988
Heinrich Schuchardt332468f2017-09-21 18:30:11 +02001989/*
1990 * Get interface of a protocol on a handle.
1991 *
1992 * This function implements the HandleProtocol service.
1993 * See the Unified Extensible Firmware Interface (UEFI) specification
1994 * for details.
1995 *
1996 * @handle handle on which the protocol shall be opened
1997 * @protocol GUID of the protocol
1998 * @protocol_interface interface implementing the protocol
1999 * @return status code
2000 */
Alexander Grafbee91162016-03-04 01:09:59 +01002001static efi_status_t EFIAPI efi_handle_protocol(void *handle,
Heinrich Schuchardt5a9682d2017-10-05 16:35:53 +02002002 const efi_guid_t *protocol,
Alexander Grafbee91162016-03-04 01:09:59 +01002003 void **protocol_interface)
2004{
xypron.glpk@gmx.de8e1d3292017-06-29 21:16:19 +02002005 return efi_open_protocol(handle, protocol, protocol_interface, NULL,
2006 NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
Alexander Grafbee91162016-03-04 01:09:59 +01002007}
2008
2009static const struct efi_boot_services efi_boot_services = {
2010 .hdr = {
2011 .headersize = sizeof(struct efi_table_hdr),
2012 },
2013 .raise_tpl = efi_raise_tpl,
2014 .restore_tpl = efi_restore_tpl,
2015 .allocate_pages = efi_allocate_pages_ext,
2016 .free_pages = efi_free_pages_ext,
2017 .get_memory_map = efi_get_memory_map_ext,
Stefan Brünsead12742016-10-09 22:17:18 +02002018 .allocate_pool = efi_allocate_pool_ext,
Stefan Brüns42417bc2016-10-09 22:17:26 +02002019 .free_pool = efi_free_pool_ext,
xypron.glpk@gmx.de49deb452017-07-18 20:17:20 +02002020 .create_event = efi_create_event_ext,
xypron.glpk@gmx.debfc72462017-07-18 20:17:21 +02002021 .set_timer = efi_set_timer_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002022 .wait_for_event = efi_wait_for_event,
xypron.glpk@gmx.dec6841592017-07-18 20:17:18 +02002023 .signal_event = efi_signal_event_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002024 .close_event = efi_close_event,
2025 .check_event = efi_check_event,
xypron.glpk@gmx.de8bee5a32017-07-11 22:06:18 +02002026 .install_protocol_interface = efi_install_protocol_interface_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002027 .reinstall_protocol_interface = efi_reinstall_protocol_interface,
xypron.glpk@gmx.de3d8e1452017-07-11 22:06:19 +02002028 .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002029 .handle_protocol = efi_handle_protocol,
2030 .reserved = NULL,
2031 .register_protocol_notify = efi_register_protocol_notify,
xypron.glpk@gmx.de26329582017-07-11 22:06:21 +02002032 .locate_handle = efi_locate_handle_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002033 .locate_device_path = efi_locate_device_path,
Alexander Graf488bf122016-08-19 01:23:24 +02002034 .install_configuration_table = efi_install_configuration_table_ext,
Alexander Grafbee91162016-03-04 01:09:59 +01002035 .load_image = efi_load_image,
2036 .start_image = efi_start_image,
Alexander Grafa86aeaf2016-05-20 23:28:23 +02002037 .exit = efi_exit,
Alexander Grafbee91162016-03-04 01:09:59 +01002038 .unload_image = efi_unload_image,
2039 .exit_boot_services = efi_exit_boot_services,
2040 .get_next_monotonic_count = efi_get_next_monotonic_count,
2041 .stall = efi_stall,
2042 .set_watchdog_timer = efi_set_watchdog_timer,
2043 .connect_controller = efi_connect_controller,
2044 .disconnect_controller = efi_disconnect_controller,
2045 .open_protocol = efi_open_protocol,
2046 .close_protocol = efi_close_protocol,
2047 .open_protocol_information = efi_open_protocol_information,
2048 .protocols_per_handle = efi_protocols_per_handle,
2049 .locate_handle_buffer = efi_locate_handle_buffer,
2050 .locate_protocol = efi_locate_protocol,
2051 .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
2052 .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
2053 .calculate_crc32 = efi_calculate_crc32,
2054 .copy_mem = efi_copy_mem,
2055 .set_mem = efi_set_mem,
2056};
2057
2058
Alexander Graf3c63db92016-10-14 13:45:30 +02002059static uint16_t __efi_runtime_data firmware_vendor[] =
Alexander Grafbee91162016-03-04 01:09:59 +01002060 { 'D','a','s',' ','U','-','b','o','o','t',0 };
2061
Alexander Graf3c63db92016-10-14 13:45:30 +02002062struct efi_system_table __efi_runtime_data systab = {
Alexander Grafbee91162016-03-04 01:09:59 +01002063 .hdr = {
2064 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
2065 .revision = 0x20005, /* 2.5 */
2066 .headersize = sizeof(struct efi_table_hdr),
2067 },
2068 .fw_vendor = (long)firmware_vendor,
2069 .con_in = (void*)&efi_con_in,
2070 .con_out = (void*)&efi_con_out,
2071 .std_err = (void*)&efi_con_out,
2072 .runtime = (void*)&efi_runtime_services,
2073 .boottime = (void*)&efi_boot_services,
2074 .nr_tables = 0,
2075 .tables = (void*)efi_conf_table,
2076};