efi_boottime.c 54 KB

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