efi_boottime.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381
  1. /*
  2. * EFI application boot time services
  3. *
  4. * Copyright (c) 2016 Alexander Graf
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <efi_loader.h>
  10. #include <malloc.h>
  11. #include <asm/global_data.h>
  12. #include <libfdt_env.h>
  13. #include <u-boot/crc.h>
  14. #include <bootm.h>
  15. #include <inttypes.h>
  16. #include <watchdog.h>
  17. DECLARE_GLOBAL_DATA_PTR;
  18. /* Task priority level */
  19. static UINTN efi_tpl = TPL_APPLICATION;
  20. /* This list contains all the EFI objects our payload has access to */
  21. LIST_HEAD(efi_obj_list);
  22. /*
  23. * If we're running on nasty systems (32bit ARM booting into non-EFI Linux)
  24. * we need to do trickery with caches. Since we don't want to break the EFI
  25. * aware boot path, only apply hacks when loading exiting directly (breaking
  26. * direct Linux EFI booting along the way - oh well).
  27. */
  28. static bool efi_is_direct_boot = true;
  29. /*
  30. * EFI can pass arbitrary additional "tables" containing vendor specific
  31. * information to the payload. One such table is the FDT table which contains
  32. * a pointer to a flattened device tree blob.
  33. *
  34. * In most cases we want to pass an FDT to the payload, so reserve one slot of
  35. * config table space for it. The pointer gets populated by do_bootefi_exec().
  36. */
  37. static struct efi_configuration_table __efi_runtime_data efi_conf_table[2];
  38. #ifdef CONFIG_ARM
  39. /*
  40. * The "gd" pointer lives in a register on ARM and AArch64 that we declare
  41. * fixed when compiling U-Boot. However, the payload does not know about that
  42. * restriction so we need to manually swap its and our view of that register on
  43. * EFI callback entry/exit.
  44. */
  45. static volatile void *efi_gd, *app_gd;
  46. #endif
  47. static int entry_count;
  48. static int nesting_level;
  49. /* Called on every callback entry */
  50. int __efi_entry_check(void)
  51. {
  52. int ret = entry_count++ == 0;
  53. #ifdef CONFIG_ARM
  54. assert(efi_gd);
  55. app_gd = gd;
  56. gd = efi_gd;
  57. #endif
  58. return ret;
  59. }
  60. /* Called on every callback exit */
  61. int __efi_exit_check(void)
  62. {
  63. int ret = --entry_count == 0;
  64. #ifdef CONFIG_ARM
  65. gd = app_gd;
  66. #endif
  67. return ret;
  68. }
  69. /* Called from do_bootefi_exec() */
  70. void efi_save_gd(void)
  71. {
  72. #ifdef CONFIG_ARM
  73. efi_gd = gd;
  74. #endif
  75. }
  76. /*
  77. * Special case handler for error/abort that just forces things back
  78. * to u-boot world so we can dump out an abort msg, without any care
  79. * about returning back to UEFI world.
  80. */
  81. void efi_restore_gd(void)
  82. {
  83. #ifdef CONFIG_ARM
  84. /* Only restore if we're already in EFI context */
  85. if (!efi_gd)
  86. return;
  87. gd = efi_gd;
  88. #endif
  89. }
  90. /*
  91. * Two spaces per indent level, maxing out at 10.. which ought to be
  92. * enough for anyone ;-)
  93. */
  94. static const char *indent_string(int level)
  95. {
  96. const char *indent = " ";
  97. const int max = strlen(indent);
  98. level = min(max, level * 2);
  99. return &indent[max - level];
  100. }
  101. const char *__efi_nesting(void)
  102. {
  103. return indent_string(nesting_level);
  104. }
  105. const char *__efi_nesting_inc(void)
  106. {
  107. return indent_string(nesting_level++);
  108. }
  109. const char *__efi_nesting_dec(void)
  110. {
  111. return indent_string(--nesting_level);
  112. }
  113. /* Low 32 bit */
  114. #define EFI_LOW32(a) (a & 0xFFFFFFFFULL)
  115. /* High 32 bit */
  116. #define EFI_HIGH32(a) (a >> 32)
  117. /*
  118. * 64bit division by 10 implemented as multiplication by 1 / 10
  119. *
  120. * Decimals of one tenth: 0x1 / 0xA = 0x0.19999...
  121. */
  122. #define EFI_TENTH 0x199999999999999A
  123. static u64 efi_div10(u64 a)
  124. {
  125. u64 prod;
  126. u64 rem;
  127. u64 ret;
  128. ret = EFI_HIGH32(a) * EFI_HIGH32(EFI_TENTH);
  129. prod = EFI_HIGH32(a) * EFI_LOW32(EFI_TENTH);
  130. rem = EFI_LOW32(prod);
  131. ret += EFI_HIGH32(prod);
  132. prod = EFI_LOW32(a) * EFI_HIGH32(EFI_TENTH);
  133. rem += EFI_LOW32(prod);
  134. ret += EFI_HIGH32(prod);
  135. prod = EFI_LOW32(a) * EFI_LOW32(EFI_TENTH);
  136. rem += EFI_HIGH32(prod);
  137. ret += EFI_HIGH32(rem);
  138. /* Round to nearest integer */
  139. if (rem >= (1 << 31))
  140. ++ret;
  141. return ret;
  142. }
  143. void efi_signal_event(struct efi_event *event)
  144. {
  145. if (event->notify_function) {
  146. event->queued = 1;
  147. /* Check TPL */
  148. if (efi_tpl >= event->notify_tpl)
  149. return;
  150. EFI_CALL_VOID(event->notify_function(event,
  151. event->notify_context));
  152. }
  153. event->queued = 0;
  154. }
  155. static efi_status_t efi_unsupported(const char *funcname)
  156. {
  157. debug("EFI: App called into unimplemented function %s\n", funcname);
  158. return EFI_EXIT(EFI_UNSUPPORTED);
  159. }
  160. static unsigned long EFIAPI efi_raise_tpl(UINTN new_tpl)
  161. {
  162. UINTN old_tpl = efi_tpl;
  163. EFI_ENTRY("0x%zx", new_tpl);
  164. if (new_tpl < efi_tpl)
  165. debug("WARNING: new_tpl < current_tpl in %s\n", __func__);
  166. efi_tpl = new_tpl;
  167. if (efi_tpl > TPL_HIGH_LEVEL)
  168. efi_tpl = TPL_HIGH_LEVEL;
  169. EFI_EXIT(EFI_SUCCESS);
  170. return old_tpl;
  171. }
  172. static void EFIAPI efi_restore_tpl(UINTN old_tpl)
  173. {
  174. EFI_ENTRY("0x%zx", old_tpl);
  175. if (old_tpl > efi_tpl)
  176. debug("WARNING: old_tpl > current_tpl in %s\n", __func__);
  177. efi_tpl = old_tpl;
  178. if (efi_tpl > TPL_HIGH_LEVEL)
  179. efi_tpl = TPL_HIGH_LEVEL;
  180. EFI_EXIT(EFI_SUCCESS);
  181. }
  182. static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
  183. unsigned long pages,
  184. uint64_t *memory)
  185. {
  186. efi_status_t r;
  187. EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory);
  188. r = efi_allocate_pages(type, memory_type, pages, memory);
  189. return EFI_EXIT(r);
  190. }
  191. static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
  192. unsigned long pages)
  193. {
  194. efi_status_t r;
  195. EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages);
  196. r = efi_free_pages(memory, pages);
  197. return EFI_EXIT(r);
  198. }
  199. static efi_status_t EFIAPI efi_get_memory_map_ext(
  200. unsigned long *memory_map_size,
  201. struct efi_mem_desc *memory_map,
  202. unsigned long *map_key,
  203. unsigned long *descriptor_size,
  204. uint32_t *descriptor_version)
  205. {
  206. efi_status_t r;
  207. EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map,
  208. map_key, descriptor_size, descriptor_version);
  209. r = efi_get_memory_map(memory_map_size, memory_map, map_key,
  210. descriptor_size, descriptor_version);
  211. return EFI_EXIT(r);
  212. }
  213. static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
  214. unsigned long size,
  215. void **buffer)
  216. {
  217. efi_status_t r;
  218. EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer);
  219. r = efi_allocate_pool(pool_type, size, buffer);
  220. return EFI_EXIT(r);
  221. }
  222. static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
  223. {
  224. efi_status_t r;
  225. EFI_ENTRY("%p", buffer);
  226. r = efi_free_pool(buffer);
  227. return EFI_EXIT(r);
  228. }
  229. /*
  230. * Our event capabilities are very limited. Only a small limited
  231. * number of events is allowed to coexist.
  232. */
  233. static struct efi_event efi_events[16];
  234. efi_status_t efi_create_event(uint32_t type, UINTN notify_tpl,
  235. void (EFIAPI *notify_function) (
  236. struct efi_event *event,
  237. void *context),
  238. void *notify_context, struct efi_event **event)
  239. {
  240. int i;
  241. if (event == NULL)
  242. return EFI_INVALID_PARAMETER;
  243. if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
  244. return EFI_INVALID_PARAMETER;
  245. if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
  246. notify_function == NULL)
  247. return EFI_INVALID_PARAMETER;
  248. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  249. if (efi_events[i].type)
  250. continue;
  251. efi_events[i].type = type;
  252. efi_events[i].notify_tpl = notify_tpl;
  253. efi_events[i].notify_function = notify_function;
  254. efi_events[i].notify_context = notify_context;
  255. /* Disable timers on bootup */
  256. efi_events[i].trigger_next = -1ULL;
  257. efi_events[i].queued = 0;
  258. efi_events[i].signaled = 0;
  259. *event = &efi_events[i];
  260. return EFI_SUCCESS;
  261. }
  262. return EFI_OUT_OF_RESOURCES;
  263. }
  264. static efi_status_t EFIAPI efi_create_event_ext(
  265. uint32_t type, UINTN notify_tpl,
  266. void (EFIAPI *notify_function) (
  267. struct efi_event *event,
  268. void *context),
  269. void *notify_context, struct efi_event **event)
  270. {
  271. EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
  272. notify_context);
  273. return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
  274. notify_context, event));
  275. }
  276. /*
  277. * Our timers have to work without interrupts, so we check whenever keyboard
  278. * input or disk accesses happen if enough time elapsed for it to fire.
  279. */
  280. void efi_timer_check(void)
  281. {
  282. int i;
  283. u64 now = timer_get_us();
  284. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  285. if (!efi_events[i].type)
  286. continue;
  287. if (efi_events[i].queued)
  288. efi_signal_event(&efi_events[i]);
  289. if (!(efi_events[i].type & EVT_TIMER) ||
  290. now < efi_events[i].trigger_next)
  291. continue;
  292. switch (efi_events[i].trigger_type) {
  293. case EFI_TIMER_RELATIVE:
  294. efi_events[i].trigger_type = EFI_TIMER_STOP;
  295. break;
  296. case EFI_TIMER_PERIODIC:
  297. efi_events[i].trigger_next +=
  298. efi_events[i].trigger_time;
  299. break;
  300. default:
  301. continue;
  302. }
  303. efi_events[i].signaled = 1;
  304. efi_signal_event(&efi_events[i]);
  305. }
  306. WATCHDOG_RESET();
  307. }
  308. efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
  309. uint64_t trigger_time)
  310. {
  311. int i;
  312. /*
  313. * The parameter defines a multiple of 100ns.
  314. * We use multiples of 1000ns. So divide by 10.
  315. */
  316. trigger_time = efi_div10(trigger_time);
  317. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  318. if (event != &efi_events[i])
  319. continue;
  320. if (!(event->type & EVT_TIMER))
  321. break;
  322. switch (type) {
  323. case EFI_TIMER_STOP:
  324. event->trigger_next = -1ULL;
  325. break;
  326. case EFI_TIMER_PERIODIC:
  327. case EFI_TIMER_RELATIVE:
  328. event->trigger_next =
  329. timer_get_us() + trigger_time;
  330. break;
  331. default:
  332. return EFI_INVALID_PARAMETER;
  333. }
  334. event->trigger_type = type;
  335. event->trigger_time = trigger_time;
  336. event->signaled = 0;
  337. return EFI_SUCCESS;
  338. }
  339. return EFI_INVALID_PARAMETER;
  340. }
  341. static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event,
  342. enum efi_timer_delay type,
  343. uint64_t trigger_time)
  344. {
  345. EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
  346. return EFI_EXIT(efi_set_timer(event, type, trigger_time));
  347. }
  348. static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events,
  349. struct efi_event **event,
  350. unsigned long *index)
  351. {
  352. int i, j;
  353. EFI_ENTRY("%ld, %p, %p", num_events, event, index);
  354. /* Check parameters */
  355. if (!num_events || !event)
  356. return EFI_EXIT(EFI_INVALID_PARAMETER);
  357. /* Check TPL */
  358. if (efi_tpl != TPL_APPLICATION)
  359. return EFI_EXIT(EFI_UNSUPPORTED);
  360. for (i = 0; i < num_events; ++i) {
  361. for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
  362. if (event[i] == &efi_events[j])
  363. goto known_event;
  364. }
  365. return EFI_EXIT(EFI_INVALID_PARAMETER);
  366. known_event:
  367. if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
  368. return EFI_EXIT(EFI_INVALID_PARAMETER);
  369. if (!event[i]->signaled)
  370. efi_signal_event(event[i]);
  371. }
  372. /* Wait for signal */
  373. for (;;) {
  374. for (i = 0; i < num_events; ++i) {
  375. if (event[i]->signaled)
  376. goto out;
  377. }
  378. /* Allow events to occur. */
  379. efi_timer_check();
  380. }
  381. out:
  382. /*
  383. * Reset the signal which is passed to the caller to allow periodic
  384. * events to occur.
  385. */
  386. event[i]->signaled = 0;
  387. if (index)
  388. *index = i;
  389. return EFI_EXIT(EFI_SUCCESS);
  390. }
  391. static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
  392. {
  393. int i;
  394. EFI_ENTRY("%p", event);
  395. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  396. if (event != &efi_events[i])
  397. continue;
  398. if (event->signaled)
  399. break;
  400. event->signaled = 1;
  401. if (event->type & EVT_NOTIFY_SIGNAL)
  402. efi_signal_event(event);
  403. break;
  404. }
  405. return EFI_EXIT(EFI_SUCCESS);
  406. }
  407. static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
  408. {
  409. int i;
  410. EFI_ENTRY("%p", event);
  411. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  412. if (event == &efi_events[i]) {
  413. event->type = 0;
  414. event->trigger_next = -1ULL;
  415. event->queued = 0;
  416. event->signaled = 0;
  417. return EFI_EXIT(EFI_SUCCESS);
  418. }
  419. }
  420. return EFI_EXIT(EFI_INVALID_PARAMETER);
  421. }
  422. static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
  423. {
  424. int i;
  425. EFI_ENTRY("%p", event);
  426. efi_timer_check();
  427. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  428. if (event != &efi_events[i])
  429. continue;
  430. if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
  431. break;
  432. if (!event->signaled)
  433. efi_signal_event(event);
  434. if (event->signaled)
  435. return EFI_EXIT(EFI_SUCCESS);
  436. return EFI_EXIT(EFI_NOT_READY);
  437. }
  438. return EFI_EXIT(EFI_INVALID_PARAMETER);
  439. }
  440. static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
  441. efi_guid_t *protocol, int protocol_interface_type,
  442. void *protocol_interface)
  443. {
  444. struct list_head *lhandle;
  445. int i;
  446. efi_status_t r;
  447. if (!handle || !protocol ||
  448. protocol_interface_type != EFI_NATIVE_INTERFACE) {
  449. r = EFI_INVALID_PARAMETER;
  450. goto out;
  451. }
  452. /* Create new handle if requested. */
  453. if (!*handle) {
  454. r = EFI_OUT_OF_RESOURCES;
  455. goto out;
  456. }
  457. /* Find object. */
  458. list_for_each(lhandle, &efi_obj_list) {
  459. struct efi_object *efiobj;
  460. efiobj = list_entry(lhandle, struct efi_object, link);
  461. if (efiobj->handle != *handle)
  462. continue;
  463. /* Check if protocol is already installed on the handle. */
  464. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  465. struct efi_handler *handler = &efiobj->protocols[i];
  466. if (!handler->guid)
  467. continue;
  468. if (!guidcmp(handler->guid, protocol)) {
  469. r = EFI_INVALID_PARAMETER;
  470. goto out;
  471. }
  472. }
  473. /* Install protocol in first empty slot. */
  474. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  475. struct efi_handler *handler = &efiobj->protocols[i];
  476. if (handler->guid)
  477. continue;
  478. handler->guid = protocol;
  479. handler->protocol_interface = protocol_interface;
  480. r = EFI_SUCCESS;
  481. goto out;
  482. }
  483. r = EFI_OUT_OF_RESOURCES;
  484. goto out;
  485. }
  486. r = EFI_INVALID_PARAMETER;
  487. out:
  488. return r;
  489. }
  490. static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
  491. efi_guid_t *protocol, int protocol_interface_type,
  492. void *protocol_interface)
  493. {
  494. EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type,
  495. protocol_interface);
  496. return EFI_EXIT(efi_install_protocol_interface(handle, protocol,
  497. protocol_interface_type,
  498. protocol_interface));
  499. }
  500. static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
  501. efi_guid_t *protocol, void *old_interface,
  502. void *new_interface)
  503. {
  504. EFI_ENTRY("%p, %p, %p, %p", handle, protocol, old_interface,
  505. new_interface);
  506. return EFI_EXIT(EFI_ACCESS_DENIED);
  507. }
  508. static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
  509. efi_guid_t *protocol, void *protocol_interface)
  510. {
  511. struct list_head *lhandle;
  512. int i;
  513. efi_status_t r = EFI_NOT_FOUND;
  514. if (!handle || !protocol) {
  515. r = EFI_INVALID_PARAMETER;
  516. goto out;
  517. }
  518. list_for_each(lhandle, &efi_obj_list) {
  519. struct efi_object *efiobj;
  520. efiobj = list_entry(lhandle, struct efi_object, link);
  521. if (efiobj->handle != handle)
  522. continue;
  523. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  524. struct efi_handler *handler = &efiobj->protocols[i];
  525. const efi_guid_t *hprotocol = handler->guid;
  526. if (!hprotocol)
  527. continue;
  528. if (!guidcmp(hprotocol, protocol)) {
  529. if (handler->protocol_interface) {
  530. r = EFI_ACCESS_DENIED;
  531. } else {
  532. handler->guid = 0;
  533. r = EFI_SUCCESS;
  534. }
  535. goto out;
  536. }
  537. }
  538. }
  539. out:
  540. return r;
  541. }
  542. static 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. return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol,
  547. protocol_interface));
  548. }
  549. static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol,
  550. struct efi_event *event,
  551. void **registration)
  552. {
  553. EFI_ENTRY("%p, %p, %p", protocol, event, registration);
  554. return EFI_EXIT(EFI_OUT_OF_RESOURCES);
  555. }
  556. static int efi_search(enum efi_locate_search_type search_type,
  557. efi_guid_t *protocol, void *search_key,
  558. struct efi_object *efiobj)
  559. {
  560. int i;
  561. switch (search_type) {
  562. case all_handles:
  563. return 0;
  564. case by_register_notify:
  565. return -1;
  566. case by_protocol:
  567. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  568. const efi_guid_t *guid = efiobj->protocols[i].guid;
  569. if (guid && !guidcmp(guid, protocol))
  570. return 0;
  571. }
  572. return -1;
  573. }
  574. return -1;
  575. }
  576. static efi_status_t efi_locate_handle(
  577. enum efi_locate_search_type search_type,
  578. efi_guid_t *protocol, void *search_key,
  579. unsigned long *buffer_size, efi_handle_t *buffer)
  580. {
  581. struct list_head *lhandle;
  582. unsigned long size = 0;
  583. /* Count how much space we need */
  584. list_for_each(lhandle, &efi_obj_list) {
  585. struct efi_object *efiobj;
  586. efiobj = list_entry(lhandle, struct efi_object, link);
  587. if (!efi_search(search_type, protocol, search_key, efiobj)) {
  588. size += sizeof(void*);
  589. }
  590. }
  591. if (*buffer_size < size) {
  592. *buffer_size = size;
  593. return EFI_BUFFER_TOO_SMALL;
  594. }
  595. *buffer_size = size;
  596. if (size == 0)
  597. return EFI_NOT_FOUND;
  598. /* Then fill the array */
  599. list_for_each(lhandle, &efi_obj_list) {
  600. struct efi_object *efiobj;
  601. efiobj = list_entry(lhandle, struct efi_object, link);
  602. if (!efi_search(search_type, protocol, search_key, efiobj)) {
  603. *(buffer++) = efiobj->handle;
  604. }
  605. }
  606. return EFI_SUCCESS;
  607. }
  608. static efi_status_t EFIAPI efi_locate_handle_ext(
  609. enum efi_locate_search_type search_type,
  610. efi_guid_t *protocol, void *search_key,
  611. unsigned long *buffer_size, efi_handle_t *buffer)
  612. {
  613. EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
  614. buffer_size, buffer);
  615. return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
  616. buffer_size, buffer));
  617. }
  618. static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol,
  619. struct efi_device_path **device_path,
  620. efi_handle_t *device)
  621. {
  622. struct efi_object *efiobj;
  623. EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device);
  624. efiobj = efi_dp_find_obj(*device_path, device_path);
  625. if (!efiobj)
  626. return EFI_EXIT(EFI_NOT_FOUND);
  627. *device = efiobj->handle;
  628. return EFI_EXIT(EFI_SUCCESS);
  629. }
  630. /* Collapses configuration table entries, removing index i */
  631. static void efi_remove_configuration_table(int i)
  632. {
  633. struct efi_configuration_table *this = &efi_conf_table[i];
  634. struct efi_configuration_table *next = &efi_conf_table[i+1];
  635. struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables];
  636. memmove(this, next, (ulong)end - (ulong)next);
  637. systab.nr_tables--;
  638. }
  639. efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
  640. {
  641. int i;
  642. /* Check for guid override */
  643. for (i = 0; i < systab.nr_tables; i++) {
  644. if (!guidcmp(guid, &efi_conf_table[i].guid)) {
  645. if (table)
  646. efi_conf_table[i].table = table;
  647. else
  648. efi_remove_configuration_table(i);
  649. return EFI_SUCCESS;
  650. }
  651. }
  652. if (!table)
  653. return EFI_NOT_FOUND;
  654. /* No override, check for overflow */
  655. if (i >= ARRAY_SIZE(efi_conf_table))
  656. return EFI_OUT_OF_RESOURCES;
  657. /* Add a new entry */
  658. memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
  659. efi_conf_table[i].table = table;
  660. systab.nr_tables = i + 1;
  661. return EFI_SUCCESS;
  662. }
  663. static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
  664. void *table)
  665. {
  666. EFI_ENTRY("%p, %p", guid, table);
  667. return EFI_EXIT(efi_install_configuration_table(guid, table));
  668. }
  669. /* Initialize a loaded_image_info + loaded_image_info object with correct
  670. * protocols, boot-device, etc.
  671. */
  672. void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *obj,
  673. struct efi_device_path *device_path,
  674. struct efi_device_path *file_path)
  675. {
  676. obj->handle = info;
  677. /*
  678. * When asking for the device path interface, return
  679. * bootefi_device_path
  680. */
  681. obj->protocols[0].guid = &efi_guid_device_path;
  682. obj->protocols[0].protocol_interface = device_path;
  683. /*
  684. * When asking for the loaded_image interface, just
  685. * return handle which points to loaded_image_info
  686. */
  687. obj->protocols[1].guid = &efi_guid_loaded_image;
  688. obj->protocols[1].protocol_interface = info;
  689. obj->protocols[2].guid = &efi_guid_console_control;
  690. obj->protocols[2].protocol_interface = (void *)&efi_console_control;
  691. obj->protocols[3].guid = &efi_guid_device_path_to_text_protocol;
  692. obj->protocols[3].protocol_interface =
  693. (void *)&efi_device_path_to_text;
  694. info->file_path = file_path;
  695. info->device_handle = efi_dp_find_obj(device_path, NULL);
  696. list_add_tail(&obj->link, &efi_obj_list);
  697. }
  698. static efi_status_t EFIAPI efi_load_image(bool boot_policy,
  699. efi_handle_t parent_image,
  700. struct efi_device_path *file_path,
  701. void *source_buffer,
  702. unsigned long source_size,
  703. efi_handle_t *image_handle)
  704. {
  705. static struct efi_object loaded_image_info_obj = {
  706. .protocols = {
  707. {
  708. .guid = &efi_guid_loaded_image,
  709. },
  710. },
  711. };
  712. struct efi_loaded_image *info;
  713. struct efi_object *obj;
  714. EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
  715. file_path, source_buffer, source_size, image_handle);
  716. info = malloc(sizeof(*info));
  717. loaded_image_info_obj.protocols[0].protocol_interface = info;
  718. obj = malloc(sizeof(loaded_image_info_obj));
  719. memset(info, 0, sizeof(*info));
  720. memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj));
  721. obj->handle = info;
  722. info->file_path = file_path;
  723. info->reserved = efi_load_pe(source_buffer, info);
  724. if (!info->reserved) {
  725. free(info);
  726. free(obj);
  727. return EFI_EXIT(EFI_UNSUPPORTED);
  728. }
  729. *image_handle = info;
  730. list_add_tail(&obj->link, &efi_obj_list);
  731. return EFI_EXIT(EFI_SUCCESS);
  732. }
  733. static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
  734. unsigned long *exit_data_size,
  735. s16 **exit_data)
  736. {
  737. ulong (*entry)(void *image_handle, struct efi_system_table *st);
  738. struct efi_loaded_image *info = image_handle;
  739. EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
  740. entry = info->reserved;
  741. efi_is_direct_boot = false;
  742. /* call the image! */
  743. if (setjmp(&info->exit_jmp)) {
  744. /* We returned from the child image */
  745. return EFI_EXIT(info->exit_status);
  746. }
  747. __efi_nesting_dec();
  748. __efi_exit_check();
  749. entry(image_handle, &systab);
  750. __efi_entry_check();
  751. __efi_nesting_inc();
  752. /* Should usually never get here */
  753. return EFI_EXIT(EFI_SUCCESS);
  754. }
  755. static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
  756. efi_status_t exit_status, unsigned long exit_data_size,
  757. int16_t *exit_data)
  758. {
  759. struct efi_loaded_image *loaded_image_info = (void*)image_handle;
  760. EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
  761. exit_data_size, exit_data);
  762. /* Make sure entry/exit counts for EFI world cross-overs match */
  763. __efi_exit_check();
  764. /*
  765. * But longjmp out with the U-Boot gd, not the application's, as
  766. * the other end is a setjmp call inside EFI context.
  767. */
  768. efi_restore_gd();
  769. loaded_image_info->exit_status = exit_status;
  770. longjmp(&loaded_image_info->exit_jmp, 1);
  771. panic("EFI application exited");
  772. }
  773. static struct efi_object *efi_search_obj(void *handle)
  774. {
  775. struct list_head *lhandle;
  776. list_for_each(lhandle, &efi_obj_list) {
  777. struct efi_object *efiobj;
  778. efiobj = list_entry(lhandle, struct efi_object, link);
  779. if (efiobj->handle == handle)
  780. return efiobj;
  781. }
  782. return NULL;
  783. }
  784. static efi_status_t EFIAPI efi_unload_image(void *image_handle)
  785. {
  786. struct efi_object *efiobj;
  787. EFI_ENTRY("%p", image_handle);
  788. efiobj = efi_search_obj(image_handle);
  789. if (efiobj)
  790. list_del(&efiobj->link);
  791. return EFI_EXIT(EFI_SUCCESS);
  792. }
  793. static void efi_exit_caches(void)
  794. {
  795. #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
  796. /*
  797. * Grub on 32bit ARM needs to have caches disabled before jumping into
  798. * a zImage, but does not know of all cache layers. Give it a hand.
  799. */
  800. if (efi_is_direct_boot)
  801. cleanup_before_linux();
  802. #endif
  803. }
  804. static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
  805. unsigned long map_key)
  806. {
  807. int i;
  808. EFI_ENTRY("%p, %ld", image_handle, map_key);
  809. /* Notify that ExitBootServices is invoked. */
  810. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  811. if (efi_events[i].type != EVT_SIGNAL_EXIT_BOOT_SERVICES)
  812. continue;
  813. efi_signal_event(&efi_events[i]);
  814. }
  815. /* Make sure that notification functions are not called anymore */
  816. efi_tpl = TPL_HIGH_LEVEL;
  817. board_quiesce_devices();
  818. /* Fix up caches for EFI payloads if necessary */
  819. efi_exit_caches();
  820. /* This stops all lingering devices */
  821. bootm_disable_interrupts();
  822. /* Give the payload some time to boot */
  823. WATCHDOG_RESET();
  824. return EFI_EXIT(EFI_SUCCESS);
  825. }
  826. static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
  827. {
  828. static uint64_t mono = 0;
  829. EFI_ENTRY("%p", count);
  830. *count = mono++;
  831. return EFI_EXIT(EFI_SUCCESS);
  832. }
  833. static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
  834. {
  835. EFI_ENTRY("%ld", microseconds);
  836. udelay(microseconds);
  837. return EFI_EXIT(EFI_SUCCESS);
  838. }
  839. static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
  840. uint64_t watchdog_code,
  841. unsigned long data_size,
  842. uint16_t *watchdog_data)
  843. {
  844. EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
  845. data_size, watchdog_data);
  846. return efi_unsupported(__func__);
  847. }
  848. static efi_status_t EFIAPI efi_connect_controller(
  849. efi_handle_t controller_handle,
  850. efi_handle_t *driver_image_handle,
  851. struct efi_device_path *remain_device_path,
  852. bool recursive)
  853. {
  854. EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
  855. remain_device_path, recursive);
  856. return EFI_EXIT(EFI_NOT_FOUND);
  857. }
  858. static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
  859. void *driver_image_handle,
  860. void *child_handle)
  861. {
  862. EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
  863. child_handle);
  864. return EFI_EXIT(EFI_INVALID_PARAMETER);
  865. }
  866. static efi_status_t EFIAPI efi_close_protocol(void *handle,
  867. efi_guid_t *protocol,
  868. void *agent_handle,
  869. void *controller_handle)
  870. {
  871. EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle,
  872. controller_handle);
  873. return EFI_EXIT(EFI_NOT_FOUND);
  874. }
  875. static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
  876. efi_guid_t *protocol,
  877. struct efi_open_protocol_info_entry **entry_buffer,
  878. unsigned long *entry_count)
  879. {
  880. EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer,
  881. entry_count);
  882. return EFI_EXIT(EFI_NOT_FOUND);
  883. }
  884. static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
  885. efi_guid_t ***protocol_buffer,
  886. unsigned long *protocol_buffer_count)
  887. {
  888. unsigned long buffer_size;
  889. struct efi_object *efiobj;
  890. unsigned long i, j;
  891. struct list_head *lhandle;
  892. efi_status_t r;
  893. EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
  894. protocol_buffer_count);
  895. if (!handle || !protocol_buffer || !protocol_buffer_count)
  896. return EFI_EXIT(EFI_INVALID_PARAMETER);
  897. *protocol_buffer = NULL;
  898. *protocol_buffer_count = 0;
  899. list_for_each(lhandle, &efi_obj_list) {
  900. efiobj = list_entry(lhandle, struct efi_object, link);
  901. if (efiobj->handle != handle)
  902. continue;
  903. /* Count protocols */
  904. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  905. if (efiobj->protocols[i].guid)
  906. ++*protocol_buffer_count;
  907. }
  908. /* Copy guids */
  909. if (*protocol_buffer_count) {
  910. buffer_size = sizeof(efi_guid_t *) *
  911. *protocol_buffer_count;
  912. r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
  913. buffer_size,
  914. (void **)protocol_buffer);
  915. if (r != EFI_SUCCESS)
  916. return EFI_EXIT(r);
  917. j = 0;
  918. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); ++i) {
  919. if (efiobj->protocols[i].guid) {
  920. (*protocol_buffer)[j] = (void *)
  921. efiobj->protocols[i].guid;
  922. ++j;
  923. }
  924. }
  925. }
  926. break;
  927. }
  928. return EFI_EXIT(EFI_SUCCESS);
  929. }
  930. static efi_status_t EFIAPI efi_locate_handle_buffer(
  931. enum efi_locate_search_type search_type,
  932. efi_guid_t *protocol, void *search_key,
  933. unsigned long *no_handles, efi_handle_t **buffer)
  934. {
  935. efi_status_t r;
  936. unsigned long buffer_size = 0;
  937. EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
  938. no_handles, buffer);
  939. if (!no_handles || !buffer) {
  940. r = EFI_INVALID_PARAMETER;
  941. goto out;
  942. }
  943. *no_handles = 0;
  944. *buffer = NULL;
  945. r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
  946. *buffer);
  947. if (r != EFI_BUFFER_TOO_SMALL)
  948. goto out;
  949. r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
  950. (void **)buffer);
  951. if (r != EFI_SUCCESS)
  952. goto out;
  953. r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
  954. *buffer);
  955. if (r == EFI_SUCCESS)
  956. *no_handles = buffer_size / sizeof(void *);
  957. out:
  958. return EFI_EXIT(r);
  959. }
  960. static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol,
  961. void *registration,
  962. void **protocol_interface)
  963. {
  964. struct list_head *lhandle;
  965. int i;
  966. EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface);
  967. if (!protocol || !protocol_interface)
  968. return EFI_EXIT(EFI_INVALID_PARAMETER);
  969. EFI_PRINT_GUID("protocol", protocol);
  970. list_for_each(lhandle, &efi_obj_list) {
  971. struct efi_object *efiobj;
  972. efiobj = list_entry(lhandle, struct efi_object, link);
  973. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  974. struct efi_handler *handler = &efiobj->protocols[i];
  975. if (!handler->guid)
  976. continue;
  977. if (!guidcmp(handler->guid, protocol)) {
  978. *protocol_interface =
  979. handler->protocol_interface;
  980. return EFI_EXIT(EFI_SUCCESS);
  981. }
  982. }
  983. }
  984. *protocol_interface = NULL;
  985. return EFI_EXIT(EFI_NOT_FOUND);
  986. }
  987. static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
  988. void **handle, ...)
  989. {
  990. EFI_ENTRY("%p", handle);
  991. va_list argptr;
  992. efi_guid_t *protocol;
  993. void *protocol_interface;
  994. efi_status_t r = EFI_SUCCESS;
  995. int i = 0;
  996. if (!handle)
  997. return EFI_EXIT(EFI_INVALID_PARAMETER);
  998. va_start(argptr, handle);
  999. for (;;) {
  1000. protocol = va_arg(argptr, efi_guid_t*);
  1001. if (!protocol)
  1002. break;
  1003. protocol_interface = va_arg(argptr, void*);
  1004. r = efi_install_protocol_interface(handle, protocol,
  1005. EFI_NATIVE_INTERFACE,
  1006. protocol_interface);
  1007. if (r != EFI_SUCCESS)
  1008. break;
  1009. i++;
  1010. }
  1011. va_end(argptr);
  1012. if (r == EFI_SUCCESS)
  1013. return EFI_EXIT(r);
  1014. /* If an error occured undo all changes. */
  1015. va_start(argptr, handle);
  1016. for (; i; --i) {
  1017. protocol = va_arg(argptr, efi_guid_t*);
  1018. protocol_interface = va_arg(argptr, void*);
  1019. efi_uninstall_protocol_interface(handle, protocol,
  1020. protocol_interface);
  1021. }
  1022. va_end(argptr);
  1023. return EFI_EXIT(r);
  1024. }
  1025. static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
  1026. void *handle, ...)
  1027. {
  1028. EFI_ENTRY("%p", handle);
  1029. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1030. }
  1031. static efi_status_t EFIAPI efi_calculate_crc32(void *data,
  1032. unsigned long data_size,
  1033. uint32_t *crc32_p)
  1034. {
  1035. EFI_ENTRY("%p, %ld", data, data_size);
  1036. *crc32_p = crc32(0, data, data_size);
  1037. return EFI_EXIT(EFI_SUCCESS);
  1038. }
  1039. static void EFIAPI efi_copy_mem(void *destination, void *source,
  1040. unsigned long length)
  1041. {
  1042. EFI_ENTRY("%p, %p, %ld", destination, source, length);
  1043. memcpy(destination, source, length);
  1044. }
  1045. static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value)
  1046. {
  1047. EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value);
  1048. memset(buffer, value, size);
  1049. }
  1050. static efi_status_t EFIAPI efi_open_protocol(
  1051. void *handle, efi_guid_t *protocol,
  1052. void **protocol_interface, void *agent_handle,
  1053. void *controller_handle, uint32_t attributes)
  1054. {
  1055. struct list_head *lhandle;
  1056. int i;
  1057. efi_status_t r = EFI_INVALID_PARAMETER;
  1058. EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol,
  1059. protocol_interface, agent_handle, controller_handle,
  1060. attributes);
  1061. if (!handle || !protocol ||
  1062. (!protocol_interface && attributes !=
  1063. EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
  1064. goto out;
  1065. }
  1066. EFI_PRINT_GUID("protocol", protocol);
  1067. switch (attributes) {
  1068. case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
  1069. case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
  1070. case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
  1071. break;
  1072. case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
  1073. if (controller_handle == handle)
  1074. goto out;
  1075. case EFI_OPEN_PROTOCOL_BY_DRIVER:
  1076. case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
  1077. if (controller_handle == NULL)
  1078. goto out;
  1079. case EFI_OPEN_PROTOCOL_EXCLUSIVE:
  1080. if (agent_handle == NULL)
  1081. goto out;
  1082. break;
  1083. default:
  1084. goto out;
  1085. }
  1086. list_for_each(lhandle, &efi_obj_list) {
  1087. struct efi_object *efiobj;
  1088. efiobj = list_entry(lhandle, struct efi_object, link);
  1089. if (efiobj->handle != handle)
  1090. continue;
  1091. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  1092. struct efi_handler *handler = &efiobj->protocols[i];
  1093. const efi_guid_t *hprotocol = handler->guid;
  1094. if (!hprotocol)
  1095. continue;
  1096. if (!guidcmp(hprotocol, protocol)) {
  1097. if (attributes !=
  1098. EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
  1099. *protocol_interface =
  1100. handler->protocol_interface;
  1101. }
  1102. r = EFI_SUCCESS;
  1103. goto out;
  1104. }
  1105. }
  1106. goto unsupported;
  1107. }
  1108. unsupported:
  1109. r = EFI_UNSUPPORTED;
  1110. out:
  1111. return EFI_EXIT(r);
  1112. }
  1113. static efi_status_t EFIAPI efi_handle_protocol(void *handle,
  1114. efi_guid_t *protocol,
  1115. void **protocol_interface)
  1116. {
  1117. return efi_open_protocol(handle, protocol, protocol_interface, NULL,
  1118. NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
  1119. }
  1120. static const struct efi_boot_services efi_boot_services = {
  1121. .hdr = {
  1122. .headersize = sizeof(struct efi_table_hdr),
  1123. },
  1124. .raise_tpl = efi_raise_tpl,
  1125. .restore_tpl = efi_restore_tpl,
  1126. .allocate_pages = efi_allocate_pages_ext,
  1127. .free_pages = efi_free_pages_ext,
  1128. .get_memory_map = efi_get_memory_map_ext,
  1129. .allocate_pool = efi_allocate_pool_ext,
  1130. .free_pool = efi_free_pool_ext,
  1131. .create_event = efi_create_event_ext,
  1132. .set_timer = efi_set_timer_ext,
  1133. .wait_for_event = efi_wait_for_event,
  1134. .signal_event = efi_signal_event_ext,
  1135. .close_event = efi_close_event,
  1136. .check_event = efi_check_event,
  1137. .install_protocol_interface = efi_install_protocol_interface_ext,
  1138. .reinstall_protocol_interface = efi_reinstall_protocol_interface,
  1139. .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext,
  1140. .handle_protocol = efi_handle_protocol,
  1141. .reserved = NULL,
  1142. .register_protocol_notify = efi_register_protocol_notify,
  1143. .locate_handle = efi_locate_handle_ext,
  1144. .locate_device_path = efi_locate_device_path,
  1145. .install_configuration_table = efi_install_configuration_table_ext,
  1146. .load_image = efi_load_image,
  1147. .start_image = efi_start_image,
  1148. .exit = efi_exit,
  1149. .unload_image = efi_unload_image,
  1150. .exit_boot_services = efi_exit_boot_services,
  1151. .get_next_monotonic_count = efi_get_next_monotonic_count,
  1152. .stall = efi_stall,
  1153. .set_watchdog_timer = efi_set_watchdog_timer,
  1154. .connect_controller = efi_connect_controller,
  1155. .disconnect_controller = efi_disconnect_controller,
  1156. .open_protocol = efi_open_protocol,
  1157. .close_protocol = efi_close_protocol,
  1158. .open_protocol_information = efi_open_protocol_information,
  1159. .protocols_per_handle = efi_protocols_per_handle,
  1160. .locate_handle_buffer = efi_locate_handle_buffer,
  1161. .locate_protocol = efi_locate_protocol,
  1162. .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
  1163. .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
  1164. .calculate_crc32 = efi_calculate_crc32,
  1165. .copy_mem = efi_copy_mem,
  1166. .set_mem = efi_set_mem,
  1167. };
  1168. static uint16_t __efi_runtime_data firmware_vendor[] =
  1169. { 'D','a','s',' ','U','-','b','o','o','t',0 };
  1170. struct efi_system_table __efi_runtime_data systab = {
  1171. .hdr = {
  1172. .signature = EFI_SYSTEM_TABLE_SIGNATURE,
  1173. .revision = 0x20005, /* 2.5 */
  1174. .headersize = sizeof(struct efi_table_hdr),
  1175. },
  1176. .fw_vendor = (long)firmware_vendor,
  1177. .con_in = (void*)&efi_con_in,
  1178. .con_out = (void*)&efi_con_out,
  1179. .std_err = (void*)&efi_con_out,
  1180. .runtime = (void*)&efi_runtime_services,
  1181. .boottime = (void*)&efi_boot_services,
  1182. .nr_tables = 0,
  1183. .tables = (void*)efi_conf_table,
  1184. };