blob: 71c244ea805ebc2d27551894ac56dccb29cf9707 [file] [log] [blame]
Alexander Grafc15d9212016-03-04 01:09:59 +01001/*
2 * EFI application boot time services
3 *
4 * Copyright (c) 2016 Alexander Graf
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
Alexander Grafc15d9212016-03-04 01:09:59 +01009#include <common.h>
Heinrich Schuchardt368ca642017-10-05 16:14:14 +020010#include <div64.h>
Alexander Grafc15d9212016-03-04 01:09:59 +010011#include <efi_loader.h>
Rob Clark15f3d742017-09-13 18:05:37 -040012#include <environment.h>
Alexander Grafc15d9212016-03-04 01:09:59 +010013#include <malloc.h>
14#include <asm/global_data.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090015#include <linux/libfdt_env.h>
Alexander Grafc15d9212016-03-04 01:09:59 +010016#include <u-boot/crc.h>
17#include <bootm.h>
18#include <inttypes.h>
19#include <watchdog.h>
20
21DECLARE_GLOBAL_DATA_PTR;
22
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +020023/* Task priority level */
Heinrich Schuchardtf8d4ec32017-11-06 21:17:47 +010024static efi_uintn_t efi_tpl = TPL_APPLICATION;
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +020025
Alexander Grafc15d9212016-03-04 01:09:59 +010026/* This list contains all the EFI objects our payload has access to */
27LIST_HEAD(efi_obj_list);
28
29/*
30 * If we're running on nasty systems (32bit ARM booting into non-EFI Linux)
31 * we need to do trickery with caches. Since we don't want to break the EFI
32 * aware boot path, only apply hacks when loading exiting directly (breaking
33 * direct Linux EFI booting along the way - oh well).
34 */
35static bool efi_is_direct_boot = true;
36
37/*
38 * EFI can pass arbitrary additional "tables" containing vendor specific
39 * information to the payload. One such table is the FDT table which contains
40 * a pointer to a flattened device tree blob.
41 *
42 * In most cases we want to pass an FDT to the payload, so reserve one slot of
43 * config table space for it. The pointer gets populated by do_bootefi_exec().
44 */
Alexander Graf393dd912016-10-14 13:45:30 +020045static struct efi_configuration_table __efi_runtime_data efi_conf_table[2];
Alexander Grafc15d9212016-03-04 01:09:59 +010046
Simon Glasscdfe6962016-09-25 15:27:35 -060047#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +010048/*
49 * The "gd" pointer lives in a register on ARM and AArch64 that we declare
50 * fixed when compiling U-Boot. However, the payload does not know about that
51 * restriction so we need to manually swap its and our view of that register on
52 * EFI callback entry/exit.
53 */
54static volatile void *efi_gd, *app_gd;
Simon Glasscdfe6962016-09-25 15:27:35 -060055#endif
Alexander Grafc15d9212016-03-04 01:09:59 +010056
Rob Clark86789d52017-07-27 08:04:18 -040057static int entry_count;
Rob Clarke7896c32017-07-27 08:04:19 -040058static int nesting_level;
Heinrich Schuchardt760255f2018-01-11 08:16:02 +010059/* GUID of the EFI_DRIVER_BINDING_PROTOCOL */
60const efi_guid_t efi_guid_driver_binding_protocol =
61 EFI_DRIVER_BINDING_PROTOCOL_GUID;
Rob Clark86789d52017-07-27 08:04:18 -040062
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +010063static efi_status_t EFIAPI efi_disconnect_controller(
64 efi_handle_t controller_handle,
65 efi_handle_t driver_image_handle,
66 efi_handle_t child_handle);
Heinrich Schuchardte9943282018-01-11 08:16:04 +010067
Rob Clark86789d52017-07-27 08:04:18 -040068/* Called on every callback entry */
69int __efi_entry_check(void)
70{
71 int ret = entry_count++ == 0;
72#ifdef CONFIG_ARM
73 assert(efi_gd);
74 app_gd = gd;
75 gd = efi_gd;
76#endif
77 return ret;
78}
79
80/* Called on every callback exit */
81int __efi_exit_check(void)
82{
83 int ret = --entry_count == 0;
84#ifdef CONFIG_ARM
85 gd = app_gd;
86#endif
87 return ret;
88}
89
Alexander Grafc15d9212016-03-04 01:09:59 +010090/* Called from do_bootefi_exec() */
91void efi_save_gd(void)
92{
Simon Glasscdfe6962016-09-25 15:27:35 -060093#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +010094 efi_gd = gd;
Simon Glasscdfe6962016-09-25 15:27:35 -060095#endif
Alexander Grafc15d9212016-03-04 01:09:59 +010096}
97
Rob Clark86789d52017-07-27 08:04:18 -040098/*
99 * Special case handler for error/abort that just forces things back
100 * to u-boot world so we can dump out an abort msg, without any care
101 * about returning back to UEFI world.
102 */
Alexander Grafc15d9212016-03-04 01:09:59 +0100103void efi_restore_gd(void)
104{
Simon Glasscdfe6962016-09-25 15:27:35 -0600105#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +0100106 /* Only restore if we're already in EFI context */
107 if (!efi_gd)
108 return;
Alexander Grafc15d9212016-03-04 01:09:59 +0100109 gd = efi_gd;
Simon Glasscdfe6962016-09-25 15:27:35 -0600110#endif
Alexander Grafc15d9212016-03-04 01:09:59 +0100111}
112
Rob Clarke7896c32017-07-27 08:04:19 -0400113/*
Heinrich Schuchardt091cf432018-01-24 19:21:36 +0100114 * Return a string for indenting with two spaces per level. A maximum of ten
115 * indent levels is supported. Higher indent levels will be truncated.
116 *
117 * @level indent level
118 * @return indent string
Rob Clarke7896c32017-07-27 08:04:19 -0400119 */
120static const char *indent_string(int level)
121{
122 const char *indent = " ";
123 const int max = strlen(indent);
124 level = min(max, level * 2);
125 return &indent[max - level];
126}
127
Heinrich Schuchardt4d664892017-08-18 17:45:16 +0200128const char *__efi_nesting(void)
129{
130 return indent_string(nesting_level);
131}
132
Rob Clarke7896c32017-07-27 08:04:19 -0400133const char *__efi_nesting_inc(void)
134{
135 return indent_string(nesting_level++);
136}
137
138const char *__efi_nesting_dec(void)
139{
140 return indent_string(--nesting_level);
141}
142
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200143/*
144 * Queue an EFI event.
145 *
146 * This function queues the notification function of the event for future
147 * execution.
148 *
149 * The notification function is called if the task priority level of the
150 * event is higher than the current task priority level.
151 *
152 * For the SignalEvent service see efi_signal_event_ext.
153 *
154 * @event event to signal
Heinrich Schuchardtd8b878a2018-01-19 20:24:51 +0100155 * @check_tpl check the TPL level
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200156 */
Heinrich Schuchardtd8b878a2018-01-19 20:24:51 +0100157void efi_signal_event(struct efi_event *event, bool check_tpl)
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200158{
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200159 if (event->notify_function) {
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200160 event->is_queued = true;
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200161 /* Check TPL */
Heinrich Schuchardtd8b878a2018-01-19 20:24:51 +0100162 if (check_tpl && efi_tpl >= event->notify_tpl)
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200163 return;
Heinrich Schuchardt91e5b8a2017-09-15 10:06:10 +0200164 EFI_CALL_VOID(event->notify_function(event,
165 event->notify_context));
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200166 }
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200167 event->is_queued = false;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200168}
169
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200170/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200171 * 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 */
Heinrich Schuchardtf8d4ec32017-11-06 21:17:47 +0100180static unsigned long EFIAPI efi_raise_tpl(efi_uintn_t new_tpl)
Alexander Grafc15d9212016-03-04 01:09:59 +0100181{
Heinrich Schuchardtf8d4ec32017-11-06 21:17:47 +0100182 efi_uintn_t old_tpl = efi_tpl;
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200183
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200184 EFI_ENTRY("0x%zx", new_tpl);
Heinrich Schuchardt0c150ca2017-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 Grafc15d9212016-03-04 01:09:59 +0100194}
195
Heinrich Schuchardta40db6e2017-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 */
Heinrich Schuchardtf8d4ec32017-11-06 21:17:47 +0100205static void EFIAPI efi_restore_tpl(efi_uintn_t old_tpl)
Alexander Grafc15d9212016-03-04 01:09:59 +0100206{
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200207 EFI_ENTRY("0x%zx", old_tpl);
Heinrich Schuchardt0c150ca2017-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 Grafc15d9212016-03-04 01:09:59 +0100216}
217
Heinrich Schuchardta40db6e2017-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 Yamadab2a05c12017-06-22 17:49:03 +0900231static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100232 efi_uintn_t pages,
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900233 uint64_t *memory)
Alexander Grafc15d9212016-03-04 01:09:59 +0100234{
235 efi_status_t r;
236
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100237 EFI_ENTRY("%d, %d, 0x%zx, %p", type, memory_type, pages, memory);
Alexander Grafc15d9212016-03-04 01:09:59 +0100238 r = efi_allocate_pages(type, memory_type, pages, memory);
239 return EFI_EXIT(r);
240}
241
Heinrich Schuchardta40db6e2017-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 Yamadab2a05c12017-06-22 17:49:03 +0900253static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100254 efi_uintn_t pages)
Alexander Grafc15d9212016-03-04 01:09:59 +0100255{
256 efi_status_t r;
257
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100258 EFI_ENTRY("%"PRIx64", 0x%zx", memory, pages);
Alexander Grafc15d9212016-03-04 01:09:59 +0100259 r = efi_free_pages(memory, pages);
260 return EFI_EXIT(r);
261}
262
Heinrich Schuchardta40db6e2017-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 Yamadab2a05c12017-06-22 17:49:03 +0900278static efi_status_t EFIAPI efi_get_memory_map_ext(
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100279 efi_uintn_t *memory_map_size,
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900280 struct efi_mem_desc *memory_map,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100281 efi_uintn_t *map_key,
282 efi_uintn_t *descriptor_size,
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900283 uint32_t *descriptor_version)
Alexander Grafc15d9212016-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 Schuchardta40db6e2017-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üns5a09aef2016-10-09 22:17:18 +0200306static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100307 efi_uintn_t size,
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200308 void **buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +0100309{
Alexander Graf1c34fa82016-03-24 01:37:37 +0100310 efi_status_t r;
311
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100312 EFI_ENTRY("%d, %zd, %p", pool_type, size, buffer);
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200313 r = efi_allocate_pool(pool_type, size, buffer);
Alexander Graf1c34fa82016-03-24 01:37:37 +0100314 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100315}
316
Heinrich Schuchardta40db6e2017-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üns67b67d92016-10-09 22:17:26 +0200327static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +0100328{
Alexander Graf1c34fa82016-03-24 01:37:37 +0100329 efi_status_t r;
330
331 EFI_ENTRY("%p", buffer);
Stefan Brüns67b67d92016-10-09 22:17:26 +0200332 r = efi_free_pool(buffer);
Alexander Graf1c34fa82016-03-24 01:37:37 +0100333 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100334}
335
Heinrich Schuchardteb6106e2017-10-26 19:25:49 +0200336/*
Heinrich Schuchardt967d7de2017-11-26 14:05:23 +0100337 * Add a new object to the object list.
338 *
339 * The protocols list is initialized.
340 * The object handle is set.
341 *
342 * @obj object to be added
343 */
344void efi_add_handle(struct efi_object *obj)
345{
346 if (!obj)
347 return;
348 INIT_LIST_HEAD(&obj->protocols);
349 obj->handle = obj;
350 list_add_tail(&obj->link, &efi_obj_list);
351}
352
353/*
Heinrich Schuchardteb6106e2017-10-26 19:25:49 +0200354 * Create handle.
355 *
356 * @handle new handle
357 * @return status code
358 */
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +0100359efi_status_t efi_create_handle(efi_handle_t *handle)
Heinrich Schuchardtcd522cb2017-08-27 00:51:09 +0200360{
361 struct efi_object *obj;
362 efi_status_t r;
363
364 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
365 sizeof(struct efi_object),
366 (void **)&obj);
367 if (r != EFI_SUCCESS)
368 return r;
Heinrich Schuchardt967d7de2017-11-26 14:05:23 +0100369 efi_add_handle(obj);
370 *handle = obj->handle;
Heinrich Schuchardtcd522cb2017-08-27 00:51:09 +0200371 return r;
372}
373
Alexander Grafc15d9212016-03-04 01:09:59 +0100374/*
Heinrich Schuchardt7d135462017-12-04 18:03:02 +0100375 * Find a protocol on a handle.
376 *
377 * @handle handle
378 * @protocol_guid GUID of the protocol
379 * @handler reference to the protocol
380 * @return status code
381 */
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +0100382efi_status_t efi_search_protocol(const efi_handle_t handle,
Heinrich Schuchardt7d135462017-12-04 18:03:02 +0100383 const efi_guid_t *protocol_guid,
384 struct efi_handler **handler)
385{
386 struct efi_object *efiobj;
387 struct list_head *lhandle;
388
389 if (!handle || !protocol_guid)
390 return EFI_INVALID_PARAMETER;
391 efiobj = efi_search_obj(handle);
392 if (!efiobj)
393 return EFI_INVALID_PARAMETER;
394 list_for_each(lhandle, &efiobj->protocols) {
395 struct efi_handler *protocol;
396
397 protocol = list_entry(lhandle, struct efi_handler, link);
398 if (!guidcmp(protocol->guid, protocol_guid)) {
399 if (handler)
400 *handler = protocol;
401 return EFI_SUCCESS;
402 }
403 }
404 return EFI_NOT_FOUND;
405}
406
407/*
408 * Delete protocol from a handle.
409 *
410 * @handle handle from which the protocol shall be deleted
411 * @protocol GUID of the protocol to be deleted
412 * @protocol_interface interface of the protocol implementation
413 * @return status code
414 */
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +0100415efi_status_t efi_remove_protocol(const efi_handle_t handle,
416 const efi_guid_t *protocol,
Heinrich Schuchardt7d135462017-12-04 18:03:02 +0100417 void *protocol_interface)
418{
419 struct efi_handler *handler;
420 efi_status_t ret;
421
422 ret = efi_search_protocol(handle, protocol, &handler);
423 if (ret != EFI_SUCCESS)
424 return ret;
425 if (guidcmp(handler->guid, protocol))
426 return EFI_INVALID_PARAMETER;
427 list_del(&handler->link);
428 free(handler);
429 return EFI_SUCCESS;
430}
431
432/*
433 * Delete all protocols from a handle.
434 *
435 * @handle handle from which the protocols shall be deleted
436 * @return status code
437 */
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +0100438efi_status_t efi_remove_all_protocols(const efi_handle_t handle)
Heinrich Schuchardt7d135462017-12-04 18:03:02 +0100439{
440 struct efi_object *efiobj;
Heinrich Schuchardta84731d2018-01-11 08:15:55 +0100441 struct efi_handler *protocol;
442 struct efi_handler *pos;
Heinrich Schuchardt7d135462017-12-04 18:03:02 +0100443
444 efiobj = efi_search_obj(handle);
445 if (!efiobj)
446 return EFI_INVALID_PARAMETER;
Heinrich Schuchardta84731d2018-01-11 08:15:55 +0100447 list_for_each_entry_safe(protocol, pos, &efiobj->protocols, link) {
Heinrich Schuchardt7d135462017-12-04 18:03:02 +0100448 efi_status_t ret;
449
Heinrich Schuchardt7d135462017-12-04 18:03:02 +0100450 ret = efi_remove_protocol(handle, protocol->guid,
451 protocol->protocol_interface);
452 if (ret != EFI_SUCCESS)
453 return ret;
454 }
455 return EFI_SUCCESS;
456}
457
458/*
459 * Delete handle.
460 *
461 * @handle handle to delete
462 */
463void efi_delete_handle(struct efi_object *obj)
464{
465 if (!obj)
466 return;
467 efi_remove_all_protocols(obj->handle);
468 list_del(&obj->link);
469 free(obj);
470}
471
472/*
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200473 * Our event capabilities are very limited. Only a small limited
474 * number of events is allowed to coexist.
Alexander Grafc15d9212016-03-04 01:09:59 +0100475 */
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200476static struct efi_event efi_events[16];
Alexander Grafc15d9212016-03-04 01:09:59 +0100477
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200478/*
479 * Create an event.
480 *
481 * This function is used inside U-Boot code to create an event.
482 *
483 * For the API function implementing the CreateEvent service see
484 * efi_create_event_ext.
485 *
486 * @type type of the event to create
487 * @notify_tpl task priority level of the event
488 * @notify_function notification function of the event
489 * @notify_context pointer passed to the notification function
490 * @event created event
491 * @return status code
492 */
Heinrich Schuchardtf8d4ec32017-11-06 21:17:47 +0100493efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl,
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200494 void (EFIAPI *notify_function) (
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200495 struct efi_event *event,
496 void *context),
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200497 void *notify_context, struct efi_event **event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100498{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200499 int i;
500
Jonathan Gray7758b212017-03-12 19:26:07 +1100501 if (event == NULL)
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200502 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100503
504 if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200505 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100506
507 if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
508 notify_function == NULL)
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200509 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100510
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200511 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
512 if (efi_events[i].type)
513 continue;
514 efi_events[i].type = type;
515 efi_events[i].notify_tpl = notify_tpl;
516 efi_events[i].notify_function = notify_function;
517 efi_events[i].notify_context = notify_context;
518 /* Disable timers on bootup */
519 efi_events[i].trigger_next = -1ULL;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200520 efi_events[i].is_queued = false;
521 efi_events[i].is_signaled = false;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200522 *event = &efi_events[i];
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200523 return EFI_SUCCESS;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200524 }
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200525 return EFI_OUT_OF_RESOURCES;
Alexander Grafc15d9212016-03-04 01:09:59 +0100526}
527
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200528/*
Heinrich Schuchardt717c4582018-02-04 23:05:13 +0100529 * Create an event in a group.
530 *
531 * This function implements the CreateEventEx service.
532 * See the Unified Extensible Firmware Interface (UEFI) specification
533 * for details.
534 * TODO: Support event groups
535 *
536 * @type type of the event to create
537 * @notify_tpl task priority level of the event
538 * @notify_function notification function of the event
539 * @notify_context pointer passed to the notification function
540 * @event created event
541 * @event_group event group
542 * @return status code
543 */
544efi_status_t EFIAPI efi_create_event_ex(uint32_t type, efi_uintn_t notify_tpl,
545 void (EFIAPI *notify_function) (
546 struct efi_event *event,
547 void *context),
548 void *notify_context,
549 efi_guid_t *event_group,
550 struct efi_event **event)
551{
552 EFI_ENTRY("%d, 0x%zx, %p, %p, %pUl", type, notify_tpl, notify_function,
553 notify_context, event_group);
554 if (event_group)
555 return EFI_EXIT(EFI_UNSUPPORTED);
556 return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
557 notify_context, event));
558}
559
560/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200561 * Create an event.
562 *
563 * This function implements the CreateEvent service.
564 * See the Unified Extensible Firmware Interface (UEFI) specification
565 * for details.
566 *
567 * @type type of the event to create
568 * @notify_tpl task priority level of the event
569 * @notify_function notification function of the event
570 * @notify_context pointer passed to the notification function
571 * @event created event
572 * @return status code
573 */
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200574static efi_status_t EFIAPI efi_create_event_ext(
Heinrich Schuchardtf8d4ec32017-11-06 21:17:47 +0100575 uint32_t type, efi_uintn_t notify_tpl,
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200576 void (EFIAPI *notify_function) (
577 struct efi_event *event,
578 void *context),
579 void *notify_context, struct efi_event **event)
580{
581 EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
582 notify_context);
583 return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
584 notify_context, event));
585}
586
587
Alexander Grafc15d9212016-03-04 01:09:59 +0100588/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200589 * Check if a timer event has occurred or a queued notification function should
590 * be called.
591 *
Alexander Grafc15d9212016-03-04 01:09:59 +0100592 * Our timers have to work without interrupts, so we check whenever keyboard
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200593 * input or disk accesses happen if enough time elapsed for them to fire.
Alexander Grafc15d9212016-03-04 01:09:59 +0100594 */
595void efi_timer_check(void)
596{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200597 int i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100598 u64 now = timer_get_us();
599
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200600 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200601 if (!efi_events[i].type)
602 continue;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200603 if (efi_events[i].is_queued)
Heinrich Schuchardtd8b878a2018-01-19 20:24:51 +0100604 efi_signal_event(&efi_events[i], true);
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200605 if (!(efi_events[i].type & EVT_TIMER) ||
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200606 now < efi_events[i].trigger_next)
607 continue;
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200608 switch (efi_events[i].trigger_type) {
609 case EFI_TIMER_RELATIVE:
610 efi_events[i].trigger_type = EFI_TIMER_STOP;
611 break;
612 case EFI_TIMER_PERIODIC:
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200613 efi_events[i].trigger_next +=
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200614 efi_events[i].trigger_time;
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200615 break;
616 default:
617 continue;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200618 }
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200619 efi_events[i].is_signaled = true;
Heinrich Schuchardtd8b878a2018-01-19 20:24:51 +0100620 efi_signal_event(&efi_events[i], true);
Alexander Grafc15d9212016-03-04 01:09:59 +0100621 }
Alexander Grafc15d9212016-03-04 01:09:59 +0100622 WATCHDOG_RESET();
623}
624
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200625/*
626 * Set the trigger time for a timer event or stop the event.
627 *
628 * This is the function for internal usage in U-Boot. For the API function
629 * implementing the SetTimer service see efi_set_timer_ext.
630 *
631 * @event event for which the timer is set
632 * @type type of the timer
633 * @trigger_time trigger period in multiples of 100ns
634 * @return status code
635 */
xypron.glpk@gmx.de3ecc6bd2017-07-19 19:22:34 +0200636efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200637 uint64_t trigger_time)
Alexander Grafc15d9212016-03-04 01:09:59 +0100638{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200639 int i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100640
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200641 /*
642 * The parameter defines a multiple of 100ns.
643 * We use multiples of 1000ns. So divide by 10.
644 */
Heinrich Schuchardt368ca642017-10-05 16:14:14 +0200645 do_div(trigger_time, 10);
Alexander Grafc15d9212016-03-04 01:09:59 +0100646
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200647 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
648 if (event != &efi_events[i])
649 continue;
Alexander Grafc15d9212016-03-04 01:09:59 +0100650
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200651 if (!(event->type & EVT_TIMER))
652 break;
653 switch (type) {
654 case EFI_TIMER_STOP:
655 event->trigger_next = -1ULL;
656 break;
657 case EFI_TIMER_PERIODIC:
658 case EFI_TIMER_RELATIVE:
659 event->trigger_next =
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200660 timer_get_us() + trigger_time;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200661 break;
662 default:
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200663 return EFI_INVALID_PARAMETER;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200664 }
665 event->trigger_type = type;
666 event->trigger_time = trigger_time;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200667 event->is_signaled = false;
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200668 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +0100669 }
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200670 return EFI_INVALID_PARAMETER;
Alexander Grafc15d9212016-03-04 01:09:59 +0100671}
672
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200673/*
674 * Set the trigger time for a timer event or stop the event.
675 *
676 * This function implements the SetTimer service.
677 * See the Unified Extensible Firmware Interface (UEFI) specification
678 * for details.
679 *
680 * @event event for which the timer is set
681 * @type type of the timer
682 * @trigger_time trigger period in multiples of 100ns
683 * @return status code
684 */
xypron.glpk@gmx.de3ecc6bd2017-07-19 19:22:34 +0200685static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event,
686 enum efi_timer_delay type,
687 uint64_t trigger_time)
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200688{
689 EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
690 return EFI_EXIT(efi_set_timer(event, type, trigger_time));
691}
692
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200693/*
694 * Wait for events to be signaled.
695 *
696 * This function implements the WaitForEvent service.
697 * See the Unified Extensible Firmware Interface (UEFI) specification
698 * for details.
699 *
700 * @num_events number of events to be waited for
701 * @events events to be waited for
702 * @index index of the event that was signaled
703 * @return status code
704 */
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100705static efi_status_t EFIAPI efi_wait_for_event(efi_uintn_t num_events,
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200706 struct efi_event **event,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100707 efi_uintn_t *index)
Alexander Grafc15d9212016-03-04 01:09:59 +0100708{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200709 int i, j;
Alexander Grafc15d9212016-03-04 01:09:59 +0100710
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100711 EFI_ENTRY("%zd, %p, %p", num_events, event, index);
Alexander Grafc15d9212016-03-04 01:09:59 +0100712
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200713 /* Check parameters */
714 if (!num_events || !event)
715 return EFI_EXIT(EFI_INVALID_PARAMETER);
Heinrich Schuchardt0c150ca2017-09-15 10:06:16 +0200716 /* Check TPL */
717 if (efi_tpl != TPL_APPLICATION)
718 return EFI_EXIT(EFI_UNSUPPORTED);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200719 for (i = 0; i < num_events; ++i) {
720 for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
721 if (event[i] == &efi_events[j])
722 goto known_event;
723 }
724 return EFI_EXIT(EFI_INVALID_PARAMETER);
725known_event:
726 if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
727 return EFI_EXIT(EFI_INVALID_PARAMETER);
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200728 if (!event[i]->is_signaled)
Heinrich Schuchardtd8b878a2018-01-19 20:24:51 +0100729 efi_signal_event(event[i], true);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200730 }
731
732 /* Wait for signal */
733 for (;;) {
734 for (i = 0; i < num_events; ++i) {
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200735 if (event[i]->is_signaled)
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200736 goto out;
737 }
738 /* Allow events to occur. */
739 efi_timer_check();
740 }
741
742out:
743 /*
744 * Reset the signal which is passed to the caller to allow periodic
745 * events to occur.
746 */
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200747 event[i]->is_signaled = false;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200748 if (index)
749 *index = i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100750
751 return EFI_EXIT(EFI_SUCCESS);
752}
753
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200754/*
755 * Signal an EFI event.
756 *
757 * This function implements the SignalEvent service.
758 * See the Unified Extensible Firmware Interface (UEFI) specification
759 * for details.
760 *
761 * This functions sets the signaled state of the event and queues the
762 * notification function for execution.
763 *
764 * @event event to signal
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +0200765 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200766 */
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200767static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100768{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200769 int i;
770
Alexander Grafc15d9212016-03-04 01:09:59 +0100771 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200772 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
773 if (event != &efi_events[i])
774 continue;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200775 if (event->is_signaled)
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200776 break;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200777 event->is_signaled = true;
Heinrich Schuchardt8b11a8a2017-09-15 10:06:13 +0200778 if (event->type & EVT_NOTIFY_SIGNAL)
Heinrich Schuchardtd8b878a2018-01-19 20:24:51 +0100779 efi_signal_event(event, true);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200780 break;
781 }
Alexander Grafc15d9212016-03-04 01:09:59 +0100782 return EFI_EXIT(EFI_SUCCESS);
783}
784
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200785/*
786 * Close an EFI event.
787 *
788 * This function implements the CloseEvent service.
789 * See the Unified Extensible Firmware Interface (UEFI) specification
790 * for details.
791 *
792 * @event event to close
793 * @return status code
794 */
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200795static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100796{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200797 int i;
798
Alexander Grafc15d9212016-03-04 01:09:59 +0100799 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200800 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
801 if (event == &efi_events[i]) {
802 event->type = 0;
803 event->trigger_next = -1ULL;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200804 event->is_queued = false;
805 event->is_signaled = false;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200806 return EFI_EXIT(EFI_SUCCESS);
807 }
808 }
809 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafc15d9212016-03-04 01:09:59 +0100810}
811
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200812/*
813 * Check if an event is signaled.
814 *
815 * This function implements the CheckEvent service.
816 * See the Unified Extensible Firmware Interface (UEFI) specification
817 * for details.
818 *
819 * If an event is not signaled yet the notification function is queued.
820 *
821 * @event event to check
822 * @return status code
823 */
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200824static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100825{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200826 int i;
827
Alexander Grafc15d9212016-03-04 01:09:59 +0100828 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200829 efi_timer_check();
830 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
831 if (event != &efi_events[i])
832 continue;
833 if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
834 break;
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200835 if (!event->is_signaled)
Heinrich Schuchardtd8b878a2018-01-19 20:24:51 +0100836 efi_signal_event(event, true);
Heinrich Schuchardt1bbee392017-10-04 15:03:24 +0200837 if (event->is_signaled)
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200838 return EFI_EXIT(EFI_SUCCESS);
839 return EFI_EXIT(EFI_NOT_READY);
840 }
841 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafc15d9212016-03-04 01:09:59 +0100842}
843
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200844/*
Heinrich Schuchardt37ebcba2017-10-18 18:13:03 +0200845 * Find the internal EFI object for a handle.
846 *
847 * @handle handle to find
848 * @return EFI object
849 */
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +0100850struct efi_object *efi_search_obj(const efi_handle_t handle)
Heinrich Schuchardt37ebcba2017-10-18 18:13:03 +0200851{
Heinrich Schuchardt274cc872017-11-06 21:17:50 +0100852 struct efi_object *efiobj;
Heinrich Schuchardt37ebcba2017-10-18 18:13:03 +0200853
Heinrich Schuchardt274cc872017-11-06 21:17:50 +0100854 list_for_each_entry(efiobj, &efi_obj_list, link) {
Heinrich Schuchardt37ebcba2017-10-18 18:13:03 +0200855 if (efiobj->handle == handle)
856 return efiobj;
857 }
858
859 return NULL;
860}
861
862/*
Heinrich Schuchardta277d3a2018-01-11 08:15:57 +0100863 * Create open protocol info entry and add it to a protocol.
864 *
865 * @handler handler of a protocol
866 * @return open protocol info entry
867 */
868static struct efi_open_protocol_info_entry *efi_create_open_info(
869 struct efi_handler *handler)
870{
871 struct efi_open_protocol_info_item *item;
872
873 item = calloc(1, sizeof(struct efi_open_protocol_info_item));
874 if (!item)
875 return NULL;
876 /* Append the item to the open protocol info list. */
877 list_add_tail(&item->link, &handler->open_infos);
878
879 return &item->info;
880}
881
882/*
883 * Remove an open protocol info entry from a protocol.
884 *
885 * @handler handler of a protocol
886 * @return status code
887 */
888static efi_status_t efi_delete_open_info(
889 struct efi_open_protocol_info_item *item)
890{
891 list_del(&item->link);
892 free(item);
893 return EFI_SUCCESS;
894}
895
896/*
Heinrich Schuchardt5aef61d2017-10-26 19:25:53 +0200897 * Install new protocol on a handle.
898 *
899 * @handle handle on which the protocol shall be installed
900 * @protocol GUID of the protocol to be installed
901 * @protocol_interface interface of the protocol implementation
902 * @return status code
903 */
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +0100904efi_status_t efi_add_protocol(const efi_handle_t handle,
905 const efi_guid_t *protocol,
Heinrich Schuchardt5aef61d2017-10-26 19:25:53 +0200906 void *protocol_interface)
907{
908 struct efi_object *efiobj;
909 struct efi_handler *handler;
910 efi_status_t ret;
Heinrich Schuchardt5aef61d2017-10-26 19:25:53 +0200911
912 efiobj = efi_search_obj(handle);
913 if (!efiobj)
914 return EFI_INVALID_PARAMETER;
915 ret = efi_search_protocol(handle, protocol, NULL);
916 if (ret != EFI_NOT_FOUND)
917 return EFI_INVALID_PARAMETER;
918 handler = calloc(1, sizeof(struct efi_handler));
919 if (!handler)
920 return EFI_OUT_OF_RESOURCES;
Heinrich Schuchardt99ce2062017-11-26 14:05:17 +0100921 handler->guid = protocol;
922 handler->protocol_interface = protocol_interface;
Heinrich Schuchardta277d3a2018-01-11 08:15:57 +0100923 INIT_LIST_HEAD(&handler->open_infos);
Heinrich Schuchardt99ce2062017-11-26 14:05:17 +0100924 list_add_tail(&handler->link, &efiobj->protocols);
Heinrich Schuchardt3d2abc32018-01-11 08:16:01 +0100925 if (!guidcmp(&efi_guid_device_path, protocol))
926 EFI_PRINT("installed device path '%pD'\n", protocol_interface);
Heinrich Schuchardt99ce2062017-11-26 14:05:17 +0100927 return EFI_SUCCESS;
Heinrich Schuchardt5aef61d2017-10-26 19:25:53 +0200928}
929
930/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200931 * Install protocol interface.
932 *
Heinrich Schuchardt0a27ac82017-11-06 21:17:44 +0100933 * This function implements the InstallProtocolInterface service.
934 * See the Unified Extensible Firmware Interface (UEFI) specification
935 * for details.
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200936 *
937 * @handle handle on which the protocol shall be installed
938 * @protocol GUID of the protocol to be installed
939 * @protocol_interface_type type of the interface to be installed,
940 * always EFI_NATIVE_INTERFACE
941 * @protocol_interface interface of the protocol implementation
942 * @return status code
943 */
Heinrich Schuchardt0a27ac82017-11-06 21:17:44 +0100944static efi_status_t EFIAPI efi_install_protocol_interface(
945 void **handle, const efi_guid_t *protocol,
946 int protocol_interface_type, void *protocol_interface)
Alexander Grafc15d9212016-03-04 01:09:59 +0100947{
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200948 efi_status_t r;
949
Heinrich Schuchardt0a27ac82017-11-06 21:17:44 +0100950 EFI_ENTRY("%p, %pUl, %d, %p", handle, protocol, protocol_interface_type,
951 protocol_interface);
952
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200953 if (!handle || !protocol ||
954 protocol_interface_type != EFI_NATIVE_INTERFACE) {
955 r = EFI_INVALID_PARAMETER;
956 goto out;
957 }
958
959 /* Create new handle if requested. */
960 if (!*handle) {
Heinrich Schuchardtcd522cb2017-08-27 00:51:09 +0200961 r = efi_create_handle(handle);
962 if (r != EFI_SUCCESS)
963 goto out;
Heinrich Schuchardt50f02102017-10-26 19:25:43 +0200964 debug("%sEFI: new handle %p\n", indent_string(nesting_level),
965 *handle);
966 } else {
967 debug("%sEFI: handle %p\n", indent_string(nesting_level),
968 *handle);
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200969 }
Heinrich Schuchardt865d5f32017-10-26 19:25:54 +0200970 /* Add new protocol */
971 r = efi_add_protocol(*handle, protocol, protocol_interface);
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200972out:
Heinrich Schuchardt0a27ac82017-11-06 21:17:44 +0100973 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100974}
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200975
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200976/*
977 * Reinstall protocol interface.
978 *
979 * This function implements the ReinstallProtocolInterface service.
980 * See the Unified Extensible Firmware Interface (UEFI) specification
981 * for details.
982 *
983 * @handle handle on which the protocol shall be
984 * reinstalled
985 * @protocol GUID of the protocol to be installed
986 * @old_interface interface to be removed
987 * @new_interface interface to be installed
988 * @return status code
989 */
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +0100990static efi_status_t EFIAPI efi_reinstall_protocol_interface(
991 efi_handle_t handle, const efi_guid_t *protocol,
992 void *old_interface, void *new_interface)
Alexander Grafc15d9212016-03-04 01:09:59 +0100993{
Rob Clark238f88c2017-09-13 18:05:41 -0400994 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, old_interface,
Alexander Grafc15d9212016-03-04 01:09:59 +0100995 new_interface);
996 return EFI_EXIT(EFI_ACCESS_DENIED);
997}
998
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +0200999/*
Heinrich Schuchardte9943282018-01-11 08:16:04 +01001000 * Get all drivers associated to a controller.
1001 * The allocated buffer has to be freed with free().
1002 *
1003 * @efiobj handle of the controller
1004 * @protocol protocol guid (optional)
1005 * @number_of_drivers number of child controllers
1006 * @driver_handle_buffer handles of the the drivers
1007 * @return status code
1008 */
1009static efi_status_t efi_get_drivers(struct efi_object *efiobj,
1010 const efi_guid_t *protocol,
1011 efi_uintn_t *number_of_drivers,
1012 efi_handle_t **driver_handle_buffer)
1013{
1014 struct efi_handler *handler;
1015 struct efi_open_protocol_info_item *item;
1016 efi_uintn_t count = 0, i;
1017 bool duplicate;
1018
1019 /* Count all driver associations */
1020 list_for_each_entry(handler, &efiobj->protocols, link) {
1021 if (protocol && guidcmp(handler->guid, protocol))
1022 continue;
1023 list_for_each_entry(item, &handler->open_infos, link) {
1024 if (item->info.attributes &
1025 EFI_OPEN_PROTOCOL_BY_DRIVER)
1026 ++count;
1027 }
1028 }
1029 /*
1030 * Create buffer. In case of duplicate driver assignments the buffer
1031 * will be too large. But that does not harm.
1032 */
1033 *number_of_drivers = 0;
1034 *driver_handle_buffer = calloc(count, sizeof(efi_handle_t));
1035 if (!*driver_handle_buffer)
1036 return EFI_OUT_OF_RESOURCES;
1037 /* Collect unique driver handles */
1038 list_for_each_entry(handler, &efiobj->protocols, link) {
1039 if (protocol && guidcmp(handler->guid, protocol))
1040 continue;
1041 list_for_each_entry(item, &handler->open_infos, link) {
1042 if (item->info.attributes &
1043 EFI_OPEN_PROTOCOL_BY_DRIVER) {
1044 /* Check this is a new driver */
1045 duplicate = false;
1046 for (i = 0; i < *number_of_drivers; ++i) {
1047 if ((*driver_handle_buffer)[i] ==
1048 item->info.agent_handle)
1049 duplicate = true;
1050 }
1051 /* Copy handle to buffer */
1052 if (!duplicate) {
1053 i = (*number_of_drivers)++;
1054 (*driver_handle_buffer)[i] =
1055 item->info.agent_handle;
1056 }
1057 }
1058 }
1059 }
1060 return EFI_SUCCESS;
1061}
1062
1063/*
1064 * Disconnect all drivers from a controller.
1065 *
1066 * This function implements the DisconnectController service.
1067 * See the Unified Extensible Firmware Interface (UEFI) specification
1068 * for details.
1069 *
1070 * @efiobj handle of the controller
1071 * @protocol protocol guid (optional)
1072 * @child_handle handle of the child to destroy
1073 * @return status code
1074 */
1075static efi_status_t efi_disconnect_all_drivers(
1076 struct efi_object *efiobj,
1077 const efi_guid_t *protocol,
1078 efi_handle_t child_handle)
1079{
1080 efi_uintn_t number_of_drivers;
1081 efi_handle_t *driver_handle_buffer;
1082 efi_status_t r, ret;
1083
1084 ret = efi_get_drivers(efiobj, protocol, &number_of_drivers,
1085 &driver_handle_buffer);
1086 if (ret != EFI_SUCCESS)
1087 return ret;
1088
1089 ret = EFI_NOT_FOUND;
1090 while (number_of_drivers) {
1091 r = EFI_CALL(efi_disconnect_controller(
1092 efiobj->handle,
1093 driver_handle_buffer[--number_of_drivers],
1094 child_handle));
1095 if (r == EFI_SUCCESS)
1096 ret = r;
1097 }
1098 free(driver_handle_buffer);
1099 return ret;
1100}
1101
1102/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001103 * Uninstall protocol interface.
1104 *
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +01001105 * This function implements the UninstallProtocolInterface service.
1106 * See the Unified Extensible Firmware Interface (UEFI) specification
1107 * for details.
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001108 *
1109 * @handle handle from which the protocol shall be removed
1110 * @protocol GUID of the protocol to be removed
1111 * @protocol_interface interface to be removed
1112 * @return status code
1113 */
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +01001114static efi_status_t EFIAPI efi_uninstall_protocol_interface(
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +01001115 efi_handle_t handle, const efi_guid_t *protocol,
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +01001116 void *protocol_interface)
Alexander Grafc15d9212016-03-04 01:09:59 +01001117{
Heinrich Schuchardt86637f32018-01-11 08:16:05 +01001118 struct efi_object *efiobj;
Heinrich Schuchardt7538c272017-10-26 19:25:56 +02001119 struct efi_handler *handler;
Heinrich Schuchardt86637f32018-01-11 08:16:05 +01001120 struct efi_open_protocol_info_item *item;
1121 struct efi_open_protocol_info_item *pos;
Heinrich Schuchardt7538c272017-10-26 19:25:56 +02001122 efi_status_t r;
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +02001123
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +01001124 EFI_ENTRY("%p, %pUl, %p", handle, protocol, protocol_interface);
1125
Heinrich Schuchardt86637f32018-01-11 08:16:05 +01001126 /* Check handle */
1127 efiobj = efi_search_obj(handle);
1128 if (!efiobj) {
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +02001129 r = EFI_INVALID_PARAMETER;
1130 goto out;
1131 }
Heinrich Schuchardt7538c272017-10-26 19:25:56 +02001132 /* Find the protocol on the handle */
1133 r = efi_search_protocol(handle, protocol, &handler);
1134 if (r != EFI_SUCCESS)
1135 goto out;
Heinrich Schuchardt86637f32018-01-11 08:16:05 +01001136 /* Disconnect controllers */
1137 efi_disconnect_all_drivers(efiobj, protocol, NULL);
1138 if (!list_empty(&handler->open_infos)) {
1139 r = EFI_ACCESS_DENIED;
1140 goto out;
1141 }
1142 /* Close protocol */
1143 list_for_each_entry_safe(item, pos, &handler->open_infos, link) {
1144 if (item->info.attributes ==
1145 EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL ||
1146 item->info.attributes == EFI_OPEN_PROTOCOL_GET_PROTOCOL ||
1147 item->info.attributes == EFI_OPEN_PROTOCOL_TEST_PROTOCOL)
1148 list_del(&item->link);
1149 }
1150 if (!list_empty(&handler->open_infos)) {
Heinrich Schuchardt7538c272017-10-26 19:25:56 +02001151 r = EFI_ACCESS_DENIED;
Heinrich Schuchardt86637f32018-01-11 08:16:05 +01001152 goto out;
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +02001153 }
Heinrich Schuchardt86637f32018-01-11 08:16:05 +01001154 r = efi_remove_protocol(handle, protocol, protocol_interface);
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +02001155out:
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +01001156 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01001157}
1158
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001159/*
1160 * Register an event for notification when a protocol is installed.
1161 *
1162 * This function implements the RegisterProtocolNotify service.
1163 * See the Unified Extensible Firmware Interface (UEFI) specification
1164 * for details.
1165 *
1166 * @protocol GUID of the protocol whose installation shall be
1167 * notified
1168 * @event event to be signaled upon installation of the protocol
1169 * @registration key for retrieving the registration information
1170 * @return status code
1171 */
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001172static efi_status_t EFIAPI efi_register_protocol_notify(
1173 const efi_guid_t *protocol,
1174 struct efi_event *event,
1175 void **registration)
Alexander Grafc15d9212016-03-04 01:09:59 +01001176{
Rob Clark238f88c2017-09-13 18:05:41 -04001177 EFI_ENTRY("%pUl, %p, %p", protocol, event, registration);
Alexander Grafc15d9212016-03-04 01:09:59 +01001178 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
1179}
1180
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001181/*
1182 * Determine if an EFI handle implements a protocol.
1183 *
1184 * See the documentation of the LocateHandle service in the UEFI specification.
1185 *
1186 * @search_type selection criterion
1187 * @protocol GUID of the protocol
1188 * @search_key registration key
1189 * @efiobj handle
1190 * @return 0 if the handle implements the protocol
1191 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001192static int efi_search(enum efi_locate_search_type search_type,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001193 const efi_guid_t *protocol, void *search_key,
Alexander Grafc15d9212016-03-04 01:09:59 +01001194 struct efi_object *efiobj)
1195{
Heinrich Schuchardt6a430752017-10-26 19:25:55 +02001196 efi_status_t ret;
Alexander Grafc15d9212016-03-04 01:09:59 +01001197
1198 switch (search_type) {
Heinrich Schuchardt68845f02017-11-06 21:17:42 +01001199 case ALL_HANDLES:
Alexander Grafc15d9212016-03-04 01:09:59 +01001200 return 0;
Heinrich Schuchardt68845f02017-11-06 21:17:42 +01001201 case BY_REGISTER_NOTIFY:
Heinrich Schuchardt6a430752017-10-26 19:25:55 +02001202 /* TODO: RegisterProtocolNotify is not implemented yet */
Alexander Grafc15d9212016-03-04 01:09:59 +01001203 return -1;
Heinrich Schuchardt68845f02017-11-06 21:17:42 +01001204 case BY_PROTOCOL:
Heinrich Schuchardt6a430752017-10-26 19:25:55 +02001205 ret = efi_search_protocol(efiobj->handle, protocol, NULL);
1206 return (ret != EFI_SUCCESS);
1207 default:
1208 /* Invalid search type */
Alexander Grafc15d9212016-03-04 01:09:59 +01001209 return -1;
1210 }
Alexander Grafc15d9212016-03-04 01:09:59 +01001211}
1212
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001213/*
1214 * Locate handles implementing a protocol.
1215 *
1216 * This function is meant for U-Boot internal calls. For the API implementation
1217 * of the LocateHandle service see efi_locate_handle_ext.
1218 *
1219 * @search_type selection criterion
1220 * @protocol GUID of the protocol
1221 * @search_key registration key
1222 * @buffer_size size of the buffer to receive the handles in bytes
1223 * @buffer buffer to receive the relevant handles
1224 * @return status code
1225 */
xypron.glpk@gmx.decab4dd52017-08-09 20:55:00 +02001226static efi_status_t efi_locate_handle(
Alexander Grafc15d9212016-03-04 01:09:59 +01001227 enum efi_locate_search_type search_type,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001228 const efi_guid_t *protocol, void *search_key,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01001229 efi_uintn_t *buffer_size, efi_handle_t *buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +01001230{
Heinrich Schuchardtec66fc82017-11-06 21:17:49 +01001231 struct efi_object *efiobj;
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01001232 efi_uintn_t size = 0;
Alexander Grafc15d9212016-03-04 01:09:59 +01001233
Heinrich Schuchardtec66fc82017-11-06 21:17:49 +01001234 /* Check parameters */
1235 switch (search_type) {
1236 case ALL_HANDLES:
1237 break;
1238 case BY_REGISTER_NOTIFY:
1239 if (!search_key)
1240 return EFI_INVALID_PARAMETER;
1241 /* RegisterProtocolNotify is not implemented yet */
1242 return EFI_UNSUPPORTED;
1243 case BY_PROTOCOL:
1244 if (!protocol)
1245 return EFI_INVALID_PARAMETER;
1246 break;
1247 default:
1248 return EFI_INVALID_PARAMETER;
1249 }
1250
1251 /*
1252 * efi_locate_handle_buffer uses this function for
1253 * the calculation of the necessary buffer size.
1254 * So do not require a buffer for buffersize == 0.
1255 */
1256 if (!buffer_size || (*buffer_size && !buffer))
1257 return EFI_INVALID_PARAMETER;
1258
Alexander Grafc15d9212016-03-04 01:09:59 +01001259 /* Count how much space we need */
Heinrich Schuchardtec66fc82017-11-06 21:17:49 +01001260 list_for_each_entry(efiobj, &efi_obj_list, link) {
1261 if (!efi_search(search_type, protocol, search_key, efiobj))
Alexander Grafc15d9212016-03-04 01:09:59 +01001262 size += sizeof(void*);
Alexander Grafc15d9212016-03-04 01:09:59 +01001263 }
1264
1265 if (*buffer_size < size) {
1266 *buffer_size = size;
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001267 return EFI_BUFFER_TOO_SMALL;
Alexander Grafc15d9212016-03-04 01:09:59 +01001268 }
1269
Rob Clarkcdee3372017-08-06 14:10:07 -04001270 *buffer_size = size;
1271 if (size == 0)
1272 return EFI_NOT_FOUND;
1273
Alexander Grafc15d9212016-03-04 01:09:59 +01001274 /* Then fill the array */
Heinrich Schuchardtec66fc82017-11-06 21:17:49 +01001275 list_for_each_entry(efiobj, &efi_obj_list, link) {
1276 if (!efi_search(search_type, protocol, search_key, efiobj))
1277 *buffer++ = efiobj->handle;
Alexander Grafc15d9212016-03-04 01:09:59 +01001278 }
1279
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001280 return EFI_SUCCESS;
1281}
1282
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001283/*
1284 * Locate handles implementing a protocol.
1285 *
1286 * This function implements the LocateHandle service.
1287 * See the Unified Extensible Firmware Interface (UEFI) specification
1288 * for details.
1289 *
1290 * @search_type selection criterion
1291 * @protocol GUID of the protocol
1292 * @search_key registration key
1293 * @buffer_size size of the buffer to receive the handles in bytes
1294 * @buffer buffer to receive the relevant handles
1295 * @return 0 if the handle implements the protocol
1296 */
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001297static efi_status_t EFIAPI efi_locate_handle_ext(
1298 enum efi_locate_search_type search_type,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001299 const efi_guid_t *protocol, void *search_key,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01001300 efi_uintn_t *buffer_size, efi_handle_t *buffer)
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001301{
Rob Clark238f88c2017-09-13 18:05:41 -04001302 EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001303 buffer_size, buffer);
1304
1305 return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
1306 buffer_size, buffer));
Alexander Grafc15d9212016-03-04 01:09:59 +01001307}
1308
Alexander Graffe3366f2017-07-26 13:41:04 +02001309/* Collapses configuration table entries, removing index i */
1310static void efi_remove_configuration_table(int i)
1311{
1312 struct efi_configuration_table *this = &efi_conf_table[i];
1313 struct efi_configuration_table *next = &efi_conf_table[i+1];
1314 struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables];
1315
1316 memmove(this, next, (ulong)end - (ulong)next);
1317 systab.nr_tables--;
1318}
1319
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001320/*
1321 * Adds, updates, or removes a configuration table.
1322 *
1323 * This function is used for internal calls. For the API implementation of the
1324 * InstallConfigurationTable service see efi_install_configuration_table_ext.
1325 *
1326 * @guid GUID of the installed table
1327 * @table table to be installed
1328 * @return status code
1329 */
Alexander Grafc5c11632016-08-19 01:23:24 +02001330efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
Alexander Grafc15d9212016-03-04 01:09:59 +01001331{
1332 int i;
1333
Alexander Grafc15d9212016-03-04 01:09:59 +01001334 /* Check for guid override */
1335 for (i = 0; i < systab.nr_tables; i++) {
1336 if (!guidcmp(guid, &efi_conf_table[i].guid)) {
Alexander Graffe3366f2017-07-26 13:41:04 +02001337 if (table)
1338 efi_conf_table[i].table = table;
1339 else
1340 efi_remove_configuration_table(i);
Alexander Grafc5c11632016-08-19 01:23:24 +02001341 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +01001342 }
1343 }
1344
Alexander Graffe3366f2017-07-26 13:41:04 +02001345 if (!table)
1346 return EFI_NOT_FOUND;
1347
Alexander Grafc15d9212016-03-04 01:09:59 +01001348 /* No override, check for overflow */
1349 if (i >= ARRAY_SIZE(efi_conf_table))
Alexander Grafc5c11632016-08-19 01:23:24 +02001350 return EFI_OUT_OF_RESOURCES;
Alexander Grafc15d9212016-03-04 01:09:59 +01001351
1352 /* Add a new entry */
1353 memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
1354 efi_conf_table[i].table = table;
Alexander Graf9982e672016-08-19 01:23:30 +02001355 systab.nr_tables = i + 1;
Alexander Grafc15d9212016-03-04 01:09:59 +01001356
Alexander Grafc5c11632016-08-19 01:23:24 +02001357 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +01001358}
1359
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001360/*
1361 * Adds, updates, or removes a configuration table.
1362 *
1363 * This function implements the InstallConfigurationTable service.
1364 * See the Unified Extensible Firmware Interface (UEFI) specification
1365 * for details.
1366 *
1367 * @guid GUID of the installed table
1368 * @table table to be installed
1369 * @return status code
1370 */
Alexander Grafc5c11632016-08-19 01:23:24 +02001371static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
1372 void *table)
1373{
Rob Clark238f88c2017-09-13 18:05:41 -04001374 EFI_ENTRY("%pUl, %p", guid, table);
Alexander Grafc5c11632016-08-19 01:23:24 +02001375 return EFI_EXIT(efi_install_configuration_table(guid, table));
1376}
1377
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001378/*
1379 * Initialize a loaded_image_info + loaded_image_info object with correct
Rob Clarkf8db9222017-09-13 18:05:33 -04001380 * protocols, boot-device, etc.
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001381 *
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001382 * @info loaded image info to be passed to the entry point of the
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001383 * image
1384 * @obj internal object associated with the loaded image
1385 * @device_path device path of the loaded image
1386 * @file_path file path of the loaded image
Heinrich Schuchardt7db9f892017-12-04 18:03:01 +01001387 * @return status code
Rob Clarkf8db9222017-09-13 18:05:33 -04001388 */
Heinrich Schuchardt7db9f892017-12-04 18:03:01 +01001389efi_status_t efi_setup_loaded_image(
1390 struct efi_loaded_image *info, struct efi_object *obj,
1391 struct efi_device_path *device_path,
1392 struct efi_device_path *file_path)
Rob Clarkf8db9222017-09-13 18:05:33 -04001393{
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001394 efi_status_t ret;
1395
Heinrich Schuchardt967d7de2017-11-26 14:05:23 +01001396 /* Add internal object to object list */
1397 efi_add_handle(obj);
1398 /* efi_exit() assumes that the handle points to the info */
Rob Clarkf8db9222017-09-13 18:05:33 -04001399 obj->handle = info;
1400
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001401 info->file_path = file_path;
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001402
Heinrich Schuchardtf3996be2018-01-26 06:50:54 +01001403 if (device_path) {
1404 info->device_handle = efi_dp_find_obj(device_path, NULL);
1405 /*
1406 * When asking for the device path interface, return
1407 * bootefi_device_path
1408 */
1409 ret = efi_add_protocol(obj->handle, &efi_guid_device_path,
1410 device_path);
1411 if (ret != EFI_SUCCESS)
1412 goto failure;
1413 }
Rob Clarkf8db9222017-09-13 18:05:33 -04001414
1415 /*
1416 * When asking for the loaded_image interface, just
1417 * return handle which points to loaded_image_info
1418 */
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001419 ret = efi_add_protocol(obj->handle, &efi_guid_loaded_image, info);
1420 if (ret != EFI_SUCCESS)
1421 goto failure;
Rob Clarkf8db9222017-09-13 18:05:33 -04001422
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001423 ret = efi_add_protocol(obj->handle,
1424 &efi_guid_device_path_to_text_protocol,
1425 (void *)&efi_device_path_to_text);
1426 if (ret != EFI_SUCCESS)
1427 goto failure;
Rob Clarkf8db9222017-09-13 18:05:33 -04001428
Heinrich Schuchardt7db9f892017-12-04 18:03:01 +01001429 return ret;
Heinrich Schuchardt24d3a662017-10-26 19:25:58 +02001430failure:
1431 printf("ERROR: Failure to install protocols for loaded image\n");
Heinrich Schuchardt7db9f892017-12-04 18:03:01 +01001432 return ret;
Rob Clarkf8db9222017-09-13 18:05:33 -04001433}
1434
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001435/*
1436 * Load an image using a file path.
1437 *
1438 * @file_path the path of the image to load
1439 * @buffer buffer containing the loaded image
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001440 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001441 */
Rob Clarkc84c1102017-09-13 18:05:38 -04001442efi_status_t efi_load_image_from_path(struct efi_device_path *file_path,
1443 void **buffer)
Rob Clark857a1222017-09-13 18:05:35 -04001444{
1445 struct efi_file_info *info = NULL;
1446 struct efi_file_handle *f;
1447 static efi_status_t ret;
1448 uint64_t bs;
1449
1450 f = efi_file_from_path(file_path);
1451 if (!f)
1452 return EFI_DEVICE_ERROR;
1453
1454 bs = 0;
1455 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1456 &bs, info));
1457 if (ret == EFI_BUFFER_TOO_SMALL) {
1458 info = malloc(bs);
1459 EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
1460 &bs, info));
1461 }
1462 if (ret != EFI_SUCCESS)
1463 goto error;
1464
1465 ret = efi_allocate_pool(EFI_LOADER_DATA, info->file_size, buffer);
1466 if (ret)
1467 goto error;
1468
1469 EFI_CALL(ret = f->read(f, &info->file_size, *buffer));
1470
1471error:
1472 free(info);
1473 EFI_CALL(f->close(f));
1474
1475 if (ret != EFI_SUCCESS) {
1476 efi_free_pool(*buffer);
1477 *buffer = NULL;
1478 }
1479
1480 return ret;
1481}
1482
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001483/*
1484 * Load an EFI image into memory.
1485 *
1486 * This function implements the LoadImage service.
1487 * See the Unified Extensible Firmware Interface (UEFI) specification
1488 * for details.
1489 *
1490 * @boot_policy true for request originating from the boot manager
Heinrich Schuchardt091cf432018-01-24 19:21:36 +01001491 * @parent_image the caller's image handle
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001492 * @file_path the path of the image to load
1493 * @source_buffer memory location from which the image is installed
1494 * @source_size size of the memory area from which the image is
1495 * installed
1496 * @image_handle handle for the newly installed image
1497 * @return status code
1498 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001499static efi_status_t EFIAPI efi_load_image(bool boot_policy,
1500 efi_handle_t parent_image,
1501 struct efi_device_path *file_path,
1502 void *source_buffer,
1503 unsigned long source_size,
1504 efi_handle_t *image_handle)
1505{
Alexander Grafc15d9212016-03-04 01:09:59 +01001506 struct efi_loaded_image *info;
1507 struct efi_object *obj;
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001508 efi_status_t ret;
Alexander Grafc15d9212016-03-04 01:09:59 +01001509
Heinrich Schuchardtba784332018-01-19 20:24:40 +01001510 EFI_ENTRY("%d, %p, %pD, %p, %ld, %p", boot_policy, parent_image,
Alexander Grafc15d9212016-03-04 01:09:59 +01001511 file_path, source_buffer, source_size, image_handle);
Rob Clark857a1222017-09-13 18:05:35 -04001512
Heinrich Schuchardtc935c2f2018-03-07 02:40:51 +01001513 if (!image_handle || !parent_image) {
1514 ret = EFI_INVALID_PARAMETER;
1515 goto error;
1516 }
1517
1518 if (!source_buffer && !file_path) {
1519 ret = EFI_NOT_FOUND;
1520 goto error;
1521 }
1522
Rob Clark857a1222017-09-13 18:05:35 -04001523 info = calloc(1, sizeof(*info));
Heinrich Schuchardtc935c2f2018-03-07 02:40:51 +01001524 if (!info) {
1525 ret = EFI_OUT_OF_RESOURCES;
1526 goto error;
1527 }
Rob Clark857a1222017-09-13 18:05:35 -04001528 obj = calloc(1, sizeof(*obj));
Heinrich Schuchardtc935c2f2018-03-07 02:40:51 +01001529 if (!obj) {
1530 free(info);
1531 ret = EFI_OUT_OF_RESOURCES;
1532 goto error;
1533 }
Rob Clark857a1222017-09-13 18:05:35 -04001534
1535 if (!source_buffer) {
1536 struct efi_device_path *dp, *fp;
Rob Clark857a1222017-09-13 18:05:35 -04001537
Rob Clarkc84c1102017-09-13 18:05:38 -04001538 ret = efi_load_image_from_path(file_path, &source_buffer);
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001539 if (ret != EFI_SUCCESS)
1540 goto failure;
Rob Clark857a1222017-09-13 18:05:35 -04001541 /*
1542 * split file_path which contains both the device and
1543 * file parts:
1544 */
1545 efi_dp_split_file_path(file_path, &dp, &fp);
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001546 ret = efi_setup_loaded_image(info, obj, dp, fp);
1547 if (ret != EFI_SUCCESS)
1548 goto failure;
Rob Clark857a1222017-09-13 18:05:35 -04001549 } else {
1550 /* In this case, file_path is the "device" path, ie.
1551 * something like a HARDWARE_DEVICE:MEMORY_MAPPED
1552 */
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001553 ret = efi_setup_loaded_image(info, obj, file_path, NULL);
1554 if (ret != EFI_SUCCESS)
1555 goto failure;
Rob Clark857a1222017-09-13 18:05:35 -04001556 }
Alexander Grafc15d9212016-03-04 01:09:59 +01001557 info->reserved = efi_load_pe(source_buffer, info);
1558 if (!info->reserved) {
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001559 ret = EFI_UNSUPPORTED;
1560 goto failure;
Alexander Grafc15d9212016-03-04 01:09:59 +01001561 }
Heinrich Schuchardt1c176932017-10-18 18:13:20 +02001562 info->system_table = &systab;
1563 info->parent_handle = parent_image;
Heinrich Schuchardt754d4972017-11-26 14:05:22 +01001564 *image_handle = obj->handle;
Alexander Grafc15d9212016-03-04 01:09:59 +01001565 return EFI_EXIT(EFI_SUCCESS);
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001566failure:
1567 free(info);
1568 efi_delete_handle(obj);
Heinrich Schuchardtc935c2f2018-03-07 02:40:51 +01001569error:
Heinrich Schuchardtd4d7ca92017-12-04 18:03:03 +01001570 return EFI_EXIT(ret);
Alexander Grafc15d9212016-03-04 01:09:59 +01001571}
1572
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001573/*
1574 * Call the entry point of an image.
1575 *
1576 * This function implements the StartImage service.
1577 * See the Unified Extensible Firmware Interface (UEFI) specification
1578 * for details.
1579 *
1580 * @image_handle handle of the image
1581 * @exit_data_size size of the buffer
1582 * @exit_data buffer to receive the exit data of the called image
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001583 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001584 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001585static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
1586 unsigned long *exit_data_size,
1587 s16 **exit_data)
1588{
Alexander Graf54d8cdf2018-01-24 00:18:08 +01001589 EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,
1590 struct efi_system_table *st);
Alexander Grafc15d9212016-03-04 01:09:59 +01001591 struct efi_loaded_image *info = image_handle;
Heinrich Schuchardt6dcd4842018-01-18 20:28:43 +01001592 efi_status_t ret;
Alexander Grafc15d9212016-03-04 01:09:59 +01001593
1594 EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
1595 entry = info->reserved;
1596
1597 efi_is_direct_boot = false;
1598
1599 /* call the image! */
Alexander Graf988c0662016-05-20 23:28:23 +02001600 if (setjmp(&info->exit_jmp)) {
Heinrich Schuchardt6dcd4842018-01-18 20:28:43 +01001601 /*
1602 * We called the entry point of the child image with EFI_CALL
1603 * in the lines below. The child image called the Exit() boot
1604 * service efi_exit() which executed the long jump that brought
1605 * us to the current line. This implies that the second half
1606 * of the EFI_CALL macro has not been executed.
1607 */
1608#ifdef CONFIG_ARM
1609 /*
1610 * efi_exit() called efi_restore_gd(). We have to undo this
1611 * otherwise __efi_entry_check() will put the wrong value into
1612 * app_gd.
1613 */
1614 gd = app_gd;
1615#endif
1616 /*
1617 * To get ready to call EFI_EXIT below we have to execute the
1618 * missed out steps of EFI_CALL.
1619 */
1620 assert(__efi_entry_check());
1621 debug("%sEFI: %lu returned by started image\n",
1622 __efi_nesting_dec(),
1623 (unsigned long)((uintptr_t)info->exit_status &
1624 ~EFI_ERROR_MASK));
Alexander Graf988c0662016-05-20 23:28:23 +02001625 return EFI_EXIT(info->exit_status);
1626 }
1627
Heinrich Schuchardt6dcd4842018-01-18 20:28:43 +01001628 ret = EFI_CALL(entry(image_handle, &systab));
Alexander Grafc15d9212016-03-04 01:09:59 +01001629
Alexander Grafeff317c2018-01-26 00:47:53 +01001630 /*
1631 * Usually UEFI applications call Exit() instead of returning.
1632 * But because the world doesn not consist of ponies and unicorns,
1633 * we're happy to emulate that behavior on behalf of a payload
1634 * that forgot.
1635 */
1636 return EFI_CALL(systab.boottime->exit(image_handle, ret, 0, NULL));
Alexander Grafc15d9212016-03-04 01:09:59 +01001637}
1638
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001639/*
1640 * Leave an EFI application or driver.
1641 *
1642 * This function implements the Exit service.
1643 * See the Unified Extensible Firmware Interface (UEFI) specification
1644 * for details.
1645 *
1646 * @image_handle handle of the application or driver that is exiting
1647 * @exit_status status code
1648 * @exit_data_size size of the buffer in bytes
1649 * @exit_data buffer with data describing an error
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001650 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001651 */
Alexander Graf988c0662016-05-20 23:28:23 +02001652static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
1653 efi_status_t exit_status, unsigned long exit_data_size,
1654 int16_t *exit_data)
Alexander Grafc15d9212016-03-04 01:09:59 +01001655{
Heinrich Schuchardt967d7de2017-11-26 14:05:23 +01001656 /*
1657 * We require that the handle points to the original loaded
1658 * image protocol interface.
1659 *
1660 * For getting the longjmp address this is safer than locating
1661 * the protocol because the protocol may have been reinstalled
1662 * pointing to another memory location.
1663 *
1664 * TODO: We should call the unload procedure of the loaded
1665 * image protocol.
1666 */
Alexander Graf988c0662016-05-20 23:28:23 +02001667 struct efi_loaded_image *loaded_image_info = (void*)image_handle;
1668
Alexander Grafc15d9212016-03-04 01:09:59 +01001669 EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
1670 exit_data_size, exit_data);
Alexander Graf988c0662016-05-20 23:28:23 +02001671
Alexander Graf87e787a2017-09-03 14:14:17 +02001672 /* Make sure entry/exit counts for EFI world cross-overs match */
Heinrich Schuchardt6dcd4842018-01-18 20:28:43 +01001673 EFI_EXIT(exit_status);
Heinrich Schuchardt4a4c6462017-08-25 19:53:14 +02001674
Alexander Graf87e787a2017-09-03 14:14:17 +02001675 /*
1676 * But longjmp out with the U-Boot gd, not the application's, as
1677 * the other end is a setjmp call inside EFI context.
1678 */
1679 efi_restore_gd();
1680
Alexander Graf988c0662016-05-20 23:28:23 +02001681 loaded_image_info->exit_status = exit_status;
Alexander Graf9d006b72016-09-27 09:30:32 +02001682 longjmp(&loaded_image_info->exit_jmp, 1);
Alexander Graf988c0662016-05-20 23:28:23 +02001683
1684 panic("EFI application exited");
Alexander Grafc15d9212016-03-04 01:09:59 +01001685}
1686
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001687/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001688 * Unload an EFI image.
1689 *
1690 * This function implements the UnloadImage service.
1691 * See the Unified Extensible Firmware Interface (UEFI) specification
1692 * for details.
1693 *
1694 * @image_handle handle of the image to be unloaded
1695 * @return status code
1696 */
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +01001697static efi_status_t EFIAPI efi_unload_image(efi_handle_t image_handle)
Alexander Grafc15d9212016-03-04 01:09:59 +01001698{
1699 struct efi_object *efiobj;
1700
1701 EFI_ENTRY("%p", image_handle);
1702 efiobj = efi_search_obj(image_handle);
1703 if (efiobj)
1704 list_del(&efiobj->link);
1705
1706 return EFI_EXIT(EFI_SUCCESS);
1707}
1708
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001709/*
1710 * Fix up caches for EFI payloads if necessary.
1711 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001712static void efi_exit_caches(void)
1713{
1714#if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
1715 /*
1716 * Grub on 32bit ARM needs to have caches disabled before jumping into
1717 * a zImage, but does not know of all cache layers. Give it a hand.
1718 */
1719 if (efi_is_direct_boot)
1720 cleanup_before_linux();
1721#endif
1722}
1723
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001724/*
Heinrich Schuchardtb1fbb212018-01-19 20:24:52 +01001725 * Stop all boot services.
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001726 *
1727 * This function implements the ExitBootServices service.
1728 * See the Unified Extensible Firmware Interface (UEFI) specification
1729 * for details.
1730 *
Heinrich Schuchardtb1fbb212018-01-19 20:24:52 +01001731 * All timer events are disabled.
1732 * For exit boot services events the notification function is called.
1733 * The boot services are disabled in the system table.
1734 *
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001735 * @image_handle handle of the loaded image
1736 * @map_key key of the memory map
1737 * @return status code
1738 */
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +01001739static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,
Alexander Grafc15d9212016-03-04 01:09:59 +01001740 unsigned long map_key)
1741{
Heinrich Schuchardt2d4c7382017-09-15 10:06:18 +02001742 int i;
1743
Alexander Grafc15d9212016-03-04 01:09:59 +01001744 EFI_ENTRY("%p, %ld", image_handle, map_key);
1745
Heinrich Schuchardtb1fbb212018-01-19 20:24:52 +01001746 /* Make sure that notification functions are not called anymore */
1747 efi_tpl = TPL_HIGH_LEVEL;
1748
1749 /* Check if ExitBootServices has already been called */
1750 if (!systab.boottime)
1751 return EFI_EXIT(EFI_SUCCESS);
1752
Heinrich Schuchardt2d4c7382017-09-15 10:06:18 +02001753 /* Notify that ExitBootServices is invoked. */
1754 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
1755 if (efi_events[i].type != EVT_SIGNAL_EXIT_BOOT_SERVICES)
1756 continue;
Heinrich Schuchardtb1fbb212018-01-19 20:24:52 +01001757 efi_events[i].is_signaled = true;
1758 efi_signal_event(&efi_events[i], false);
Heinrich Schuchardt2d4c7382017-09-15 10:06:18 +02001759 }
Heinrich Schuchardt2d4c7382017-09-15 10:06:18 +02001760
Heinrich Schuchardtb1fbb212018-01-19 20:24:52 +01001761 /* TODO Should persist EFI variables here */
Rob Clark15f3d742017-09-13 18:05:37 -04001762
Alexander Graf2ebeb442016-11-17 01:02:57 +01001763 board_quiesce_devices();
1764
Alexander Grafc15d9212016-03-04 01:09:59 +01001765 /* Fix up caches for EFI payloads if necessary */
1766 efi_exit_caches();
1767
1768 /* This stops all lingering devices */
1769 bootm_disable_interrupts();
1770
Heinrich Schuchardtb1fbb212018-01-19 20:24:52 +01001771 /* Disable boottime services */
1772 systab.con_in_handle = NULL;
1773 systab.con_in = NULL;
1774 systab.con_out_handle = NULL;
1775 systab.con_out = NULL;
1776 systab.stderr_handle = NULL;
1777 systab.std_err = NULL;
1778 systab.boottime = NULL;
1779
1780 /* Recalculate CRC32 */
1781 systab.hdr.crc32 = 0;
1782 systab.hdr.crc32 = crc32(0, (const unsigned char *)&systab,
1783 sizeof(struct efi_system_table));
1784
Alexander Grafc15d9212016-03-04 01:09:59 +01001785 /* Give the payload some time to boot */
Heinrich Schuchardt18081d42017-10-18 18:13:04 +02001786 efi_set_watchdog(0);
Alexander Grafc15d9212016-03-04 01:09:59 +01001787 WATCHDOG_RESET();
1788
1789 return EFI_EXIT(EFI_SUCCESS);
1790}
1791
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001792/*
1793 * Get next value of the counter.
1794 *
1795 * This function implements the NextMonotonicCount service.
1796 * See the Unified Extensible Firmware Interface (UEFI) specification
1797 * for details.
1798 *
1799 * @count returned value of the counter
1800 * @return status code
1801 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001802static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
1803{
1804 static uint64_t mono = 0;
1805 EFI_ENTRY("%p", count);
1806 *count = mono++;
1807 return EFI_EXIT(EFI_SUCCESS);
1808}
1809
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001810/*
1811 * Sleep.
1812 *
1813 * This function implements the Stall sercive.
1814 * See the Unified Extensible Firmware Interface (UEFI) specification
1815 * for details.
1816 *
1817 * @microseconds period to sleep in microseconds
1818 * @return status code
1819 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001820static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
1821{
1822 EFI_ENTRY("%ld", microseconds);
1823 udelay(microseconds);
1824 return EFI_EXIT(EFI_SUCCESS);
1825}
1826
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001827/*
1828 * Reset the watchdog timer.
1829 *
Heinrich Schuchardt18081d42017-10-18 18:13:04 +02001830 * This function implements the SetWatchdogTimer service.
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001831 * See the Unified Extensible Firmware Interface (UEFI) specification
1832 * for details.
1833 *
1834 * @timeout seconds before reset by watchdog
1835 * @watchdog_code code to be logged when resetting
1836 * @data_size size of buffer in bytes
1837 * @watchdog_data buffer with data describing the reset reason
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001838 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001839 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001840static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
1841 uint64_t watchdog_code,
1842 unsigned long data_size,
1843 uint16_t *watchdog_data)
1844{
1845 EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
1846 data_size, watchdog_data);
Heinrich Schuchardt18081d42017-10-18 18:13:04 +02001847 return EFI_EXIT(efi_set_watchdog(timeout));
Alexander Grafc15d9212016-03-04 01:09:59 +01001848}
1849
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001850/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001851 * Close a protocol.
1852 *
1853 * This function implements the CloseProtocol service.
1854 * See the Unified Extensible Firmware Interface (UEFI) specification
1855 * for details.
1856 *
1857 * @handle handle on which the protocol shall be closed
1858 * @protocol GUID of the protocol to close
1859 * @agent_handle handle of the driver
1860 * @controller_handle handle of the controller
1861 * @return status code
1862 */
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +01001863static efi_status_t EFIAPI efi_close_protocol(efi_handle_t handle,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001864 const efi_guid_t *protocol,
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +01001865 efi_handle_t agent_handle,
1866 efi_handle_t controller_handle)
Alexander Grafc15d9212016-03-04 01:09:59 +01001867{
Heinrich Schuchardt4fd1ee22018-01-11 08:15:59 +01001868 struct efi_handler *handler;
1869 struct efi_open_protocol_info_item *item;
1870 struct efi_open_protocol_info_item *pos;
1871 efi_status_t r;
1872
Rob Clark238f88c2017-09-13 18:05:41 -04001873 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, agent_handle,
Alexander Grafc15d9212016-03-04 01:09:59 +01001874 controller_handle);
Heinrich Schuchardt4fd1ee22018-01-11 08:15:59 +01001875
1876 if (!agent_handle) {
1877 r = EFI_INVALID_PARAMETER;
1878 goto out;
1879 }
1880 r = efi_search_protocol(handle, protocol, &handler);
1881 if (r != EFI_SUCCESS)
1882 goto out;
1883
1884 r = EFI_NOT_FOUND;
1885 list_for_each_entry_safe(item, pos, &handler->open_infos, link) {
1886 if (item->info.agent_handle == agent_handle &&
1887 item->info.controller_handle == controller_handle) {
1888 efi_delete_open_info(item);
1889 r = EFI_SUCCESS;
1890 break;
1891 }
1892 }
1893out:
1894 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01001895}
1896
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001897/*
1898 * Provide information about then open status of a protocol on a handle
1899 *
1900 * This function implements the OpenProtocolInformation service.
1901 * See the Unified Extensible Firmware Interface (UEFI) specification
1902 * for details.
1903 *
1904 * @handle handle for which the information shall be retrieved
1905 * @protocol GUID of the protocol
1906 * @entry_buffer buffer to receive the open protocol information
1907 * @entry_count number of entries available in the buffer
1908 * @return status code
1909 */
Alexander Grafc15d9212016-03-04 01:09:59 +01001910static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02001911 const efi_guid_t *protocol,
Alexander Grafc15d9212016-03-04 01:09:59 +01001912 struct efi_open_protocol_info_entry **entry_buffer,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01001913 efi_uintn_t *entry_count)
Alexander Grafc15d9212016-03-04 01:09:59 +01001914{
Heinrich Schuchardtf2ef22e2018-01-11 08:16:00 +01001915 unsigned long buffer_size;
1916 unsigned long count;
1917 struct efi_handler *handler;
1918 struct efi_open_protocol_info_item *item;
1919 efi_status_t r;
1920
Rob Clark238f88c2017-09-13 18:05:41 -04001921 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, entry_buffer,
Alexander Grafc15d9212016-03-04 01:09:59 +01001922 entry_count);
Heinrich Schuchardtf2ef22e2018-01-11 08:16:00 +01001923
1924 /* Check parameters */
1925 if (!entry_buffer) {
1926 r = EFI_INVALID_PARAMETER;
1927 goto out;
1928 }
1929 r = efi_search_protocol(handle, protocol, &handler);
1930 if (r != EFI_SUCCESS)
1931 goto out;
1932
1933 /* Count entries */
1934 count = 0;
1935 list_for_each_entry(item, &handler->open_infos, link) {
1936 if (item->info.open_count)
1937 ++count;
1938 }
1939 *entry_count = count;
1940 *entry_buffer = NULL;
1941 if (!count) {
1942 r = EFI_SUCCESS;
1943 goto out;
1944 }
1945
1946 /* Copy entries */
1947 buffer_size = count * sizeof(struct efi_open_protocol_info_entry);
1948 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
1949 (void **)entry_buffer);
1950 if (r != EFI_SUCCESS)
1951 goto out;
1952 list_for_each_entry_reverse(item, &handler->open_infos, link) {
1953 if (item->info.open_count)
1954 (*entry_buffer)[--count] = item->info;
1955 }
1956out:
1957 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01001958}
1959
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001960/*
1961 * Get protocols installed on a handle.
1962 *
1963 * This function implements the ProtocolsPerHandleService.
1964 * See the Unified Extensible Firmware Interface (UEFI) specification
1965 * for details.
1966 *
1967 * @handle handle for which the information is retrieved
1968 * @protocol_buffer buffer with protocol GUIDs
1969 * @protocol_buffer_count number of entries in the buffer
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02001970 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02001971 */
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +01001972static efi_status_t EFIAPI efi_protocols_per_handle(
1973 efi_handle_t handle, efi_guid_t ***protocol_buffer,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01001974 efi_uintn_t *protocol_buffer_count)
Alexander Grafc15d9212016-03-04 01:09:59 +01001975{
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001976 unsigned long buffer_size;
1977 struct efi_object *efiobj;
Heinrich Schuchardt99ce2062017-11-26 14:05:17 +01001978 struct list_head *protocol_handle;
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001979 efi_status_t r;
1980
Alexander Grafc15d9212016-03-04 01:09:59 +01001981 EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
1982 protocol_buffer_count);
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001983
1984 if (!handle || !protocol_buffer || !protocol_buffer_count)
1985 return EFI_EXIT(EFI_INVALID_PARAMETER);
1986
1987 *protocol_buffer = NULL;
Rob Clarkd51b8ca2017-07-20 07:59:39 -04001988 *protocol_buffer_count = 0;
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001989
Heinrich Schuchardt99ce2062017-11-26 14:05:17 +01001990 efiobj = efi_search_obj(handle);
1991 if (!efiobj)
1992 return EFI_EXIT(EFI_INVALID_PARAMETER);
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02001993
Heinrich Schuchardt99ce2062017-11-26 14:05:17 +01001994 /* Count protocols */
1995 list_for_each(protocol_handle, &efiobj->protocols) {
1996 ++*protocol_buffer_count;
1997 }
1998
1999 /* Copy guids */
2000 if (*protocol_buffer_count) {
2001 size_t j = 0;
2002
2003 buffer_size = sizeof(efi_guid_t *) * *protocol_buffer_count;
2004 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
2005 (void **)protocol_buffer);
2006 if (r != EFI_SUCCESS)
2007 return EFI_EXIT(r);
2008 list_for_each(protocol_handle, &efiobj->protocols) {
2009 struct efi_handler *protocol;
2010
2011 protocol = list_entry(protocol_handle,
2012 struct efi_handler, link);
2013 (*protocol_buffer)[j] = (void *)protocol->guid;
2014 ++j;
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02002015 }
xypron.glpk@gmx.de8960c972017-07-13 23:24:32 +02002016 }
2017
2018 return EFI_EXIT(EFI_SUCCESS);
Alexander Grafc15d9212016-03-04 01:09:59 +01002019}
2020
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002021/*
2022 * Locate handles implementing a protocol.
2023 *
2024 * This function implements the LocateHandleBuffer service.
2025 * See the Unified Extensible Firmware Interface (UEFI) specification
2026 * for details.
2027 *
2028 * @search_type selection criterion
2029 * @protocol GUID of the protocol
2030 * @search_key registration key
2031 * @no_handles number of returned handles
2032 * @buffer buffer with the returned handles
2033 * @return status code
2034 */
Alexander Grafc15d9212016-03-04 01:09:59 +01002035static efi_status_t EFIAPI efi_locate_handle_buffer(
2036 enum efi_locate_search_type search_type,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02002037 const efi_guid_t *protocol, void *search_key,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01002038 efi_uintn_t *no_handles, efi_handle_t **buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +01002039{
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +02002040 efi_status_t r;
Heinrich Schuchardt798a4412017-11-06 21:17:48 +01002041 efi_uintn_t buffer_size = 0;
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +02002042
Rob Clark238f88c2017-09-13 18:05:41 -04002043 EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
Alexander Grafc15d9212016-03-04 01:09:59 +01002044 no_handles, buffer);
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +02002045
2046 if (!no_handles || !buffer) {
2047 r = EFI_INVALID_PARAMETER;
2048 goto out;
2049 }
2050 *no_handles = 0;
2051 *buffer = NULL;
2052 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
2053 *buffer);
2054 if (r != EFI_BUFFER_TOO_SMALL)
2055 goto out;
2056 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
2057 (void **)buffer);
2058 if (r != EFI_SUCCESS)
2059 goto out;
2060 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
2061 *buffer);
2062 if (r == EFI_SUCCESS)
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +01002063 *no_handles = buffer_size / sizeof(efi_handle_t);
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +02002064out:
2065 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01002066}
2067
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002068/*
2069 * Find an interface implementing a protocol.
2070 *
2071 * This function implements the LocateProtocol service.
2072 * See the Unified Extensible Firmware Interface (UEFI) specification
2073 * for details.
2074 *
2075 * @protocol GUID of the protocol
2076 * @registration registration key passed to the notification function
2077 * @protocol_interface interface implementing the protocol
Heinrich Schuchardtf1066d62017-10-08 06:57:27 +02002078 * @return status code
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002079 */
Heinrich Schuchardte547c662017-10-05 16:35:53 +02002080static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,
Alexander Grafc15d9212016-03-04 01:09:59 +01002081 void *registration,
2082 void **protocol_interface)
2083{
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02002084 struct list_head *lhandle;
Heinrich Schuchardt57505e92017-10-26 19:25:57 +02002085 efi_status_t ret;
Alexander Grafc15d9212016-03-04 01:09:59 +01002086
Rob Clark238f88c2017-09-13 18:05:41 -04002087 EFI_ENTRY("%pUl, %p, %p", protocol, registration, protocol_interface);
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02002088
2089 if (!protocol || !protocol_interface)
2090 return EFI_EXIT(EFI_INVALID_PARAMETER);
2091
2092 list_for_each(lhandle, &efi_obj_list) {
2093 struct efi_object *efiobj;
Heinrich Schuchardt57505e92017-10-26 19:25:57 +02002094 struct efi_handler *handler;
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02002095
2096 efiobj = list_entry(lhandle, struct efi_object, link);
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02002097
Heinrich Schuchardt57505e92017-10-26 19:25:57 +02002098 ret = efi_search_protocol(efiobj->handle, protocol, &handler);
2099 if (ret == EFI_SUCCESS) {
2100 *protocol_interface = handler->protocol_interface;
2101 return EFI_EXIT(EFI_SUCCESS);
Alexander Grafc15d9212016-03-04 01:09:59 +01002102 }
2103 }
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +02002104 *protocol_interface = NULL;
Alexander Grafc15d9212016-03-04 01:09:59 +01002105
2106 return EFI_EXIT(EFI_NOT_FOUND);
2107}
2108
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002109/*
Heinrich Schuchardt06ec6892017-11-26 14:05:10 +01002110 * Get the device path and handle of an device implementing a protocol.
2111 *
2112 * This function implements the LocateDevicePath service.
2113 * See the Unified Extensible Firmware Interface (UEFI) specification
2114 * for details.
2115 *
2116 * @protocol GUID of the protocol
2117 * @device_path device path
2118 * @device handle of the device
2119 * @return status code
2120 */
2121static efi_status_t EFIAPI efi_locate_device_path(
2122 const efi_guid_t *protocol,
2123 struct efi_device_path **device_path,
2124 efi_handle_t *device)
2125{
2126 struct efi_device_path *dp;
2127 size_t i;
2128 struct efi_handler *handler;
2129 efi_handle_t *handles;
2130 size_t len, len_dp;
2131 size_t len_best = 0;
2132 efi_uintn_t no_handles;
2133 u8 *remainder;
2134 efi_status_t ret;
2135
2136 EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device);
2137
2138 if (!protocol || !device_path || !*device_path || !device) {
2139 ret = EFI_INVALID_PARAMETER;
2140 goto out;
2141 }
2142
2143 /* Find end of device path */
2144 len = efi_dp_size(*device_path);
2145
2146 /* Get all handles implementing the protocol */
2147 ret = EFI_CALL(efi_locate_handle_buffer(BY_PROTOCOL, protocol, NULL,
2148 &no_handles, &handles));
2149 if (ret != EFI_SUCCESS)
2150 goto out;
2151
2152 for (i = 0; i < no_handles; ++i) {
2153 /* Find the device path protocol */
2154 ret = efi_search_protocol(handles[i], &efi_guid_device_path,
2155 &handler);
2156 if (ret != EFI_SUCCESS)
2157 continue;
2158 dp = (struct efi_device_path *)handler->protocol_interface;
2159 len_dp = efi_dp_size(dp);
2160 /*
2161 * This handle can only be a better fit
2162 * if its device path length is longer than the best fit and
2163 * if its device path length is shorter of equal the searched
2164 * device path.
2165 */
2166 if (len_dp <= len_best || len_dp > len)
2167 continue;
2168 /* Check if dp is a subpath of device_path */
2169 if (memcmp(*device_path, dp, len_dp))
2170 continue;
2171 *device = handles[i];
2172 len_best = len_dp;
2173 }
2174 if (len_best) {
2175 remainder = (u8 *)*device_path + len_best;
2176 *device_path = (struct efi_device_path *)remainder;
2177 ret = EFI_SUCCESS;
2178 } else {
2179 ret = EFI_NOT_FOUND;
2180 }
2181out:
2182 return EFI_EXIT(ret);
2183}
2184
2185/*
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002186 * Install multiple protocol interfaces.
2187 *
2188 * This function implements the MultipleProtocolInterfaces service.
2189 * See the Unified Extensible Firmware Interface (UEFI) specification
2190 * for details.
2191 *
2192 * @handle handle on which the protocol interfaces shall be installed
2193 * @... NULL terminated argument list with pairs of protocol GUIDS and
2194 * interfaces
2195 * @return status code
2196 */
Alexander Grafc15d9212016-03-04 01:09:59 +01002197static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
2198 void **handle, ...)
2199{
2200 EFI_ENTRY("%p", handle);
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +02002201
2202 va_list argptr;
Heinrich Schuchardte547c662017-10-05 16:35:53 +02002203 const efi_guid_t *protocol;
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +02002204 void *protocol_interface;
2205 efi_status_t r = EFI_SUCCESS;
2206 int i = 0;
2207
2208 if (!handle)
2209 return EFI_EXIT(EFI_INVALID_PARAMETER);
2210
2211 va_start(argptr, handle);
2212 for (;;) {
2213 protocol = va_arg(argptr, efi_guid_t*);
2214 if (!protocol)
2215 break;
2216 protocol_interface = va_arg(argptr, void*);
Heinrich Schuchardt0a27ac82017-11-06 21:17:44 +01002217 r = EFI_CALL(efi_install_protocol_interface(
2218 handle, protocol,
2219 EFI_NATIVE_INTERFACE,
2220 protocol_interface));
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +02002221 if (r != EFI_SUCCESS)
2222 break;
2223 i++;
2224 }
2225 va_end(argptr);
2226 if (r == EFI_SUCCESS)
2227 return EFI_EXIT(r);
2228
Heinrich Schuchardtec47f3e2017-10-26 19:25:42 +02002229 /* If an error occurred undo all changes. */
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +02002230 va_start(argptr, handle);
2231 for (; i; --i) {
2232 protocol = va_arg(argptr, efi_guid_t*);
2233 protocol_interface = va_arg(argptr, void*);
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +01002234 EFI_CALL(efi_uninstall_protocol_interface(handle, protocol,
2235 protocol_interface));
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +02002236 }
2237 va_end(argptr);
2238
2239 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01002240}
2241
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002242/*
2243 * Uninstall multiple protocol interfaces.
2244 *
2245 * This function implements the UninstallMultipleProtocolInterfaces service.
2246 * See the Unified Extensible Firmware Interface (UEFI) specification
2247 * for details.
2248 *
2249 * @handle handle from which the protocol interfaces shall be removed
2250 * @... NULL terminated argument list with pairs of protocol GUIDS and
2251 * interfaces
2252 * @return status code
2253 */
Alexander Grafc15d9212016-03-04 01:09:59 +01002254static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
2255 void *handle, ...)
2256{
2257 EFI_ENTRY("%p", handle);
Heinrich Schuchardta616dcf2017-10-26 19:25:44 +02002258
2259 va_list argptr;
2260 const efi_guid_t *protocol;
2261 void *protocol_interface;
2262 efi_status_t r = EFI_SUCCESS;
2263 size_t i = 0;
2264
2265 if (!handle)
2266 return EFI_EXIT(EFI_INVALID_PARAMETER);
2267
2268 va_start(argptr, handle);
2269 for (;;) {
2270 protocol = va_arg(argptr, efi_guid_t*);
2271 if (!protocol)
2272 break;
2273 protocol_interface = va_arg(argptr, void*);
2274 r = EFI_CALL(efi_uninstall_protocol_interface(
2275 handle, protocol,
2276 protocol_interface));
2277 if (r != EFI_SUCCESS)
2278 break;
2279 i++;
2280 }
2281 va_end(argptr);
2282 if (r == EFI_SUCCESS)
2283 return EFI_EXIT(r);
2284
2285 /* If an error occurred undo all changes. */
2286 va_start(argptr, handle);
2287 for (; i; --i) {
2288 protocol = va_arg(argptr, efi_guid_t*);
2289 protocol_interface = va_arg(argptr, void*);
2290 EFI_CALL(efi_install_protocol_interface(&handle, protocol,
2291 EFI_NATIVE_INTERFACE,
2292 protocol_interface));
2293 }
2294 va_end(argptr);
2295
2296 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +01002297}
2298
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002299/*
2300 * Calculate cyclic redundancy code.
2301 *
2302 * This function implements the CalculateCrc32 service.
2303 * See the Unified Extensible Firmware Interface (UEFI) specification
2304 * for details.
2305 *
2306 * @data buffer with data
2307 * @data_size size of buffer in bytes
2308 * @crc32_p cyclic redundancy code
2309 * @return status code
2310 */
Alexander Grafc15d9212016-03-04 01:09:59 +01002311static efi_status_t EFIAPI efi_calculate_crc32(void *data,
2312 unsigned long data_size,
2313 uint32_t *crc32_p)
2314{
2315 EFI_ENTRY("%p, %ld", data, data_size);
2316 *crc32_p = crc32(0, data, data_size);
2317 return EFI_EXIT(EFI_SUCCESS);
2318}
2319
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002320/*
2321 * Copy memory.
2322 *
2323 * This function implements the CopyMem service.
2324 * See the Unified Extensible Firmware Interface (UEFI) specification
2325 * for details.
2326 *
2327 * @destination destination of the copy operation
2328 * @source source of the copy operation
2329 * @length number of bytes to copy
2330 */
Heinrich Schuchardtd0a349e2017-10-05 16:35:52 +02002331static void EFIAPI efi_copy_mem(void *destination, const void *source,
2332 size_t length)
Alexander Grafc15d9212016-03-04 01:09:59 +01002333{
Heinrich Schuchardtd0a349e2017-10-05 16:35:52 +02002334 EFI_ENTRY("%p, %p, %ld", destination, source, (unsigned long)length);
Alexander Grafc15d9212016-03-04 01:09:59 +01002335 memcpy(destination, source, length);
Heinrich Schuchardta5270e02017-10-05 16:35:51 +02002336 EFI_EXIT(EFI_SUCCESS);
Alexander Grafc15d9212016-03-04 01:09:59 +01002337}
2338
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002339/*
2340 * Fill memory with a byte value.
2341 *
2342 * This function implements the SetMem service.
2343 * See the Unified Extensible Firmware Interface (UEFI) specification
2344 * for details.
2345 *
2346 * @buffer buffer to fill
2347 * @size size of buffer in bytes
2348 * @value byte to copy to the buffer
2349 */
Heinrich Schuchardtd0a349e2017-10-05 16:35:52 +02002350static void EFIAPI efi_set_mem(void *buffer, size_t size, uint8_t value)
Alexander Grafc15d9212016-03-04 01:09:59 +01002351{
Heinrich Schuchardtd0a349e2017-10-05 16:35:52 +02002352 EFI_ENTRY("%p, %ld, 0x%x", buffer, (unsigned long)size, value);
Alexander Grafc15d9212016-03-04 01:09:59 +01002353 memset(buffer, value, size);
Heinrich Schuchardta5270e02017-10-05 16:35:51 +02002354 EFI_EXIT(EFI_SUCCESS);
Alexander Grafc15d9212016-03-04 01:09:59 +01002355}
2356
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002357/*
2358 * Open protocol interface on a handle.
2359 *
Heinrich Schuchardt8cb38c02018-01-11 08:15:58 +01002360 * @handler handler of a protocol
2361 * @protocol_interface interface implementing the protocol
2362 * @agent_handle handle of the driver
2363 * @controller_handle handle of the controller
2364 * @attributes attributes indicating how to open the protocol
2365 * @return status code
2366 */
2367static efi_status_t efi_protocol_open(
2368 struct efi_handler *handler,
2369 void **protocol_interface, void *agent_handle,
2370 void *controller_handle, uint32_t attributes)
2371{
2372 struct efi_open_protocol_info_item *item;
2373 struct efi_open_protocol_info_entry *match = NULL;
2374 bool opened_by_driver = false;
2375 bool opened_exclusive = false;
2376
2377 /* If there is no agent, only return the interface */
2378 if (!agent_handle)
2379 goto out;
2380
2381 /* For TEST_PROTOCOL ignore interface attribute */
2382 if (attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL)
2383 *protocol_interface = NULL;
2384
2385 /*
2386 * Check if the protocol is already opened by a driver with the same
2387 * attributes or opened exclusively
2388 */
2389 list_for_each_entry(item, &handler->open_infos, link) {
2390 if (item->info.agent_handle == agent_handle) {
2391 if ((attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) &&
2392 (item->info.attributes == attributes))
2393 return EFI_ALREADY_STARTED;
2394 }
2395 if (item->info.attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE)
2396 opened_exclusive = true;
2397 }
2398
2399 /* Only one controller can open the protocol exclusively */
2400 if (opened_exclusive && attributes &
2401 (EFI_OPEN_PROTOCOL_EXCLUSIVE | EFI_OPEN_PROTOCOL_BY_DRIVER))
2402 return EFI_ACCESS_DENIED;
2403
2404 /* Prepare exclusive opening */
2405 if (attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) {
2406 /* Try to disconnect controllers */
2407 list_for_each_entry(item, &handler->open_infos, link) {
2408 if (item->info.attributes ==
2409 EFI_OPEN_PROTOCOL_BY_DRIVER)
2410 EFI_CALL(efi_disconnect_controller(
2411 item->info.controller_handle,
2412 item->info.agent_handle,
2413 NULL));
2414 }
2415 opened_by_driver = false;
2416 /* Check if all controllers are disconnected */
2417 list_for_each_entry(item, &handler->open_infos, link) {
2418 if (item->info.attributes & EFI_OPEN_PROTOCOL_BY_DRIVER)
2419 opened_by_driver = true;
2420 }
2421 /* Only one controller can be conncected */
2422 if (opened_by_driver)
2423 return EFI_ACCESS_DENIED;
2424 }
2425
2426 /* Find existing entry */
2427 list_for_each_entry(item, &handler->open_infos, link) {
2428 if (item->info.agent_handle == agent_handle &&
2429 item->info.controller_handle == controller_handle)
2430 match = &item->info;
2431 }
2432 /* None found, create one */
2433 if (!match) {
2434 match = efi_create_open_info(handler);
2435 if (!match)
2436 return EFI_OUT_OF_RESOURCES;
2437 }
2438
2439 match->agent_handle = agent_handle;
2440 match->controller_handle = controller_handle;
2441 match->attributes = attributes;
2442 match->open_count++;
2443
2444out:
2445 /* For TEST_PROTOCOL ignore interface attribute. */
2446 if (attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL)
2447 *protocol_interface = handler->protocol_interface;
2448
2449 return EFI_SUCCESS;
2450}
2451
2452/*
2453 * Open protocol interface on a handle.
2454 *
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002455 * This function implements the OpenProtocol interface.
2456 * See the Unified Extensible Firmware Interface (UEFI) specification
2457 * for details.
2458 *
2459 * @handle handle on which the protocol shall be opened
2460 * @protocol GUID of the protocol
2461 * @protocol_interface interface implementing the protocol
2462 * @agent_handle handle of the driver
2463 * @controller_handle handle of the controller
2464 * @attributes attributes indicating how to open the protocol
2465 * @return status code
2466 */
Alexander Grafc15d9212016-03-04 01:09:59 +01002467static efi_status_t EFIAPI efi_open_protocol(
Heinrich Schuchardte547c662017-10-05 16:35:53 +02002468 void *handle, const efi_guid_t *protocol,
Alexander Grafc15d9212016-03-04 01:09:59 +01002469 void **protocol_interface, void *agent_handle,
2470 void *controller_handle, uint32_t attributes)
2471{
Heinrich Schuchardte5e78a32017-11-26 14:05:15 +01002472 struct efi_handler *handler;
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002473 efi_status_t r = EFI_INVALID_PARAMETER;
Alexander Grafc15d9212016-03-04 01:09:59 +01002474
Rob Clark238f88c2017-09-13 18:05:41 -04002475 EFI_ENTRY("%p, %pUl, %p, %p, %p, 0x%x", handle, protocol,
Alexander Grafc15d9212016-03-04 01:09:59 +01002476 protocol_interface, agent_handle, controller_handle,
2477 attributes);
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02002478
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002479 if (!handle || !protocol ||
2480 (!protocol_interface && attributes !=
2481 EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02002482 goto out;
2483 }
2484
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002485 switch (attributes) {
2486 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
2487 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
2488 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
2489 break;
2490 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
2491 if (controller_handle == handle)
2492 goto out;
Heinrich Schuchardt8cb38c02018-01-11 08:15:58 +01002493 /* fall-through */
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002494 case EFI_OPEN_PROTOCOL_BY_DRIVER:
2495 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
Heinrich Schuchardt8cb38c02018-01-11 08:15:58 +01002496 /* Check that the controller handle is valid */
2497 if (!efi_search_obj(controller_handle))
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002498 goto out;
Heinrich Schuchardt8cb38c02018-01-11 08:15:58 +01002499 /* fall-through */
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002500 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
Heinrich Schuchardt8cb38c02018-01-11 08:15:58 +01002501 /* Check that the agent handle is valid */
2502 if (!efi_search_obj(agent_handle))
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02002503 goto out;
2504 break;
2505 default:
2506 goto out;
2507 }
2508
Heinrich Schuchardte5e78a32017-11-26 14:05:15 +01002509 r = efi_search_protocol(handle, protocol, &handler);
2510 if (r != EFI_SUCCESS)
2511 goto out;
Alexander Grafc15d9212016-03-04 01:09:59 +01002512
Heinrich Schuchardt8cb38c02018-01-11 08:15:58 +01002513 r = efi_protocol_open(handler, protocol_interface, agent_handle,
2514 controller_handle, attributes);
Alexander Grafc15d9212016-03-04 01:09:59 +01002515out:
2516 return EFI_EXIT(r);
2517}
2518
Heinrich Schuchardta40db6e2017-09-21 18:30:11 +02002519/*
2520 * Get interface of a protocol on a handle.
2521 *
2522 * This function implements the HandleProtocol service.
2523 * See the Unified Extensible Firmware Interface (UEFI) specification
2524 * for details.
2525 *
2526 * @handle handle on which the protocol shall be opened
2527 * @protocol GUID of the protocol
2528 * @protocol_interface interface implementing the protocol
2529 * @return status code
2530 */
Heinrich Schuchardtb7cb8b42018-01-11 08:16:09 +01002531static efi_status_t EFIAPI efi_handle_protocol(efi_handle_t handle,
Heinrich Schuchardte547c662017-10-05 16:35:53 +02002532 const efi_guid_t *protocol,
Alexander Grafc15d9212016-03-04 01:09:59 +01002533 void **protocol_interface)
2534{
xypron.glpk@gmx.de1bf5d872017-06-29 21:16:19 +02002535 return efi_open_protocol(handle, protocol, protocol_interface, NULL,
2536 NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
Alexander Grafc15d9212016-03-04 01:09:59 +01002537}
2538
Heinrich Schuchardt760255f2018-01-11 08:16:02 +01002539static efi_status_t efi_bind_controller(
2540 efi_handle_t controller_handle,
2541 efi_handle_t driver_image_handle,
2542 struct efi_device_path *remain_device_path)
2543{
2544 struct efi_driver_binding_protocol *binding_protocol;
2545 efi_status_t r;
2546
2547 r = EFI_CALL(efi_open_protocol(driver_image_handle,
2548 &efi_guid_driver_binding_protocol,
2549 (void **)&binding_protocol,
2550 driver_image_handle, NULL,
2551 EFI_OPEN_PROTOCOL_GET_PROTOCOL));
2552 if (r != EFI_SUCCESS)
2553 return r;
2554 r = EFI_CALL(binding_protocol->supported(binding_protocol,
2555 controller_handle,
2556 remain_device_path));
2557 if (r == EFI_SUCCESS)
2558 r = EFI_CALL(binding_protocol->start(binding_protocol,
2559 controller_handle,
2560 remain_device_path));
2561 EFI_CALL(efi_close_protocol(driver_image_handle,
2562 &efi_guid_driver_binding_protocol,
2563 driver_image_handle, NULL));
2564 return r;
2565}
2566
2567static efi_status_t efi_connect_single_controller(
2568 efi_handle_t controller_handle,
2569 efi_handle_t *driver_image_handle,
2570 struct efi_device_path *remain_device_path)
2571{
2572 efi_handle_t *buffer;
2573 size_t count;
2574 size_t i;
2575 efi_status_t r;
2576 size_t connected = 0;
2577
2578 /* Get buffer with all handles with driver binding protocol */
2579 r = EFI_CALL(efi_locate_handle_buffer(BY_PROTOCOL,
2580 &efi_guid_driver_binding_protocol,
2581 NULL, &count, &buffer));
2582 if (r != EFI_SUCCESS)
2583 return r;
2584
2585 /* Context Override */
2586 if (driver_image_handle) {
2587 for (; *driver_image_handle; ++driver_image_handle) {
2588 for (i = 0; i < count; ++i) {
2589 if (buffer[i] == *driver_image_handle) {
2590 buffer[i] = NULL;
2591 r = efi_bind_controller(
2592 controller_handle,
2593 *driver_image_handle,
2594 remain_device_path);
2595 /*
2596 * For drivers that do not support the
2597 * controller or are already connected
2598 * we receive an error code here.
2599 */
2600 if (r == EFI_SUCCESS)
2601 ++connected;
2602 }
2603 }
2604 }
2605 }
2606
2607 /*
2608 * TODO: Some overrides are not yet implemented:
2609 * - Platform Driver Override
2610 * - Driver Family Override Search
2611 * - Bus Specific Driver Override
2612 */
2613
2614 /* Driver Binding Search */
2615 for (i = 0; i < count; ++i) {
2616 if (buffer[i]) {
2617 r = efi_bind_controller(controller_handle,
2618 buffer[i],
2619 remain_device_path);
2620 if (r == EFI_SUCCESS)
2621 ++connected;
2622 }
2623 }
2624
2625 efi_free_pool(buffer);
2626 if (!connected)
2627 return EFI_NOT_FOUND;
2628 return EFI_SUCCESS;
2629}
2630
2631/*
2632 * Connect a controller to a driver.
2633 *
2634 * This function implements the ConnectController service.
2635 * See the Unified Extensible Firmware Interface (UEFI) specification
2636 * for details.
2637 *
2638 * First all driver binding protocol handles are tried for binding drivers.
2639 * Afterwards all handles that have openened a protocol of the controller
2640 * with EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER are connected to drivers.
2641 *
2642 * @controller_handle handle of the controller
2643 * @driver_image_handle handle of the driver
2644 * @remain_device_path device path of a child controller
2645 * @recursive true to connect all child controllers
2646 * @return status code
2647 */
2648static efi_status_t EFIAPI efi_connect_controller(
2649 efi_handle_t controller_handle,
2650 efi_handle_t *driver_image_handle,
2651 struct efi_device_path *remain_device_path,
2652 bool recursive)
2653{
2654 efi_status_t r;
2655 efi_status_t ret = EFI_NOT_FOUND;
2656 struct efi_object *efiobj;
2657
2658 EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
2659 remain_device_path, recursive);
2660
2661 efiobj = efi_search_obj(controller_handle);
2662 if (!efiobj) {
2663 ret = EFI_INVALID_PARAMETER;
2664 goto out;
2665 }
2666
2667 r = efi_connect_single_controller(controller_handle,
2668 driver_image_handle,
2669 remain_device_path);
2670 if (r == EFI_SUCCESS)
2671 ret = EFI_SUCCESS;
2672 if (recursive) {
2673 struct efi_handler *handler;
2674 struct efi_open_protocol_info_item *item;
2675
2676 list_for_each_entry(handler, &efiobj->protocols, link) {
2677 list_for_each_entry(item, &handler->open_infos, link) {
2678 if (item->info.attributes &
2679 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
2680 r = EFI_CALL(efi_connect_controller(
2681 item->info.controller_handle,
2682 driver_image_handle,
2683 remain_device_path,
2684 recursive));
2685 if (r == EFI_SUCCESS)
2686 ret = EFI_SUCCESS;
2687 }
2688 }
2689 }
2690 }
2691 /* Check for child controller specified by end node */
2692 if (ret != EFI_SUCCESS && remain_device_path &&
2693 remain_device_path->type == DEVICE_PATH_TYPE_END)
2694 ret = EFI_SUCCESS;
2695out:
2696 return EFI_EXIT(ret);
2697}
2698
Heinrich Schuchardte9943282018-01-11 08:16:04 +01002699/*
2700 * Get all child controllers associated to a driver.
2701 * The allocated buffer has to be freed with free().
2702 *
2703 * @efiobj handle of the controller
2704 * @driver_handle handle of the driver
2705 * @number_of_children number of child controllers
2706 * @child_handle_buffer handles of the the child controllers
2707 */
2708static efi_status_t efi_get_child_controllers(
2709 struct efi_object *efiobj,
2710 efi_handle_t driver_handle,
2711 efi_uintn_t *number_of_children,
2712 efi_handle_t **child_handle_buffer)
2713{
2714 struct efi_handler *handler;
2715 struct efi_open_protocol_info_item *item;
2716 efi_uintn_t count = 0, i;
2717 bool duplicate;
2718
2719 /* Count all child controller associations */
2720 list_for_each_entry(handler, &efiobj->protocols, link) {
2721 list_for_each_entry(item, &handler->open_infos, link) {
2722 if (item->info.agent_handle == driver_handle &&
2723 item->info.attributes &
2724 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER)
2725 ++count;
2726 }
2727 }
2728 /*
2729 * Create buffer. In case of duplicate child controller assignments
2730 * the buffer will be too large. But that does not harm.
2731 */
2732 *number_of_children = 0;
2733 *child_handle_buffer = calloc(count, sizeof(efi_handle_t));
2734 if (!*child_handle_buffer)
2735 return EFI_OUT_OF_RESOURCES;
2736 /* Copy unique child handles */
2737 list_for_each_entry(handler, &efiobj->protocols, link) {
2738 list_for_each_entry(item, &handler->open_infos, link) {
2739 if (item->info.agent_handle == driver_handle &&
2740 item->info.attributes &
2741 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
2742 /* Check this is a new child controller */
2743 duplicate = false;
2744 for (i = 0; i < *number_of_children; ++i) {
2745 if ((*child_handle_buffer)[i] ==
2746 item->info.controller_handle)
2747 duplicate = true;
2748 }
2749 /* Copy handle to buffer */
2750 if (!duplicate) {
2751 i = (*number_of_children)++;
2752 (*child_handle_buffer)[i] =
2753 item->info.controller_handle;
2754 }
2755 }
2756 }
2757 }
2758 return EFI_SUCCESS;
2759}
2760
2761/*
2762 * Disconnect a controller from a driver.
2763 *
2764 * This function implements the DisconnectController service.
2765 * See the Unified Extensible Firmware Interface (UEFI) specification
2766 * for details.
2767 *
2768 * @controller_handle handle of the controller
2769 * @driver_image_handle handle of the driver
2770 * @child_handle handle of the child to destroy
2771 * @return status code
2772 */
2773static efi_status_t EFIAPI efi_disconnect_controller(
2774 efi_handle_t controller_handle,
2775 efi_handle_t driver_image_handle,
2776 efi_handle_t child_handle)
2777{
2778 struct efi_driver_binding_protocol *binding_protocol;
2779 efi_handle_t *child_handle_buffer = NULL;
2780 size_t number_of_children = 0;
2781 efi_status_t r;
2782 size_t stop_count = 0;
2783 struct efi_object *efiobj;
2784
2785 EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
2786 child_handle);
2787
2788 efiobj = efi_search_obj(controller_handle);
2789 if (!efiobj) {
2790 r = EFI_INVALID_PARAMETER;
2791 goto out;
2792 }
2793
2794 if (child_handle && !efi_search_obj(child_handle)) {
2795 r = EFI_INVALID_PARAMETER;
2796 goto out;
2797 }
2798
2799 /* If no driver handle is supplied, disconnect all drivers */
2800 if (!driver_image_handle) {
2801 r = efi_disconnect_all_drivers(efiobj, NULL, child_handle);
2802 goto out;
2803 }
2804
2805 /* Create list of child handles */
2806 if (child_handle) {
2807 number_of_children = 1;
2808 child_handle_buffer = &child_handle;
2809 } else {
2810 efi_get_child_controllers(efiobj,
2811 driver_image_handle,
2812 &number_of_children,
2813 &child_handle_buffer);
2814 }
2815
2816 /* Get the driver binding protocol */
2817 r = EFI_CALL(efi_open_protocol(driver_image_handle,
2818 &efi_guid_driver_binding_protocol,
2819 (void **)&binding_protocol,
2820 driver_image_handle, NULL,
2821 EFI_OPEN_PROTOCOL_GET_PROTOCOL));
2822 if (r != EFI_SUCCESS)
2823 goto out;
2824 /* Remove the children */
2825 if (number_of_children) {
2826 r = EFI_CALL(binding_protocol->stop(binding_protocol,
2827 controller_handle,
2828 number_of_children,
2829 child_handle_buffer));
2830 if (r == EFI_SUCCESS)
2831 ++stop_count;
2832 }
2833 /* Remove the driver */
2834 if (!child_handle)
2835 r = EFI_CALL(binding_protocol->stop(binding_protocol,
2836 controller_handle,
2837 0, NULL));
2838 if (r == EFI_SUCCESS)
2839 ++stop_count;
2840 EFI_CALL(efi_close_protocol(driver_image_handle,
2841 &efi_guid_driver_binding_protocol,
2842 driver_image_handle, NULL));
2843
2844 if (stop_count)
2845 r = EFI_SUCCESS;
2846 else
2847 r = EFI_NOT_FOUND;
2848out:
2849 if (!child_handle)
2850 free(child_handle_buffer);
2851 return EFI_EXIT(r);
2852}
2853
Alexander Grafc15d9212016-03-04 01:09:59 +01002854static const struct efi_boot_services efi_boot_services = {
2855 .hdr = {
2856 .headersize = sizeof(struct efi_table_hdr),
2857 },
2858 .raise_tpl = efi_raise_tpl,
2859 .restore_tpl = efi_restore_tpl,
2860 .allocate_pages = efi_allocate_pages_ext,
2861 .free_pages = efi_free_pages_ext,
2862 .get_memory_map = efi_get_memory_map_ext,
Stefan Brüns5a09aef2016-10-09 22:17:18 +02002863 .allocate_pool = efi_allocate_pool_ext,
Stefan Brüns67b67d92016-10-09 22:17:26 +02002864 .free_pool = efi_free_pool_ext,
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +02002865 .create_event = efi_create_event_ext,
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +02002866 .set_timer = efi_set_timer_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002867 .wait_for_event = efi_wait_for_event,
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +02002868 .signal_event = efi_signal_event_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002869 .close_event = efi_close_event,
2870 .check_event = efi_check_event,
Heinrich Schuchardt0a27ac82017-11-06 21:17:44 +01002871 .install_protocol_interface = efi_install_protocol_interface,
Alexander Grafc15d9212016-03-04 01:09:59 +01002872 .reinstall_protocol_interface = efi_reinstall_protocol_interface,
Heinrich Schuchardt7cdc17f2017-11-06 21:17:45 +01002873 .uninstall_protocol_interface = efi_uninstall_protocol_interface,
Alexander Grafc15d9212016-03-04 01:09:59 +01002874 .handle_protocol = efi_handle_protocol,
2875 .reserved = NULL,
2876 .register_protocol_notify = efi_register_protocol_notify,
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02002877 .locate_handle = efi_locate_handle_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002878 .locate_device_path = efi_locate_device_path,
Alexander Grafc5c11632016-08-19 01:23:24 +02002879 .install_configuration_table = efi_install_configuration_table_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01002880 .load_image = efi_load_image,
2881 .start_image = efi_start_image,
Alexander Graf988c0662016-05-20 23:28:23 +02002882 .exit = efi_exit,
Alexander Grafc15d9212016-03-04 01:09:59 +01002883 .unload_image = efi_unload_image,
2884 .exit_boot_services = efi_exit_boot_services,
2885 .get_next_monotonic_count = efi_get_next_monotonic_count,
2886 .stall = efi_stall,
2887 .set_watchdog_timer = efi_set_watchdog_timer,
2888 .connect_controller = efi_connect_controller,
2889 .disconnect_controller = efi_disconnect_controller,
2890 .open_protocol = efi_open_protocol,
2891 .close_protocol = efi_close_protocol,
2892 .open_protocol_information = efi_open_protocol_information,
2893 .protocols_per_handle = efi_protocols_per_handle,
2894 .locate_handle_buffer = efi_locate_handle_buffer,
2895 .locate_protocol = efi_locate_protocol,
2896 .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
2897 .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
2898 .calculate_crc32 = efi_calculate_crc32,
2899 .copy_mem = efi_copy_mem,
2900 .set_mem = efi_set_mem,
Heinrich Schuchardt717c4582018-02-04 23:05:13 +01002901 .create_event_ex = efi_create_event_ex,
Alexander Grafc15d9212016-03-04 01:09:59 +01002902};
2903
2904
Heinrich Schuchardt3579b692017-12-11 20:10:20 +01002905static uint16_t __efi_runtime_data firmware_vendor[] = L"Das U-Boot";
Alexander Grafc15d9212016-03-04 01:09:59 +01002906
Alexander Graf393dd912016-10-14 13:45:30 +02002907struct efi_system_table __efi_runtime_data systab = {
Alexander Grafc15d9212016-03-04 01:09:59 +01002908 .hdr = {
2909 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
Heinrich Schuchardt7d495df2018-02-05 18:04:21 +01002910 .revision = 2 << 16 | 70, /* 2.7 */
Alexander Grafc15d9212016-03-04 01:09:59 +01002911 .headersize = sizeof(struct efi_table_hdr),
2912 },
2913 .fw_vendor = (long)firmware_vendor,
2914 .con_in = (void*)&efi_con_in,
2915 .con_out = (void*)&efi_con_out,
2916 .std_err = (void*)&efi_con_out,
2917 .runtime = (void*)&efi_runtime_services,
2918 .boottime = (void*)&efi_boot_services,
2919 .nr_tables = 0,
2920 .tables = (void*)efi_conf_table,
2921};