efi_boottime.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025
  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 <div64.h>
  10. #include <efi_loader.h>
  11. #include <environment.h>
  12. #include <malloc.h>
  13. #include <asm/global_data.h>
  14. #include <libfdt_env.h>
  15. #include <u-boot/crc.h>
  16. #include <bootm.h>
  17. #include <inttypes.h>
  18. #include <watchdog.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. /* Task priority level */
  21. static efi_uintn_t efi_tpl = TPL_APPLICATION;
  22. /* This list contains all the EFI objects our payload has access to */
  23. LIST_HEAD(efi_obj_list);
  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. */
  30. static bool efi_is_direct_boot = true;
  31. /*
  32. * EFI can pass arbitrary additional "tables" containing vendor specific
  33. * information to the payload. One such table is the FDT table which contains
  34. * a pointer to a flattened device tree blob.
  35. *
  36. * In most cases we want to pass an FDT to the payload, so reserve one slot of
  37. * config table space for it. The pointer gets populated by do_bootefi_exec().
  38. */
  39. static struct efi_configuration_table __efi_runtime_data efi_conf_table[2];
  40. #ifdef CONFIG_ARM
  41. /*
  42. * The "gd" pointer lives in a register on ARM and AArch64 that we declare
  43. * fixed when compiling U-Boot. However, the payload does not know about that
  44. * restriction so we need to manually swap its and our view of that register on
  45. * EFI callback entry/exit.
  46. */
  47. static volatile void *efi_gd, *app_gd;
  48. #endif
  49. static int entry_count;
  50. static int nesting_level;
  51. /* Called on every callback entry */
  52. int __efi_entry_check(void)
  53. {
  54. int ret = entry_count++ == 0;
  55. #ifdef CONFIG_ARM
  56. assert(efi_gd);
  57. app_gd = gd;
  58. gd = efi_gd;
  59. #endif
  60. return ret;
  61. }
  62. /* Called on every callback exit */
  63. int __efi_exit_check(void)
  64. {
  65. int ret = --entry_count == 0;
  66. #ifdef CONFIG_ARM
  67. gd = app_gd;
  68. #endif
  69. return ret;
  70. }
  71. /* Called from do_bootefi_exec() */
  72. void efi_save_gd(void)
  73. {
  74. #ifdef CONFIG_ARM
  75. efi_gd = gd;
  76. #endif
  77. }
  78. /*
  79. * Special case handler for error/abort that just forces things back
  80. * to u-boot world so we can dump out an abort msg, without any care
  81. * about returning back to UEFI world.
  82. */
  83. void efi_restore_gd(void)
  84. {
  85. #ifdef CONFIG_ARM
  86. /* Only restore if we're already in EFI context */
  87. if (!efi_gd)
  88. return;
  89. gd = efi_gd;
  90. #endif
  91. }
  92. /*
  93. * Two spaces per indent level, maxing out at 10.. which ought to be
  94. * enough for anyone ;-)
  95. */
  96. static const char *indent_string(int level)
  97. {
  98. const char *indent = " ";
  99. const int max = strlen(indent);
  100. level = min(max, level * 2);
  101. return &indent[max - level];
  102. }
  103. const char *__efi_nesting(void)
  104. {
  105. return indent_string(nesting_level);
  106. }
  107. const char *__efi_nesting_inc(void)
  108. {
  109. return indent_string(nesting_level++);
  110. }
  111. const char *__efi_nesting_dec(void)
  112. {
  113. return indent_string(--nesting_level);
  114. }
  115. /*
  116. * Queue an EFI event.
  117. *
  118. * This function queues the notification function of the event for future
  119. * execution.
  120. *
  121. * The notification function is called if the task priority level of the
  122. * event is higher than the current task priority level.
  123. *
  124. * For the SignalEvent service see efi_signal_event_ext.
  125. *
  126. * @event event to signal
  127. */
  128. void efi_signal_event(struct efi_event *event)
  129. {
  130. if (event->notify_function) {
  131. event->is_queued = true;
  132. /* Check TPL */
  133. if (efi_tpl >= event->notify_tpl)
  134. return;
  135. EFI_CALL_VOID(event->notify_function(event,
  136. event->notify_context));
  137. }
  138. event->is_queued = false;
  139. }
  140. /*
  141. * Raise the task priority level.
  142. *
  143. * This function implements the RaiseTpl service.
  144. * See the Unified Extensible Firmware Interface (UEFI) specification
  145. * for details.
  146. *
  147. * @new_tpl new value of the task priority level
  148. * @return old value of the task priority level
  149. */
  150. static unsigned long EFIAPI efi_raise_tpl(efi_uintn_t new_tpl)
  151. {
  152. efi_uintn_t old_tpl = efi_tpl;
  153. EFI_ENTRY("0x%zx", new_tpl);
  154. if (new_tpl < efi_tpl)
  155. debug("WARNING: new_tpl < current_tpl in %s\n", __func__);
  156. efi_tpl = new_tpl;
  157. if (efi_tpl > TPL_HIGH_LEVEL)
  158. efi_tpl = TPL_HIGH_LEVEL;
  159. EFI_EXIT(EFI_SUCCESS);
  160. return old_tpl;
  161. }
  162. /*
  163. * Lower the task priority level.
  164. *
  165. * This function implements the RestoreTpl service.
  166. * See the Unified Extensible Firmware Interface (UEFI) specification
  167. * for details.
  168. *
  169. * @old_tpl value of the task priority level to be restored
  170. */
  171. static void EFIAPI efi_restore_tpl(efi_uintn_t old_tpl)
  172. {
  173. EFI_ENTRY("0x%zx", old_tpl);
  174. if (old_tpl > efi_tpl)
  175. debug("WARNING: old_tpl > current_tpl in %s\n", __func__);
  176. efi_tpl = old_tpl;
  177. if (efi_tpl > TPL_HIGH_LEVEL)
  178. efi_tpl = TPL_HIGH_LEVEL;
  179. EFI_EXIT(EFI_SUCCESS);
  180. }
  181. /*
  182. * Allocate memory pages.
  183. *
  184. * This function implements the AllocatePages service.
  185. * See the Unified Extensible Firmware Interface (UEFI) specification
  186. * for details.
  187. *
  188. * @type type of allocation to be performed
  189. * @memory_type usage type of the allocated memory
  190. * @pages number of pages to be allocated
  191. * @memory allocated memory
  192. * @return status code
  193. */
  194. static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
  195. unsigned long pages,
  196. uint64_t *memory)
  197. {
  198. efi_status_t r;
  199. EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory);
  200. r = efi_allocate_pages(type, memory_type, pages, memory);
  201. return EFI_EXIT(r);
  202. }
  203. /*
  204. * Free memory pages.
  205. *
  206. * This function implements the FreePages service.
  207. * See the Unified Extensible Firmware Interface (UEFI) specification
  208. * for details.
  209. *
  210. * @memory start of the memory area to be freed
  211. * @pages number of pages to be freed
  212. * @return status code
  213. */
  214. static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
  215. unsigned long pages)
  216. {
  217. efi_status_t r;
  218. EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages);
  219. r = efi_free_pages(memory, pages);
  220. return EFI_EXIT(r);
  221. }
  222. /*
  223. * Get map describing memory usage.
  224. *
  225. * This function implements the GetMemoryMap service.
  226. * See the Unified Extensible Firmware Interface (UEFI) specification
  227. * for details.
  228. *
  229. * @memory_map_size on entry the size, in bytes, of the memory map buffer,
  230. * on exit the size of the copied memory map
  231. * @memory_map buffer to which the memory map is written
  232. * @map_key key for the memory map
  233. * @descriptor_size size of an individual memory descriptor
  234. * @descriptor_version version number of the memory descriptor structure
  235. * @return status code
  236. */
  237. static efi_status_t EFIAPI efi_get_memory_map_ext(
  238. unsigned long *memory_map_size,
  239. struct efi_mem_desc *memory_map,
  240. unsigned long *map_key,
  241. unsigned long *descriptor_size,
  242. uint32_t *descriptor_version)
  243. {
  244. efi_status_t r;
  245. EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map,
  246. map_key, descriptor_size, descriptor_version);
  247. r = efi_get_memory_map(memory_map_size, memory_map, map_key,
  248. descriptor_size, descriptor_version);
  249. return EFI_EXIT(r);
  250. }
  251. /*
  252. * Allocate memory from pool.
  253. *
  254. * This function implements the AllocatePool service.
  255. * See the Unified Extensible Firmware Interface (UEFI) specification
  256. * for details.
  257. *
  258. * @pool_type type of the pool from which memory is to be allocated
  259. * @size number of bytes to be allocated
  260. * @buffer allocated memory
  261. * @return status code
  262. */
  263. static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
  264. unsigned long size,
  265. void **buffer)
  266. {
  267. efi_status_t r;
  268. EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer);
  269. r = efi_allocate_pool(pool_type, size, buffer);
  270. return EFI_EXIT(r);
  271. }
  272. /*
  273. * Free memory from pool.
  274. *
  275. * This function implements the FreePool service.
  276. * See the Unified Extensible Firmware Interface (UEFI) specification
  277. * for details.
  278. *
  279. * @buffer start of memory to be freed
  280. * @return status code
  281. */
  282. static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
  283. {
  284. efi_status_t r;
  285. EFI_ENTRY("%p", buffer);
  286. r = efi_free_pool(buffer);
  287. return EFI_EXIT(r);
  288. }
  289. static efi_status_t efi_create_handle(void **handle)
  290. {
  291. struct efi_object *obj;
  292. efi_status_t r;
  293. r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
  294. sizeof(struct efi_object),
  295. (void **)&obj);
  296. if (r != EFI_SUCCESS)
  297. return r;
  298. memset(obj, 0, sizeof(struct efi_object));
  299. obj->handle = obj;
  300. list_add_tail(&obj->link, &efi_obj_list);
  301. *handle = obj;
  302. return r;
  303. }
  304. /*
  305. * Our event capabilities are very limited. Only a small limited
  306. * number of events is allowed to coexist.
  307. */
  308. static struct efi_event efi_events[16];
  309. /*
  310. * Create an event.
  311. *
  312. * This function is used inside U-Boot code to create an event.
  313. *
  314. * For the API function implementing the CreateEvent service see
  315. * efi_create_event_ext.
  316. *
  317. * @type type of the event to create
  318. * @notify_tpl task priority level of the event
  319. * @notify_function notification function of the event
  320. * @notify_context pointer passed to the notification function
  321. * @event created event
  322. * @return status code
  323. */
  324. efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl,
  325. void (EFIAPI *notify_function) (
  326. struct efi_event *event,
  327. void *context),
  328. void *notify_context, struct efi_event **event)
  329. {
  330. int i;
  331. if (event == NULL)
  332. return EFI_INVALID_PARAMETER;
  333. if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
  334. return EFI_INVALID_PARAMETER;
  335. if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
  336. notify_function == NULL)
  337. return EFI_INVALID_PARAMETER;
  338. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  339. if (efi_events[i].type)
  340. continue;
  341. efi_events[i].type = type;
  342. efi_events[i].notify_tpl = notify_tpl;
  343. efi_events[i].notify_function = notify_function;
  344. efi_events[i].notify_context = notify_context;
  345. /* Disable timers on bootup */
  346. efi_events[i].trigger_next = -1ULL;
  347. efi_events[i].is_queued = false;
  348. efi_events[i].is_signaled = false;
  349. *event = &efi_events[i];
  350. return EFI_SUCCESS;
  351. }
  352. return EFI_OUT_OF_RESOURCES;
  353. }
  354. /*
  355. * Create an event.
  356. *
  357. * This function implements the CreateEvent service.
  358. * See the Unified Extensible Firmware Interface (UEFI) specification
  359. * for details.
  360. *
  361. * @type type of the event to create
  362. * @notify_tpl task priority level of the event
  363. * @notify_function notification function of the event
  364. * @notify_context pointer passed to the notification function
  365. * @event created event
  366. * @return status code
  367. */
  368. static efi_status_t EFIAPI efi_create_event_ext(
  369. uint32_t type, efi_uintn_t notify_tpl,
  370. void (EFIAPI *notify_function) (
  371. struct efi_event *event,
  372. void *context),
  373. void *notify_context, struct efi_event **event)
  374. {
  375. EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
  376. notify_context);
  377. return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
  378. notify_context, event));
  379. }
  380. /*
  381. * Check if a timer event has occurred or a queued notification function should
  382. * be called.
  383. *
  384. * Our timers have to work without interrupts, so we check whenever keyboard
  385. * input or disk accesses happen if enough time elapsed for them to fire.
  386. */
  387. void efi_timer_check(void)
  388. {
  389. int i;
  390. u64 now = timer_get_us();
  391. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  392. if (!efi_events[i].type)
  393. continue;
  394. if (efi_events[i].is_queued)
  395. efi_signal_event(&efi_events[i]);
  396. if (!(efi_events[i].type & EVT_TIMER) ||
  397. now < efi_events[i].trigger_next)
  398. continue;
  399. switch (efi_events[i].trigger_type) {
  400. case EFI_TIMER_RELATIVE:
  401. efi_events[i].trigger_type = EFI_TIMER_STOP;
  402. break;
  403. case EFI_TIMER_PERIODIC:
  404. efi_events[i].trigger_next +=
  405. efi_events[i].trigger_time;
  406. break;
  407. default:
  408. continue;
  409. }
  410. efi_events[i].is_signaled = true;
  411. efi_signal_event(&efi_events[i]);
  412. }
  413. WATCHDOG_RESET();
  414. }
  415. /*
  416. * Set the trigger time for a timer event or stop the event.
  417. *
  418. * This is the function for internal usage in U-Boot. For the API function
  419. * implementing the SetTimer service see efi_set_timer_ext.
  420. *
  421. * @event event for which the timer is set
  422. * @type type of the timer
  423. * @trigger_time trigger period in multiples of 100ns
  424. * @return status code
  425. */
  426. efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
  427. uint64_t trigger_time)
  428. {
  429. int i;
  430. /*
  431. * The parameter defines a multiple of 100ns.
  432. * We use multiples of 1000ns. So divide by 10.
  433. */
  434. do_div(trigger_time, 10);
  435. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  436. if (event != &efi_events[i])
  437. continue;
  438. if (!(event->type & EVT_TIMER))
  439. break;
  440. switch (type) {
  441. case EFI_TIMER_STOP:
  442. event->trigger_next = -1ULL;
  443. break;
  444. case EFI_TIMER_PERIODIC:
  445. case EFI_TIMER_RELATIVE:
  446. event->trigger_next =
  447. timer_get_us() + trigger_time;
  448. break;
  449. default:
  450. return EFI_INVALID_PARAMETER;
  451. }
  452. event->trigger_type = type;
  453. event->trigger_time = trigger_time;
  454. event->is_signaled = false;
  455. return EFI_SUCCESS;
  456. }
  457. return EFI_INVALID_PARAMETER;
  458. }
  459. /*
  460. * Set the trigger time for a timer event or stop the event.
  461. *
  462. * This function implements the SetTimer service.
  463. * See the Unified Extensible Firmware Interface (UEFI) specification
  464. * for details.
  465. *
  466. * @event event for which the timer is set
  467. * @type type of the timer
  468. * @trigger_time trigger period in multiples of 100ns
  469. * @return status code
  470. */
  471. static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event,
  472. enum efi_timer_delay type,
  473. uint64_t trigger_time)
  474. {
  475. EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
  476. return EFI_EXIT(efi_set_timer(event, type, trigger_time));
  477. }
  478. /*
  479. * Wait for events to be signaled.
  480. *
  481. * This function implements the WaitForEvent service.
  482. * See the Unified Extensible Firmware Interface (UEFI) specification
  483. * for details.
  484. *
  485. * @num_events number of events to be waited for
  486. * @events events to be waited for
  487. * @index index of the event that was signaled
  488. * @return status code
  489. */
  490. static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events,
  491. struct efi_event **event,
  492. size_t *index)
  493. {
  494. int i, j;
  495. EFI_ENTRY("%ld, %p, %p", num_events, event, index);
  496. /* Check parameters */
  497. if (!num_events || !event)
  498. return EFI_EXIT(EFI_INVALID_PARAMETER);
  499. /* Check TPL */
  500. if (efi_tpl != TPL_APPLICATION)
  501. return EFI_EXIT(EFI_UNSUPPORTED);
  502. for (i = 0; i < num_events; ++i) {
  503. for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
  504. if (event[i] == &efi_events[j])
  505. goto known_event;
  506. }
  507. return EFI_EXIT(EFI_INVALID_PARAMETER);
  508. known_event:
  509. if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
  510. return EFI_EXIT(EFI_INVALID_PARAMETER);
  511. if (!event[i]->is_signaled)
  512. efi_signal_event(event[i]);
  513. }
  514. /* Wait for signal */
  515. for (;;) {
  516. for (i = 0; i < num_events; ++i) {
  517. if (event[i]->is_signaled)
  518. goto out;
  519. }
  520. /* Allow events to occur. */
  521. efi_timer_check();
  522. }
  523. out:
  524. /*
  525. * Reset the signal which is passed to the caller to allow periodic
  526. * events to occur.
  527. */
  528. event[i]->is_signaled = false;
  529. if (index)
  530. *index = i;
  531. return EFI_EXIT(EFI_SUCCESS);
  532. }
  533. /*
  534. * Signal an EFI event.
  535. *
  536. * This function implements the SignalEvent service.
  537. * See the Unified Extensible Firmware Interface (UEFI) specification
  538. * for details.
  539. *
  540. * This functions sets the signaled state of the event and queues the
  541. * notification function for execution.
  542. *
  543. * @event event to signal
  544. * @return status code
  545. */
  546. static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
  547. {
  548. int i;
  549. EFI_ENTRY("%p", event);
  550. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  551. if (event != &efi_events[i])
  552. continue;
  553. if (event->is_signaled)
  554. break;
  555. event->is_signaled = true;
  556. if (event->type & EVT_NOTIFY_SIGNAL)
  557. efi_signal_event(event);
  558. break;
  559. }
  560. return EFI_EXIT(EFI_SUCCESS);
  561. }
  562. /*
  563. * Close an EFI event.
  564. *
  565. * This function implements the CloseEvent service.
  566. * See the Unified Extensible Firmware Interface (UEFI) specification
  567. * for details.
  568. *
  569. * @event event to close
  570. * @return status code
  571. */
  572. static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
  573. {
  574. int i;
  575. EFI_ENTRY("%p", event);
  576. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  577. if (event == &efi_events[i]) {
  578. event->type = 0;
  579. event->trigger_next = -1ULL;
  580. event->is_queued = false;
  581. event->is_signaled = false;
  582. return EFI_EXIT(EFI_SUCCESS);
  583. }
  584. }
  585. return EFI_EXIT(EFI_INVALID_PARAMETER);
  586. }
  587. /*
  588. * Check if an event is signaled.
  589. *
  590. * This function implements the CheckEvent service.
  591. * See the Unified Extensible Firmware Interface (UEFI) specification
  592. * for details.
  593. *
  594. * If an event is not signaled yet the notification function is queued.
  595. *
  596. * @event event to check
  597. * @return status code
  598. */
  599. static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
  600. {
  601. int i;
  602. EFI_ENTRY("%p", event);
  603. efi_timer_check();
  604. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  605. if (event != &efi_events[i])
  606. continue;
  607. if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
  608. break;
  609. if (!event->is_signaled)
  610. efi_signal_event(event);
  611. if (event->is_signaled)
  612. return EFI_EXIT(EFI_SUCCESS);
  613. return EFI_EXIT(EFI_NOT_READY);
  614. }
  615. return EFI_EXIT(EFI_INVALID_PARAMETER);
  616. }
  617. /*
  618. * Find the internal EFI object for a handle.
  619. *
  620. * @handle handle to find
  621. * @return EFI object
  622. */
  623. static struct efi_object *efi_search_obj(void *handle)
  624. {
  625. struct list_head *lhandle;
  626. list_for_each(lhandle, &efi_obj_list) {
  627. struct efi_object *efiobj;
  628. efiobj = list_entry(lhandle, struct efi_object, link);
  629. if (efiobj->handle == handle)
  630. return efiobj;
  631. }
  632. return NULL;
  633. }
  634. /*
  635. * Install protocol interface.
  636. *
  637. * This function implements the InstallProtocolInterface service.
  638. * See the Unified Extensible Firmware Interface (UEFI) specification
  639. * for details.
  640. *
  641. * @handle handle on which the protocol shall be installed
  642. * @protocol GUID of the protocol to be installed
  643. * @protocol_interface_type type of the interface to be installed,
  644. * always EFI_NATIVE_INTERFACE
  645. * @protocol_interface interface of the protocol implementation
  646. * @return status code
  647. */
  648. static efi_status_t EFIAPI efi_install_protocol_interface(
  649. void **handle, const efi_guid_t *protocol,
  650. int protocol_interface_type, void *protocol_interface)
  651. {
  652. struct list_head *lhandle;
  653. int i;
  654. efi_status_t r;
  655. EFI_ENTRY("%p, %pUl, %d, %p", handle, protocol, protocol_interface_type,
  656. protocol_interface);
  657. if (!handle || !protocol ||
  658. protocol_interface_type != EFI_NATIVE_INTERFACE) {
  659. r = EFI_INVALID_PARAMETER;
  660. goto out;
  661. }
  662. /* Create new handle if requested. */
  663. if (!*handle) {
  664. r = efi_create_handle(handle);
  665. if (r != EFI_SUCCESS)
  666. goto out;
  667. }
  668. /* Find object. */
  669. list_for_each(lhandle, &efi_obj_list) {
  670. struct efi_object *efiobj;
  671. efiobj = list_entry(lhandle, struct efi_object, link);
  672. if (efiobj->handle != *handle)
  673. continue;
  674. /* Check if protocol is already installed on the handle. */
  675. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  676. struct efi_handler *handler = &efiobj->protocols[i];
  677. if (!handler->guid)
  678. continue;
  679. if (!guidcmp(handler->guid, protocol)) {
  680. r = EFI_INVALID_PARAMETER;
  681. goto out;
  682. }
  683. }
  684. /* Install protocol in first empty slot. */
  685. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  686. struct efi_handler *handler = &efiobj->protocols[i];
  687. if (handler->guid)
  688. continue;
  689. handler->guid = protocol;
  690. handler->protocol_interface = protocol_interface;
  691. r = EFI_SUCCESS;
  692. goto out;
  693. }
  694. r = EFI_OUT_OF_RESOURCES;
  695. goto out;
  696. }
  697. r = EFI_INVALID_PARAMETER;
  698. out:
  699. return EFI_EXIT(r);
  700. }
  701. /*
  702. * Reinstall protocol interface.
  703. *
  704. * This function implements the ReinstallProtocolInterface service.
  705. * See the Unified Extensible Firmware Interface (UEFI) specification
  706. * for details.
  707. *
  708. * @handle handle on which the protocol shall be
  709. * reinstalled
  710. * @protocol GUID of the protocol to be installed
  711. * @old_interface interface to be removed
  712. * @new_interface interface to be installed
  713. * @return status code
  714. */
  715. static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
  716. const efi_guid_t *protocol, void *old_interface,
  717. void *new_interface)
  718. {
  719. EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, old_interface,
  720. new_interface);
  721. return EFI_EXIT(EFI_ACCESS_DENIED);
  722. }
  723. /*
  724. * Uninstall protocol interface.
  725. *
  726. * This function implements the UninstallProtocolInterface service.
  727. * See the Unified Extensible Firmware Interface (UEFI) specification
  728. * for details.
  729. *
  730. * @handle handle from which the protocol shall be removed
  731. * @protocol GUID of the protocol to be removed
  732. * @protocol_interface interface to be removed
  733. * @return status code
  734. */
  735. static efi_status_t EFIAPI efi_uninstall_protocol_interface(
  736. void *handle, const efi_guid_t *protocol,
  737. void *protocol_interface)
  738. {
  739. struct list_head *lhandle;
  740. int i;
  741. efi_status_t r = EFI_NOT_FOUND;
  742. EFI_ENTRY("%p, %pUl, %p", handle, protocol, protocol_interface);
  743. if (!handle || !protocol) {
  744. r = EFI_INVALID_PARAMETER;
  745. goto out;
  746. }
  747. list_for_each(lhandle, &efi_obj_list) {
  748. struct efi_object *efiobj;
  749. efiobj = list_entry(lhandle, struct efi_object, link);
  750. if (efiobj->handle != handle)
  751. continue;
  752. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  753. struct efi_handler *handler = &efiobj->protocols[i];
  754. const efi_guid_t *hprotocol = handler->guid;
  755. if (!hprotocol)
  756. continue;
  757. if (!guidcmp(hprotocol, protocol)) {
  758. if (handler->protocol_interface) {
  759. r = EFI_ACCESS_DENIED;
  760. } else {
  761. handler->guid = 0;
  762. r = EFI_SUCCESS;
  763. }
  764. goto out;
  765. }
  766. }
  767. }
  768. out:
  769. return EFI_EXIT(r);
  770. }
  771. /*
  772. * Register an event for notification when a protocol is installed.
  773. *
  774. * This function implements the RegisterProtocolNotify service.
  775. * See the Unified Extensible Firmware Interface (UEFI) specification
  776. * for details.
  777. *
  778. * @protocol GUID of the protocol whose installation shall be
  779. * notified
  780. * @event event to be signaled upon installation of the protocol
  781. * @registration key for retrieving the registration information
  782. * @return status code
  783. */
  784. static efi_status_t EFIAPI efi_register_protocol_notify(
  785. const efi_guid_t *protocol,
  786. struct efi_event *event,
  787. void **registration)
  788. {
  789. EFI_ENTRY("%pUl, %p, %p", protocol, event, registration);
  790. return EFI_EXIT(EFI_OUT_OF_RESOURCES);
  791. }
  792. /*
  793. * Determine if an EFI handle implements a protocol.
  794. *
  795. * See the documentation of the LocateHandle service in the UEFI specification.
  796. *
  797. * @search_type selection criterion
  798. * @protocol GUID of the protocol
  799. * @search_key registration key
  800. * @efiobj handle
  801. * @return 0 if the handle implements the protocol
  802. */
  803. static int efi_search(enum efi_locate_search_type search_type,
  804. const efi_guid_t *protocol, void *search_key,
  805. struct efi_object *efiobj)
  806. {
  807. int i;
  808. switch (search_type) {
  809. case ALL_HANDLES:
  810. return 0;
  811. case BY_REGISTER_NOTIFY:
  812. return -1;
  813. case BY_PROTOCOL:
  814. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  815. const efi_guid_t *guid = efiobj->protocols[i].guid;
  816. if (guid && !guidcmp(guid, protocol))
  817. return 0;
  818. }
  819. return -1;
  820. }
  821. return -1;
  822. }
  823. /*
  824. * Locate handles implementing a protocol.
  825. *
  826. * This function is meant for U-Boot internal calls. For the API implementation
  827. * of the LocateHandle service see efi_locate_handle_ext.
  828. *
  829. * @search_type selection criterion
  830. * @protocol GUID of the protocol
  831. * @search_key registration key
  832. * @buffer_size size of the buffer to receive the handles in bytes
  833. * @buffer buffer to receive the relevant handles
  834. * @return status code
  835. */
  836. static efi_status_t efi_locate_handle(
  837. enum efi_locate_search_type search_type,
  838. const efi_guid_t *protocol, void *search_key,
  839. unsigned long *buffer_size, efi_handle_t *buffer)
  840. {
  841. struct list_head *lhandle;
  842. unsigned long size = 0;
  843. /* Count how much space we need */
  844. list_for_each(lhandle, &efi_obj_list) {
  845. struct efi_object *efiobj;
  846. efiobj = list_entry(lhandle, struct efi_object, link);
  847. if (!efi_search(search_type, protocol, search_key, efiobj)) {
  848. size += sizeof(void*);
  849. }
  850. }
  851. if (*buffer_size < size) {
  852. *buffer_size = size;
  853. return EFI_BUFFER_TOO_SMALL;
  854. }
  855. *buffer_size = size;
  856. if (size == 0)
  857. return EFI_NOT_FOUND;
  858. /* Then fill the array */
  859. list_for_each(lhandle, &efi_obj_list) {
  860. struct efi_object *efiobj;
  861. efiobj = list_entry(lhandle, struct efi_object, link);
  862. if (!efi_search(search_type, protocol, search_key, efiobj)) {
  863. *(buffer++) = efiobj->handle;
  864. }
  865. }
  866. return EFI_SUCCESS;
  867. }
  868. /*
  869. * Locate handles implementing a protocol.
  870. *
  871. * This function implements the LocateHandle service.
  872. * See the Unified Extensible Firmware Interface (UEFI) specification
  873. * for details.
  874. *
  875. * @search_type selection criterion
  876. * @protocol GUID of the protocol
  877. * @search_key registration key
  878. * @buffer_size size of the buffer to receive the handles in bytes
  879. * @buffer buffer to receive the relevant handles
  880. * @return 0 if the handle implements the protocol
  881. */
  882. static efi_status_t EFIAPI efi_locate_handle_ext(
  883. enum efi_locate_search_type search_type,
  884. const efi_guid_t *protocol, void *search_key,
  885. unsigned long *buffer_size, efi_handle_t *buffer)
  886. {
  887. EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
  888. buffer_size, buffer);
  889. return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
  890. buffer_size, buffer));
  891. }
  892. /*
  893. * Get the device path and handle of an device implementing a protocol.
  894. *
  895. * This function implements the LocateDevicePath service.
  896. * See the Unified Extensible Firmware Interface (UEFI) specification
  897. * for details.
  898. *
  899. * @protocol GUID of the protocol
  900. * @device_path device path
  901. * @device handle of the device
  902. * @return status code
  903. */
  904. static efi_status_t EFIAPI efi_locate_device_path(
  905. const efi_guid_t *protocol,
  906. struct efi_device_path **device_path,
  907. efi_handle_t *device)
  908. {
  909. struct efi_object *efiobj;
  910. EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device);
  911. efiobj = efi_dp_find_obj(*device_path, device_path);
  912. if (!efiobj)
  913. return EFI_EXIT(EFI_NOT_FOUND);
  914. *device = efiobj->handle;
  915. return EFI_EXIT(EFI_SUCCESS);
  916. }
  917. /* Collapses configuration table entries, removing index i */
  918. static void efi_remove_configuration_table(int i)
  919. {
  920. struct efi_configuration_table *this = &efi_conf_table[i];
  921. struct efi_configuration_table *next = &efi_conf_table[i+1];
  922. struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables];
  923. memmove(this, next, (ulong)end - (ulong)next);
  924. systab.nr_tables--;
  925. }
  926. /*
  927. * Adds, updates, or removes a configuration table.
  928. *
  929. * This function is used for internal calls. For the API implementation of the
  930. * InstallConfigurationTable service see efi_install_configuration_table_ext.
  931. *
  932. * @guid GUID of the installed table
  933. * @table table to be installed
  934. * @return status code
  935. */
  936. efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
  937. {
  938. int i;
  939. /* Check for guid override */
  940. for (i = 0; i < systab.nr_tables; i++) {
  941. if (!guidcmp(guid, &efi_conf_table[i].guid)) {
  942. if (table)
  943. efi_conf_table[i].table = table;
  944. else
  945. efi_remove_configuration_table(i);
  946. return EFI_SUCCESS;
  947. }
  948. }
  949. if (!table)
  950. return EFI_NOT_FOUND;
  951. /* No override, check for overflow */
  952. if (i >= ARRAY_SIZE(efi_conf_table))
  953. return EFI_OUT_OF_RESOURCES;
  954. /* Add a new entry */
  955. memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
  956. efi_conf_table[i].table = table;
  957. systab.nr_tables = i + 1;
  958. return EFI_SUCCESS;
  959. }
  960. /*
  961. * Adds, updates, or removes a configuration table.
  962. *
  963. * This function implements the InstallConfigurationTable service.
  964. * See the Unified Extensible Firmware Interface (UEFI) specification
  965. * for details.
  966. *
  967. * @guid GUID of the installed table
  968. * @table table to be installed
  969. * @return status code
  970. */
  971. static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
  972. void *table)
  973. {
  974. EFI_ENTRY("%pUl, %p", guid, table);
  975. return EFI_EXIT(efi_install_configuration_table(guid, table));
  976. }
  977. /*
  978. * Initialize a loaded_image_info + loaded_image_info object with correct
  979. * protocols, boot-device, etc.
  980. *
  981. * @info loaded image info to be passed to the entry point of the
  982. * image
  983. * @obj internal object associated with the loaded image
  984. * @device_path device path of the loaded image
  985. * @file_path file path of the loaded image
  986. */
  987. void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *obj,
  988. struct efi_device_path *device_path,
  989. struct efi_device_path *file_path)
  990. {
  991. obj->handle = info;
  992. /*
  993. * When asking for the device path interface, return
  994. * bootefi_device_path
  995. */
  996. obj->protocols[0].guid = &efi_guid_device_path;
  997. obj->protocols[0].protocol_interface = device_path;
  998. /*
  999. * When asking for the loaded_image interface, just
  1000. * return handle which points to loaded_image_info
  1001. */
  1002. obj->protocols[1].guid = &efi_guid_loaded_image;
  1003. obj->protocols[1].protocol_interface = info;
  1004. obj->protocols[2].guid = &efi_guid_console_control;
  1005. obj->protocols[2].protocol_interface = (void *)&efi_console_control;
  1006. obj->protocols[3].guid = &efi_guid_device_path_to_text_protocol;
  1007. obj->protocols[3].protocol_interface =
  1008. (void *)&efi_device_path_to_text;
  1009. info->file_path = file_path;
  1010. if (device_path)
  1011. info->device_handle = efi_dp_find_obj(device_path, NULL);
  1012. list_add_tail(&obj->link, &efi_obj_list);
  1013. }
  1014. /*
  1015. * Load an image using a file path.
  1016. *
  1017. * @file_path the path of the image to load
  1018. * @buffer buffer containing the loaded image
  1019. * @return status code
  1020. */
  1021. efi_status_t efi_load_image_from_path(struct efi_device_path *file_path,
  1022. void **buffer)
  1023. {
  1024. struct efi_file_info *info = NULL;
  1025. struct efi_file_handle *f;
  1026. static efi_status_t ret;
  1027. uint64_t bs;
  1028. f = efi_file_from_path(file_path);
  1029. if (!f)
  1030. return EFI_DEVICE_ERROR;
  1031. bs = 0;
  1032. EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
  1033. &bs, info));
  1034. if (ret == EFI_BUFFER_TOO_SMALL) {
  1035. info = malloc(bs);
  1036. EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
  1037. &bs, info));
  1038. }
  1039. if (ret != EFI_SUCCESS)
  1040. goto error;
  1041. ret = efi_allocate_pool(EFI_LOADER_DATA, info->file_size, buffer);
  1042. if (ret)
  1043. goto error;
  1044. EFI_CALL(ret = f->read(f, &info->file_size, *buffer));
  1045. error:
  1046. free(info);
  1047. EFI_CALL(f->close(f));
  1048. if (ret != EFI_SUCCESS) {
  1049. efi_free_pool(*buffer);
  1050. *buffer = NULL;
  1051. }
  1052. return ret;
  1053. }
  1054. /*
  1055. * Load an EFI image into memory.
  1056. *
  1057. * This function implements the LoadImage service.
  1058. * See the Unified Extensible Firmware Interface (UEFI) specification
  1059. * for details.
  1060. *
  1061. * @boot_policy true for request originating from the boot manager
  1062. * @parent_image the calles's image handle
  1063. * @file_path the path of the image to load
  1064. * @source_buffer memory location from which the image is installed
  1065. * @source_size size of the memory area from which the image is
  1066. * installed
  1067. * @image_handle handle for the newly installed image
  1068. * @return status code
  1069. */
  1070. static efi_status_t EFIAPI efi_load_image(bool boot_policy,
  1071. efi_handle_t parent_image,
  1072. struct efi_device_path *file_path,
  1073. void *source_buffer,
  1074. unsigned long source_size,
  1075. efi_handle_t *image_handle)
  1076. {
  1077. struct efi_loaded_image *info;
  1078. struct efi_object *obj;
  1079. EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
  1080. file_path, source_buffer, source_size, image_handle);
  1081. info = calloc(1, sizeof(*info));
  1082. obj = calloc(1, sizeof(*obj));
  1083. if (!source_buffer) {
  1084. struct efi_device_path *dp, *fp;
  1085. efi_status_t ret;
  1086. ret = efi_load_image_from_path(file_path, &source_buffer);
  1087. if (ret != EFI_SUCCESS) {
  1088. free(info);
  1089. free(obj);
  1090. return EFI_EXIT(ret);
  1091. }
  1092. /*
  1093. * split file_path which contains both the device and
  1094. * file parts:
  1095. */
  1096. efi_dp_split_file_path(file_path, &dp, &fp);
  1097. efi_setup_loaded_image(info, obj, dp, fp);
  1098. } else {
  1099. /* In this case, file_path is the "device" path, ie.
  1100. * something like a HARDWARE_DEVICE:MEMORY_MAPPED
  1101. */
  1102. efi_setup_loaded_image(info, obj, file_path, NULL);
  1103. }
  1104. info->reserved = efi_load_pe(source_buffer, info);
  1105. if (!info->reserved) {
  1106. free(info);
  1107. free(obj);
  1108. return EFI_EXIT(EFI_UNSUPPORTED);
  1109. }
  1110. info->system_table = &systab;
  1111. info->parent_handle = parent_image;
  1112. *image_handle = info;
  1113. return EFI_EXIT(EFI_SUCCESS);
  1114. }
  1115. /*
  1116. * Call the entry point of an image.
  1117. *
  1118. * This function implements the StartImage service.
  1119. * See the Unified Extensible Firmware Interface (UEFI) specification
  1120. * for details.
  1121. *
  1122. * @image_handle handle of the image
  1123. * @exit_data_size size of the buffer
  1124. * @exit_data buffer to receive the exit data of the called image
  1125. * @return status code
  1126. */
  1127. static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
  1128. unsigned long *exit_data_size,
  1129. s16 **exit_data)
  1130. {
  1131. ulong (*entry)(void *image_handle, struct efi_system_table *st);
  1132. struct efi_loaded_image *info = image_handle;
  1133. EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
  1134. entry = info->reserved;
  1135. efi_is_direct_boot = false;
  1136. /* call the image! */
  1137. if (setjmp(&info->exit_jmp)) {
  1138. /* We returned from the child image */
  1139. return EFI_EXIT(info->exit_status);
  1140. }
  1141. __efi_nesting_dec();
  1142. __efi_exit_check();
  1143. entry(image_handle, &systab);
  1144. __efi_entry_check();
  1145. __efi_nesting_inc();
  1146. /* Should usually never get here */
  1147. return EFI_EXIT(EFI_SUCCESS);
  1148. }
  1149. /*
  1150. * Leave an EFI application or driver.
  1151. *
  1152. * This function implements the Exit service.
  1153. * See the Unified Extensible Firmware Interface (UEFI) specification
  1154. * for details.
  1155. *
  1156. * @image_handle handle of the application or driver that is exiting
  1157. * @exit_status status code
  1158. * @exit_data_size size of the buffer in bytes
  1159. * @exit_data buffer with data describing an error
  1160. * @return status code
  1161. */
  1162. static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
  1163. efi_status_t exit_status, unsigned long exit_data_size,
  1164. int16_t *exit_data)
  1165. {
  1166. struct efi_loaded_image *loaded_image_info = (void*)image_handle;
  1167. EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
  1168. exit_data_size, exit_data);
  1169. /* Make sure entry/exit counts for EFI world cross-overs match */
  1170. __efi_exit_check();
  1171. /*
  1172. * But longjmp out with the U-Boot gd, not the application's, as
  1173. * the other end is a setjmp call inside EFI context.
  1174. */
  1175. efi_restore_gd();
  1176. loaded_image_info->exit_status = exit_status;
  1177. longjmp(&loaded_image_info->exit_jmp, 1);
  1178. panic("EFI application exited");
  1179. }
  1180. /*
  1181. * Unload an EFI image.
  1182. *
  1183. * This function implements the UnloadImage service.
  1184. * See the Unified Extensible Firmware Interface (UEFI) specification
  1185. * for details.
  1186. *
  1187. * @image_handle handle of the image to be unloaded
  1188. * @return status code
  1189. */
  1190. static efi_status_t EFIAPI efi_unload_image(void *image_handle)
  1191. {
  1192. struct efi_object *efiobj;
  1193. EFI_ENTRY("%p", image_handle);
  1194. efiobj = efi_search_obj(image_handle);
  1195. if (efiobj)
  1196. list_del(&efiobj->link);
  1197. return EFI_EXIT(EFI_SUCCESS);
  1198. }
  1199. /*
  1200. * Fix up caches for EFI payloads if necessary.
  1201. */
  1202. static void efi_exit_caches(void)
  1203. {
  1204. #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
  1205. /*
  1206. * Grub on 32bit ARM needs to have caches disabled before jumping into
  1207. * a zImage, but does not know of all cache layers. Give it a hand.
  1208. */
  1209. if (efi_is_direct_boot)
  1210. cleanup_before_linux();
  1211. #endif
  1212. }
  1213. /*
  1214. * Stop boot services.
  1215. *
  1216. * This function implements the ExitBootServices service.
  1217. * See the Unified Extensible Firmware Interface (UEFI) specification
  1218. * for details.
  1219. *
  1220. * @image_handle handle of the loaded image
  1221. * @map_key key of the memory map
  1222. * @return status code
  1223. */
  1224. static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
  1225. unsigned long map_key)
  1226. {
  1227. int i;
  1228. EFI_ENTRY("%p, %ld", image_handle, map_key);
  1229. /* Notify that ExitBootServices is invoked. */
  1230. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  1231. if (efi_events[i].type != EVT_SIGNAL_EXIT_BOOT_SERVICES)
  1232. continue;
  1233. efi_signal_event(&efi_events[i]);
  1234. }
  1235. /* Make sure that notification functions are not called anymore */
  1236. efi_tpl = TPL_HIGH_LEVEL;
  1237. /* XXX Should persist EFI variables here */
  1238. board_quiesce_devices();
  1239. /* Fix up caches for EFI payloads if necessary */
  1240. efi_exit_caches();
  1241. /* This stops all lingering devices */
  1242. bootm_disable_interrupts();
  1243. /* Give the payload some time to boot */
  1244. efi_set_watchdog(0);
  1245. WATCHDOG_RESET();
  1246. return EFI_EXIT(EFI_SUCCESS);
  1247. }
  1248. /*
  1249. * Get next value of the counter.
  1250. *
  1251. * This function implements the NextMonotonicCount service.
  1252. * See the Unified Extensible Firmware Interface (UEFI) specification
  1253. * for details.
  1254. *
  1255. * @count returned value of the counter
  1256. * @return status code
  1257. */
  1258. static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
  1259. {
  1260. static uint64_t mono = 0;
  1261. EFI_ENTRY("%p", count);
  1262. *count = mono++;
  1263. return EFI_EXIT(EFI_SUCCESS);
  1264. }
  1265. /*
  1266. * Sleep.
  1267. *
  1268. * This function implements the Stall sercive.
  1269. * See the Unified Extensible Firmware Interface (UEFI) specification
  1270. * for details.
  1271. *
  1272. * @microseconds period to sleep in microseconds
  1273. * @return status code
  1274. */
  1275. static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
  1276. {
  1277. EFI_ENTRY("%ld", microseconds);
  1278. udelay(microseconds);
  1279. return EFI_EXIT(EFI_SUCCESS);
  1280. }
  1281. /*
  1282. * Reset the watchdog timer.
  1283. *
  1284. * This function implements the SetWatchdogTimer service.
  1285. * See the Unified Extensible Firmware Interface (UEFI) specification
  1286. * for details.
  1287. *
  1288. * @timeout seconds before reset by watchdog
  1289. * @watchdog_code code to be logged when resetting
  1290. * @data_size size of buffer in bytes
  1291. * @watchdog_data buffer with data describing the reset reason
  1292. * @return status code
  1293. */
  1294. static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
  1295. uint64_t watchdog_code,
  1296. unsigned long data_size,
  1297. uint16_t *watchdog_data)
  1298. {
  1299. EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
  1300. data_size, watchdog_data);
  1301. return EFI_EXIT(efi_set_watchdog(timeout));
  1302. }
  1303. /*
  1304. * Connect a controller to a driver.
  1305. *
  1306. * This function implements the ConnectController service.
  1307. * See the Unified Extensible Firmware Interface (UEFI) specification
  1308. * for details.
  1309. *
  1310. * @controller_handle handle of the controller
  1311. * @driver_image_handle handle of the driver
  1312. * @remain_device_path device path of a child controller
  1313. * @recursive true to connect all child controllers
  1314. * @return status code
  1315. */
  1316. static efi_status_t EFIAPI efi_connect_controller(
  1317. efi_handle_t controller_handle,
  1318. efi_handle_t *driver_image_handle,
  1319. struct efi_device_path *remain_device_path,
  1320. bool recursive)
  1321. {
  1322. EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
  1323. remain_device_path, recursive);
  1324. return EFI_EXIT(EFI_NOT_FOUND);
  1325. }
  1326. /*
  1327. * Disconnect a controller from a driver.
  1328. *
  1329. * This function implements the DisconnectController service.
  1330. * See the Unified Extensible Firmware Interface (UEFI) specification
  1331. * for details.
  1332. *
  1333. * @controller_handle handle of the controller
  1334. * @driver_image_handle handle of the driver
  1335. * @child_handle handle of the child to destroy
  1336. * @return status code
  1337. */
  1338. static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
  1339. void *driver_image_handle,
  1340. void *child_handle)
  1341. {
  1342. EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
  1343. child_handle);
  1344. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1345. }
  1346. /*
  1347. * Close a protocol.
  1348. *
  1349. * This function implements the CloseProtocol service.
  1350. * See the Unified Extensible Firmware Interface (UEFI) specification
  1351. * for details.
  1352. *
  1353. * @handle handle on which the protocol shall be closed
  1354. * @protocol GUID of the protocol to close
  1355. * @agent_handle handle of the driver
  1356. * @controller_handle handle of the controller
  1357. * @return status code
  1358. */
  1359. static efi_status_t EFIAPI efi_close_protocol(void *handle,
  1360. const efi_guid_t *protocol,
  1361. void *agent_handle,
  1362. void *controller_handle)
  1363. {
  1364. EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, agent_handle,
  1365. controller_handle);
  1366. return EFI_EXIT(EFI_NOT_FOUND);
  1367. }
  1368. /*
  1369. * Provide information about then open status of a protocol on a handle
  1370. *
  1371. * This function implements the OpenProtocolInformation service.
  1372. * See the Unified Extensible Firmware Interface (UEFI) specification
  1373. * for details.
  1374. *
  1375. * @handle handle for which the information shall be retrieved
  1376. * @protocol GUID of the protocol
  1377. * @entry_buffer buffer to receive the open protocol information
  1378. * @entry_count number of entries available in the buffer
  1379. * @return status code
  1380. */
  1381. static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
  1382. const efi_guid_t *protocol,
  1383. struct efi_open_protocol_info_entry **entry_buffer,
  1384. unsigned long *entry_count)
  1385. {
  1386. EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, entry_buffer,
  1387. entry_count);
  1388. return EFI_EXIT(EFI_NOT_FOUND);
  1389. }
  1390. /*
  1391. * Get protocols installed on a handle.
  1392. *
  1393. * This function implements the ProtocolsPerHandleService.
  1394. * See the Unified Extensible Firmware Interface (UEFI) specification
  1395. * for details.
  1396. *
  1397. * @handle handle for which the information is retrieved
  1398. * @protocol_buffer buffer with protocol GUIDs
  1399. * @protocol_buffer_count number of entries in the buffer
  1400. * @return status code
  1401. */
  1402. static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
  1403. efi_guid_t ***protocol_buffer,
  1404. unsigned long *protocol_buffer_count)
  1405. {
  1406. unsigned long buffer_size;
  1407. struct efi_object *efiobj;
  1408. unsigned long i, j;
  1409. struct list_head *lhandle;
  1410. efi_status_t r;
  1411. EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
  1412. protocol_buffer_count);
  1413. if (!handle || !protocol_buffer || !protocol_buffer_count)
  1414. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1415. *protocol_buffer = NULL;
  1416. *protocol_buffer_count = 0;
  1417. list_for_each(lhandle, &efi_obj_list) {
  1418. efiobj = list_entry(lhandle, struct efi_object, link);
  1419. if (efiobj->handle != handle)
  1420. continue;
  1421. /* Count protocols */
  1422. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  1423. if (efiobj->protocols[i].guid)
  1424. ++*protocol_buffer_count;
  1425. }
  1426. /* Copy guids */
  1427. if (*protocol_buffer_count) {
  1428. buffer_size = sizeof(efi_guid_t *) *
  1429. *protocol_buffer_count;
  1430. r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
  1431. buffer_size,
  1432. (void **)protocol_buffer);
  1433. if (r != EFI_SUCCESS)
  1434. return EFI_EXIT(r);
  1435. j = 0;
  1436. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); ++i) {
  1437. if (efiobj->protocols[i].guid) {
  1438. (*protocol_buffer)[j] = (void *)
  1439. efiobj->protocols[i].guid;
  1440. ++j;
  1441. }
  1442. }
  1443. }
  1444. break;
  1445. }
  1446. return EFI_EXIT(EFI_SUCCESS);
  1447. }
  1448. /*
  1449. * Locate handles implementing a protocol.
  1450. *
  1451. * This function implements the LocateHandleBuffer service.
  1452. * See the Unified Extensible Firmware Interface (UEFI) specification
  1453. * for details.
  1454. *
  1455. * @search_type selection criterion
  1456. * @protocol GUID of the protocol
  1457. * @search_key registration key
  1458. * @no_handles number of returned handles
  1459. * @buffer buffer with the returned handles
  1460. * @return status code
  1461. */
  1462. static efi_status_t EFIAPI efi_locate_handle_buffer(
  1463. enum efi_locate_search_type search_type,
  1464. const efi_guid_t *protocol, void *search_key,
  1465. unsigned long *no_handles, efi_handle_t **buffer)
  1466. {
  1467. efi_status_t r;
  1468. unsigned long buffer_size = 0;
  1469. EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
  1470. no_handles, buffer);
  1471. if (!no_handles || !buffer) {
  1472. r = EFI_INVALID_PARAMETER;
  1473. goto out;
  1474. }
  1475. *no_handles = 0;
  1476. *buffer = NULL;
  1477. r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
  1478. *buffer);
  1479. if (r != EFI_BUFFER_TOO_SMALL)
  1480. goto out;
  1481. r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
  1482. (void **)buffer);
  1483. if (r != EFI_SUCCESS)
  1484. goto out;
  1485. r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
  1486. *buffer);
  1487. if (r == EFI_SUCCESS)
  1488. *no_handles = buffer_size / sizeof(void *);
  1489. out:
  1490. return EFI_EXIT(r);
  1491. }
  1492. /*
  1493. * Find an interface implementing a protocol.
  1494. *
  1495. * This function implements the LocateProtocol service.
  1496. * See the Unified Extensible Firmware Interface (UEFI) specification
  1497. * for details.
  1498. *
  1499. * @protocol GUID of the protocol
  1500. * @registration registration key passed to the notification function
  1501. * @protocol_interface interface implementing the protocol
  1502. * @return status code
  1503. */
  1504. static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,
  1505. void *registration,
  1506. void **protocol_interface)
  1507. {
  1508. struct list_head *lhandle;
  1509. int i;
  1510. EFI_ENTRY("%pUl, %p, %p", protocol, registration, protocol_interface);
  1511. if (!protocol || !protocol_interface)
  1512. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1513. EFI_PRINT_GUID("protocol", protocol);
  1514. list_for_each(lhandle, &efi_obj_list) {
  1515. struct efi_object *efiobj;
  1516. efiobj = list_entry(lhandle, struct efi_object, link);
  1517. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  1518. struct efi_handler *handler = &efiobj->protocols[i];
  1519. if (!handler->guid)
  1520. continue;
  1521. if (!guidcmp(handler->guid, protocol)) {
  1522. *protocol_interface =
  1523. handler->protocol_interface;
  1524. return EFI_EXIT(EFI_SUCCESS);
  1525. }
  1526. }
  1527. }
  1528. *protocol_interface = NULL;
  1529. return EFI_EXIT(EFI_NOT_FOUND);
  1530. }
  1531. /*
  1532. * Install multiple protocol interfaces.
  1533. *
  1534. * This function implements the MultipleProtocolInterfaces service.
  1535. * See the Unified Extensible Firmware Interface (UEFI) specification
  1536. * for details.
  1537. *
  1538. * @handle handle on which the protocol interfaces shall be installed
  1539. * @... NULL terminated argument list with pairs of protocol GUIDS and
  1540. * interfaces
  1541. * @return status code
  1542. */
  1543. static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
  1544. void **handle, ...)
  1545. {
  1546. EFI_ENTRY("%p", handle);
  1547. va_list argptr;
  1548. const efi_guid_t *protocol;
  1549. void *protocol_interface;
  1550. efi_status_t r = EFI_SUCCESS;
  1551. int i = 0;
  1552. if (!handle)
  1553. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1554. va_start(argptr, handle);
  1555. for (;;) {
  1556. protocol = va_arg(argptr, efi_guid_t*);
  1557. if (!protocol)
  1558. break;
  1559. protocol_interface = va_arg(argptr, void*);
  1560. r = EFI_CALL(efi_install_protocol_interface(
  1561. handle, protocol,
  1562. EFI_NATIVE_INTERFACE,
  1563. protocol_interface));
  1564. if (r != EFI_SUCCESS)
  1565. break;
  1566. i++;
  1567. }
  1568. va_end(argptr);
  1569. if (r == EFI_SUCCESS)
  1570. return EFI_EXIT(r);
  1571. /* If an error occured undo all changes. */
  1572. va_start(argptr, handle);
  1573. for (; i; --i) {
  1574. protocol = va_arg(argptr, efi_guid_t*);
  1575. protocol_interface = va_arg(argptr, void*);
  1576. EFI_CALL(efi_uninstall_protocol_interface(handle, protocol,
  1577. protocol_interface));
  1578. }
  1579. va_end(argptr);
  1580. return EFI_EXIT(r);
  1581. }
  1582. /*
  1583. * Uninstall multiple protocol interfaces.
  1584. *
  1585. * This function implements the UninstallMultipleProtocolInterfaces service.
  1586. * See the Unified Extensible Firmware Interface (UEFI) specification
  1587. * for details.
  1588. *
  1589. * @handle handle from which the protocol interfaces shall be removed
  1590. * @... NULL terminated argument list with pairs of protocol GUIDS and
  1591. * interfaces
  1592. * @return status code
  1593. */
  1594. static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
  1595. void *handle, ...)
  1596. {
  1597. EFI_ENTRY("%p", handle);
  1598. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1599. }
  1600. /*
  1601. * Calculate cyclic redundancy code.
  1602. *
  1603. * This function implements the CalculateCrc32 service.
  1604. * See the Unified Extensible Firmware Interface (UEFI) specification
  1605. * for details.
  1606. *
  1607. * @data buffer with data
  1608. * @data_size size of buffer in bytes
  1609. * @crc32_p cyclic redundancy code
  1610. * @return status code
  1611. */
  1612. static efi_status_t EFIAPI efi_calculate_crc32(void *data,
  1613. unsigned long data_size,
  1614. uint32_t *crc32_p)
  1615. {
  1616. EFI_ENTRY("%p, %ld", data, data_size);
  1617. *crc32_p = crc32(0, data, data_size);
  1618. return EFI_EXIT(EFI_SUCCESS);
  1619. }
  1620. /*
  1621. * Copy memory.
  1622. *
  1623. * This function implements the CopyMem service.
  1624. * See the Unified Extensible Firmware Interface (UEFI) specification
  1625. * for details.
  1626. *
  1627. * @destination destination of the copy operation
  1628. * @source source of the copy operation
  1629. * @length number of bytes to copy
  1630. */
  1631. static void EFIAPI efi_copy_mem(void *destination, const void *source,
  1632. size_t length)
  1633. {
  1634. EFI_ENTRY("%p, %p, %ld", destination, source, (unsigned long)length);
  1635. memcpy(destination, source, length);
  1636. EFI_EXIT(EFI_SUCCESS);
  1637. }
  1638. /*
  1639. * Fill memory with a byte value.
  1640. *
  1641. * This function implements the SetMem service.
  1642. * See the Unified Extensible Firmware Interface (UEFI) specification
  1643. * for details.
  1644. *
  1645. * @buffer buffer to fill
  1646. * @size size of buffer in bytes
  1647. * @value byte to copy to the buffer
  1648. */
  1649. static void EFIAPI efi_set_mem(void *buffer, size_t size, uint8_t value)
  1650. {
  1651. EFI_ENTRY("%p, %ld, 0x%x", buffer, (unsigned long)size, value);
  1652. memset(buffer, value, size);
  1653. EFI_EXIT(EFI_SUCCESS);
  1654. }
  1655. /*
  1656. * Open protocol interface on a handle.
  1657. *
  1658. * This function implements the OpenProtocol interface.
  1659. * See the Unified Extensible Firmware Interface (UEFI) specification
  1660. * for details.
  1661. *
  1662. * @handle handle on which the protocol shall be opened
  1663. * @protocol GUID of the protocol
  1664. * @protocol_interface interface implementing the protocol
  1665. * @agent_handle handle of the driver
  1666. * @controller_handle handle of the controller
  1667. * @attributes attributes indicating how to open the protocol
  1668. * @return status code
  1669. */
  1670. static efi_status_t EFIAPI efi_open_protocol(
  1671. void *handle, const efi_guid_t *protocol,
  1672. void **protocol_interface, void *agent_handle,
  1673. void *controller_handle, uint32_t attributes)
  1674. {
  1675. struct list_head *lhandle;
  1676. int i;
  1677. efi_status_t r = EFI_INVALID_PARAMETER;
  1678. EFI_ENTRY("%p, %pUl, %p, %p, %p, 0x%x", handle, protocol,
  1679. protocol_interface, agent_handle, controller_handle,
  1680. attributes);
  1681. if (!handle || !protocol ||
  1682. (!protocol_interface && attributes !=
  1683. EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
  1684. goto out;
  1685. }
  1686. EFI_PRINT_GUID("protocol", protocol);
  1687. switch (attributes) {
  1688. case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
  1689. case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
  1690. case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
  1691. break;
  1692. case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
  1693. if (controller_handle == handle)
  1694. goto out;
  1695. case EFI_OPEN_PROTOCOL_BY_DRIVER:
  1696. case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
  1697. if (controller_handle == NULL)
  1698. goto out;
  1699. case EFI_OPEN_PROTOCOL_EXCLUSIVE:
  1700. if (agent_handle == NULL)
  1701. goto out;
  1702. break;
  1703. default:
  1704. goto out;
  1705. }
  1706. list_for_each(lhandle, &efi_obj_list) {
  1707. struct efi_object *efiobj;
  1708. efiobj = list_entry(lhandle, struct efi_object, link);
  1709. if (efiobj->handle != handle)
  1710. continue;
  1711. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  1712. struct efi_handler *handler = &efiobj->protocols[i];
  1713. const efi_guid_t *hprotocol = handler->guid;
  1714. if (!hprotocol)
  1715. continue;
  1716. if (!guidcmp(hprotocol, protocol)) {
  1717. if (attributes !=
  1718. EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
  1719. *protocol_interface =
  1720. handler->protocol_interface;
  1721. }
  1722. r = EFI_SUCCESS;
  1723. goto out;
  1724. }
  1725. }
  1726. goto unsupported;
  1727. }
  1728. unsupported:
  1729. r = EFI_UNSUPPORTED;
  1730. out:
  1731. return EFI_EXIT(r);
  1732. }
  1733. /*
  1734. * Get interface of a protocol on a handle.
  1735. *
  1736. * This function implements the HandleProtocol service.
  1737. * See the Unified Extensible Firmware Interface (UEFI) specification
  1738. * for details.
  1739. *
  1740. * @handle handle on which the protocol shall be opened
  1741. * @protocol GUID of the protocol
  1742. * @protocol_interface interface implementing the protocol
  1743. * @return status code
  1744. */
  1745. static efi_status_t EFIAPI efi_handle_protocol(void *handle,
  1746. const efi_guid_t *protocol,
  1747. void **protocol_interface)
  1748. {
  1749. return efi_open_protocol(handle, protocol, protocol_interface, NULL,
  1750. NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
  1751. }
  1752. static const struct efi_boot_services efi_boot_services = {
  1753. .hdr = {
  1754. .headersize = sizeof(struct efi_table_hdr),
  1755. },
  1756. .raise_tpl = efi_raise_tpl,
  1757. .restore_tpl = efi_restore_tpl,
  1758. .allocate_pages = efi_allocate_pages_ext,
  1759. .free_pages = efi_free_pages_ext,
  1760. .get_memory_map = efi_get_memory_map_ext,
  1761. .allocate_pool = efi_allocate_pool_ext,
  1762. .free_pool = efi_free_pool_ext,
  1763. .create_event = efi_create_event_ext,
  1764. .set_timer = efi_set_timer_ext,
  1765. .wait_for_event = efi_wait_for_event,
  1766. .signal_event = efi_signal_event_ext,
  1767. .close_event = efi_close_event,
  1768. .check_event = efi_check_event,
  1769. .install_protocol_interface = efi_install_protocol_interface,
  1770. .reinstall_protocol_interface = efi_reinstall_protocol_interface,
  1771. .uninstall_protocol_interface = efi_uninstall_protocol_interface,
  1772. .handle_protocol = efi_handle_protocol,
  1773. .reserved = NULL,
  1774. .register_protocol_notify = efi_register_protocol_notify,
  1775. .locate_handle = efi_locate_handle_ext,
  1776. .locate_device_path = efi_locate_device_path,
  1777. .install_configuration_table = efi_install_configuration_table_ext,
  1778. .load_image = efi_load_image,
  1779. .start_image = efi_start_image,
  1780. .exit = efi_exit,
  1781. .unload_image = efi_unload_image,
  1782. .exit_boot_services = efi_exit_boot_services,
  1783. .get_next_monotonic_count = efi_get_next_monotonic_count,
  1784. .stall = efi_stall,
  1785. .set_watchdog_timer = efi_set_watchdog_timer,
  1786. .connect_controller = efi_connect_controller,
  1787. .disconnect_controller = efi_disconnect_controller,
  1788. .open_protocol = efi_open_protocol,
  1789. .close_protocol = efi_close_protocol,
  1790. .open_protocol_information = efi_open_protocol_information,
  1791. .protocols_per_handle = efi_protocols_per_handle,
  1792. .locate_handle_buffer = efi_locate_handle_buffer,
  1793. .locate_protocol = efi_locate_protocol,
  1794. .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
  1795. .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
  1796. .calculate_crc32 = efi_calculate_crc32,
  1797. .copy_mem = efi_copy_mem,
  1798. .set_mem = efi_set_mem,
  1799. };
  1800. static uint16_t __efi_runtime_data firmware_vendor[] =
  1801. { 'D','a','s',' ','U','-','b','o','o','t',0 };
  1802. struct efi_system_table __efi_runtime_data systab = {
  1803. .hdr = {
  1804. .signature = EFI_SYSTEM_TABLE_SIGNATURE,
  1805. .revision = 0x20005, /* 2.5 */
  1806. .headersize = sizeof(struct efi_table_hdr),
  1807. },
  1808. .fw_vendor = (long)firmware_vendor,
  1809. .con_in = (void*)&efi_con_in,
  1810. .con_out = (void*)&efi_con_out,
  1811. .std_err = (void*)&efi_con_out,
  1812. .runtime = (void*)&efi_runtime_services,
  1813. .boottime = (void*)&efi_boot_services,
  1814. .nr_tables = 0,
  1815. .tables = (void*)efi_conf_table,
  1816. };