blob: e09f9dac5c875576af6efef14db1da30202a7026 [file] [log] [blame]
Alexander Grafc15d9212016-03-04 01:09:59 +01001/*
2 * EFI application boot time services
3 *
4 * Copyright (c) 2016 Alexander Graf
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
Alexander Grafc15d9212016-03-04 01:09:59 +01009#include <common.h>
10#include <efi_loader.h>
11#include <malloc.h>
12#include <asm/global_data.h>
13#include <libfdt_env.h>
14#include <u-boot/crc.h>
15#include <bootm.h>
16#include <inttypes.h>
17#include <watchdog.h>
18
19DECLARE_GLOBAL_DATA_PTR;
20
21/* This list contains all the EFI objects our payload has access to */
22LIST_HEAD(efi_obj_list);
23
24/*
25 * If we're running on nasty systems (32bit ARM booting into non-EFI Linux)
26 * we need to do trickery with caches. Since we don't want to break the EFI
27 * aware boot path, only apply hacks when loading exiting directly (breaking
28 * direct Linux EFI booting along the way - oh well).
29 */
30static bool efi_is_direct_boot = true;
31
32/*
33 * EFI can pass arbitrary additional "tables" containing vendor specific
34 * information to the payload. One such table is the FDT table which contains
35 * a pointer to a flattened device tree blob.
36 *
37 * In most cases we want to pass an FDT to the payload, so reserve one slot of
38 * config table space for it. The pointer gets populated by do_bootefi_exec().
39 */
Alexander Graf393dd912016-10-14 13:45:30 +020040static struct efi_configuration_table __efi_runtime_data efi_conf_table[2];
Alexander Grafc15d9212016-03-04 01:09:59 +010041
Simon Glasscdfe6962016-09-25 15:27:35 -060042#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +010043/*
44 * The "gd" pointer lives in a register on ARM and AArch64 that we declare
45 * fixed when compiling U-Boot. However, the payload does not know about that
46 * restriction so we need to manually swap its and our view of that register on
47 * EFI callback entry/exit.
48 */
49static volatile void *efi_gd, *app_gd;
Simon Glasscdfe6962016-09-25 15:27:35 -060050#endif
Alexander Grafc15d9212016-03-04 01:09:59 +010051
52/* Called from do_bootefi_exec() */
53void efi_save_gd(void)
54{
Simon Glasscdfe6962016-09-25 15:27:35 -060055#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +010056 efi_gd = gd;
Simon Glasscdfe6962016-09-25 15:27:35 -060057#endif
Alexander Grafc15d9212016-03-04 01:09:59 +010058}
59
60/* Called on every callback entry */
61void efi_restore_gd(void)
62{
Simon Glasscdfe6962016-09-25 15:27:35 -060063#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +010064 /* Only restore if we're already in EFI context */
65 if (!efi_gd)
66 return;
67
68 if (gd != efi_gd)
69 app_gd = gd;
70 gd = efi_gd;
Simon Glasscdfe6962016-09-25 15:27:35 -060071#endif
Alexander Grafc15d9212016-03-04 01:09:59 +010072}
73
74/* Called on every callback exit */
75efi_status_t efi_exit_func(efi_status_t ret)
76{
Simon Glasscdfe6962016-09-25 15:27:35 -060077#ifdef CONFIG_ARM
Alexander Grafc15d9212016-03-04 01:09:59 +010078 gd = app_gd;
Simon Glasscdfe6962016-09-25 15:27:35 -060079#endif
80
Alexander Grafc15d9212016-03-04 01:09:59 +010081 return ret;
82}
83
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +020084/* Low 32 bit */
85#define EFI_LOW32(a) (a & 0xFFFFFFFFULL)
86/* High 32 bit */
87#define EFI_HIGH32(a) (a >> 32)
88
89/*
90 * 64bit division by 10 implemented as multiplication by 1 / 10
91 *
92 * Decimals of one tenth: 0x1 / 0xA = 0x0.19999...
93 */
94#define EFI_TENTH 0x199999999999999A
95static u64 efi_div10(u64 a)
96{
97 u64 prod;
98 u64 rem;
99 u64 ret;
100
101 ret = EFI_HIGH32(a) * EFI_HIGH32(EFI_TENTH);
102 prod = EFI_HIGH32(a) * EFI_LOW32(EFI_TENTH);
103 rem = EFI_LOW32(prod);
104 ret += EFI_HIGH32(prod);
105 prod = EFI_LOW32(a) * EFI_HIGH32(EFI_TENTH);
106 rem += EFI_LOW32(prod);
107 ret += EFI_HIGH32(prod);
108 prod = EFI_LOW32(a) * EFI_LOW32(EFI_TENTH);
109 rem += EFI_HIGH32(prod);
110 ret += EFI_HIGH32(rem);
111 /* Round to nearest integer */
112 if (rem >= (1 << 31))
113 ++ret;
114 return ret;
115}
116
xypron.glpk@gmx.de54c7a8e2017-07-18 20:17:22 +0200117void efi_signal_event(struct efi_event *event)
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200118{
119 if (event->signaled)
120 return;
121 event->signaled = 1;
122 if (event->type & EVT_NOTIFY_SIGNAL) {
123 EFI_EXIT(EFI_SUCCESS);
124 event->notify_function(event, event->notify_context);
125 EFI_ENTRY("returning from notification function");
126 }
127}
128
Alexander Grafc15d9212016-03-04 01:09:59 +0100129static efi_status_t efi_unsupported(const char *funcname)
130{
Alexander Graf62a67482016-06-02 11:38:27 +0200131 debug("EFI: App called into unimplemented function %s\n", funcname);
Alexander Grafc15d9212016-03-04 01:09:59 +0100132 return EFI_EXIT(EFI_UNSUPPORTED);
133}
134
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200135static unsigned long EFIAPI efi_raise_tpl(UINTN new_tpl)
Alexander Grafc15d9212016-03-04 01:09:59 +0100136{
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200137 EFI_ENTRY("0x%zx", new_tpl);
Alexander Grafc15d9212016-03-04 01:09:59 +0100138 return EFI_EXIT(0);
139}
140
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200141static void EFIAPI efi_restore_tpl(UINTN old_tpl)
Alexander Grafc15d9212016-03-04 01:09:59 +0100142{
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200143 EFI_ENTRY("0x%zx", old_tpl);
Alexander Grafc15d9212016-03-04 01:09:59 +0100144 EFI_EXIT(efi_unsupported(__func__));
145}
146
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900147static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
148 unsigned long pages,
149 uint64_t *memory)
Alexander Grafc15d9212016-03-04 01:09:59 +0100150{
151 efi_status_t r;
152
153 EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory);
154 r = efi_allocate_pages(type, memory_type, pages, memory);
155 return EFI_EXIT(r);
156}
157
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900158static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
159 unsigned long pages)
Alexander Grafc15d9212016-03-04 01:09:59 +0100160{
161 efi_status_t r;
162
163 EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages);
164 r = efi_free_pages(memory, pages);
165 return EFI_EXIT(r);
166}
167
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900168static efi_status_t EFIAPI efi_get_memory_map_ext(
169 unsigned long *memory_map_size,
170 struct efi_mem_desc *memory_map,
171 unsigned long *map_key,
172 unsigned long *descriptor_size,
173 uint32_t *descriptor_version)
Alexander Grafc15d9212016-03-04 01:09:59 +0100174{
175 efi_status_t r;
176
177 EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map,
178 map_key, descriptor_size, descriptor_version);
179 r = efi_get_memory_map(memory_map_size, memory_map, map_key,
180 descriptor_size, descriptor_version);
181 return EFI_EXIT(r);
182}
183
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200184static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
185 unsigned long size,
186 void **buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +0100187{
Alexander Graf1c34fa82016-03-24 01:37:37 +0100188 efi_status_t r;
189
190 EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer);
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200191 r = efi_allocate_pool(pool_type, size, buffer);
Alexander Graf1c34fa82016-03-24 01:37:37 +0100192 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100193}
194
Stefan Brüns67b67d92016-10-09 22:17:26 +0200195static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +0100196{
Alexander Graf1c34fa82016-03-24 01:37:37 +0100197 efi_status_t r;
198
199 EFI_ENTRY("%p", buffer);
Stefan Brüns67b67d92016-10-09 22:17:26 +0200200 r = efi_free_pool(buffer);
Alexander Graf1c34fa82016-03-24 01:37:37 +0100201 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100202}
203
204/*
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200205 * Our event capabilities are very limited. Only a small limited
206 * number of events is allowed to coexist.
Alexander Grafc15d9212016-03-04 01:09:59 +0100207 */
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200208static struct efi_event efi_events[16];
Alexander Grafc15d9212016-03-04 01:09:59 +0100209
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200210efi_status_t efi_create_event(enum efi_event_type type, UINTN notify_tpl,
211 void (EFIAPI *notify_function) (
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200212 struct efi_event *event,
213 void *context),
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200214 void *notify_context, struct efi_event **event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100215{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200216 int i;
217
Jonathan Gray7758b212017-03-12 19:26:07 +1100218 if (event == NULL)
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200219 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100220
221 if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200222 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100223
224 if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
225 notify_function == NULL)
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200226 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100227
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200228 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
229 if (efi_events[i].type)
230 continue;
231 efi_events[i].type = type;
232 efi_events[i].notify_tpl = notify_tpl;
233 efi_events[i].notify_function = notify_function;
234 efi_events[i].notify_context = notify_context;
235 /* Disable timers on bootup */
236 efi_events[i].trigger_next = -1ULL;
237 efi_events[i].signaled = 0;
238 *event = &efi_events[i];
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200239 return EFI_SUCCESS;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200240 }
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200241 return EFI_OUT_OF_RESOURCES;
Alexander Grafc15d9212016-03-04 01:09:59 +0100242}
243
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200244static efi_status_t EFIAPI efi_create_event_ext(
245 enum efi_event_type type, UINTN notify_tpl,
246 void (EFIAPI *notify_function) (
247 struct efi_event *event,
248 void *context),
249 void *notify_context, struct efi_event **event)
250{
251 EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
252 notify_context);
253 return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
254 notify_context, event));
255}
256
257
Alexander Grafc15d9212016-03-04 01:09:59 +0100258/*
259 * Our timers have to work without interrupts, so we check whenever keyboard
260 * input or disk accesses happen if enough time elapsed for it to fire.
261 */
262void efi_timer_check(void)
263{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200264 int i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100265 u64 now = timer_get_us();
266
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200267 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
268 if (!efi_events[i].type ||
269 !(efi_events[i].type & EVT_TIMER) ||
270 efi_events[i].trigger_type == EFI_TIMER_STOP ||
271 now < efi_events[i].trigger_next)
272 continue;
273 if (efi_events[i].trigger_type == EFI_TIMER_PERIODIC) {
274 efi_events[i].trigger_next +=
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200275 efi_events[i].trigger_time;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200276 efi_events[i].signaled = 0;
277 }
278 efi_signal_event(&efi_events[i]);
Alexander Grafc15d9212016-03-04 01:09:59 +0100279 }
Alexander Grafc15d9212016-03-04 01:09:59 +0100280 WATCHDOG_RESET();
281}
282
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200283efi_status_t efi_set_timer(struct efi_event *event, int type,
284 uint64_t trigger_time)
Alexander Grafc15d9212016-03-04 01:09:59 +0100285{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200286 int i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100287
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200288 /*
289 * The parameter defines a multiple of 100ns.
290 * We use multiples of 1000ns. So divide by 10.
291 */
292 trigger_time = efi_div10(trigger_time);
Alexander Grafc15d9212016-03-04 01:09:59 +0100293
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200294 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
295 if (event != &efi_events[i])
296 continue;
Alexander Grafc15d9212016-03-04 01:09:59 +0100297
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200298 if (!(event->type & EVT_TIMER))
299 break;
300 switch (type) {
301 case EFI_TIMER_STOP:
302 event->trigger_next = -1ULL;
303 break;
304 case EFI_TIMER_PERIODIC:
305 case EFI_TIMER_RELATIVE:
306 event->trigger_next =
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200307 timer_get_us() + trigger_time;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200308 break;
309 default:
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200310 return EFI_INVALID_PARAMETER;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200311 }
312 event->trigger_type = type;
313 event->trigger_time = trigger_time;
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200314 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +0100315 }
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200316 return EFI_INVALID_PARAMETER;
Alexander Grafc15d9212016-03-04 01:09:59 +0100317}
318
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200319static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event, int type,
320 uint64_t trigger_time)
321{
322 EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
323 return EFI_EXIT(efi_set_timer(event, type, trigger_time));
324}
325
Alexander Grafc15d9212016-03-04 01:09:59 +0100326static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events,
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200327 struct efi_event **event,
328 unsigned long *index)
Alexander Grafc15d9212016-03-04 01:09:59 +0100329{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200330 int i, j;
Alexander Grafc15d9212016-03-04 01:09:59 +0100331
332 EFI_ENTRY("%ld, %p, %p", num_events, event, index);
333
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200334 /* Check parameters */
335 if (!num_events || !event)
336 return EFI_EXIT(EFI_INVALID_PARAMETER);
337 for (i = 0; i < num_events; ++i) {
338 for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
339 if (event[i] == &efi_events[j])
340 goto known_event;
341 }
342 return EFI_EXIT(EFI_INVALID_PARAMETER);
343known_event:
344 if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
345 return EFI_EXIT(EFI_INVALID_PARAMETER);
346 }
347
348 /* Wait for signal */
349 for (;;) {
350 for (i = 0; i < num_events; ++i) {
351 if (event[i]->signaled)
352 goto out;
353 }
354 /* Allow events to occur. */
355 efi_timer_check();
356 }
357
358out:
359 /*
360 * Reset the signal which is passed to the caller to allow periodic
361 * events to occur.
362 */
363 event[i]->signaled = 0;
364 if (index)
365 *index = i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100366
367 return EFI_EXIT(EFI_SUCCESS);
368}
369
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200370static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100371{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200372 int i;
373
Alexander Grafc15d9212016-03-04 01:09:59 +0100374 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200375 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
376 if (event != &efi_events[i])
377 continue;
378 efi_signal_event(event);
379 break;
380 }
Alexander Grafc15d9212016-03-04 01:09:59 +0100381 return EFI_EXIT(EFI_SUCCESS);
382}
383
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200384static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100385{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200386 int i;
387
Alexander Grafc15d9212016-03-04 01:09:59 +0100388 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200389 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
390 if (event == &efi_events[i]) {
391 event->type = 0;
392 event->trigger_next = -1ULL;
393 event->signaled = 0;
394 return EFI_EXIT(EFI_SUCCESS);
395 }
396 }
397 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafc15d9212016-03-04 01:09:59 +0100398}
399
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200400static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100401{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200402 int i;
403
Alexander Grafc15d9212016-03-04 01:09:59 +0100404 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200405 efi_timer_check();
406 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
407 if (event != &efi_events[i])
408 continue;
409 if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
410 break;
411 if (event->signaled)
412 return EFI_EXIT(EFI_SUCCESS);
413 return EFI_EXIT(EFI_NOT_READY);
414 }
415 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafc15d9212016-03-04 01:09:59 +0100416}
417
418static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
419 efi_guid_t *protocol, int protocol_interface_type,
420 void *protocol_interface)
421{
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200422 struct list_head *lhandle;
423 int i;
424 efi_status_t r;
425
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200426 if (!handle || !protocol ||
427 protocol_interface_type != EFI_NATIVE_INTERFACE) {
428 r = EFI_INVALID_PARAMETER;
429 goto out;
430 }
431
432 /* Create new handle if requested. */
433 if (!*handle) {
434 r = EFI_OUT_OF_RESOURCES;
435 goto out;
436 }
437 /* Find object. */
438 list_for_each(lhandle, &efi_obj_list) {
439 struct efi_object *efiobj;
440 efiobj = list_entry(lhandle, struct efi_object, link);
441
442 if (efiobj->handle != *handle)
443 continue;
444 /* Check if protocol is already installed on the handle. */
445 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
446 struct efi_handler *handler = &efiobj->protocols[i];
447
448 if (!handler->guid)
449 continue;
450 if (!guidcmp(handler->guid, protocol)) {
451 r = EFI_INVALID_PARAMETER;
452 goto out;
453 }
454 }
455 /* Install protocol in first empty slot. */
456 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
457 struct efi_handler *handler = &efiobj->protocols[i];
458
459 if (handler->guid)
460 continue;
461
462 handler->guid = protocol;
463 handler->protocol_interface = protocol_interface;
464 r = EFI_SUCCESS;
465 goto out;
466 }
467 r = EFI_OUT_OF_RESOURCES;
468 goto out;
469 }
470 r = EFI_INVALID_PARAMETER;
471out:
xypron.glpk@gmx.de8b7b5df2017-07-11 22:06:18 +0200472 return r;
473}
474
475static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
476 efi_guid_t *protocol, int protocol_interface_type,
477 void *protocol_interface)
478{
479 EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type,
480 protocol_interface);
481
482 return EFI_EXIT(efi_install_protocol_interface(handle, protocol,
483 protocol_interface_type,
484 protocol_interface));
Alexander Grafc15d9212016-03-04 01:09:59 +0100485}
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200486
Alexander Grafc15d9212016-03-04 01:09:59 +0100487static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
488 efi_guid_t *protocol, void *old_interface,
489 void *new_interface)
490{
491 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, old_interface,
492 new_interface);
493 return EFI_EXIT(EFI_ACCESS_DENIED);
494}
495
496static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
497 efi_guid_t *protocol, void *protocol_interface)
498{
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +0200499 struct list_head *lhandle;
500 int i;
501 efi_status_t r = EFI_NOT_FOUND;
502
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +0200503 if (!handle || !protocol) {
504 r = EFI_INVALID_PARAMETER;
505 goto out;
506 }
507
508 list_for_each(lhandle, &efi_obj_list) {
509 struct efi_object *efiobj;
510 efiobj = list_entry(lhandle, struct efi_object, link);
511
512 if (efiobj->handle != handle)
513 continue;
514
515 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
516 struct efi_handler *handler = &efiobj->protocols[i];
517 const efi_guid_t *hprotocol = handler->guid;
518
519 if (!hprotocol)
520 continue;
521 if (!guidcmp(hprotocol, protocol)) {
522 if (handler->protocol_interface) {
523 r = EFI_ACCESS_DENIED;
524 } else {
525 handler->guid = 0;
526 r = EFI_SUCCESS;
527 }
528 goto out;
529 }
530 }
531 }
532
533out:
xypron.glpk@gmx.dea453e462017-07-11 22:06:19 +0200534 return r;
535}
536
537static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle,
538 efi_guid_t *protocol, void *protocol_interface)
539{
540 EFI_ENTRY("%p, %p, %p", handle, protocol, protocol_interface);
541
542 return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol,
543 protocol_interface));
Alexander Grafc15d9212016-03-04 01:09:59 +0100544}
545
546static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol,
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200547 struct efi_event *event,
Alexander Grafc15d9212016-03-04 01:09:59 +0100548 void **registration)
549{
550 EFI_ENTRY("%p, %p, %p", protocol, event, registration);
551 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
552}
553
554static int efi_search(enum efi_locate_search_type search_type,
555 efi_guid_t *protocol, void *search_key,
556 struct efi_object *efiobj)
557{
558 int i;
559
560 switch (search_type) {
561 case all_handles:
562 return 0;
563 case by_register_notify:
564 return -1;
565 case by_protocol:
566 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
567 const efi_guid_t *guid = efiobj->protocols[i].guid;
568 if (guid && !guidcmp(guid, protocol))
569 return 0;
570 }
571 return -1;
572 }
573
574 return -1;
575}
576
577static efi_status_t EFIAPI efi_locate_handle(
578 enum efi_locate_search_type search_type,
579 efi_guid_t *protocol, void *search_key,
580 unsigned long *buffer_size, efi_handle_t *buffer)
581{
582 struct list_head *lhandle;
583 unsigned long size = 0;
584
Alexander Grafc15d9212016-03-04 01:09:59 +0100585 /* Count how much space we need */
586 list_for_each(lhandle, &efi_obj_list) {
587 struct efi_object *efiobj;
588 efiobj = list_entry(lhandle, struct efi_object, link);
589 if (!efi_search(search_type, protocol, search_key, efiobj)) {
590 size += sizeof(void*);
591 }
592 }
593
594 if (*buffer_size < size) {
595 *buffer_size = size;
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +0200596 return EFI_BUFFER_TOO_SMALL;
Alexander Grafc15d9212016-03-04 01:09:59 +0100597 }
598
599 /* Then fill the array */
600 list_for_each(lhandle, &efi_obj_list) {
601 struct efi_object *efiobj;
602 efiobj = list_entry(lhandle, struct efi_object, link);
603 if (!efi_search(search_type, protocol, search_key, efiobj)) {
604 *(buffer++) = efiobj->handle;
605 }
606 }
607
608 *buffer_size = size;
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +0200609 return EFI_SUCCESS;
610}
611
612static efi_status_t EFIAPI efi_locate_handle_ext(
613 enum efi_locate_search_type search_type,
614 efi_guid_t *protocol, void *search_key,
615 unsigned long *buffer_size, efi_handle_t *buffer)
616{
617 EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
618 buffer_size, buffer);
619
620 return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
621 buffer_size, buffer));
Alexander Grafc15d9212016-03-04 01:09:59 +0100622}
623
624static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol,
625 struct efi_device_path **device_path,
626 efi_handle_t *device)
627{
628 EFI_ENTRY("%p, %p, %p", protocol, device_path, device);
629 return EFI_EXIT(EFI_NOT_FOUND);
630}
631
Alexander Grafc5c11632016-08-19 01:23:24 +0200632efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
Alexander Grafc15d9212016-03-04 01:09:59 +0100633{
634 int i;
635
Alexander Grafc15d9212016-03-04 01:09:59 +0100636 /* Check for guid override */
637 for (i = 0; i < systab.nr_tables; i++) {
638 if (!guidcmp(guid, &efi_conf_table[i].guid)) {
639 efi_conf_table[i].table = table;
Alexander Grafc5c11632016-08-19 01:23:24 +0200640 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +0100641 }
642 }
643
644 /* No override, check for overflow */
645 if (i >= ARRAY_SIZE(efi_conf_table))
Alexander Grafc5c11632016-08-19 01:23:24 +0200646 return EFI_OUT_OF_RESOURCES;
Alexander Grafc15d9212016-03-04 01:09:59 +0100647
648 /* Add a new entry */
649 memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
650 efi_conf_table[i].table = table;
Alexander Graf9982e672016-08-19 01:23:30 +0200651 systab.nr_tables = i + 1;
Alexander Grafc15d9212016-03-04 01:09:59 +0100652
Alexander Grafc5c11632016-08-19 01:23:24 +0200653 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +0100654}
655
Alexander Grafc5c11632016-08-19 01:23:24 +0200656static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
657 void *table)
658{
659 EFI_ENTRY("%p, %p", guid, table);
660 return EFI_EXIT(efi_install_configuration_table(guid, table));
661}
662
Alexander Grafc15d9212016-03-04 01:09:59 +0100663static efi_status_t EFIAPI efi_load_image(bool boot_policy,
664 efi_handle_t parent_image,
665 struct efi_device_path *file_path,
666 void *source_buffer,
667 unsigned long source_size,
668 efi_handle_t *image_handle)
669{
670 static struct efi_object loaded_image_info_obj = {
671 .protocols = {
672 {
673 .guid = &efi_guid_loaded_image,
Alexander Grafc15d9212016-03-04 01:09:59 +0100674 },
675 },
676 };
677 struct efi_loaded_image *info;
678 struct efi_object *obj;
679
680 EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
681 file_path, source_buffer, source_size, image_handle);
682 info = malloc(sizeof(*info));
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +0200683 loaded_image_info_obj.protocols[0].protocol_interface = info;
Alexander Grafc15d9212016-03-04 01:09:59 +0100684 obj = malloc(sizeof(loaded_image_info_obj));
685 memset(info, 0, sizeof(*info));
686 memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj));
687 obj->handle = info;
688 info->file_path = file_path;
689 info->reserved = efi_load_pe(source_buffer, info);
690 if (!info->reserved) {
691 free(info);
692 free(obj);
693 return EFI_EXIT(EFI_UNSUPPORTED);
694 }
695
696 *image_handle = info;
697 list_add_tail(&obj->link, &efi_obj_list);
698
699 return EFI_EXIT(EFI_SUCCESS);
700}
701
702static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
703 unsigned long *exit_data_size,
704 s16 **exit_data)
705{
706 ulong (*entry)(void *image_handle, struct efi_system_table *st);
707 struct efi_loaded_image *info = image_handle;
708
709 EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
710 entry = info->reserved;
711
712 efi_is_direct_boot = false;
713
714 /* call the image! */
Alexander Graf988c0662016-05-20 23:28:23 +0200715 if (setjmp(&info->exit_jmp)) {
716 /* We returned from the child image */
717 return EFI_EXIT(info->exit_status);
718 }
719
Alexander Grafc15d9212016-03-04 01:09:59 +0100720 entry(image_handle, &systab);
721
722 /* Should usually never get here */
723 return EFI_EXIT(EFI_SUCCESS);
724}
725
Alexander Graf988c0662016-05-20 23:28:23 +0200726static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
727 efi_status_t exit_status, unsigned long exit_data_size,
728 int16_t *exit_data)
Alexander Grafc15d9212016-03-04 01:09:59 +0100729{
Alexander Graf988c0662016-05-20 23:28:23 +0200730 struct efi_loaded_image *loaded_image_info = (void*)image_handle;
731
Alexander Grafc15d9212016-03-04 01:09:59 +0100732 EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
733 exit_data_size, exit_data);
Alexander Graf988c0662016-05-20 23:28:23 +0200734
735 loaded_image_info->exit_status = exit_status;
Alexander Graf9d006b72016-09-27 09:30:32 +0200736 longjmp(&loaded_image_info->exit_jmp, 1);
Alexander Graf988c0662016-05-20 23:28:23 +0200737
738 panic("EFI application exited");
Alexander Grafc15d9212016-03-04 01:09:59 +0100739}
740
741static struct efi_object *efi_search_obj(void *handle)
742{
743 struct list_head *lhandle;
744
745 list_for_each(lhandle, &efi_obj_list) {
746 struct efi_object *efiobj;
747 efiobj = list_entry(lhandle, struct efi_object, link);
748 if (efiobj->handle == handle)
749 return efiobj;
750 }
751
752 return NULL;
753}
754
755static efi_status_t EFIAPI efi_unload_image(void *image_handle)
756{
757 struct efi_object *efiobj;
758
759 EFI_ENTRY("%p", image_handle);
760 efiobj = efi_search_obj(image_handle);
761 if (efiobj)
762 list_del(&efiobj->link);
763
764 return EFI_EXIT(EFI_SUCCESS);
765}
766
767static void efi_exit_caches(void)
768{
769#if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
770 /*
771 * Grub on 32bit ARM needs to have caches disabled before jumping into
772 * a zImage, but does not know of all cache layers. Give it a hand.
773 */
774 if (efi_is_direct_boot)
775 cleanup_before_linux();
776#endif
777}
778
779static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
780 unsigned long map_key)
781{
782 EFI_ENTRY("%p, %ld", image_handle, map_key);
783
Alexander Graf2ebeb442016-11-17 01:02:57 +0100784 board_quiesce_devices();
785
Alexander Grafc15d9212016-03-04 01:09:59 +0100786 /* Fix up caches for EFI payloads if necessary */
787 efi_exit_caches();
788
789 /* This stops all lingering devices */
790 bootm_disable_interrupts();
791
792 /* Give the payload some time to boot */
793 WATCHDOG_RESET();
794
795 return EFI_EXIT(EFI_SUCCESS);
796}
797
798static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
799{
800 static uint64_t mono = 0;
801 EFI_ENTRY("%p", count);
802 *count = mono++;
803 return EFI_EXIT(EFI_SUCCESS);
804}
805
806static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
807{
808 EFI_ENTRY("%ld", microseconds);
809 udelay(microseconds);
810 return EFI_EXIT(EFI_SUCCESS);
811}
812
813static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
814 uint64_t watchdog_code,
815 unsigned long data_size,
816 uint16_t *watchdog_data)
817{
818 EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
819 data_size, watchdog_data);
820 return EFI_EXIT(efi_unsupported(__func__));
821}
822
823static efi_status_t EFIAPI efi_connect_controller(
824 efi_handle_t controller_handle,
825 efi_handle_t *driver_image_handle,
826 struct efi_device_path *remain_device_path,
827 bool recursive)
828{
829 EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
830 remain_device_path, recursive);
831 return EFI_EXIT(EFI_NOT_FOUND);
832}
833
834static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
835 void *driver_image_handle,
836 void *child_handle)
837{
838 EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
839 child_handle);
840 return EFI_EXIT(EFI_INVALID_PARAMETER);
841}
842
843static efi_status_t EFIAPI efi_close_protocol(void *handle,
844 efi_guid_t *protocol,
845 void *agent_handle,
846 void *controller_handle)
847{
848 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle,
849 controller_handle);
850 return EFI_EXIT(EFI_NOT_FOUND);
851}
852
853static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
854 efi_guid_t *protocol,
855 struct efi_open_protocol_info_entry **entry_buffer,
856 unsigned long *entry_count)
857{
858 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer,
859 entry_count);
860 return EFI_EXIT(EFI_NOT_FOUND);
861}
862
863static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
864 efi_guid_t ***protocol_buffer,
865 unsigned long *protocol_buffer_count)
866{
867 EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
868 protocol_buffer_count);
869 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
870}
871
872static efi_status_t EFIAPI efi_locate_handle_buffer(
873 enum efi_locate_search_type search_type,
874 efi_guid_t *protocol, void *search_key,
875 unsigned long *no_handles, efi_handle_t **buffer)
876{
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +0200877 efi_status_t r;
878 unsigned long buffer_size = 0;
879
Alexander Grafc15d9212016-03-04 01:09:59 +0100880 EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
881 no_handles, buffer);
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +0200882
883 if (!no_handles || !buffer) {
884 r = EFI_INVALID_PARAMETER;
885 goto out;
886 }
887 *no_handles = 0;
888 *buffer = NULL;
889 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
890 *buffer);
891 if (r != EFI_BUFFER_TOO_SMALL)
892 goto out;
893 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
894 (void **)buffer);
895 if (r != EFI_SUCCESS)
896 goto out;
897 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
898 *buffer);
899 if (r == EFI_SUCCESS)
900 *no_handles = buffer_size / sizeof(void *);
901out:
902 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100903}
904
Alexander Grafc15d9212016-03-04 01:09:59 +0100905static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol,
906 void *registration,
907 void **protocol_interface)
908{
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +0200909 struct list_head *lhandle;
Alexander Grafc15d9212016-03-04 01:09:59 +0100910 int i;
911
912 EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface);
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +0200913
914 if (!protocol || !protocol_interface)
915 return EFI_EXIT(EFI_INVALID_PARAMETER);
916
917 list_for_each(lhandle, &efi_obj_list) {
918 struct efi_object *efiobj;
919
920 efiobj = list_entry(lhandle, struct efi_object, link);
921 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
922 struct efi_handler *handler = &efiobj->protocols[i];
923
924 if (!handler->guid)
925 continue;
926 if (!guidcmp(handler->guid, protocol)) {
927 *protocol_interface =
928 handler->protocol_interface;
929 return EFI_EXIT(EFI_SUCCESS);
930 }
Alexander Grafc15d9212016-03-04 01:09:59 +0100931 }
932 }
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +0200933 *protocol_interface = NULL;
Alexander Grafc15d9212016-03-04 01:09:59 +0100934
935 return EFI_EXIT(EFI_NOT_FOUND);
936}
937
938static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
939 void **handle, ...)
940{
941 EFI_ENTRY("%p", handle);
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +0200942
943 va_list argptr;
944 efi_guid_t *protocol;
945 void *protocol_interface;
946 efi_status_t r = EFI_SUCCESS;
947 int i = 0;
948
949 if (!handle)
950 return EFI_EXIT(EFI_INVALID_PARAMETER);
951
952 va_start(argptr, handle);
953 for (;;) {
954 protocol = va_arg(argptr, efi_guid_t*);
955 if (!protocol)
956 break;
957 protocol_interface = va_arg(argptr, void*);
958 r = efi_install_protocol_interface(handle, protocol,
959 EFI_NATIVE_INTERFACE,
960 protocol_interface);
961 if (r != EFI_SUCCESS)
962 break;
963 i++;
964 }
965 va_end(argptr);
966 if (r == EFI_SUCCESS)
967 return EFI_EXIT(r);
968
969 /* If an error occured undo all changes. */
970 va_start(argptr, handle);
971 for (; i; --i) {
972 protocol = va_arg(argptr, efi_guid_t*);
973 protocol_interface = va_arg(argptr, void*);
974 efi_uninstall_protocol_interface(handle, protocol,
975 protocol_interface);
976 }
977 va_end(argptr);
978
979 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100980}
981
982static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
983 void *handle, ...)
984{
985 EFI_ENTRY("%p", handle);
986 return EFI_EXIT(EFI_INVALID_PARAMETER);
987}
988
989static efi_status_t EFIAPI efi_calculate_crc32(void *data,
990 unsigned long data_size,
991 uint32_t *crc32_p)
992{
993 EFI_ENTRY("%p, %ld", data, data_size);
994 *crc32_p = crc32(0, data, data_size);
995 return EFI_EXIT(EFI_SUCCESS);
996}
997
998static void EFIAPI efi_copy_mem(void *destination, void *source,
999 unsigned long length)
1000{
1001 EFI_ENTRY("%p, %p, %ld", destination, source, length);
1002 memcpy(destination, source, length);
1003}
1004
1005static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value)
1006{
1007 EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value);
1008 memset(buffer, value, size);
1009}
1010
1011static efi_status_t EFIAPI efi_open_protocol(
1012 void *handle, efi_guid_t *protocol,
1013 void **protocol_interface, void *agent_handle,
1014 void *controller_handle, uint32_t attributes)
1015{
1016 struct list_head *lhandle;
1017 int i;
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001018 efi_status_t r = EFI_INVALID_PARAMETER;
Alexander Grafc15d9212016-03-04 01:09:59 +01001019
1020 EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol,
1021 protocol_interface, agent_handle, controller_handle,
1022 attributes);
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02001023
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001024 if (!handle || !protocol ||
1025 (!protocol_interface && attributes !=
1026 EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02001027 goto out;
1028 }
1029
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001030 switch (attributes) {
1031 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
1032 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
1033 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
1034 break;
1035 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
1036 if (controller_handle == handle)
1037 goto out;
1038 case EFI_OPEN_PROTOCOL_BY_DRIVER:
1039 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
1040 if (controller_handle == NULL)
1041 goto out;
1042 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
1043 if (agent_handle == NULL)
1044 goto out;
1045 break;
1046 default:
1047 goto out;
1048 }
1049
Alexander Grafc15d9212016-03-04 01:09:59 +01001050 list_for_each(lhandle, &efi_obj_list) {
1051 struct efi_object *efiobj;
1052 efiobj = list_entry(lhandle, struct efi_object, link);
1053
1054 if (efiobj->handle != handle)
1055 continue;
1056
1057 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1058 struct efi_handler *handler = &efiobj->protocols[i];
1059 const efi_guid_t *hprotocol = handler->guid;
1060 if (!hprotocol)
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +02001061 continue;
Alexander Grafc15d9212016-03-04 01:09:59 +01001062 if (!guidcmp(hprotocol, protocol)) {
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02001063 if (attributes !=
1064 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
1065 *protocol_interface =
1066 handler->protocol_interface;
1067 }
1068 r = EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +01001069 goto out;
1070 }
1071 }
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001072 goto unsupported;
Alexander Grafc15d9212016-03-04 01:09:59 +01001073 }
1074
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001075unsupported:
1076 r = EFI_UNSUPPORTED;
Alexander Grafc15d9212016-03-04 01:09:59 +01001077out:
1078 return EFI_EXIT(r);
1079}
1080
1081static efi_status_t EFIAPI efi_handle_protocol(void *handle,
1082 efi_guid_t *protocol,
1083 void **protocol_interface)
1084{
xypron.glpk@gmx.de1bf5d872017-06-29 21:16:19 +02001085 return efi_open_protocol(handle, protocol, protocol_interface, NULL,
1086 NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
Alexander Grafc15d9212016-03-04 01:09:59 +01001087}
1088
1089static const struct efi_boot_services efi_boot_services = {
1090 .hdr = {
1091 .headersize = sizeof(struct efi_table_hdr),
1092 },
1093 .raise_tpl = efi_raise_tpl,
1094 .restore_tpl = efi_restore_tpl,
1095 .allocate_pages = efi_allocate_pages_ext,
1096 .free_pages = efi_free_pages_ext,
1097 .get_memory_map = efi_get_memory_map_ext,
Stefan Brüns5a09aef2016-10-09 22:17:18 +02001098 .allocate_pool = efi_allocate_pool_ext,
Stefan Brüns67b67d92016-10-09 22:17:26 +02001099 .free_pool = efi_free_pool_ext,
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +02001100 .create_event = efi_create_event_ext,
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +02001101 .set_timer = efi_set_timer_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01001102 .wait_for_event = efi_wait_for_event,
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +02001103 .signal_event = efi_signal_event_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01001104 .close_event = efi_close_event,
1105 .check_event = efi_check_event,
xypron.glpk@gmx.de8b7b5df2017-07-11 22:06:18 +02001106 .install_protocol_interface = efi_install_protocol_interface_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01001107 .reinstall_protocol_interface = efi_reinstall_protocol_interface,
xypron.glpk@gmx.dea453e462017-07-11 22:06:19 +02001108 .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01001109 .handle_protocol = efi_handle_protocol,
1110 .reserved = NULL,
1111 .register_protocol_notify = efi_register_protocol_notify,
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001112 .locate_handle = efi_locate_handle_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01001113 .locate_device_path = efi_locate_device_path,
Alexander Grafc5c11632016-08-19 01:23:24 +02001114 .install_configuration_table = efi_install_configuration_table_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01001115 .load_image = efi_load_image,
1116 .start_image = efi_start_image,
Alexander Graf988c0662016-05-20 23:28:23 +02001117 .exit = efi_exit,
Alexander Grafc15d9212016-03-04 01:09:59 +01001118 .unload_image = efi_unload_image,
1119 .exit_boot_services = efi_exit_boot_services,
1120 .get_next_monotonic_count = efi_get_next_monotonic_count,
1121 .stall = efi_stall,
1122 .set_watchdog_timer = efi_set_watchdog_timer,
1123 .connect_controller = efi_connect_controller,
1124 .disconnect_controller = efi_disconnect_controller,
1125 .open_protocol = efi_open_protocol,
1126 .close_protocol = efi_close_protocol,
1127 .open_protocol_information = efi_open_protocol_information,
1128 .protocols_per_handle = efi_protocols_per_handle,
1129 .locate_handle_buffer = efi_locate_handle_buffer,
1130 .locate_protocol = efi_locate_protocol,
1131 .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
1132 .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
1133 .calculate_crc32 = efi_calculate_crc32,
1134 .copy_mem = efi_copy_mem,
1135 .set_mem = efi_set_mem,
1136};
1137
1138
Alexander Graf393dd912016-10-14 13:45:30 +02001139static uint16_t __efi_runtime_data firmware_vendor[] =
Alexander Grafc15d9212016-03-04 01:09:59 +01001140 { 'D','a','s',' ','U','-','b','o','o','t',0 };
1141
Alexander Graf393dd912016-10-14 13:45:30 +02001142struct efi_system_table __efi_runtime_data systab = {
Alexander Grafc15d9212016-03-04 01:09:59 +01001143 .hdr = {
1144 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
1145 .revision = 0x20005, /* 2.5 */
1146 .headersize = sizeof(struct efi_table_hdr),
1147 },
1148 .fw_vendor = (long)firmware_vendor,
1149 .con_in = (void*)&efi_con_in,
1150 .con_out = (void*)&efi_con_out,
1151 .std_err = (void*)&efi_con_out,
1152 .runtime = (void*)&efi_runtime_services,
1153 .boottime = (void*)&efi_boot_services,
1154 .nr_tables = 0,
1155 .tables = (void*)efi_conf_table,
1156};