efi_boottime.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577
  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. /* GUID of the EFI_DRIVER_BINDING_PROTOCOL */
  52. const efi_guid_t efi_guid_driver_binding_protocol =
  53. EFI_DRIVER_BINDING_PROTOCOL_GUID;
  54. /* Called on every callback entry */
  55. int __efi_entry_check(void)
  56. {
  57. int ret = entry_count++ == 0;
  58. #ifdef CONFIG_ARM
  59. assert(efi_gd);
  60. app_gd = gd;
  61. gd = efi_gd;
  62. #endif
  63. return ret;
  64. }
  65. /* Called on every callback exit */
  66. int __efi_exit_check(void)
  67. {
  68. int ret = --entry_count == 0;
  69. #ifdef CONFIG_ARM
  70. gd = app_gd;
  71. #endif
  72. return ret;
  73. }
  74. /* Called from do_bootefi_exec() */
  75. void efi_save_gd(void)
  76. {
  77. #ifdef CONFIG_ARM
  78. efi_gd = gd;
  79. #endif
  80. }
  81. /*
  82. * Special case handler for error/abort that just forces things back
  83. * to u-boot world so we can dump out an abort msg, without any care
  84. * about returning back to UEFI world.
  85. */
  86. void efi_restore_gd(void)
  87. {
  88. #ifdef CONFIG_ARM
  89. /* Only restore if we're already in EFI context */
  90. if (!efi_gd)
  91. return;
  92. gd = efi_gd;
  93. #endif
  94. }
  95. /*
  96. * Two spaces per indent level, maxing out at 10.. which ought to be
  97. * enough for anyone ;-)
  98. */
  99. static const char *indent_string(int level)
  100. {
  101. const char *indent = " ";
  102. const int max = strlen(indent);
  103. level = min(max, level * 2);
  104. return &indent[max - level];
  105. }
  106. const char *__efi_nesting(void)
  107. {
  108. return indent_string(nesting_level);
  109. }
  110. const char *__efi_nesting_inc(void)
  111. {
  112. return indent_string(nesting_level++);
  113. }
  114. const char *__efi_nesting_dec(void)
  115. {
  116. return indent_string(--nesting_level);
  117. }
  118. /*
  119. * Queue an EFI event.
  120. *
  121. * This function queues the notification function of the event for future
  122. * execution.
  123. *
  124. * The notification function is called if the task priority level of the
  125. * event is higher than the current task priority level.
  126. *
  127. * For the SignalEvent service see efi_signal_event_ext.
  128. *
  129. * @event event to signal
  130. */
  131. void efi_signal_event(struct efi_event *event)
  132. {
  133. if (event->notify_function) {
  134. event->is_queued = true;
  135. /* Check TPL */
  136. if (efi_tpl >= event->notify_tpl)
  137. return;
  138. EFI_CALL_VOID(event->notify_function(event,
  139. event->notify_context));
  140. }
  141. event->is_queued = false;
  142. }
  143. /*
  144. * Raise the task priority level.
  145. *
  146. * This function implements the RaiseTpl service.
  147. * See the Unified Extensible Firmware Interface (UEFI) specification
  148. * for details.
  149. *
  150. * @new_tpl new value of the task priority level
  151. * @return old value of the task priority level
  152. */
  153. static unsigned long EFIAPI efi_raise_tpl(efi_uintn_t new_tpl)
  154. {
  155. efi_uintn_t old_tpl = efi_tpl;
  156. EFI_ENTRY("0x%zx", new_tpl);
  157. if (new_tpl < efi_tpl)
  158. debug("WARNING: new_tpl < current_tpl in %s\n", __func__);
  159. efi_tpl = new_tpl;
  160. if (efi_tpl > TPL_HIGH_LEVEL)
  161. efi_tpl = TPL_HIGH_LEVEL;
  162. EFI_EXIT(EFI_SUCCESS);
  163. return old_tpl;
  164. }
  165. /*
  166. * Lower the task priority level.
  167. *
  168. * This function implements the RestoreTpl service.
  169. * See the Unified Extensible Firmware Interface (UEFI) specification
  170. * for details.
  171. *
  172. * @old_tpl value of the task priority level to be restored
  173. */
  174. static void EFIAPI efi_restore_tpl(efi_uintn_t old_tpl)
  175. {
  176. EFI_ENTRY("0x%zx", old_tpl);
  177. if (old_tpl > efi_tpl)
  178. debug("WARNING: old_tpl > current_tpl in %s\n", __func__);
  179. efi_tpl = old_tpl;
  180. if (efi_tpl > TPL_HIGH_LEVEL)
  181. efi_tpl = TPL_HIGH_LEVEL;
  182. EFI_EXIT(EFI_SUCCESS);
  183. }
  184. /*
  185. * Allocate memory pages.
  186. *
  187. * This function implements the AllocatePages service.
  188. * See the Unified Extensible Firmware Interface (UEFI) specification
  189. * for details.
  190. *
  191. * @type type of allocation to be performed
  192. * @memory_type usage type of the allocated memory
  193. * @pages number of pages to be allocated
  194. * @memory allocated memory
  195. * @return status code
  196. */
  197. static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
  198. efi_uintn_t pages,
  199. uint64_t *memory)
  200. {
  201. efi_status_t r;
  202. EFI_ENTRY("%d, %d, 0x%zx, %p", type, memory_type, pages, memory);
  203. r = efi_allocate_pages(type, memory_type, pages, memory);
  204. return EFI_EXIT(r);
  205. }
  206. /*
  207. * Free memory pages.
  208. *
  209. * This function implements the FreePages service.
  210. * See the Unified Extensible Firmware Interface (UEFI) specification
  211. * for details.
  212. *
  213. * @memory start of the memory area to be freed
  214. * @pages number of pages to be freed
  215. * @return status code
  216. */
  217. static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory,
  218. efi_uintn_t pages)
  219. {
  220. efi_status_t r;
  221. EFI_ENTRY("%"PRIx64", 0x%zx", memory, pages);
  222. r = efi_free_pages(memory, pages);
  223. return EFI_EXIT(r);
  224. }
  225. /*
  226. * Get map describing memory usage.
  227. *
  228. * This function implements the GetMemoryMap service.
  229. * See the Unified Extensible Firmware Interface (UEFI) specification
  230. * for details.
  231. *
  232. * @memory_map_size on entry the size, in bytes, of the memory map buffer,
  233. * on exit the size of the copied memory map
  234. * @memory_map buffer to which the memory map is written
  235. * @map_key key for the memory map
  236. * @descriptor_size size of an individual memory descriptor
  237. * @descriptor_version version number of the memory descriptor structure
  238. * @return status code
  239. */
  240. static efi_status_t EFIAPI efi_get_memory_map_ext(
  241. efi_uintn_t *memory_map_size,
  242. struct efi_mem_desc *memory_map,
  243. efi_uintn_t *map_key,
  244. efi_uintn_t *descriptor_size,
  245. uint32_t *descriptor_version)
  246. {
  247. efi_status_t r;
  248. EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map,
  249. map_key, descriptor_size, descriptor_version);
  250. r = efi_get_memory_map(memory_map_size, memory_map, map_key,
  251. descriptor_size, descriptor_version);
  252. return EFI_EXIT(r);
  253. }
  254. /*
  255. * Allocate memory from pool.
  256. *
  257. * This function implements the AllocatePool service.
  258. * See the Unified Extensible Firmware Interface (UEFI) specification
  259. * for details.
  260. *
  261. * @pool_type type of the pool from which memory is to be allocated
  262. * @size number of bytes to be allocated
  263. * @buffer allocated memory
  264. * @return status code
  265. */
  266. static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
  267. efi_uintn_t size,
  268. void **buffer)
  269. {
  270. efi_status_t r;
  271. EFI_ENTRY("%d, %zd, %p", pool_type, size, buffer);
  272. r = efi_allocate_pool(pool_type, size, buffer);
  273. return EFI_EXIT(r);
  274. }
  275. /*
  276. * Free memory from pool.
  277. *
  278. * This function implements the FreePool service.
  279. * See the Unified Extensible Firmware Interface (UEFI) specification
  280. * for details.
  281. *
  282. * @buffer start of memory to be freed
  283. * @return status code
  284. */
  285. static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
  286. {
  287. efi_status_t r;
  288. EFI_ENTRY("%p", buffer);
  289. r = efi_free_pool(buffer);
  290. return EFI_EXIT(r);
  291. }
  292. /*
  293. * Add a new object to the object list.
  294. *
  295. * The protocols list is initialized.
  296. * The object handle is set.
  297. *
  298. * @obj object to be added
  299. */
  300. void efi_add_handle(struct efi_object *obj)
  301. {
  302. if (!obj)
  303. return;
  304. INIT_LIST_HEAD(&obj->protocols);
  305. obj->handle = obj;
  306. list_add_tail(&obj->link, &efi_obj_list);
  307. }
  308. /*
  309. * Create handle.
  310. *
  311. * @handle new handle
  312. * @return status code
  313. */
  314. efi_status_t efi_create_handle(void **handle)
  315. {
  316. struct efi_object *obj;
  317. efi_status_t r;
  318. r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
  319. sizeof(struct efi_object),
  320. (void **)&obj);
  321. if (r != EFI_SUCCESS)
  322. return r;
  323. efi_add_handle(obj);
  324. *handle = obj->handle;
  325. return r;
  326. }
  327. /*
  328. * Find a protocol on a handle.
  329. *
  330. * @handle handle
  331. * @protocol_guid GUID of the protocol
  332. * @handler reference to the protocol
  333. * @return status code
  334. */
  335. efi_status_t efi_search_protocol(const void *handle,
  336. const efi_guid_t *protocol_guid,
  337. struct efi_handler **handler)
  338. {
  339. struct efi_object *efiobj;
  340. struct list_head *lhandle;
  341. if (!handle || !protocol_guid)
  342. return EFI_INVALID_PARAMETER;
  343. efiobj = efi_search_obj(handle);
  344. if (!efiobj)
  345. return EFI_INVALID_PARAMETER;
  346. list_for_each(lhandle, &efiobj->protocols) {
  347. struct efi_handler *protocol;
  348. protocol = list_entry(lhandle, struct efi_handler, link);
  349. if (!guidcmp(protocol->guid, protocol_guid)) {
  350. if (handler)
  351. *handler = protocol;
  352. return EFI_SUCCESS;
  353. }
  354. }
  355. return EFI_NOT_FOUND;
  356. }
  357. /*
  358. * Delete protocol from a handle.
  359. *
  360. * @handle handle from which the protocol shall be deleted
  361. * @protocol GUID of the protocol to be deleted
  362. * @protocol_interface interface of the protocol implementation
  363. * @return status code
  364. */
  365. efi_status_t efi_remove_protocol(const void *handle, const efi_guid_t *protocol,
  366. void *protocol_interface)
  367. {
  368. struct efi_handler *handler;
  369. efi_status_t ret;
  370. ret = efi_search_protocol(handle, protocol, &handler);
  371. if (ret != EFI_SUCCESS)
  372. return ret;
  373. if (guidcmp(handler->guid, protocol))
  374. return EFI_INVALID_PARAMETER;
  375. list_del(&handler->link);
  376. free(handler);
  377. return EFI_SUCCESS;
  378. }
  379. /*
  380. * Delete all protocols from a handle.
  381. *
  382. * @handle handle from which the protocols shall be deleted
  383. * @return status code
  384. */
  385. efi_status_t efi_remove_all_protocols(const void *handle)
  386. {
  387. struct efi_object *efiobj;
  388. struct efi_handler *protocol;
  389. struct efi_handler *pos;
  390. efiobj = efi_search_obj(handle);
  391. if (!efiobj)
  392. return EFI_INVALID_PARAMETER;
  393. list_for_each_entry_safe(protocol, pos, &efiobj->protocols, link) {
  394. efi_status_t ret;
  395. ret = efi_remove_protocol(handle, protocol->guid,
  396. protocol->protocol_interface);
  397. if (ret != EFI_SUCCESS)
  398. return ret;
  399. }
  400. return EFI_SUCCESS;
  401. }
  402. /*
  403. * Delete handle.
  404. *
  405. * @handle handle to delete
  406. */
  407. void efi_delete_handle(struct efi_object *obj)
  408. {
  409. if (!obj)
  410. return;
  411. efi_remove_all_protocols(obj->handle);
  412. list_del(&obj->link);
  413. free(obj);
  414. }
  415. /*
  416. * Our event capabilities are very limited. Only a small limited
  417. * number of events is allowed to coexist.
  418. */
  419. static struct efi_event efi_events[16];
  420. /*
  421. * Create an event.
  422. *
  423. * This function is used inside U-Boot code to create an event.
  424. *
  425. * For the API function implementing the CreateEvent service see
  426. * efi_create_event_ext.
  427. *
  428. * @type type of the event to create
  429. * @notify_tpl task priority level of the event
  430. * @notify_function notification function of the event
  431. * @notify_context pointer passed to the notification function
  432. * @event created event
  433. * @return status code
  434. */
  435. efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl,
  436. void (EFIAPI *notify_function) (
  437. struct efi_event *event,
  438. void *context),
  439. void *notify_context, struct efi_event **event)
  440. {
  441. int i;
  442. if (event == NULL)
  443. return EFI_INVALID_PARAMETER;
  444. if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
  445. return EFI_INVALID_PARAMETER;
  446. if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
  447. notify_function == NULL)
  448. return EFI_INVALID_PARAMETER;
  449. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  450. if (efi_events[i].type)
  451. continue;
  452. efi_events[i].type = type;
  453. efi_events[i].notify_tpl = notify_tpl;
  454. efi_events[i].notify_function = notify_function;
  455. efi_events[i].notify_context = notify_context;
  456. /* Disable timers on bootup */
  457. efi_events[i].trigger_next = -1ULL;
  458. efi_events[i].is_queued = false;
  459. efi_events[i].is_signaled = false;
  460. *event = &efi_events[i];
  461. return EFI_SUCCESS;
  462. }
  463. return EFI_OUT_OF_RESOURCES;
  464. }
  465. /*
  466. * Create an event.
  467. *
  468. * This function implements the CreateEvent service.
  469. * See the Unified Extensible Firmware Interface (UEFI) specification
  470. * for details.
  471. *
  472. * @type type of the event to create
  473. * @notify_tpl task priority level of the event
  474. * @notify_function notification function of the event
  475. * @notify_context pointer passed to the notification function
  476. * @event created event
  477. * @return status code
  478. */
  479. static efi_status_t EFIAPI efi_create_event_ext(
  480. uint32_t type, efi_uintn_t notify_tpl,
  481. void (EFIAPI *notify_function) (
  482. struct efi_event *event,
  483. void *context),
  484. void *notify_context, struct efi_event **event)
  485. {
  486. EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function,
  487. notify_context);
  488. return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function,
  489. notify_context, event));
  490. }
  491. /*
  492. * Check if a timer event has occurred or a queued notification function should
  493. * be called.
  494. *
  495. * Our timers have to work without interrupts, so we check whenever keyboard
  496. * input or disk accesses happen if enough time elapsed for them to fire.
  497. */
  498. void efi_timer_check(void)
  499. {
  500. int i;
  501. u64 now = timer_get_us();
  502. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  503. if (!efi_events[i].type)
  504. continue;
  505. if (efi_events[i].is_queued)
  506. efi_signal_event(&efi_events[i]);
  507. if (!(efi_events[i].type & EVT_TIMER) ||
  508. now < efi_events[i].trigger_next)
  509. continue;
  510. switch (efi_events[i].trigger_type) {
  511. case EFI_TIMER_RELATIVE:
  512. efi_events[i].trigger_type = EFI_TIMER_STOP;
  513. break;
  514. case EFI_TIMER_PERIODIC:
  515. efi_events[i].trigger_next +=
  516. efi_events[i].trigger_time;
  517. break;
  518. default:
  519. continue;
  520. }
  521. efi_events[i].is_signaled = true;
  522. efi_signal_event(&efi_events[i]);
  523. }
  524. WATCHDOG_RESET();
  525. }
  526. /*
  527. * Set the trigger time for a timer event or stop the event.
  528. *
  529. * This is the function for internal usage in U-Boot. For the API function
  530. * implementing the SetTimer service see efi_set_timer_ext.
  531. *
  532. * @event event for which the timer is set
  533. * @type type of the timer
  534. * @trigger_time trigger period in multiples of 100ns
  535. * @return status code
  536. */
  537. efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
  538. uint64_t trigger_time)
  539. {
  540. int i;
  541. /*
  542. * The parameter defines a multiple of 100ns.
  543. * We use multiples of 1000ns. So divide by 10.
  544. */
  545. do_div(trigger_time, 10);
  546. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  547. if (event != &efi_events[i])
  548. continue;
  549. if (!(event->type & EVT_TIMER))
  550. break;
  551. switch (type) {
  552. case EFI_TIMER_STOP:
  553. event->trigger_next = -1ULL;
  554. break;
  555. case EFI_TIMER_PERIODIC:
  556. case EFI_TIMER_RELATIVE:
  557. event->trigger_next =
  558. timer_get_us() + trigger_time;
  559. break;
  560. default:
  561. return EFI_INVALID_PARAMETER;
  562. }
  563. event->trigger_type = type;
  564. event->trigger_time = trigger_time;
  565. event->is_signaled = false;
  566. return EFI_SUCCESS;
  567. }
  568. return EFI_INVALID_PARAMETER;
  569. }
  570. /*
  571. * Set the trigger time for a timer event or stop the event.
  572. *
  573. * This function implements the SetTimer service.
  574. * See the Unified Extensible Firmware Interface (UEFI) specification
  575. * for details.
  576. *
  577. * @event event for which the timer is set
  578. * @type type of the timer
  579. * @trigger_time trigger period in multiples of 100ns
  580. * @return status code
  581. */
  582. static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event,
  583. enum efi_timer_delay type,
  584. uint64_t trigger_time)
  585. {
  586. EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
  587. return EFI_EXIT(efi_set_timer(event, type, trigger_time));
  588. }
  589. /*
  590. * Wait for events to be signaled.
  591. *
  592. * This function implements the WaitForEvent service.
  593. * See the Unified Extensible Firmware Interface (UEFI) specification
  594. * for details.
  595. *
  596. * @num_events number of events to be waited for
  597. * @events events to be waited for
  598. * @index index of the event that was signaled
  599. * @return status code
  600. */
  601. static efi_status_t EFIAPI efi_wait_for_event(efi_uintn_t num_events,
  602. struct efi_event **event,
  603. efi_uintn_t *index)
  604. {
  605. int i, j;
  606. EFI_ENTRY("%zd, %p, %p", num_events, event, index);
  607. /* Check parameters */
  608. if (!num_events || !event)
  609. return EFI_EXIT(EFI_INVALID_PARAMETER);
  610. /* Check TPL */
  611. if (efi_tpl != TPL_APPLICATION)
  612. return EFI_EXIT(EFI_UNSUPPORTED);
  613. for (i = 0; i < num_events; ++i) {
  614. for (j = 0; j < ARRAY_SIZE(efi_events); ++j) {
  615. if (event[i] == &efi_events[j])
  616. goto known_event;
  617. }
  618. return EFI_EXIT(EFI_INVALID_PARAMETER);
  619. known_event:
  620. if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL)
  621. return EFI_EXIT(EFI_INVALID_PARAMETER);
  622. if (!event[i]->is_signaled)
  623. efi_signal_event(event[i]);
  624. }
  625. /* Wait for signal */
  626. for (;;) {
  627. for (i = 0; i < num_events; ++i) {
  628. if (event[i]->is_signaled)
  629. goto out;
  630. }
  631. /* Allow events to occur. */
  632. efi_timer_check();
  633. }
  634. out:
  635. /*
  636. * Reset the signal which is passed to the caller to allow periodic
  637. * events to occur.
  638. */
  639. event[i]->is_signaled = false;
  640. if (index)
  641. *index = i;
  642. return EFI_EXIT(EFI_SUCCESS);
  643. }
  644. /*
  645. * Signal an EFI event.
  646. *
  647. * This function implements the SignalEvent service.
  648. * See the Unified Extensible Firmware Interface (UEFI) specification
  649. * for details.
  650. *
  651. * This functions sets the signaled state of the event and queues the
  652. * notification function for execution.
  653. *
  654. * @event event to signal
  655. * @return status code
  656. */
  657. static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event)
  658. {
  659. int i;
  660. EFI_ENTRY("%p", event);
  661. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  662. if (event != &efi_events[i])
  663. continue;
  664. if (event->is_signaled)
  665. break;
  666. event->is_signaled = true;
  667. if (event->type & EVT_NOTIFY_SIGNAL)
  668. efi_signal_event(event);
  669. break;
  670. }
  671. return EFI_EXIT(EFI_SUCCESS);
  672. }
  673. /*
  674. * Close an EFI event.
  675. *
  676. * This function implements the CloseEvent service.
  677. * See the Unified Extensible Firmware Interface (UEFI) specification
  678. * for details.
  679. *
  680. * @event event to close
  681. * @return status code
  682. */
  683. static efi_status_t EFIAPI efi_close_event(struct efi_event *event)
  684. {
  685. int i;
  686. EFI_ENTRY("%p", event);
  687. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  688. if (event == &efi_events[i]) {
  689. event->type = 0;
  690. event->trigger_next = -1ULL;
  691. event->is_queued = false;
  692. event->is_signaled = false;
  693. return EFI_EXIT(EFI_SUCCESS);
  694. }
  695. }
  696. return EFI_EXIT(EFI_INVALID_PARAMETER);
  697. }
  698. /*
  699. * Check if an event is signaled.
  700. *
  701. * This function implements the CheckEvent service.
  702. * See the Unified Extensible Firmware Interface (UEFI) specification
  703. * for details.
  704. *
  705. * If an event is not signaled yet the notification function is queued.
  706. *
  707. * @event event to check
  708. * @return status code
  709. */
  710. static efi_status_t EFIAPI efi_check_event(struct efi_event *event)
  711. {
  712. int i;
  713. EFI_ENTRY("%p", event);
  714. efi_timer_check();
  715. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  716. if (event != &efi_events[i])
  717. continue;
  718. if (!event->type || event->type & EVT_NOTIFY_SIGNAL)
  719. break;
  720. if (!event->is_signaled)
  721. efi_signal_event(event);
  722. if (event->is_signaled)
  723. return EFI_EXIT(EFI_SUCCESS);
  724. return EFI_EXIT(EFI_NOT_READY);
  725. }
  726. return EFI_EXIT(EFI_INVALID_PARAMETER);
  727. }
  728. /*
  729. * Find the internal EFI object for a handle.
  730. *
  731. * @handle handle to find
  732. * @return EFI object
  733. */
  734. struct efi_object *efi_search_obj(const void *handle)
  735. {
  736. struct efi_object *efiobj;
  737. list_for_each_entry(efiobj, &efi_obj_list, link) {
  738. if (efiobj->handle == handle)
  739. return efiobj;
  740. }
  741. return NULL;
  742. }
  743. /*
  744. * Create open protocol info entry and add it to a protocol.
  745. *
  746. * @handler handler of a protocol
  747. * @return open protocol info entry
  748. */
  749. static struct efi_open_protocol_info_entry *efi_create_open_info(
  750. struct efi_handler *handler)
  751. {
  752. struct efi_open_protocol_info_item *item;
  753. item = calloc(1, sizeof(struct efi_open_protocol_info_item));
  754. if (!item)
  755. return NULL;
  756. /* Append the item to the open protocol info list. */
  757. list_add_tail(&item->link, &handler->open_infos);
  758. return &item->info;
  759. }
  760. /*
  761. * Remove an open protocol info entry from a protocol.
  762. *
  763. * @handler handler of a protocol
  764. * @return status code
  765. */
  766. static efi_status_t efi_delete_open_info(
  767. struct efi_open_protocol_info_item *item)
  768. {
  769. list_del(&item->link);
  770. free(item);
  771. return EFI_SUCCESS;
  772. }
  773. /*
  774. * Install new protocol on a handle.
  775. *
  776. * @handle handle on which the protocol shall be installed
  777. * @protocol GUID of the protocol to be installed
  778. * @protocol_interface interface of the protocol implementation
  779. * @return status code
  780. */
  781. efi_status_t efi_add_protocol(const void *handle, const efi_guid_t *protocol,
  782. void *protocol_interface)
  783. {
  784. struct efi_object *efiobj;
  785. struct efi_handler *handler;
  786. efi_status_t ret;
  787. efiobj = efi_search_obj(handle);
  788. if (!efiobj)
  789. return EFI_INVALID_PARAMETER;
  790. ret = efi_search_protocol(handle, protocol, NULL);
  791. if (ret != EFI_NOT_FOUND)
  792. return EFI_INVALID_PARAMETER;
  793. handler = calloc(1, sizeof(struct efi_handler));
  794. if (!handler)
  795. return EFI_OUT_OF_RESOURCES;
  796. handler->guid = protocol;
  797. handler->protocol_interface = protocol_interface;
  798. INIT_LIST_HEAD(&handler->open_infos);
  799. list_add_tail(&handler->link, &efiobj->protocols);
  800. if (!guidcmp(&efi_guid_device_path, protocol))
  801. EFI_PRINT("installed device path '%pD'\n", protocol_interface);
  802. return EFI_SUCCESS;
  803. }
  804. /*
  805. * Install protocol interface.
  806. *
  807. * This function implements the InstallProtocolInterface service.
  808. * See the Unified Extensible Firmware Interface (UEFI) specification
  809. * for details.
  810. *
  811. * @handle handle on which the protocol shall be installed
  812. * @protocol GUID of the protocol to be installed
  813. * @protocol_interface_type type of the interface to be installed,
  814. * always EFI_NATIVE_INTERFACE
  815. * @protocol_interface interface of the protocol implementation
  816. * @return status code
  817. */
  818. static efi_status_t EFIAPI efi_install_protocol_interface(
  819. void **handle, const efi_guid_t *protocol,
  820. int protocol_interface_type, void *protocol_interface)
  821. {
  822. efi_status_t r;
  823. EFI_ENTRY("%p, %pUl, %d, %p", handle, protocol, protocol_interface_type,
  824. protocol_interface);
  825. if (!handle || !protocol ||
  826. protocol_interface_type != EFI_NATIVE_INTERFACE) {
  827. r = EFI_INVALID_PARAMETER;
  828. goto out;
  829. }
  830. /* Create new handle if requested. */
  831. if (!*handle) {
  832. r = efi_create_handle(handle);
  833. if (r != EFI_SUCCESS)
  834. goto out;
  835. debug("%sEFI: new handle %p\n", indent_string(nesting_level),
  836. *handle);
  837. } else {
  838. debug("%sEFI: handle %p\n", indent_string(nesting_level),
  839. *handle);
  840. }
  841. /* Add new protocol */
  842. r = efi_add_protocol(*handle, protocol, protocol_interface);
  843. out:
  844. return EFI_EXIT(r);
  845. }
  846. /*
  847. * Reinstall protocol interface.
  848. *
  849. * This function implements the ReinstallProtocolInterface service.
  850. * See the Unified Extensible Firmware Interface (UEFI) specification
  851. * for details.
  852. *
  853. * @handle handle on which the protocol shall be
  854. * reinstalled
  855. * @protocol GUID of the protocol to be installed
  856. * @old_interface interface to be removed
  857. * @new_interface interface to be installed
  858. * @return status code
  859. */
  860. static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
  861. const efi_guid_t *protocol, void *old_interface,
  862. void *new_interface)
  863. {
  864. EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, old_interface,
  865. new_interface);
  866. return EFI_EXIT(EFI_ACCESS_DENIED);
  867. }
  868. /*
  869. * Uninstall protocol interface.
  870. *
  871. * This function implements the UninstallProtocolInterface service.
  872. * See the Unified Extensible Firmware Interface (UEFI) specification
  873. * for details.
  874. *
  875. * @handle handle from which the protocol shall be removed
  876. * @protocol GUID of the protocol to be removed
  877. * @protocol_interface interface to be removed
  878. * @return status code
  879. */
  880. static efi_status_t EFIAPI efi_uninstall_protocol_interface(
  881. void *handle, const efi_guid_t *protocol,
  882. void *protocol_interface)
  883. {
  884. struct efi_handler *handler;
  885. efi_status_t r;
  886. EFI_ENTRY("%p, %pUl, %p", handle, protocol, protocol_interface);
  887. if (!handle || !protocol) {
  888. r = EFI_INVALID_PARAMETER;
  889. goto out;
  890. }
  891. /* Find the protocol on the handle */
  892. r = efi_search_protocol(handle, protocol, &handler);
  893. if (r != EFI_SUCCESS)
  894. goto out;
  895. if (handler->protocol_interface) {
  896. /* TODO disconnect controllers */
  897. r = EFI_ACCESS_DENIED;
  898. } else {
  899. r = efi_remove_protocol(handle, protocol, protocol_interface);
  900. }
  901. out:
  902. return EFI_EXIT(r);
  903. }
  904. /*
  905. * Register an event for notification when a protocol is installed.
  906. *
  907. * This function implements the RegisterProtocolNotify service.
  908. * See the Unified Extensible Firmware Interface (UEFI) specification
  909. * for details.
  910. *
  911. * @protocol GUID of the protocol whose installation shall be
  912. * notified
  913. * @event event to be signaled upon installation of the protocol
  914. * @registration key for retrieving the registration information
  915. * @return status code
  916. */
  917. static efi_status_t EFIAPI efi_register_protocol_notify(
  918. const efi_guid_t *protocol,
  919. struct efi_event *event,
  920. void **registration)
  921. {
  922. EFI_ENTRY("%pUl, %p, %p", protocol, event, registration);
  923. return EFI_EXIT(EFI_OUT_OF_RESOURCES);
  924. }
  925. /*
  926. * Determine if an EFI handle implements a protocol.
  927. *
  928. * See the documentation of the LocateHandle service in the UEFI specification.
  929. *
  930. * @search_type selection criterion
  931. * @protocol GUID of the protocol
  932. * @search_key registration key
  933. * @efiobj handle
  934. * @return 0 if the handle implements the protocol
  935. */
  936. static int efi_search(enum efi_locate_search_type search_type,
  937. const efi_guid_t *protocol, void *search_key,
  938. struct efi_object *efiobj)
  939. {
  940. efi_status_t ret;
  941. switch (search_type) {
  942. case ALL_HANDLES:
  943. return 0;
  944. case BY_REGISTER_NOTIFY:
  945. /* TODO: RegisterProtocolNotify is not implemented yet */
  946. return -1;
  947. case BY_PROTOCOL:
  948. ret = efi_search_protocol(efiobj->handle, protocol, NULL);
  949. return (ret != EFI_SUCCESS);
  950. default:
  951. /* Invalid search type */
  952. return -1;
  953. }
  954. }
  955. /*
  956. * Locate handles implementing a protocol.
  957. *
  958. * This function is meant for U-Boot internal calls. For the API implementation
  959. * of the LocateHandle service see efi_locate_handle_ext.
  960. *
  961. * @search_type selection criterion
  962. * @protocol GUID of the protocol
  963. * @search_key registration key
  964. * @buffer_size size of the buffer to receive the handles in bytes
  965. * @buffer buffer to receive the relevant handles
  966. * @return status code
  967. */
  968. static efi_status_t efi_locate_handle(
  969. enum efi_locate_search_type search_type,
  970. const efi_guid_t *protocol, void *search_key,
  971. efi_uintn_t *buffer_size, efi_handle_t *buffer)
  972. {
  973. struct efi_object *efiobj;
  974. efi_uintn_t size = 0;
  975. /* Check parameters */
  976. switch (search_type) {
  977. case ALL_HANDLES:
  978. break;
  979. case BY_REGISTER_NOTIFY:
  980. if (!search_key)
  981. return EFI_INVALID_PARAMETER;
  982. /* RegisterProtocolNotify is not implemented yet */
  983. return EFI_UNSUPPORTED;
  984. case BY_PROTOCOL:
  985. if (!protocol)
  986. return EFI_INVALID_PARAMETER;
  987. break;
  988. default:
  989. return EFI_INVALID_PARAMETER;
  990. }
  991. /*
  992. * efi_locate_handle_buffer uses this function for
  993. * the calculation of the necessary buffer size.
  994. * So do not require a buffer for buffersize == 0.
  995. */
  996. if (!buffer_size || (*buffer_size && !buffer))
  997. return EFI_INVALID_PARAMETER;
  998. /* Count how much space we need */
  999. list_for_each_entry(efiobj, &efi_obj_list, link) {
  1000. if (!efi_search(search_type, protocol, search_key, efiobj))
  1001. size += sizeof(void*);
  1002. }
  1003. if (*buffer_size < size) {
  1004. *buffer_size = size;
  1005. return EFI_BUFFER_TOO_SMALL;
  1006. }
  1007. *buffer_size = size;
  1008. if (size == 0)
  1009. return EFI_NOT_FOUND;
  1010. /* Then fill the array */
  1011. list_for_each_entry(efiobj, &efi_obj_list, link) {
  1012. if (!efi_search(search_type, protocol, search_key, efiobj))
  1013. *buffer++ = efiobj->handle;
  1014. }
  1015. return EFI_SUCCESS;
  1016. }
  1017. /*
  1018. * Locate handles implementing a protocol.
  1019. *
  1020. * This function implements the LocateHandle service.
  1021. * See the Unified Extensible Firmware Interface (UEFI) specification
  1022. * for details.
  1023. *
  1024. * @search_type selection criterion
  1025. * @protocol GUID of the protocol
  1026. * @search_key registration key
  1027. * @buffer_size size of the buffer to receive the handles in bytes
  1028. * @buffer buffer to receive the relevant handles
  1029. * @return 0 if the handle implements the protocol
  1030. */
  1031. static efi_status_t EFIAPI efi_locate_handle_ext(
  1032. enum efi_locate_search_type search_type,
  1033. const efi_guid_t *protocol, void *search_key,
  1034. efi_uintn_t *buffer_size, efi_handle_t *buffer)
  1035. {
  1036. EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
  1037. buffer_size, buffer);
  1038. return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
  1039. buffer_size, buffer));
  1040. }
  1041. /* Collapses configuration table entries, removing index i */
  1042. static void efi_remove_configuration_table(int i)
  1043. {
  1044. struct efi_configuration_table *this = &efi_conf_table[i];
  1045. struct efi_configuration_table *next = &efi_conf_table[i+1];
  1046. struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables];
  1047. memmove(this, next, (ulong)end - (ulong)next);
  1048. systab.nr_tables--;
  1049. }
  1050. /*
  1051. * Adds, updates, or removes a configuration table.
  1052. *
  1053. * This function is used for internal calls. For the API implementation of the
  1054. * InstallConfigurationTable service see efi_install_configuration_table_ext.
  1055. *
  1056. * @guid GUID of the installed table
  1057. * @table table to be installed
  1058. * @return status code
  1059. */
  1060. efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
  1061. {
  1062. int i;
  1063. /* Check for guid override */
  1064. for (i = 0; i < systab.nr_tables; i++) {
  1065. if (!guidcmp(guid, &efi_conf_table[i].guid)) {
  1066. if (table)
  1067. efi_conf_table[i].table = table;
  1068. else
  1069. efi_remove_configuration_table(i);
  1070. return EFI_SUCCESS;
  1071. }
  1072. }
  1073. if (!table)
  1074. return EFI_NOT_FOUND;
  1075. /* No override, check for overflow */
  1076. if (i >= ARRAY_SIZE(efi_conf_table))
  1077. return EFI_OUT_OF_RESOURCES;
  1078. /* Add a new entry */
  1079. memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
  1080. efi_conf_table[i].table = table;
  1081. systab.nr_tables = i + 1;
  1082. return EFI_SUCCESS;
  1083. }
  1084. /*
  1085. * Adds, updates, or removes a configuration table.
  1086. *
  1087. * This function implements the InstallConfigurationTable service.
  1088. * See the Unified Extensible Firmware Interface (UEFI) specification
  1089. * for details.
  1090. *
  1091. * @guid GUID of the installed table
  1092. * @table table to be installed
  1093. * @return status code
  1094. */
  1095. static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
  1096. void *table)
  1097. {
  1098. EFI_ENTRY("%pUl, %p", guid, table);
  1099. return EFI_EXIT(efi_install_configuration_table(guid, table));
  1100. }
  1101. /*
  1102. * Initialize a loaded_image_info + loaded_image_info object with correct
  1103. * protocols, boot-device, etc.
  1104. *
  1105. * @info loaded image info to be passed to the entry point of the
  1106. * image
  1107. * @obj internal object associated with the loaded image
  1108. * @device_path device path of the loaded image
  1109. * @file_path file path of the loaded image
  1110. * @return status code
  1111. */
  1112. efi_status_t efi_setup_loaded_image(
  1113. struct efi_loaded_image *info, struct efi_object *obj,
  1114. struct efi_device_path *device_path,
  1115. struct efi_device_path *file_path)
  1116. {
  1117. efi_status_t ret;
  1118. /* Add internal object to object list */
  1119. efi_add_handle(obj);
  1120. /* efi_exit() assumes that the handle points to the info */
  1121. obj->handle = info;
  1122. info->file_path = file_path;
  1123. if (device_path)
  1124. info->device_handle = efi_dp_find_obj(device_path, NULL);
  1125. /*
  1126. * When asking for the device path interface, return
  1127. * bootefi_device_path
  1128. */
  1129. ret = efi_add_protocol(obj->handle, &efi_guid_device_path, device_path);
  1130. if (ret != EFI_SUCCESS)
  1131. goto failure;
  1132. /*
  1133. * When asking for the loaded_image interface, just
  1134. * return handle which points to loaded_image_info
  1135. */
  1136. ret = efi_add_protocol(obj->handle, &efi_guid_loaded_image, info);
  1137. if (ret != EFI_SUCCESS)
  1138. goto failure;
  1139. ret = efi_add_protocol(obj->handle, &efi_guid_console_control,
  1140. (void *)&efi_console_control);
  1141. if (ret != EFI_SUCCESS)
  1142. goto failure;
  1143. ret = efi_add_protocol(obj->handle,
  1144. &efi_guid_device_path_to_text_protocol,
  1145. (void *)&efi_device_path_to_text);
  1146. if (ret != EFI_SUCCESS)
  1147. goto failure;
  1148. return ret;
  1149. failure:
  1150. printf("ERROR: Failure to install protocols for loaded image\n");
  1151. return ret;
  1152. }
  1153. /*
  1154. * Load an image using a file path.
  1155. *
  1156. * @file_path the path of the image to load
  1157. * @buffer buffer containing the loaded image
  1158. * @return status code
  1159. */
  1160. efi_status_t efi_load_image_from_path(struct efi_device_path *file_path,
  1161. void **buffer)
  1162. {
  1163. struct efi_file_info *info = NULL;
  1164. struct efi_file_handle *f;
  1165. static efi_status_t ret;
  1166. uint64_t bs;
  1167. f = efi_file_from_path(file_path);
  1168. if (!f)
  1169. return EFI_DEVICE_ERROR;
  1170. bs = 0;
  1171. EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
  1172. &bs, info));
  1173. if (ret == EFI_BUFFER_TOO_SMALL) {
  1174. info = malloc(bs);
  1175. EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
  1176. &bs, info));
  1177. }
  1178. if (ret != EFI_SUCCESS)
  1179. goto error;
  1180. ret = efi_allocate_pool(EFI_LOADER_DATA, info->file_size, buffer);
  1181. if (ret)
  1182. goto error;
  1183. EFI_CALL(ret = f->read(f, &info->file_size, *buffer));
  1184. error:
  1185. free(info);
  1186. EFI_CALL(f->close(f));
  1187. if (ret != EFI_SUCCESS) {
  1188. efi_free_pool(*buffer);
  1189. *buffer = NULL;
  1190. }
  1191. return ret;
  1192. }
  1193. /*
  1194. * Load an EFI image into memory.
  1195. *
  1196. * This function implements the LoadImage service.
  1197. * See the Unified Extensible Firmware Interface (UEFI) specification
  1198. * for details.
  1199. *
  1200. * @boot_policy true for request originating from the boot manager
  1201. * @parent_image the calles's image handle
  1202. * @file_path the path of the image to load
  1203. * @source_buffer memory location from which the image is installed
  1204. * @source_size size of the memory area from which the image is
  1205. * installed
  1206. * @image_handle handle for the newly installed image
  1207. * @return status code
  1208. */
  1209. static efi_status_t EFIAPI efi_load_image(bool boot_policy,
  1210. efi_handle_t parent_image,
  1211. struct efi_device_path *file_path,
  1212. void *source_buffer,
  1213. unsigned long source_size,
  1214. efi_handle_t *image_handle)
  1215. {
  1216. struct efi_loaded_image *info;
  1217. struct efi_object *obj;
  1218. efi_status_t ret;
  1219. EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
  1220. file_path, source_buffer, source_size, image_handle);
  1221. info = calloc(1, sizeof(*info));
  1222. obj = calloc(1, sizeof(*obj));
  1223. if (!source_buffer) {
  1224. struct efi_device_path *dp, *fp;
  1225. ret = efi_load_image_from_path(file_path, &source_buffer);
  1226. if (ret != EFI_SUCCESS)
  1227. goto failure;
  1228. /*
  1229. * split file_path which contains both the device and
  1230. * file parts:
  1231. */
  1232. efi_dp_split_file_path(file_path, &dp, &fp);
  1233. ret = efi_setup_loaded_image(info, obj, dp, fp);
  1234. if (ret != EFI_SUCCESS)
  1235. goto failure;
  1236. } else {
  1237. /* In this case, file_path is the "device" path, ie.
  1238. * something like a HARDWARE_DEVICE:MEMORY_MAPPED
  1239. */
  1240. ret = efi_setup_loaded_image(info, obj, file_path, NULL);
  1241. if (ret != EFI_SUCCESS)
  1242. goto failure;
  1243. }
  1244. info->reserved = efi_load_pe(source_buffer, info);
  1245. if (!info->reserved) {
  1246. ret = EFI_UNSUPPORTED;
  1247. goto failure;
  1248. }
  1249. info->system_table = &systab;
  1250. info->parent_handle = parent_image;
  1251. *image_handle = obj->handle;
  1252. return EFI_EXIT(EFI_SUCCESS);
  1253. failure:
  1254. free(info);
  1255. efi_delete_handle(obj);
  1256. return EFI_EXIT(ret);
  1257. }
  1258. /*
  1259. * Call the entry point of an image.
  1260. *
  1261. * This function implements the StartImage service.
  1262. * See the Unified Extensible Firmware Interface (UEFI) specification
  1263. * for details.
  1264. *
  1265. * @image_handle handle of the image
  1266. * @exit_data_size size of the buffer
  1267. * @exit_data buffer to receive the exit data of the called image
  1268. * @return status code
  1269. */
  1270. static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
  1271. unsigned long *exit_data_size,
  1272. s16 **exit_data)
  1273. {
  1274. ulong (*entry)(void *image_handle, struct efi_system_table *st);
  1275. struct efi_loaded_image *info = image_handle;
  1276. efi_status_t ret;
  1277. EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
  1278. entry = info->reserved;
  1279. efi_is_direct_boot = false;
  1280. /* call the image! */
  1281. if (setjmp(&info->exit_jmp)) {
  1282. /*
  1283. * We called the entry point of the child image with EFI_CALL
  1284. * in the lines below. The child image called the Exit() boot
  1285. * service efi_exit() which executed the long jump that brought
  1286. * us to the current line. This implies that the second half
  1287. * of the EFI_CALL macro has not been executed.
  1288. */
  1289. #ifdef CONFIG_ARM
  1290. /*
  1291. * efi_exit() called efi_restore_gd(). We have to undo this
  1292. * otherwise __efi_entry_check() will put the wrong value into
  1293. * app_gd.
  1294. */
  1295. gd = app_gd;
  1296. #endif
  1297. /*
  1298. * To get ready to call EFI_EXIT below we have to execute the
  1299. * missed out steps of EFI_CALL.
  1300. */
  1301. assert(__efi_entry_check());
  1302. debug("%sEFI: %lu returned by started image\n",
  1303. __efi_nesting_dec(),
  1304. (unsigned long)((uintptr_t)info->exit_status &
  1305. ~EFI_ERROR_MASK));
  1306. return EFI_EXIT(info->exit_status);
  1307. }
  1308. ret = EFI_CALL(entry(image_handle, &systab));
  1309. /* Should usually never get here */
  1310. return EFI_EXIT(ret);
  1311. }
  1312. /*
  1313. * Leave an EFI application or driver.
  1314. *
  1315. * This function implements the Exit service.
  1316. * See the Unified Extensible Firmware Interface (UEFI) specification
  1317. * for details.
  1318. *
  1319. * @image_handle handle of the application or driver that is exiting
  1320. * @exit_status status code
  1321. * @exit_data_size size of the buffer in bytes
  1322. * @exit_data buffer with data describing an error
  1323. * @return status code
  1324. */
  1325. static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
  1326. efi_status_t exit_status, unsigned long exit_data_size,
  1327. int16_t *exit_data)
  1328. {
  1329. /*
  1330. * We require that the handle points to the original loaded
  1331. * image protocol interface.
  1332. *
  1333. * For getting the longjmp address this is safer than locating
  1334. * the protocol because the protocol may have been reinstalled
  1335. * pointing to another memory location.
  1336. *
  1337. * TODO: We should call the unload procedure of the loaded
  1338. * image protocol.
  1339. */
  1340. struct efi_loaded_image *loaded_image_info = (void*)image_handle;
  1341. EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
  1342. exit_data_size, exit_data);
  1343. /* Make sure entry/exit counts for EFI world cross-overs match */
  1344. EFI_EXIT(exit_status);
  1345. /*
  1346. * But longjmp out with the U-Boot gd, not the application's, as
  1347. * the other end is a setjmp call inside EFI context.
  1348. */
  1349. efi_restore_gd();
  1350. loaded_image_info->exit_status = exit_status;
  1351. longjmp(&loaded_image_info->exit_jmp, 1);
  1352. panic("EFI application exited");
  1353. }
  1354. /*
  1355. * Unload an EFI image.
  1356. *
  1357. * This function implements the UnloadImage service.
  1358. * See the Unified Extensible Firmware Interface (UEFI) specification
  1359. * for details.
  1360. *
  1361. * @image_handle handle of the image to be unloaded
  1362. * @return status code
  1363. */
  1364. static efi_status_t EFIAPI efi_unload_image(void *image_handle)
  1365. {
  1366. struct efi_object *efiobj;
  1367. EFI_ENTRY("%p", image_handle);
  1368. efiobj = efi_search_obj(image_handle);
  1369. if (efiobj)
  1370. list_del(&efiobj->link);
  1371. return EFI_EXIT(EFI_SUCCESS);
  1372. }
  1373. /*
  1374. * Fix up caches for EFI payloads if necessary.
  1375. */
  1376. static void efi_exit_caches(void)
  1377. {
  1378. #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
  1379. /*
  1380. * Grub on 32bit ARM needs to have caches disabled before jumping into
  1381. * a zImage, but does not know of all cache layers. Give it a hand.
  1382. */
  1383. if (efi_is_direct_boot)
  1384. cleanup_before_linux();
  1385. #endif
  1386. }
  1387. /*
  1388. * Stop boot services.
  1389. *
  1390. * This function implements the ExitBootServices service.
  1391. * See the Unified Extensible Firmware Interface (UEFI) specification
  1392. * for details.
  1393. *
  1394. * @image_handle handle of the loaded image
  1395. * @map_key key of the memory map
  1396. * @return status code
  1397. */
  1398. static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
  1399. unsigned long map_key)
  1400. {
  1401. int i;
  1402. EFI_ENTRY("%p, %ld", image_handle, map_key);
  1403. /* Notify that ExitBootServices is invoked. */
  1404. for (i = 0; i < ARRAY_SIZE(efi_events); ++i) {
  1405. if (efi_events[i].type != EVT_SIGNAL_EXIT_BOOT_SERVICES)
  1406. continue;
  1407. efi_signal_event(&efi_events[i]);
  1408. }
  1409. /* Make sure that notification functions are not called anymore */
  1410. efi_tpl = TPL_HIGH_LEVEL;
  1411. /* XXX Should persist EFI variables here */
  1412. board_quiesce_devices();
  1413. /* Fix up caches for EFI payloads if necessary */
  1414. efi_exit_caches();
  1415. /* This stops all lingering devices */
  1416. bootm_disable_interrupts();
  1417. /* Give the payload some time to boot */
  1418. efi_set_watchdog(0);
  1419. WATCHDOG_RESET();
  1420. return EFI_EXIT(EFI_SUCCESS);
  1421. }
  1422. /*
  1423. * Get next value of the counter.
  1424. *
  1425. * This function implements the NextMonotonicCount service.
  1426. * See the Unified Extensible Firmware Interface (UEFI) specification
  1427. * for details.
  1428. *
  1429. * @count returned value of the counter
  1430. * @return status code
  1431. */
  1432. static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
  1433. {
  1434. static uint64_t mono = 0;
  1435. EFI_ENTRY("%p", count);
  1436. *count = mono++;
  1437. return EFI_EXIT(EFI_SUCCESS);
  1438. }
  1439. /*
  1440. * Sleep.
  1441. *
  1442. * This function implements the Stall sercive.
  1443. * See the Unified Extensible Firmware Interface (UEFI) specification
  1444. * for details.
  1445. *
  1446. * @microseconds period to sleep in microseconds
  1447. * @return status code
  1448. */
  1449. static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
  1450. {
  1451. EFI_ENTRY("%ld", microseconds);
  1452. udelay(microseconds);
  1453. return EFI_EXIT(EFI_SUCCESS);
  1454. }
  1455. /*
  1456. * Reset the watchdog timer.
  1457. *
  1458. * This function implements the SetWatchdogTimer service.
  1459. * See the Unified Extensible Firmware Interface (UEFI) specification
  1460. * for details.
  1461. *
  1462. * @timeout seconds before reset by watchdog
  1463. * @watchdog_code code to be logged when resetting
  1464. * @data_size size of buffer in bytes
  1465. * @watchdog_data buffer with data describing the reset reason
  1466. * @return status code
  1467. */
  1468. static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
  1469. uint64_t watchdog_code,
  1470. unsigned long data_size,
  1471. uint16_t *watchdog_data)
  1472. {
  1473. EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
  1474. data_size, watchdog_data);
  1475. return EFI_EXIT(efi_set_watchdog(timeout));
  1476. }
  1477. /*
  1478. * Disconnect a controller from a driver.
  1479. *
  1480. * This function implements the DisconnectController service.
  1481. * See the Unified Extensible Firmware Interface (UEFI) specification
  1482. * for details.
  1483. *
  1484. * @controller_handle handle of the controller
  1485. * @driver_image_handle handle of the driver
  1486. * @child_handle handle of the child to destroy
  1487. * @return status code
  1488. */
  1489. static efi_status_t EFIAPI efi_disconnect_controller(
  1490. efi_handle_t controller_handle,
  1491. efi_handle_t driver_image_handle,
  1492. efi_handle_t child_handle)
  1493. {
  1494. EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
  1495. child_handle);
  1496. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1497. }
  1498. /*
  1499. * Close a protocol.
  1500. *
  1501. * This function implements the CloseProtocol service.
  1502. * See the Unified Extensible Firmware Interface (UEFI) specification
  1503. * for details.
  1504. *
  1505. * @handle handle on which the protocol shall be closed
  1506. * @protocol GUID of the protocol to close
  1507. * @agent_handle handle of the driver
  1508. * @controller_handle handle of the controller
  1509. * @return status code
  1510. */
  1511. static efi_status_t EFIAPI efi_close_protocol(void *handle,
  1512. const efi_guid_t *protocol,
  1513. void *agent_handle,
  1514. void *controller_handle)
  1515. {
  1516. struct efi_handler *handler;
  1517. struct efi_open_protocol_info_item *item;
  1518. struct efi_open_protocol_info_item *pos;
  1519. efi_status_t r;
  1520. EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, agent_handle,
  1521. controller_handle);
  1522. if (!agent_handle) {
  1523. r = EFI_INVALID_PARAMETER;
  1524. goto out;
  1525. }
  1526. r = efi_search_protocol(handle, protocol, &handler);
  1527. if (r != EFI_SUCCESS)
  1528. goto out;
  1529. r = EFI_NOT_FOUND;
  1530. list_for_each_entry_safe(item, pos, &handler->open_infos, link) {
  1531. if (item->info.agent_handle == agent_handle &&
  1532. item->info.controller_handle == controller_handle) {
  1533. efi_delete_open_info(item);
  1534. r = EFI_SUCCESS;
  1535. break;
  1536. }
  1537. }
  1538. out:
  1539. return EFI_EXIT(r);
  1540. }
  1541. /*
  1542. * Provide information about then open status of a protocol on a handle
  1543. *
  1544. * This function implements the OpenProtocolInformation service.
  1545. * See the Unified Extensible Firmware Interface (UEFI) specification
  1546. * for details.
  1547. *
  1548. * @handle handle for which the information shall be retrieved
  1549. * @protocol GUID of the protocol
  1550. * @entry_buffer buffer to receive the open protocol information
  1551. * @entry_count number of entries available in the buffer
  1552. * @return status code
  1553. */
  1554. static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
  1555. const efi_guid_t *protocol,
  1556. struct efi_open_protocol_info_entry **entry_buffer,
  1557. efi_uintn_t *entry_count)
  1558. {
  1559. unsigned long buffer_size;
  1560. unsigned long count;
  1561. struct efi_handler *handler;
  1562. struct efi_open_protocol_info_item *item;
  1563. efi_status_t r;
  1564. EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, entry_buffer,
  1565. entry_count);
  1566. /* Check parameters */
  1567. if (!entry_buffer) {
  1568. r = EFI_INVALID_PARAMETER;
  1569. goto out;
  1570. }
  1571. r = efi_search_protocol(handle, protocol, &handler);
  1572. if (r != EFI_SUCCESS)
  1573. goto out;
  1574. /* Count entries */
  1575. count = 0;
  1576. list_for_each_entry(item, &handler->open_infos, link) {
  1577. if (item->info.open_count)
  1578. ++count;
  1579. }
  1580. *entry_count = count;
  1581. *entry_buffer = NULL;
  1582. if (!count) {
  1583. r = EFI_SUCCESS;
  1584. goto out;
  1585. }
  1586. /* Copy entries */
  1587. buffer_size = count * sizeof(struct efi_open_protocol_info_entry);
  1588. r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
  1589. (void **)entry_buffer);
  1590. if (r != EFI_SUCCESS)
  1591. goto out;
  1592. list_for_each_entry_reverse(item, &handler->open_infos, link) {
  1593. if (item->info.open_count)
  1594. (*entry_buffer)[--count] = item->info;
  1595. }
  1596. out:
  1597. return EFI_EXIT(r);
  1598. }
  1599. /*
  1600. * Get protocols installed on a handle.
  1601. *
  1602. * This function implements the ProtocolsPerHandleService.
  1603. * See the Unified Extensible Firmware Interface (UEFI) specification
  1604. * for details.
  1605. *
  1606. * @handle handle for which the information is retrieved
  1607. * @protocol_buffer buffer with protocol GUIDs
  1608. * @protocol_buffer_count number of entries in the buffer
  1609. * @return status code
  1610. */
  1611. static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
  1612. efi_guid_t ***protocol_buffer,
  1613. efi_uintn_t *protocol_buffer_count)
  1614. {
  1615. unsigned long buffer_size;
  1616. struct efi_object *efiobj;
  1617. struct list_head *protocol_handle;
  1618. efi_status_t r;
  1619. EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
  1620. protocol_buffer_count);
  1621. if (!handle || !protocol_buffer || !protocol_buffer_count)
  1622. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1623. *protocol_buffer = NULL;
  1624. *protocol_buffer_count = 0;
  1625. efiobj = efi_search_obj(handle);
  1626. if (!efiobj)
  1627. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1628. /* Count protocols */
  1629. list_for_each(protocol_handle, &efiobj->protocols) {
  1630. ++*protocol_buffer_count;
  1631. }
  1632. /* Copy guids */
  1633. if (*protocol_buffer_count) {
  1634. size_t j = 0;
  1635. buffer_size = sizeof(efi_guid_t *) * *protocol_buffer_count;
  1636. r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
  1637. (void **)protocol_buffer);
  1638. if (r != EFI_SUCCESS)
  1639. return EFI_EXIT(r);
  1640. list_for_each(protocol_handle, &efiobj->protocols) {
  1641. struct efi_handler *protocol;
  1642. protocol = list_entry(protocol_handle,
  1643. struct efi_handler, link);
  1644. (*protocol_buffer)[j] = (void *)protocol->guid;
  1645. ++j;
  1646. }
  1647. }
  1648. return EFI_EXIT(EFI_SUCCESS);
  1649. }
  1650. /*
  1651. * Locate handles implementing a protocol.
  1652. *
  1653. * This function implements the LocateHandleBuffer service.
  1654. * See the Unified Extensible Firmware Interface (UEFI) specification
  1655. * for details.
  1656. *
  1657. * @search_type selection criterion
  1658. * @protocol GUID of the protocol
  1659. * @search_key registration key
  1660. * @no_handles number of returned handles
  1661. * @buffer buffer with the returned handles
  1662. * @return status code
  1663. */
  1664. static efi_status_t EFIAPI efi_locate_handle_buffer(
  1665. enum efi_locate_search_type search_type,
  1666. const efi_guid_t *protocol, void *search_key,
  1667. efi_uintn_t *no_handles, efi_handle_t **buffer)
  1668. {
  1669. efi_status_t r;
  1670. efi_uintn_t buffer_size = 0;
  1671. EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
  1672. no_handles, buffer);
  1673. if (!no_handles || !buffer) {
  1674. r = EFI_INVALID_PARAMETER;
  1675. goto out;
  1676. }
  1677. *no_handles = 0;
  1678. *buffer = NULL;
  1679. r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
  1680. *buffer);
  1681. if (r != EFI_BUFFER_TOO_SMALL)
  1682. goto out;
  1683. r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
  1684. (void **)buffer);
  1685. if (r != EFI_SUCCESS)
  1686. goto out;
  1687. r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
  1688. *buffer);
  1689. if (r == EFI_SUCCESS)
  1690. *no_handles = buffer_size / sizeof(void *);
  1691. out:
  1692. return EFI_EXIT(r);
  1693. }
  1694. /*
  1695. * Find an interface implementing a protocol.
  1696. *
  1697. * This function implements the LocateProtocol service.
  1698. * See the Unified Extensible Firmware Interface (UEFI) specification
  1699. * for details.
  1700. *
  1701. * @protocol GUID of the protocol
  1702. * @registration registration key passed to the notification function
  1703. * @protocol_interface interface implementing the protocol
  1704. * @return status code
  1705. */
  1706. static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,
  1707. void *registration,
  1708. void **protocol_interface)
  1709. {
  1710. struct list_head *lhandle;
  1711. efi_status_t ret;
  1712. EFI_ENTRY("%pUl, %p, %p", protocol, registration, protocol_interface);
  1713. if (!protocol || !protocol_interface)
  1714. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1715. list_for_each(lhandle, &efi_obj_list) {
  1716. struct efi_object *efiobj;
  1717. struct efi_handler *handler;
  1718. efiobj = list_entry(lhandle, struct efi_object, link);
  1719. ret = efi_search_protocol(efiobj->handle, protocol, &handler);
  1720. if (ret == EFI_SUCCESS) {
  1721. *protocol_interface = handler->protocol_interface;
  1722. return EFI_EXIT(EFI_SUCCESS);
  1723. }
  1724. }
  1725. *protocol_interface = NULL;
  1726. return EFI_EXIT(EFI_NOT_FOUND);
  1727. }
  1728. /*
  1729. * Get the device path and handle of an device implementing a protocol.
  1730. *
  1731. * This function implements the LocateDevicePath service.
  1732. * See the Unified Extensible Firmware Interface (UEFI) specification
  1733. * for details.
  1734. *
  1735. * @protocol GUID of the protocol
  1736. * @device_path device path
  1737. * @device handle of the device
  1738. * @return status code
  1739. */
  1740. static efi_status_t EFIAPI efi_locate_device_path(
  1741. const efi_guid_t *protocol,
  1742. struct efi_device_path **device_path,
  1743. efi_handle_t *device)
  1744. {
  1745. struct efi_device_path *dp;
  1746. size_t i;
  1747. struct efi_handler *handler;
  1748. efi_handle_t *handles;
  1749. size_t len, len_dp;
  1750. size_t len_best = 0;
  1751. efi_uintn_t no_handles;
  1752. u8 *remainder;
  1753. efi_status_t ret;
  1754. EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device);
  1755. if (!protocol || !device_path || !*device_path || !device) {
  1756. ret = EFI_INVALID_PARAMETER;
  1757. goto out;
  1758. }
  1759. /* Find end of device path */
  1760. len = efi_dp_size(*device_path);
  1761. /* Get all handles implementing the protocol */
  1762. ret = EFI_CALL(efi_locate_handle_buffer(BY_PROTOCOL, protocol, NULL,
  1763. &no_handles, &handles));
  1764. if (ret != EFI_SUCCESS)
  1765. goto out;
  1766. for (i = 0; i < no_handles; ++i) {
  1767. /* Find the device path protocol */
  1768. ret = efi_search_protocol(handles[i], &efi_guid_device_path,
  1769. &handler);
  1770. if (ret != EFI_SUCCESS)
  1771. continue;
  1772. dp = (struct efi_device_path *)handler->protocol_interface;
  1773. len_dp = efi_dp_size(dp);
  1774. /*
  1775. * This handle can only be a better fit
  1776. * if its device path length is longer than the best fit and
  1777. * if its device path length is shorter of equal the searched
  1778. * device path.
  1779. */
  1780. if (len_dp <= len_best || len_dp > len)
  1781. continue;
  1782. /* Check if dp is a subpath of device_path */
  1783. if (memcmp(*device_path, dp, len_dp))
  1784. continue;
  1785. *device = handles[i];
  1786. len_best = len_dp;
  1787. }
  1788. if (len_best) {
  1789. remainder = (u8 *)*device_path + len_best;
  1790. *device_path = (struct efi_device_path *)remainder;
  1791. ret = EFI_SUCCESS;
  1792. } else {
  1793. ret = EFI_NOT_FOUND;
  1794. }
  1795. out:
  1796. return EFI_EXIT(ret);
  1797. }
  1798. /*
  1799. * Install multiple protocol interfaces.
  1800. *
  1801. * This function implements the MultipleProtocolInterfaces service.
  1802. * See the Unified Extensible Firmware Interface (UEFI) specification
  1803. * for details.
  1804. *
  1805. * @handle handle on which the protocol interfaces shall be installed
  1806. * @... NULL terminated argument list with pairs of protocol GUIDS and
  1807. * interfaces
  1808. * @return status code
  1809. */
  1810. static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
  1811. void **handle, ...)
  1812. {
  1813. EFI_ENTRY("%p", handle);
  1814. va_list argptr;
  1815. const efi_guid_t *protocol;
  1816. void *protocol_interface;
  1817. efi_status_t r = EFI_SUCCESS;
  1818. int i = 0;
  1819. if (!handle)
  1820. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1821. va_start(argptr, handle);
  1822. for (;;) {
  1823. protocol = va_arg(argptr, efi_guid_t*);
  1824. if (!protocol)
  1825. break;
  1826. protocol_interface = va_arg(argptr, void*);
  1827. r = EFI_CALL(efi_install_protocol_interface(
  1828. handle, protocol,
  1829. EFI_NATIVE_INTERFACE,
  1830. protocol_interface));
  1831. if (r != EFI_SUCCESS)
  1832. break;
  1833. i++;
  1834. }
  1835. va_end(argptr);
  1836. if (r == EFI_SUCCESS)
  1837. return EFI_EXIT(r);
  1838. /* If an error occurred undo all changes. */
  1839. va_start(argptr, handle);
  1840. for (; i; --i) {
  1841. protocol = va_arg(argptr, efi_guid_t*);
  1842. protocol_interface = va_arg(argptr, void*);
  1843. EFI_CALL(efi_uninstall_protocol_interface(handle, protocol,
  1844. protocol_interface));
  1845. }
  1846. va_end(argptr);
  1847. return EFI_EXIT(r);
  1848. }
  1849. /*
  1850. * Uninstall multiple protocol interfaces.
  1851. *
  1852. * This function implements the UninstallMultipleProtocolInterfaces service.
  1853. * See the Unified Extensible Firmware Interface (UEFI) specification
  1854. * for details.
  1855. *
  1856. * @handle handle from which the protocol interfaces shall be removed
  1857. * @... NULL terminated argument list with pairs of protocol GUIDS and
  1858. * interfaces
  1859. * @return status code
  1860. */
  1861. static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
  1862. void *handle, ...)
  1863. {
  1864. EFI_ENTRY("%p", handle);
  1865. va_list argptr;
  1866. const efi_guid_t *protocol;
  1867. void *protocol_interface;
  1868. efi_status_t r = EFI_SUCCESS;
  1869. size_t i = 0;
  1870. if (!handle)
  1871. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1872. va_start(argptr, handle);
  1873. for (;;) {
  1874. protocol = va_arg(argptr, efi_guid_t*);
  1875. if (!protocol)
  1876. break;
  1877. protocol_interface = va_arg(argptr, void*);
  1878. r = EFI_CALL(efi_uninstall_protocol_interface(
  1879. handle, protocol,
  1880. protocol_interface));
  1881. if (r != EFI_SUCCESS)
  1882. break;
  1883. i++;
  1884. }
  1885. va_end(argptr);
  1886. if (r == EFI_SUCCESS)
  1887. return EFI_EXIT(r);
  1888. /* If an error occurred undo all changes. */
  1889. va_start(argptr, handle);
  1890. for (; i; --i) {
  1891. protocol = va_arg(argptr, efi_guid_t*);
  1892. protocol_interface = va_arg(argptr, void*);
  1893. EFI_CALL(efi_install_protocol_interface(&handle, protocol,
  1894. EFI_NATIVE_INTERFACE,
  1895. protocol_interface));
  1896. }
  1897. va_end(argptr);
  1898. return EFI_EXIT(r);
  1899. }
  1900. /*
  1901. * Calculate cyclic redundancy code.
  1902. *
  1903. * This function implements the CalculateCrc32 service.
  1904. * See the Unified Extensible Firmware Interface (UEFI) specification
  1905. * for details.
  1906. *
  1907. * @data buffer with data
  1908. * @data_size size of buffer in bytes
  1909. * @crc32_p cyclic redundancy code
  1910. * @return status code
  1911. */
  1912. static efi_status_t EFIAPI efi_calculate_crc32(void *data,
  1913. unsigned long data_size,
  1914. uint32_t *crc32_p)
  1915. {
  1916. EFI_ENTRY("%p, %ld", data, data_size);
  1917. *crc32_p = crc32(0, data, data_size);
  1918. return EFI_EXIT(EFI_SUCCESS);
  1919. }
  1920. /*
  1921. * Copy memory.
  1922. *
  1923. * This function implements the CopyMem service.
  1924. * See the Unified Extensible Firmware Interface (UEFI) specification
  1925. * for details.
  1926. *
  1927. * @destination destination of the copy operation
  1928. * @source source of the copy operation
  1929. * @length number of bytes to copy
  1930. */
  1931. static void EFIAPI efi_copy_mem(void *destination, const void *source,
  1932. size_t length)
  1933. {
  1934. EFI_ENTRY("%p, %p, %ld", destination, source, (unsigned long)length);
  1935. memcpy(destination, source, length);
  1936. EFI_EXIT(EFI_SUCCESS);
  1937. }
  1938. /*
  1939. * Fill memory with a byte value.
  1940. *
  1941. * This function implements the SetMem service.
  1942. * See the Unified Extensible Firmware Interface (UEFI) specification
  1943. * for details.
  1944. *
  1945. * @buffer buffer to fill
  1946. * @size size of buffer in bytes
  1947. * @value byte to copy to the buffer
  1948. */
  1949. static void EFIAPI efi_set_mem(void *buffer, size_t size, uint8_t value)
  1950. {
  1951. EFI_ENTRY("%p, %ld, 0x%x", buffer, (unsigned long)size, value);
  1952. memset(buffer, value, size);
  1953. EFI_EXIT(EFI_SUCCESS);
  1954. }
  1955. /*
  1956. * Open protocol interface on a handle.
  1957. *
  1958. * @handler handler of a protocol
  1959. * @protocol_interface interface implementing the protocol
  1960. * @agent_handle handle of the driver
  1961. * @controller_handle handle of the controller
  1962. * @attributes attributes indicating how to open the protocol
  1963. * @return status code
  1964. */
  1965. static efi_status_t efi_protocol_open(
  1966. struct efi_handler *handler,
  1967. void **protocol_interface, void *agent_handle,
  1968. void *controller_handle, uint32_t attributes)
  1969. {
  1970. struct efi_open_protocol_info_item *item;
  1971. struct efi_open_protocol_info_entry *match = NULL;
  1972. bool opened_by_driver = false;
  1973. bool opened_exclusive = false;
  1974. /* If there is no agent, only return the interface */
  1975. if (!agent_handle)
  1976. goto out;
  1977. /* For TEST_PROTOCOL ignore interface attribute */
  1978. if (attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL)
  1979. *protocol_interface = NULL;
  1980. /*
  1981. * Check if the protocol is already opened by a driver with the same
  1982. * attributes or opened exclusively
  1983. */
  1984. list_for_each_entry(item, &handler->open_infos, link) {
  1985. if (item->info.agent_handle == agent_handle) {
  1986. if ((attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) &&
  1987. (item->info.attributes == attributes))
  1988. return EFI_ALREADY_STARTED;
  1989. }
  1990. if (item->info.attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE)
  1991. opened_exclusive = true;
  1992. }
  1993. /* Only one controller can open the protocol exclusively */
  1994. if (opened_exclusive && attributes &
  1995. (EFI_OPEN_PROTOCOL_EXCLUSIVE | EFI_OPEN_PROTOCOL_BY_DRIVER))
  1996. return EFI_ACCESS_DENIED;
  1997. /* Prepare exclusive opening */
  1998. if (attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) {
  1999. /* Try to disconnect controllers */
  2000. list_for_each_entry(item, &handler->open_infos, link) {
  2001. if (item->info.attributes ==
  2002. EFI_OPEN_PROTOCOL_BY_DRIVER)
  2003. EFI_CALL(efi_disconnect_controller(
  2004. item->info.controller_handle,
  2005. item->info.agent_handle,
  2006. NULL));
  2007. }
  2008. opened_by_driver = false;
  2009. /* Check if all controllers are disconnected */
  2010. list_for_each_entry(item, &handler->open_infos, link) {
  2011. if (item->info.attributes & EFI_OPEN_PROTOCOL_BY_DRIVER)
  2012. opened_by_driver = true;
  2013. }
  2014. /* Only one controller can be conncected */
  2015. if (opened_by_driver)
  2016. return EFI_ACCESS_DENIED;
  2017. }
  2018. /* Find existing entry */
  2019. list_for_each_entry(item, &handler->open_infos, link) {
  2020. if (item->info.agent_handle == agent_handle &&
  2021. item->info.controller_handle == controller_handle)
  2022. match = &item->info;
  2023. }
  2024. /* None found, create one */
  2025. if (!match) {
  2026. match = efi_create_open_info(handler);
  2027. if (!match)
  2028. return EFI_OUT_OF_RESOURCES;
  2029. }
  2030. match->agent_handle = agent_handle;
  2031. match->controller_handle = controller_handle;
  2032. match->attributes = attributes;
  2033. match->open_count++;
  2034. out:
  2035. /* For TEST_PROTOCOL ignore interface attribute. */
  2036. if (attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL)
  2037. *protocol_interface = handler->protocol_interface;
  2038. return EFI_SUCCESS;
  2039. }
  2040. /*
  2041. * Open protocol interface on a handle.
  2042. *
  2043. * This function implements the OpenProtocol interface.
  2044. * See the Unified Extensible Firmware Interface (UEFI) specification
  2045. * for details.
  2046. *
  2047. * @handle handle on which the protocol shall be opened
  2048. * @protocol GUID of the protocol
  2049. * @protocol_interface interface implementing the protocol
  2050. * @agent_handle handle of the driver
  2051. * @controller_handle handle of the controller
  2052. * @attributes attributes indicating how to open the protocol
  2053. * @return status code
  2054. */
  2055. static efi_status_t EFIAPI efi_open_protocol(
  2056. void *handle, const efi_guid_t *protocol,
  2057. void **protocol_interface, void *agent_handle,
  2058. void *controller_handle, uint32_t attributes)
  2059. {
  2060. struct efi_handler *handler;
  2061. efi_status_t r = EFI_INVALID_PARAMETER;
  2062. EFI_ENTRY("%p, %pUl, %p, %p, %p, 0x%x", handle, protocol,
  2063. protocol_interface, agent_handle, controller_handle,
  2064. attributes);
  2065. if (!handle || !protocol ||
  2066. (!protocol_interface && attributes !=
  2067. EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
  2068. goto out;
  2069. }
  2070. switch (attributes) {
  2071. case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
  2072. case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
  2073. case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
  2074. break;
  2075. case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
  2076. if (controller_handle == handle)
  2077. goto out;
  2078. /* fall-through */
  2079. case EFI_OPEN_PROTOCOL_BY_DRIVER:
  2080. case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
  2081. /* Check that the controller handle is valid */
  2082. if (!efi_search_obj(controller_handle))
  2083. goto out;
  2084. /* fall-through */
  2085. case EFI_OPEN_PROTOCOL_EXCLUSIVE:
  2086. /* Check that the agent handle is valid */
  2087. if (!efi_search_obj(agent_handle))
  2088. goto out;
  2089. break;
  2090. default:
  2091. goto out;
  2092. }
  2093. r = efi_search_protocol(handle, protocol, &handler);
  2094. if (r != EFI_SUCCESS)
  2095. goto out;
  2096. r = efi_protocol_open(handler, protocol_interface, agent_handle,
  2097. controller_handle, attributes);
  2098. out:
  2099. return EFI_EXIT(r);
  2100. }
  2101. /*
  2102. * Get interface of a protocol on a handle.
  2103. *
  2104. * This function implements the HandleProtocol service.
  2105. * See the Unified Extensible Firmware Interface (UEFI) specification
  2106. * for details.
  2107. *
  2108. * @handle handle on which the protocol shall be opened
  2109. * @protocol GUID of the protocol
  2110. * @protocol_interface interface implementing the protocol
  2111. * @return status code
  2112. */
  2113. static efi_status_t EFIAPI efi_handle_protocol(void *handle,
  2114. const efi_guid_t *protocol,
  2115. void **protocol_interface)
  2116. {
  2117. return efi_open_protocol(handle, protocol, protocol_interface, NULL,
  2118. NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
  2119. }
  2120. static efi_status_t efi_bind_controller(
  2121. efi_handle_t controller_handle,
  2122. efi_handle_t driver_image_handle,
  2123. struct efi_device_path *remain_device_path)
  2124. {
  2125. struct efi_driver_binding_protocol *binding_protocol;
  2126. efi_status_t r;
  2127. r = EFI_CALL(efi_open_protocol(driver_image_handle,
  2128. &efi_guid_driver_binding_protocol,
  2129. (void **)&binding_protocol,
  2130. driver_image_handle, NULL,
  2131. EFI_OPEN_PROTOCOL_GET_PROTOCOL));
  2132. if (r != EFI_SUCCESS)
  2133. return r;
  2134. r = EFI_CALL(binding_protocol->supported(binding_protocol,
  2135. controller_handle,
  2136. remain_device_path));
  2137. if (r == EFI_SUCCESS)
  2138. r = EFI_CALL(binding_protocol->start(binding_protocol,
  2139. controller_handle,
  2140. remain_device_path));
  2141. EFI_CALL(efi_close_protocol(driver_image_handle,
  2142. &efi_guid_driver_binding_protocol,
  2143. driver_image_handle, NULL));
  2144. return r;
  2145. }
  2146. static efi_status_t efi_connect_single_controller(
  2147. efi_handle_t controller_handle,
  2148. efi_handle_t *driver_image_handle,
  2149. struct efi_device_path *remain_device_path)
  2150. {
  2151. efi_handle_t *buffer;
  2152. size_t count;
  2153. size_t i;
  2154. efi_status_t r;
  2155. size_t connected = 0;
  2156. /* Get buffer with all handles with driver binding protocol */
  2157. r = EFI_CALL(efi_locate_handle_buffer(BY_PROTOCOL,
  2158. &efi_guid_driver_binding_protocol,
  2159. NULL, &count, &buffer));
  2160. if (r != EFI_SUCCESS)
  2161. return r;
  2162. /* Context Override */
  2163. if (driver_image_handle) {
  2164. for (; *driver_image_handle; ++driver_image_handle) {
  2165. for (i = 0; i < count; ++i) {
  2166. if (buffer[i] == *driver_image_handle) {
  2167. buffer[i] = NULL;
  2168. r = efi_bind_controller(
  2169. controller_handle,
  2170. *driver_image_handle,
  2171. remain_device_path);
  2172. /*
  2173. * For drivers that do not support the
  2174. * controller or are already connected
  2175. * we receive an error code here.
  2176. */
  2177. if (r == EFI_SUCCESS)
  2178. ++connected;
  2179. }
  2180. }
  2181. }
  2182. }
  2183. /*
  2184. * TODO: Some overrides are not yet implemented:
  2185. * - Platform Driver Override
  2186. * - Driver Family Override Search
  2187. * - Bus Specific Driver Override
  2188. */
  2189. /* Driver Binding Search */
  2190. for (i = 0; i < count; ++i) {
  2191. if (buffer[i]) {
  2192. r = efi_bind_controller(controller_handle,
  2193. buffer[i],
  2194. remain_device_path);
  2195. if (r == EFI_SUCCESS)
  2196. ++connected;
  2197. }
  2198. }
  2199. efi_free_pool(buffer);
  2200. if (!connected)
  2201. return EFI_NOT_FOUND;
  2202. return EFI_SUCCESS;
  2203. }
  2204. /*
  2205. * Connect a controller to a driver.
  2206. *
  2207. * This function implements the ConnectController service.
  2208. * See the Unified Extensible Firmware Interface (UEFI) specification
  2209. * for details.
  2210. *
  2211. * First all driver binding protocol handles are tried for binding drivers.
  2212. * Afterwards all handles that have openened a protocol of the controller
  2213. * with EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER are connected to drivers.
  2214. *
  2215. * @controller_handle handle of the controller
  2216. * @driver_image_handle handle of the driver
  2217. * @remain_device_path device path of a child controller
  2218. * @recursive true to connect all child controllers
  2219. * @return status code
  2220. */
  2221. static efi_status_t EFIAPI efi_connect_controller(
  2222. efi_handle_t controller_handle,
  2223. efi_handle_t *driver_image_handle,
  2224. struct efi_device_path *remain_device_path,
  2225. bool recursive)
  2226. {
  2227. efi_status_t r;
  2228. efi_status_t ret = EFI_NOT_FOUND;
  2229. struct efi_object *efiobj;
  2230. EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
  2231. remain_device_path, recursive);
  2232. efiobj = efi_search_obj(controller_handle);
  2233. if (!efiobj) {
  2234. ret = EFI_INVALID_PARAMETER;
  2235. goto out;
  2236. }
  2237. r = efi_connect_single_controller(controller_handle,
  2238. driver_image_handle,
  2239. remain_device_path);
  2240. if (r == EFI_SUCCESS)
  2241. ret = EFI_SUCCESS;
  2242. if (recursive) {
  2243. struct efi_handler *handler;
  2244. struct efi_open_protocol_info_item *item;
  2245. list_for_each_entry(handler, &efiobj->protocols, link) {
  2246. list_for_each_entry(item, &handler->open_infos, link) {
  2247. if (item->info.attributes &
  2248. EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
  2249. r = EFI_CALL(efi_connect_controller(
  2250. item->info.controller_handle,
  2251. driver_image_handle,
  2252. remain_device_path,
  2253. recursive));
  2254. if (r == EFI_SUCCESS)
  2255. ret = EFI_SUCCESS;
  2256. }
  2257. }
  2258. }
  2259. }
  2260. /* Check for child controller specified by end node */
  2261. if (ret != EFI_SUCCESS && remain_device_path &&
  2262. remain_device_path->type == DEVICE_PATH_TYPE_END)
  2263. ret = EFI_SUCCESS;
  2264. out:
  2265. return EFI_EXIT(ret);
  2266. }
  2267. static const struct efi_boot_services efi_boot_services = {
  2268. .hdr = {
  2269. .headersize = sizeof(struct efi_table_hdr),
  2270. },
  2271. .raise_tpl = efi_raise_tpl,
  2272. .restore_tpl = efi_restore_tpl,
  2273. .allocate_pages = efi_allocate_pages_ext,
  2274. .free_pages = efi_free_pages_ext,
  2275. .get_memory_map = efi_get_memory_map_ext,
  2276. .allocate_pool = efi_allocate_pool_ext,
  2277. .free_pool = efi_free_pool_ext,
  2278. .create_event = efi_create_event_ext,
  2279. .set_timer = efi_set_timer_ext,
  2280. .wait_for_event = efi_wait_for_event,
  2281. .signal_event = efi_signal_event_ext,
  2282. .close_event = efi_close_event,
  2283. .check_event = efi_check_event,
  2284. .install_protocol_interface = efi_install_protocol_interface,
  2285. .reinstall_protocol_interface = efi_reinstall_protocol_interface,
  2286. .uninstall_protocol_interface = efi_uninstall_protocol_interface,
  2287. .handle_protocol = efi_handle_protocol,
  2288. .reserved = NULL,
  2289. .register_protocol_notify = efi_register_protocol_notify,
  2290. .locate_handle = efi_locate_handle_ext,
  2291. .locate_device_path = efi_locate_device_path,
  2292. .install_configuration_table = efi_install_configuration_table_ext,
  2293. .load_image = efi_load_image,
  2294. .start_image = efi_start_image,
  2295. .exit = efi_exit,
  2296. .unload_image = efi_unload_image,
  2297. .exit_boot_services = efi_exit_boot_services,
  2298. .get_next_monotonic_count = efi_get_next_monotonic_count,
  2299. .stall = efi_stall,
  2300. .set_watchdog_timer = efi_set_watchdog_timer,
  2301. .connect_controller = efi_connect_controller,
  2302. .disconnect_controller = efi_disconnect_controller,
  2303. .open_protocol = efi_open_protocol,
  2304. .close_protocol = efi_close_protocol,
  2305. .open_protocol_information = efi_open_protocol_information,
  2306. .protocols_per_handle = efi_protocols_per_handle,
  2307. .locate_handle_buffer = efi_locate_handle_buffer,
  2308. .locate_protocol = efi_locate_protocol,
  2309. .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
  2310. .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
  2311. .calculate_crc32 = efi_calculate_crc32,
  2312. .copy_mem = efi_copy_mem,
  2313. .set_mem = efi_set_mem,
  2314. };
  2315. static uint16_t __efi_runtime_data firmware_vendor[] = L"Das U-Boot";
  2316. struct efi_system_table __efi_runtime_data systab = {
  2317. .hdr = {
  2318. .signature = EFI_SYSTEM_TABLE_SIGNATURE,
  2319. .revision = 0x20005, /* 2.5 */
  2320. .headersize = sizeof(struct efi_table_hdr),
  2321. },
  2322. .fw_vendor = (long)firmware_vendor,
  2323. .con_in = (void*)&efi_con_in,
  2324. .con_out = (void*)&efi_con_out,
  2325. .std_err = (void*)&efi_con_out,
  2326. .runtime = (void*)&efi_runtime_services,
  2327. .boottime = (void*)&efi_boot_services,
  2328. .nr_tables = 0,
  2329. .tables = (void*)efi_conf_table,
  2330. };