blob: a89a62940624e7021562c2b8212b65c63d0fde21 [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
135static int guidcmp(const efi_guid_t *g1, const efi_guid_t *g2)
136{
137 return memcmp(g1, g2, sizeof(efi_guid_t));
138}
139
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200140static unsigned long EFIAPI efi_raise_tpl(UINTN new_tpl)
Alexander Grafc15d9212016-03-04 01:09:59 +0100141{
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200142 EFI_ENTRY("0x%zx", new_tpl);
Alexander Grafc15d9212016-03-04 01:09:59 +0100143 return EFI_EXIT(0);
144}
145
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200146static void EFIAPI efi_restore_tpl(UINTN old_tpl)
Alexander Grafc15d9212016-03-04 01:09:59 +0100147{
xypron.glpk@gmx.de48df2092017-07-18 20:17:19 +0200148 EFI_ENTRY("0x%zx", old_tpl);
Alexander Grafc15d9212016-03-04 01:09:59 +0100149 EFI_EXIT(efi_unsupported(__func__));
150}
151
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900152static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
153 unsigned long pages,
154 uint64_t *memory)
Alexander Grafc15d9212016-03-04 01:09:59 +0100155{
156 efi_status_t r;
157
158 EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory);
159 r = efi_allocate_pages(type, memory_type, pages, memory);
160 return EFI_EXIT(r);
161}
162
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900163static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
164 unsigned long pages)
Alexander Grafc15d9212016-03-04 01:09:59 +0100165{
166 efi_status_t r;
167
168 EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages);
169 r = efi_free_pages(memory, pages);
170 return EFI_EXIT(r);
171}
172
Masahiro Yamadab2a05c12017-06-22 17:49:03 +0900173static efi_status_t EFIAPI efi_get_memory_map_ext(
174 unsigned long *memory_map_size,
175 struct efi_mem_desc *memory_map,
176 unsigned long *map_key,
177 unsigned long *descriptor_size,
178 uint32_t *descriptor_version)
Alexander Grafc15d9212016-03-04 01:09:59 +0100179{
180 efi_status_t r;
181
182 EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map,
183 map_key, descriptor_size, descriptor_version);
184 r = efi_get_memory_map(memory_map_size, memory_map, map_key,
185 descriptor_size, descriptor_version);
186 return EFI_EXIT(r);
187}
188
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200189static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
190 unsigned long size,
191 void **buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +0100192{
Alexander Graf1c34fa82016-03-24 01:37:37 +0100193 efi_status_t r;
194
195 EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer);
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200196 r = efi_allocate_pool(pool_type, size, buffer);
Alexander Graf1c34fa82016-03-24 01:37:37 +0100197 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100198}
199
Stefan Brüns67b67d92016-10-09 22:17:26 +0200200static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
Alexander Grafc15d9212016-03-04 01:09:59 +0100201{
Alexander Graf1c34fa82016-03-24 01:37:37 +0100202 efi_status_t r;
203
204 EFI_ENTRY("%p", buffer);
Stefan Brüns67b67d92016-10-09 22:17:26 +0200205 r = efi_free_pool(buffer);
Alexander Graf1c34fa82016-03-24 01:37:37 +0100206 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100207}
208
209/*
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200210 * Our event capabilities are very limited. Only a small limited
211 * number of events is allowed to coexist.
Alexander Grafc15d9212016-03-04 01:09:59 +0100212 */
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200213static struct efi_event efi_events[16];
Alexander Grafc15d9212016-03-04 01:09:59 +0100214
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200215efi_status_t efi_create_event(enum efi_event_type type, UINTN notify_tpl,
216 void (EFIAPI *notify_function) (
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200217 struct efi_event *event,
218 void *context),
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200219 void *notify_context, struct efi_event **event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100220{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200221 int i;
222
Jonathan Gray7758b212017-03-12 19:26:07 +1100223 if (event == NULL)
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200224 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100225
226 if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200227 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100228
229 if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
230 notify_function == NULL)
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200231 return EFI_INVALID_PARAMETER;
Jonathan Gray7758b212017-03-12 19:26:07 +1100232
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200233 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
234 if (efi_events[i].type)
235 continue;
236 efi_events[i].type = type;
237 efi_events[i].notify_tpl = notify_tpl;
238 efi_events[i].notify_function = notify_function;
239 efi_events[i].notify_context = notify_context;
240 /* Disable timers on bootup */
241 efi_events[i].trigger_next = -1ULL;
242 efi_events[i].signaled = 0;
243 *event = &efi_events[i];
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200244 return EFI_SUCCESS;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200245 }
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200246 return EFI_OUT_OF_RESOURCES;
Alexander Grafc15d9212016-03-04 01:09:59 +0100247}
248
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +0200249static efi_status_t EFIAPI efi_create_event_ext(
250 enum efi_event_type type, UINTN notify_tpl,
251 void (EFIAPI *notify_function) (
252 struct efi_event *event,
253 void *context),
254 void *notify_context, struct efi_event **event)
255{
256 EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
257 notify_context);
258 return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
259 notify_context, event));
260}
261
262
Alexander Grafc15d9212016-03-04 01:09:59 +0100263/*
264 * Our timers have to work without interrupts, so we check whenever keyboard
265 * input or disk accesses happen if enough time elapsed for it to fire.
266 */
267void efi_timer_check(void)
268{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200269 int i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100270 u64 now = timer_get_us();
271
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200272 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
273 if (!efi_events[i].type ||
274 !(efi_events[i].type & EVT_TIMER) ||
275 efi_events[i].trigger_type == EFI_TIMER_STOP ||
276 now < efi_events[i].trigger_next)
277 continue;
278 if (efi_events[i].trigger_type == EFI_TIMER_PERIODIC) {
279 efi_events[i].trigger_next +=
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200280 efi_events[i].trigger_time;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200281 efi_events[i].signaled = 0;
282 }
283 efi_signal_event(&efi_events[i]);
Alexander Grafc15d9212016-03-04 01:09:59 +0100284 }
Alexander Grafc15d9212016-03-04 01:09:59 +0100285 WATCHDOG_RESET();
286}
287
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200288efi_status_t efi_set_timer(struct efi_event *event, int type,
289 uint64_t trigger_time)
Alexander Grafc15d9212016-03-04 01:09:59 +0100290{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200291 int i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100292
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200293 /*
294 * The parameter defines a multiple of 100ns.
295 * We use multiples of 1000ns. So divide by 10.
296 */
297 trigger_time = efi_div10(trigger_time);
Alexander Grafc15d9212016-03-04 01:09:59 +0100298
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200299 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
300 if (event != &efi_events[i])
301 continue;
Alexander Grafc15d9212016-03-04 01:09:59 +0100302
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200303 if (!(event->type & EVT_TIMER))
304 break;
305 switch (type) {
306 case EFI_TIMER_STOP:
307 event->trigger_next = -1ULL;
308 break;
309 case EFI_TIMER_PERIODIC:
310 case EFI_TIMER_RELATIVE:
311 event->trigger_next =
xypron.glpk@gmx.de44c4be02017-07-18 20:17:23 +0200312 timer_get_us() + trigger_time;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200313 break;
314 default:
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200315 return EFI_INVALID_PARAMETER;
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200316 }
317 event->trigger_type = type;
318 event->trigger_time = trigger_time;
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200319 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +0100320 }
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200321 return EFI_INVALID_PARAMETER;
Alexander Grafc15d9212016-03-04 01:09:59 +0100322}
323
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +0200324static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event, int type,
325 uint64_t trigger_time)
326{
327 EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
328 return EFI_EXIT(efi_set_timer(event, type, trigger_time));
329}
330
Alexander Grafc15d9212016-03-04 01:09:59 +0100331static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events,
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200332 struct efi_event **event,
333 unsigned long *index)
Alexander Grafc15d9212016-03-04 01:09:59 +0100334{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200335 int i, j;
Alexander Grafc15d9212016-03-04 01:09:59 +0100336
337 EFI_ENTRY("%ld, %p, %p", num_events, event, index);
338
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200339 /* Check parameters */
340 if (!num_events || !event)
341 return EFI_EXIT(EFI_INVALID_PARAMETER);
342 for (i = 0; i < num_events; ++i) {
343 for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
344 if (event[i] == &efi_events[j])
345 goto known_event;
346 }
347 return EFI_EXIT(EFI_INVALID_PARAMETER);
348known_event:
349 if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
350 return EFI_EXIT(EFI_INVALID_PARAMETER);
351 }
352
353 /* Wait for signal */
354 for (;;) {
355 for (i = 0; i < num_events; ++i) {
356 if (event[i]->signaled)
357 goto out;
358 }
359 /* Allow events to occur. */
360 efi_timer_check();
361 }
362
363out:
364 /*
365 * Reset the signal which is passed to the caller to allow periodic
366 * events to occur.
367 */
368 event[i]->signaled = 0;
369 if (index)
370 *index = i;
Alexander Grafc15d9212016-03-04 01:09:59 +0100371
372 return EFI_EXIT(EFI_SUCCESS);
373}
374
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200375static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100376{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200377 int i;
378
Alexander Grafc15d9212016-03-04 01:09:59 +0100379 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200380 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
381 if (event != &efi_events[i])
382 continue;
383 efi_signal_event(event);
384 break;
385 }
Alexander Grafc15d9212016-03-04 01:09:59 +0100386 return EFI_EXIT(EFI_SUCCESS);
387}
388
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200389static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100390{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200391 int i;
392
Alexander Grafc15d9212016-03-04 01:09:59 +0100393 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200394 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
395 if (event == &efi_events[i]) {
396 event->type = 0;
397 event->trigger_next = -1ULL;
398 event->signaled = 0;
399 return EFI_EXIT(EFI_SUCCESS);
400 }
401 }
402 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafc15d9212016-03-04 01:09:59 +0100403}
404
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200405static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
Alexander Grafc15d9212016-03-04 01:09:59 +0100406{
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200407 int i;
408
Alexander Grafc15d9212016-03-04 01:09:59 +0100409 EFI_ENTRY("%p", event);
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +0200410 efi_timer_check();
411 for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
412 if (event != &efi_events[i])
413 continue;
414 if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
415 break;
416 if (event->signaled)
417 return EFI_EXIT(EFI_SUCCESS);
418 return EFI_EXIT(EFI_NOT_READY);
419 }
420 return EFI_EXIT(EFI_INVALID_PARAMETER);
Alexander Grafc15d9212016-03-04 01:09:59 +0100421}
422
423static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
424 efi_guid_t *protocol, int protocol_interface_type,
425 void *protocol_interface)
426{
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200427 struct list_head *lhandle;
428 int i;
429 efi_status_t r;
430
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200431 if (!handle || !protocol ||
432 protocol_interface_type != EFI_NATIVE_INTERFACE) {
433 r = EFI_INVALID_PARAMETER;
434 goto out;
435 }
436
437 /* Create new handle if requested. */
438 if (!*handle) {
439 r = EFI_OUT_OF_RESOURCES;
440 goto out;
441 }
442 /* Find object. */
443 list_for_each(lhandle, &efi_obj_list) {
444 struct efi_object *efiobj;
445 efiobj = list_entry(lhandle, struct efi_object, link);
446
447 if (efiobj->handle != *handle)
448 continue;
449 /* Check if protocol is already installed on the handle. */
450 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
451 struct efi_handler *handler = &efiobj->protocols[i];
452
453 if (!handler->guid)
454 continue;
455 if (!guidcmp(handler->guid, protocol)) {
456 r = EFI_INVALID_PARAMETER;
457 goto out;
458 }
459 }
460 /* Install protocol in first empty slot. */
461 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
462 struct efi_handler *handler = &efiobj->protocols[i];
463
464 if (handler->guid)
465 continue;
466
467 handler->guid = protocol;
468 handler->protocol_interface = protocol_interface;
469 r = EFI_SUCCESS;
470 goto out;
471 }
472 r = EFI_OUT_OF_RESOURCES;
473 goto out;
474 }
475 r = EFI_INVALID_PARAMETER;
476out:
xypron.glpk@gmx.de8b7b5df2017-07-11 22:06:18 +0200477 return r;
478}
479
480static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
481 efi_guid_t *protocol, int protocol_interface_type,
482 void *protocol_interface)
483{
484 EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type,
485 protocol_interface);
486
487 return EFI_EXIT(efi_install_protocol_interface(handle, protocol,
488 protocol_interface_type,
489 protocol_interface));
Alexander Grafc15d9212016-03-04 01:09:59 +0100490}
xypron.glpk@gmx.de0581fa82017-07-11 22:06:16 +0200491
Alexander Grafc15d9212016-03-04 01:09:59 +0100492static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
493 efi_guid_t *protocol, void *old_interface,
494 void *new_interface)
495{
496 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, old_interface,
497 new_interface);
498 return EFI_EXIT(EFI_ACCESS_DENIED);
499}
500
501static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
502 efi_guid_t *protocol, void *protocol_interface)
503{
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +0200504 struct list_head *lhandle;
505 int i;
506 efi_status_t r = EFI_NOT_FOUND;
507
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +0200508 if (!handle || !protocol) {
509 r = EFI_INVALID_PARAMETER;
510 goto out;
511 }
512
513 list_for_each(lhandle, &efi_obj_list) {
514 struct efi_object *efiobj;
515 efiobj = list_entry(lhandle, struct efi_object, link);
516
517 if (efiobj->handle != handle)
518 continue;
519
520 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
521 struct efi_handler *handler = &efiobj->protocols[i];
522 const efi_guid_t *hprotocol = handler->guid;
523
524 if (!hprotocol)
525 continue;
526 if (!guidcmp(hprotocol, protocol)) {
527 if (handler->protocol_interface) {
528 r = EFI_ACCESS_DENIED;
529 } else {
530 handler->guid = 0;
531 r = EFI_SUCCESS;
532 }
533 goto out;
534 }
535 }
536 }
537
538out:
xypron.glpk@gmx.dea453e462017-07-11 22:06:19 +0200539 return r;
540}
541
542static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle,
543 efi_guid_t *protocol, void *protocol_interface)
544{
545 EFI_ENTRY("%p, %p, %p", handle, protocol, protocol_interface);
546
547 return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol,
548 protocol_interface));
Alexander Grafc15d9212016-03-04 01:09:59 +0100549}
550
551static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol,
xypron.glpk@gmx.decdbf3ac2017-07-18 20:17:17 +0200552 struct efi_event *event,
Alexander Grafc15d9212016-03-04 01:09:59 +0100553 void **registration)
554{
555 EFI_ENTRY("%p, %p, %p", protocol, event, registration);
556 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
557}
558
559static int efi_search(enum efi_locate_search_type search_type,
560 efi_guid_t *protocol, void *search_key,
561 struct efi_object *efiobj)
562{
563 int i;
564
565 switch (search_type) {
566 case all_handles:
567 return 0;
568 case by_register_notify:
569 return -1;
570 case by_protocol:
571 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
572 const efi_guid_t *guid = efiobj->protocols[i].guid;
573 if (guid && !guidcmp(guid, protocol))
574 return 0;
575 }
576 return -1;
577 }
578
579 return -1;
580}
581
582static efi_status_t EFIAPI efi_locate_handle(
583 enum efi_locate_search_type search_type,
584 efi_guid_t *protocol, void *search_key,
585 unsigned long *buffer_size, efi_handle_t *buffer)
586{
587 struct list_head *lhandle;
588 unsigned long size = 0;
589
Alexander Grafc15d9212016-03-04 01:09:59 +0100590 /* Count how much space we need */
591 list_for_each(lhandle, &efi_obj_list) {
592 struct efi_object *efiobj;
593 efiobj = list_entry(lhandle, struct efi_object, link);
594 if (!efi_search(search_type, protocol, search_key, efiobj)) {
595 size += sizeof(void*);
596 }
597 }
598
599 if (*buffer_size < size) {
600 *buffer_size = size;
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +0200601 return EFI_BUFFER_TOO_SMALL;
Alexander Grafc15d9212016-03-04 01:09:59 +0100602 }
603
604 /* Then fill the array */
605 list_for_each(lhandle, &efi_obj_list) {
606 struct efi_object *efiobj;
607 efiobj = list_entry(lhandle, struct efi_object, link);
608 if (!efi_search(search_type, protocol, search_key, efiobj)) {
609 *(buffer++) = efiobj->handle;
610 }
611 }
612
613 *buffer_size = size;
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +0200614 return EFI_SUCCESS;
615}
616
617static efi_status_t EFIAPI efi_locate_handle_ext(
618 enum efi_locate_search_type search_type,
619 efi_guid_t *protocol, void *search_key,
620 unsigned long *buffer_size, efi_handle_t *buffer)
621{
622 EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
623 buffer_size, buffer);
624
625 return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
626 buffer_size, buffer));
Alexander Grafc15d9212016-03-04 01:09:59 +0100627}
628
629static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol,
630 struct efi_device_path **device_path,
631 efi_handle_t *device)
632{
633 EFI_ENTRY("%p, %p, %p", protocol, device_path, device);
634 return EFI_EXIT(EFI_NOT_FOUND);
635}
636
Alexander Grafc5c11632016-08-19 01:23:24 +0200637efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
Alexander Grafc15d9212016-03-04 01:09:59 +0100638{
639 int i;
640
Alexander Grafc15d9212016-03-04 01:09:59 +0100641 /* Check for guid override */
642 for (i = 0; i < systab.nr_tables; i++) {
643 if (!guidcmp(guid, &efi_conf_table[i].guid)) {
644 efi_conf_table[i].table = table;
Alexander Grafc5c11632016-08-19 01:23:24 +0200645 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +0100646 }
647 }
648
649 /* No override, check for overflow */
650 if (i >= ARRAY_SIZE(efi_conf_table))
Alexander Grafc5c11632016-08-19 01:23:24 +0200651 return EFI_OUT_OF_RESOURCES;
Alexander Grafc15d9212016-03-04 01:09:59 +0100652
653 /* Add a new entry */
654 memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
655 efi_conf_table[i].table = table;
Alexander Graf9982e672016-08-19 01:23:30 +0200656 systab.nr_tables = i + 1;
Alexander Grafc15d9212016-03-04 01:09:59 +0100657
Alexander Grafc5c11632016-08-19 01:23:24 +0200658 return EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +0100659}
660
Alexander Grafc5c11632016-08-19 01:23:24 +0200661static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
662 void *table)
663{
664 EFI_ENTRY("%p, %p", guid, table);
665 return EFI_EXIT(efi_install_configuration_table(guid, table));
666}
667
Alexander Grafc15d9212016-03-04 01:09:59 +0100668static efi_status_t EFIAPI efi_load_image(bool boot_policy,
669 efi_handle_t parent_image,
670 struct efi_device_path *file_path,
671 void *source_buffer,
672 unsigned long source_size,
673 efi_handle_t *image_handle)
674{
675 static struct efi_object loaded_image_info_obj = {
676 .protocols = {
677 {
678 .guid = &efi_guid_loaded_image,
Alexander Grafc15d9212016-03-04 01:09:59 +0100679 },
680 },
681 };
682 struct efi_loaded_image *info;
683 struct efi_object *obj;
684
685 EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
686 file_path, source_buffer, source_size, image_handle);
687 info = malloc(sizeof(*info));
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +0200688 loaded_image_info_obj.protocols[0].protocol_interface = info;
Alexander Grafc15d9212016-03-04 01:09:59 +0100689 obj = malloc(sizeof(loaded_image_info_obj));
690 memset(info, 0, sizeof(*info));
691 memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj));
692 obj->handle = info;
693 info->file_path = file_path;
694 info->reserved = efi_load_pe(source_buffer, info);
695 if (!info->reserved) {
696 free(info);
697 free(obj);
698 return EFI_EXIT(EFI_UNSUPPORTED);
699 }
700
701 *image_handle = info;
702 list_add_tail(&obj->link, &efi_obj_list);
703
704 return EFI_EXIT(EFI_SUCCESS);
705}
706
707static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
708 unsigned long *exit_data_size,
709 s16 **exit_data)
710{
711 ulong (*entry)(void *image_handle, struct efi_system_table *st);
712 struct efi_loaded_image *info = image_handle;
713
714 EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
715 entry = info->reserved;
716
717 efi_is_direct_boot = false;
718
719 /* call the image! */
Alexander Graf988c0662016-05-20 23:28:23 +0200720 if (setjmp(&info->exit_jmp)) {
721 /* We returned from the child image */
722 return EFI_EXIT(info->exit_status);
723 }
724
Alexander Grafc15d9212016-03-04 01:09:59 +0100725 entry(image_handle, &systab);
726
727 /* Should usually never get here */
728 return EFI_EXIT(EFI_SUCCESS);
729}
730
Alexander Graf988c0662016-05-20 23:28:23 +0200731static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
732 efi_status_t exit_status, unsigned long exit_data_size,
733 int16_t *exit_data)
Alexander Grafc15d9212016-03-04 01:09:59 +0100734{
Alexander Graf988c0662016-05-20 23:28:23 +0200735 struct efi_loaded_image *loaded_image_info = (void*)image_handle;
736
Alexander Grafc15d9212016-03-04 01:09:59 +0100737 EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
738 exit_data_size, exit_data);
Alexander Graf988c0662016-05-20 23:28:23 +0200739
740 loaded_image_info->exit_status = exit_status;
Alexander Graf9d006b72016-09-27 09:30:32 +0200741 longjmp(&loaded_image_info->exit_jmp, 1);
Alexander Graf988c0662016-05-20 23:28:23 +0200742
743 panic("EFI application exited");
Alexander Grafc15d9212016-03-04 01:09:59 +0100744}
745
746static struct efi_object *efi_search_obj(void *handle)
747{
748 struct list_head *lhandle;
749
750 list_for_each(lhandle, &efi_obj_list) {
751 struct efi_object *efiobj;
752 efiobj = list_entry(lhandle, struct efi_object, link);
753 if (efiobj->handle == handle)
754 return efiobj;
755 }
756
757 return NULL;
758}
759
760static efi_status_t EFIAPI efi_unload_image(void *image_handle)
761{
762 struct efi_object *efiobj;
763
764 EFI_ENTRY("%p", image_handle);
765 efiobj = efi_search_obj(image_handle);
766 if (efiobj)
767 list_del(&efiobj->link);
768
769 return EFI_EXIT(EFI_SUCCESS);
770}
771
772static void efi_exit_caches(void)
773{
774#if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
775 /*
776 * Grub on 32bit ARM needs to have caches disabled before jumping into
777 * a zImage, but does not know of all cache layers. Give it a hand.
778 */
779 if (efi_is_direct_boot)
780 cleanup_before_linux();
781#endif
782}
783
784static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
785 unsigned long map_key)
786{
787 EFI_ENTRY("%p, %ld", image_handle, map_key);
788
Alexander Graf2ebeb442016-11-17 01:02:57 +0100789 board_quiesce_devices();
790
Alexander Grafc15d9212016-03-04 01:09:59 +0100791 /* Fix up caches for EFI payloads if necessary */
792 efi_exit_caches();
793
794 /* This stops all lingering devices */
795 bootm_disable_interrupts();
796
797 /* Give the payload some time to boot */
798 WATCHDOG_RESET();
799
800 return EFI_EXIT(EFI_SUCCESS);
801}
802
803static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
804{
805 static uint64_t mono = 0;
806 EFI_ENTRY("%p", count);
807 *count = mono++;
808 return EFI_EXIT(EFI_SUCCESS);
809}
810
811static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
812{
813 EFI_ENTRY("%ld", microseconds);
814 udelay(microseconds);
815 return EFI_EXIT(EFI_SUCCESS);
816}
817
818static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
819 uint64_t watchdog_code,
820 unsigned long data_size,
821 uint16_t *watchdog_data)
822{
823 EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
824 data_size, watchdog_data);
825 return EFI_EXIT(efi_unsupported(__func__));
826}
827
828static efi_status_t EFIAPI efi_connect_controller(
829 efi_handle_t controller_handle,
830 efi_handle_t *driver_image_handle,
831 struct efi_device_path *remain_device_path,
832 bool recursive)
833{
834 EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
835 remain_device_path, recursive);
836 return EFI_EXIT(EFI_NOT_FOUND);
837}
838
839static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
840 void *driver_image_handle,
841 void *child_handle)
842{
843 EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
844 child_handle);
845 return EFI_EXIT(EFI_INVALID_PARAMETER);
846}
847
848static efi_status_t EFIAPI efi_close_protocol(void *handle,
849 efi_guid_t *protocol,
850 void *agent_handle,
851 void *controller_handle)
852{
853 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle,
854 controller_handle);
855 return EFI_EXIT(EFI_NOT_FOUND);
856}
857
858static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
859 efi_guid_t *protocol,
860 struct efi_open_protocol_info_entry **entry_buffer,
861 unsigned long *entry_count)
862{
863 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer,
864 entry_count);
865 return EFI_EXIT(EFI_NOT_FOUND);
866}
867
868static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
869 efi_guid_t ***protocol_buffer,
870 unsigned long *protocol_buffer_count)
871{
872 EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
873 protocol_buffer_count);
874 return EFI_EXIT(EFI_OUT_OF_RESOURCES);
875}
876
877static efi_status_t EFIAPI efi_locate_handle_buffer(
878 enum efi_locate_search_type search_type,
879 efi_guid_t *protocol, void *search_key,
880 unsigned long *no_handles, efi_handle_t **buffer)
881{
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +0200882 efi_status_t r;
883 unsigned long buffer_size = 0;
884
Alexander Grafc15d9212016-03-04 01:09:59 +0100885 EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
886 no_handles, buffer);
xypron.glpk@gmx.de550a68a2017-07-11 22:06:22 +0200887
888 if (!no_handles || !buffer) {
889 r = EFI_INVALID_PARAMETER;
890 goto out;
891 }
892 *no_handles = 0;
893 *buffer = NULL;
894 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
895 *buffer);
896 if (r != EFI_BUFFER_TOO_SMALL)
897 goto out;
898 r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
899 (void **)buffer);
900 if (r != EFI_SUCCESS)
901 goto out;
902 r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
903 *buffer);
904 if (r == EFI_SUCCESS)
905 *no_handles = buffer_size / sizeof(void *);
906out:
907 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100908}
909
Alexander Grafc15d9212016-03-04 01:09:59 +0100910static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol,
911 void *registration,
912 void **protocol_interface)
913{
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +0200914 struct list_head *lhandle;
Alexander Grafc15d9212016-03-04 01:09:59 +0100915 int i;
916
917 EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface);
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +0200918
919 if (!protocol || !protocol_interface)
920 return EFI_EXIT(EFI_INVALID_PARAMETER);
921
922 list_for_each(lhandle, &efi_obj_list) {
923 struct efi_object *efiobj;
924
925 efiobj = list_entry(lhandle, struct efi_object, link);
926 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
927 struct efi_handler *handler = &efiobj->protocols[i];
928
929 if (!handler->guid)
930 continue;
931 if (!guidcmp(handler->guid, protocol)) {
932 *protocol_interface =
933 handler->protocol_interface;
934 return EFI_EXIT(EFI_SUCCESS);
935 }
Alexander Grafc15d9212016-03-04 01:09:59 +0100936 }
937 }
xypron.glpk@gmx.de4534ad62017-07-11 22:06:24 +0200938 *protocol_interface = NULL;
Alexander Grafc15d9212016-03-04 01:09:59 +0100939
940 return EFI_EXIT(EFI_NOT_FOUND);
941}
942
943static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
944 void **handle, ...)
945{
946 EFI_ENTRY("%p", handle);
xypron.glpk@gmx.de83eebc72017-07-11 22:06:20 +0200947
948 va_list argptr;
949 efi_guid_t *protocol;
950 void *protocol_interface;
951 efi_status_t r = EFI_SUCCESS;
952 int i = 0;
953
954 if (!handle)
955 return EFI_EXIT(EFI_INVALID_PARAMETER);
956
957 va_start(argptr, handle);
958 for (;;) {
959 protocol = va_arg(argptr, efi_guid_t*);
960 if (!protocol)
961 break;
962 protocol_interface = va_arg(argptr, void*);
963 r = efi_install_protocol_interface(handle, protocol,
964 EFI_NATIVE_INTERFACE,
965 protocol_interface);
966 if (r != EFI_SUCCESS)
967 break;
968 i++;
969 }
970 va_end(argptr);
971 if (r == EFI_SUCCESS)
972 return EFI_EXIT(r);
973
974 /* If an error occured undo all changes. */
975 va_start(argptr, handle);
976 for (; i; --i) {
977 protocol = va_arg(argptr, efi_guid_t*);
978 protocol_interface = va_arg(argptr, void*);
979 efi_uninstall_protocol_interface(handle, protocol,
980 protocol_interface);
981 }
982 va_end(argptr);
983
984 return EFI_EXIT(r);
Alexander Grafc15d9212016-03-04 01:09:59 +0100985}
986
987static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
988 void *handle, ...)
989{
990 EFI_ENTRY("%p", handle);
991 return EFI_EXIT(EFI_INVALID_PARAMETER);
992}
993
994static efi_status_t EFIAPI efi_calculate_crc32(void *data,
995 unsigned long data_size,
996 uint32_t *crc32_p)
997{
998 EFI_ENTRY("%p, %ld", data, data_size);
999 *crc32_p = crc32(0, data, data_size);
1000 return EFI_EXIT(EFI_SUCCESS);
1001}
1002
1003static void EFIAPI efi_copy_mem(void *destination, void *source,
1004 unsigned long length)
1005{
1006 EFI_ENTRY("%p, %p, %ld", destination, source, length);
1007 memcpy(destination, source, length);
1008}
1009
1010static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value)
1011{
1012 EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value);
1013 memset(buffer, value, size);
1014}
1015
1016static efi_status_t EFIAPI efi_open_protocol(
1017 void *handle, efi_guid_t *protocol,
1018 void **protocol_interface, void *agent_handle,
1019 void *controller_handle, uint32_t attributes)
1020{
1021 struct list_head *lhandle;
1022 int i;
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001023 efi_status_t r = EFI_INVALID_PARAMETER;
Alexander Grafc15d9212016-03-04 01:09:59 +01001024
1025 EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol,
1026 protocol_interface, agent_handle, controller_handle,
1027 attributes);
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02001028
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001029 if (!handle || !protocol ||
1030 (!protocol_interface && attributes !=
1031 EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02001032 goto out;
1033 }
1034
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001035 switch (attributes) {
1036 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
1037 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
1038 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
1039 break;
1040 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
1041 if (controller_handle == handle)
1042 goto out;
1043 case EFI_OPEN_PROTOCOL_BY_DRIVER:
1044 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
1045 if (controller_handle == NULL)
1046 goto out;
1047 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
1048 if (agent_handle == NULL)
1049 goto out;
1050 break;
1051 default:
1052 goto out;
1053 }
1054
Alexander Grafc15d9212016-03-04 01:09:59 +01001055 list_for_each(lhandle, &efi_obj_list) {
1056 struct efi_object *efiobj;
1057 efiobj = list_entry(lhandle, struct efi_object, link);
1058
1059 if (efiobj->handle != handle)
1060 continue;
1061
1062 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
1063 struct efi_handler *handler = &efiobj->protocols[i];
1064 const efi_guid_t *hprotocol = handler->guid;
1065 if (!hprotocol)
xypron.glpk@gmx.de2cfad482017-07-11 22:06:17 +02001066 continue;
Alexander Grafc15d9212016-03-04 01:09:59 +01001067 if (!guidcmp(hprotocol, protocol)) {
xypron.glpk@gmx.dec35c9242017-07-11 22:06:14 +02001068 if (attributes !=
1069 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
1070 *protocol_interface =
1071 handler->protocol_interface;
1072 }
1073 r = EFI_SUCCESS;
Alexander Grafc15d9212016-03-04 01:09:59 +01001074 goto out;
1075 }
1076 }
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001077 goto unsupported;
Alexander Grafc15d9212016-03-04 01:09:59 +01001078 }
1079
xypron.glpk@gmx.def097c842017-07-11 22:06:15 +02001080unsupported:
1081 r = EFI_UNSUPPORTED;
Alexander Grafc15d9212016-03-04 01:09:59 +01001082out:
1083 return EFI_EXIT(r);
1084}
1085
1086static efi_status_t EFIAPI efi_handle_protocol(void *handle,
1087 efi_guid_t *protocol,
1088 void **protocol_interface)
1089{
xypron.glpk@gmx.de1bf5d872017-06-29 21:16:19 +02001090 return efi_open_protocol(handle, protocol, protocol_interface, NULL,
1091 NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
Alexander Grafc15d9212016-03-04 01:09:59 +01001092}
1093
1094static const struct efi_boot_services efi_boot_services = {
1095 .hdr = {
1096 .headersize = sizeof(struct efi_table_hdr),
1097 },
1098 .raise_tpl = efi_raise_tpl,
1099 .restore_tpl = efi_restore_tpl,
1100 .allocate_pages = efi_allocate_pages_ext,
1101 .free_pages = efi_free_pages_ext,
1102 .get_memory_map = efi_get_memory_map_ext,
Stefan Brüns5a09aef2016-10-09 22:17:18 +02001103 .allocate_pool = efi_allocate_pool_ext,
Stefan Brüns67b67d92016-10-09 22:17:26 +02001104 .free_pool = efi_free_pool_ext,
xypron.glpk@gmx.de852a0e1772017-07-18 20:17:20 +02001105 .create_event = efi_create_event_ext,
xypron.glpk@gmx.dea587fd12017-07-18 20:17:21 +02001106 .set_timer = efi_set_timer_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01001107 .wait_for_event = efi_wait_for_event,
xypron.glpk@gmx.de30708232017-07-18 20:17:18 +02001108 .signal_event = efi_signal_event_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01001109 .close_event = efi_close_event,
1110 .check_event = efi_check_event,
xypron.glpk@gmx.de8b7b5df2017-07-11 22:06:18 +02001111 .install_protocol_interface = efi_install_protocol_interface_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01001112 .reinstall_protocol_interface = efi_reinstall_protocol_interface,
xypron.glpk@gmx.dea453e462017-07-11 22:06:19 +02001113 .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01001114 .handle_protocol = efi_handle_protocol,
1115 .reserved = NULL,
1116 .register_protocol_notify = efi_register_protocol_notify,
xypron.glpk@gmx.de69f94032017-07-11 22:06:21 +02001117 .locate_handle = efi_locate_handle_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01001118 .locate_device_path = efi_locate_device_path,
Alexander Grafc5c11632016-08-19 01:23:24 +02001119 .install_configuration_table = efi_install_configuration_table_ext,
Alexander Grafc15d9212016-03-04 01:09:59 +01001120 .load_image = efi_load_image,
1121 .start_image = efi_start_image,
Alexander Graf988c0662016-05-20 23:28:23 +02001122 .exit = efi_exit,
Alexander Grafc15d9212016-03-04 01:09:59 +01001123 .unload_image = efi_unload_image,
1124 .exit_boot_services = efi_exit_boot_services,
1125 .get_next_monotonic_count = efi_get_next_monotonic_count,
1126 .stall = efi_stall,
1127 .set_watchdog_timer = efi_set_watchdog_timer,
1128 .connect_controller = efi_connect_controller,
1129 .disconnect_controller = efi_disconnect_controller,
1130 .open_protocol = efi_open_protocol,
1131 .close_protocol = efi_close_protocol,
1132 .open_protocol_information = efi_open_protocol_information,
1133 .protocols_per_handle = efi_protocols_per_handle,
1134 .locate_handle_buffer = efi_locate_handle_buffer,
1135 .locate_protocol = efi_locate_protocol,
1136 .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
1137 .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
1138 .calculate_crc32 = efi_calculate_crc32,
1139 .copy_mem = efi_copy_mem,
1140 .set_mem = efi_set_mem,
1141};
1142
1143
Alexander Graf393dd912016-10-14 13:45:30 +02001144static uint16_t __efi_runtime_data firmware_vendor[] =
Alexander Grafc15d9212016-03-04 01:09:59 +01001145 { 'D','a','s',' ','U','-','b','o','o','t',0 };
1146
Alexander Graf393dd912016-10-14 13:45:30 +02001147struct efi_system_table __efi_runtime_data systab = {
Alexander Grafc15d9212016-03-04 01:09:59 +01001148 .hdr = {
1149 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
1150 .revision = 0x20005, /* 2.5 */
1151 .headersize = sizeof(struct efi_table_hdr),
1152 },
1153 .fw_vendor = (long)firmware_vendor,
1154 .con_in = (void*)&efi_con_in,
1155 .con_out = (void*)&efi_con_out,
1156 .std_err = (void*)&efi_con_out,
1157 .runtime = (void*)&efi_runtime_services,
1158 .boottime = (void*)&efi_boot_services,
1159 .nr_tables = 0,
1160 .tables = (void*)efi_conf_table,
1161};