efi_boottime.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074
  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. * Find the internal EFI object for a handle.
  630. *
  631. * @handle handle to find
  632. * @return EFI object
  633. */
  634. static struct efi_object *efi_search_obj(void *handle)
  635. {
  636. struct list_head *lhandle;
  637. list_for_each(lhandle, &efi_obj_list) {
  638. struct efi_object *efiobj;
  639. efiobj = list_entry(lhandle, struct efi_object, link);
  640. if (efiobj->handle == handle)
  641. return efiobj;
  642. }
  643. return NULL;
  644. }
  645. /*
  646. * Install protocol interface.
  647. *
  648. * This is the function for internal calls. For the API implementation of the
  649. * InstallProtocolInterface service see function
  650. * efi_install_protocol_interface_ext.
  651. *
  652. * @handle handle on which the protocol shall be installed
  653. * @protocol GUID of the protocol to be installed
  654. * @protocol_interface_type type of the interface to be installed,
  655. * always EFI_NATIVE_INTERFACE
  656. * @protocol_interface interface of the protocol implementation
  657. * @return status code
  658. */
  659. static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
  660. const efi_guid_t *protocol, int protocol_interface_type,
  661. void *protocol_interface)
  662. {
  663. struct list_head *lhandle;
  664. int i;
  665. efi_status_t r;
  666. if (!handle || !protocol ||
  667. protocol_interface_type != EFI_NATIVE_INTERFACE) {
  668. r = EFI_INVALID_PARAMETER;
  669. goto out;
  670. }
  671. /* Create new handle if requested. */
  672. if (!*handle) {
  673. r = efi_create_handle(handle);
  674. if (r != EFI_SUCCESS)
  675. goto out;
  676. }
  677. /* Find object. */
  678. list_for_each(lhandle, &efi_obj_list) {
  679. struct efi_object *efiobj;
  680. efiobj = list_entry(lhandle, struct efi_object, link);
  681. if (efiobj->handle != *handle)
  682. continue;
  683. /* Check if protocol is already installed on the handle. */
  684. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  685. struct efi_handler *handler = &efiobj->protocols[i];
  686. if (!handler->guid)
  687. continue;
  688. if (!guidcmp(handler->guid, protocol)) {
  689. r = EFI_INVALID_PARAMETER;
  690. goto out;
  691. }
  692. }
  693. /* Install protocol in first empty slot. */
  694. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  695. struct efi_handler *handler = &efiobj->protocols[i];
  696. if (handler->guid)
  697. continue;
  698. handler->guid = protocol;
  699. handler->protocol_interface = protocol_interface;
  700. r = EFI_SUCCESS;
  701. goto out;
  702. }
  703. r = EFI_OUT_OF_RESOURCES;
  704. goto out;
  705. }
  706. r = EFI_INVALID_PARAMETER;
  707. out:
  708. return r;
  709. }
  710. /*
  711. * Install protocol interface.
  712. *
  713. * This function implements the InstallProtocolInterface service.
  714. * See the Unified Extensible Firmware Interface (UEFI) specification
  715. * for details.
  716. *
  717. * @handle handle on which the protocol shall be installed
  718. * @protocol GUID of the protocol to be installed
  719. * @protocol_interface_type type of the interface to be installed,
  720. * always EFI_NATIVE_INTERFACE
  721. * @protocol_interface interface of the protocol implementation
  722. * @return status code
  723. */
  724. static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
  725. const efi_guid_t *protocol, int protocol_interface_type,
  726. void *protocol_interface)
  727. {
  728. EFI_ENTRY("%p, %pUl, %d, %p", handle, protocol, protocol_interface_type,
  729. protocol_interface);
  730. return EFI_EXIT(efi_install_protocol_interface(handle, protocol,
  731. protocol_interface_type,
  732. protocol_interface));
  733. }
  734. /*
  735. * Reinstall protocol interface.
  736. *
  737. * This function implements the ReinstallProtocolInterface service.
  738. * See the Unified Extensible Firmware Interface (UEFI) specification
  739. * for details.
  740. *
  741. * @handle handle on which the protocol shall be
  742. * reinstalled
  743. * @protocol GUID of the protocol to be installed
  744. * @old_interface interface to be removed
  745. * @new_interface interface to be installed
  746. * @return status code
  747. */
  748. static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
  749. const efi_guid_t *protocol, void *old_interface,
  750. void *new_interface)
  751. {
  752. EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, old_interface,
  753. new_interface);
  754. return EFI_EXIT(EFI_ACCESS_DENIED);
  755. }
  756. /*
  757. * Uninstall protocol interface.
  758. *
  759. * This is the function for internal calls. For the API implementation of the
  760. * UninstallProtocolInterface service see function
  761. * efi_uninstall_protocol_interface_ext.
  762. *
  763. * @handle handle from which the protocol shall be removed
  764. * @protocol GUID of the protocol to be removed
  765. * @protocol_interface interface to be removed
  766. * @return status code
  767. */
  768. static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
  769. const efi_guid_t *protocol, void *protocol_interface)
  770. {
  771. struct list_head *lhandle;
  772. int i;
  773. efi_status_t r = EFI_NOT_FOUND;
  774. if (!handle || !protocol) {
  775. r = EFI_INVALID_PARAMETER;
  776. goto out;
  777. }
  778. list_for_each(lhandle, &efi_obj_list) {
  779. struct efi_object *efiobj;
  780. efiobj = list_entry(lhandle, struct efi_object, link);
  781. if (efiobj->handle != handle)
  782. continue;
  783. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  784. struct efi_handler *handler = &efiobj->protocols[i];
  785. const efi_guid_t *hprotocol = handler->guid;
  786. if (!hprotocol)
  787. continue;
  788. if (!guidcmp(hprotocol, protocol)) {
  789. if (handler->protocol_interface) {
  790. r = EFI_ACCESS_DENIED;
  791. } else {
  792. handler->guid = 0;
  793. r = EFI_SUCCESS;
  794. }
  795. goto out;
  796. }
  797. }
  798. }
  799. out:
  800. return r;
  801. }
  802. /*
  803. * Uninstall protocol interface.
  804. *
  805. * This function implements the UninstallProtocolInterface service.
  806. * See the Unified Extensible Firmware Interface (UEFI) specification
  807. * for details.
  808. *
  809. * @handle handle from which the protocol shall be removed
  810. * @protocol GUID of the protocol to be removed
  811. * @protocol_interface interface to be removed
  812. * @return status code
  813. */
  814. static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle,
  815. const efi_guid_t *protocol, void *protocol_interface)
  816. {
  817. EFI_ENTRY("%p, %pUl, %p", handle, protocol, protocol_interface);
  818. return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol,
  819. protocol_interface));
  820. }
  821. /*
  822. * Register an event for notification when a protocol is installed.
  823. *
  824. * This function implements the RegisterProtocolNotify service.
  825. * See the Unified Extensible Firmware Interface (UEFI) specification
  826. * for details.
  827. *
  828. * @protocol GUID of the protocol whose installation shall be
  829. * notified
  830. * @event event to be signaled upon installation of the protocol
  831. * @registration key for retrieving the registration information
  832. * @return status code
  833. */
  834. static efi_status_t EFIAPI efi_register_protocol_notify(
  835. const efi_guid_t *protocol,
  836. struct efi_event *event,
  837. void **registration)
  838. {
  839. EFI_ENTRY("%pUl, %p, %p", protocol, event, registration);
  840. return EFI_EXIT(EFI_OUT_OF_RESOURCES);
  841. }
  842. /*
  843. * Determine if an EFI handle implements a protocol.
  844. *
  845. * See the documentation of the LocateHandle service in the UEFI specification.
  846. *
  847. * @search_type selection criterion
  848. * @protocol GUID of the protocol
  849. * @search_key registration key
  850. * @efiobj handle
  851. * @return 0 if the handle implements the protocol
  852. */
  853. static int efi_search(enum efi_locate_search_type search_type,
  854. const efi_guid_t *protocol, void *search_key,
  855. struct efi_object *efiobj)
  856. {
  857. int i;
  858. switch (search_type) {
  859. case all_handles:
  860. return 0;
  861. case by_register_notify:
  862. return -1;
  863. case by_protocol:
  864. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  865. const efi_guid_t *guid = efiobj->protocols[i].guid;
  866. if (guid && !guidcmp(guid, protocol))
  867. return 0;
  868. }
  869. return -1;
  870. }
  871. return -1;
  872. }
  873. /*
  874. * Locate handles implementing a protocol.
  875. *
  876. * This function is meant for U-Boot internal calls. For the API implementation
  877. * of the LocateHandle service see efi_locate_handle_ext.
  878. *
  879. * @search_type selection criterion
  880. * @protocol GUID of the protocol
  881. * @search_key registration key
  882. * @buffer_size size of the buffer to receive the handles in bytes
  883. * @buffer buffer to receive the relevant handles
  884. * @return status code
  885. */
  886. static efi_status_t efi_locate_handle(
  887. enum efi_locate_search_type search_type,
  888. const efi_guid_t *protocol, void *search_key,
  889. unsigned long *buffer_size, efi_handle_t *buffer)
  890. {
  891. struct list_head *lhandle;
  892. unsigned long size = 0;
  893. /* Count how much space we need */
  894. list_for_each(lhandle, &efi_obj_list) {
  895. struct efi_object *efiobj;
  896. efiobj = list_entry(lhandle, struct efi_object, link);
  897. if (!efi_search(search_type, protocol, search_key, efiobj)) {
  898. size += sizeof(void*);
  899. }
  900. }
  901. if (*buffer_size < size) {
  902. *buffer_size = size;
  903. return EFI_BUFFER_TOO_SMALL;
  904. }
  905. *buffer_size = size;
  906. if (size == 0)
  907. return EFI_NOT_FOUND;
  908. /* Then fill the array */
  909. list_for_each(lhandle, &efi_obj_list) {
  910. struct efi_object *efiobj;
  911. efiobj = list_entry(lhandle, struct efi_object, link);
  912. if (!efi_search(search_type, protocol, search_key, efiobj)) {
  913. *(buffer++) = efiobj->handle;
  914. }
  915. }
  916. return EFI_SUCCESS;
  917. }
  918. /*
  919. * Locate handles implementing a protocol.
  920. *
  921. * This function implements the LocateHandle service.
  922. * See the Unified Extensible Firmware Interface (UEFI) specification
  923. * for details.
  924. *
  925. * @search_type selection criterion
  926. * @protocol GUID of the protocol
  927. * @search_key registration key
  928. * @buffer_size size of the buffer to receive the handles in bytes
  929. * @buffer buffer to receive the relevant handles
  930. * @return 0 if the handle implements the protocol
  931. */
  932. static efi_status_t EFIAPI efi_locate_handle_ext(
  933. enum efi_locate_search_type search_type,
  934. const efi_guid_t *protocol, void *search_key,
  935. unsigned long *buffer_size, efi_handle_t *buffer)
  936. {
  937. EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
  938. buffer_size, buffer);
  939. return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key,
  940. buffer_size, buffer));
  941. }
  942. /*
  943. * Get the device path and handle of an device implementing a protocol.
  944. *
  945. * This function implements the LocateDevicePath service.
  946. * See the Unified Extensible Firmware Interface (UEFI) specification
  947. * for details.
  948. *
  949. * @protocol GUID of the protocol
  950. * @device_path device path
  951. * @device handle of the device
  952. * @return status code
  953. */
  954. static efi_status_t EFIAPI efi_locate_device_path(
  955. const efi_guid_t *protocol,
  956. struct efi_device_path **device_path,
  957. efi_handle_t *device)
  958. {
  959. struct efi_object *efiobj;
  960. EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device);
  961. efiobj = efi_dp_find_obj(*device_path, device_path);
  962. if (!efiobj)
  963. return EFI_EXIT(EFI_NOT_FOUND);
  964. *device = efiobj->handle;
  965. return EFI_EXIT(EFI_SUCCESS);
  966. }
  967. /* Collapses configuration table entries, removing index i */
  968. static void efi_remove_configuration_table(int i)
  969. {
  970. struct efi_configuration_table *this = &efi_conf_table[i];
  971. struct efi_configuration_table *next = &efi_conf_table[i+1];
  972. struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables];
  973. memmove(this, next, (ulong)end - (ulong)next);
  974. systab.nr_tables--;
  975. }
  976. /*
  977. * Adds, updates, or removes a configuration table.
  978. *
  979. * This function is used for internal calls. For the API implementation of the
  980. * InstallConfigurationTable service see efi_install_configuration_table_ext.
  981. *
  982. * @guid GUID of the installed table
  983. * @table table to be installed
  984. * @return status code
  985. */
  986. efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table)
  987. {
  988. int i;
  989. /* Check for guid override */
  990. for (i = 0; i < systab.nr_tables; i++) {
  991. if (!guidcmp(guid, &efi_conf_table[i].guid)) {
  992. if (table)
  993. efi_conf_table[i].table = table;
  994. else
  995. efi_remove_configuration_table(i);
  996. return EFI_SUCCESS;
  997. }
  998. }
  999. if (!table)
  1000. return EFI_NOT_FOUND;
  1001. /* No override, check for overflow */
  1002. if (i >= ARRAY_SIZE(efi_conf_table))
  1003. return EFI_OUT_OF_RESOURCES;
  1004. /* Add a new entry */
  1005. memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
  1006. efi_conf_table[i].table = table;
  1007. systab.nr_tables = i + 1;
  1008. return EFI_SUCCESS;
  1009. }
  1010. /*
  1011. * Adds, updates, or removes a configuration table.
  1012. *
  1013. * This function implements the InstallConfigurationTable service.
  1014. * See the Unified Extensible Firmware Interface (UEFI) specification
  1015. * for details.
  1016. *
  1017. * @guid GUID of the installed table
  1018. * @table table to be installed
  1019. * @return status code
  1020. */
  1021. static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid,
  1022. void *table)
  1023. {
  1024. EFI_ENTRY("%pUl, %p", guid, table);
  1025. return EFI_EXIT(efi_install_configuration_table(guid, table));
  1026. }
  1027. /*
  1028. * Initialize a loaded_image_info + loaded_image_info object with correct
  1029. * protocols, boot-device, etc.
  1030. *
  1031. * @info loaded image info to be passed to the entry point of the
  1032. * image
  1033. * @obj internal object associated with the loaded image
  1034. * @device_path device path of the loaded image
  1035. * @file_path file path of the loaded image
  1036. */
  1037. void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *obj,
  1038. struct efi_device_path *device_path,
  1039. struct efi_device_path *file_path)
  1040. {
  1041. obj->handle = info;
  1042. /*
  1043. * When asking for the device path interface, return
  1044. * bootefi_device_path
  1045. */
  1046. obj->protocols[0].guid = &efi_guid_device_path;
  1047. obj->protocols[0].protocol_interface = device_path;
  1048. /*
  1049. * When asking for the loaded_image interface, just
  1050. * return handle which points to loaded_image_info
  1051. */
  1052. obj->protocols[1].guid = &efi_guid_loaded_image;
  1053. obj->protocols[1].protocol_interface = info;
  1054. obj->protocols[2].guid = &efi_guid_console_control;
  1055. obj->protocols[2].protocol_interface = (void *)&efi_console_control;
  1056. obj->protocols[3].guid = &efi_guid_device_path_to_text_protocol;
  1057. obj->protocols[3].protocol_interface =
  1058. (void *)&efi_device_path_to_text;
  1059. info->file_path = file_path;
  1060. if (device_path)
  1061. info->device_handle = efi_dp_find_obj(device_path, NULL);
  1062. list_add_tail(&obj->link, &efi_obj_list);
  1063. }
  1064. /*
  1065. * Load an image using a file path.
  1066. *
  1067. * @file_path the path of the image to load
  1068. * @buffer buffer containing the loaded image
  1069. * @return status code
  1070. */
  1071. efi_status_t efi_load_image_from_path(struct efi_device_path *file_path,
  1072. void **buffer)
  1073. {
  1074. struct efi_file_info *info = NULL;
  1075. struct efi_file_handle *f;
  1076. static efi_status_t ret;
  1077. uint64_t bs;
  1078. f = efi_file_from_path(file_path);
  1079. if (!f)
  1080. return EFI_DEVICE_ERROR;
  1081. bs = 0;
  1082. EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
  1083. &bs, info));
  1084. if (ret == EFI_BUFFER_TOO_SMALL) {
  1085. info = malloc(bs);
  1086. EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
  1087. &bs, info));
  1088. }
  1089. if (ret != EFI_SUCCESS)
  1090. goto error;
  1091. ret = efi_allocate_pool(EFI_LOADER_DATA, info->file_size, buffer);
  1092. if (ret)
  1093. goto error;
  1094. EFI_CALL(ret = f->read(f, &info->file_size, *buffer));
  1095. error:
  1096. free(info);
  1097. EFI_CALL(f->close(f));
  1098. if (ret != EFI_SUCCESS) {
  1099. efi_free_pool(*buffer);
  1100. *buffer = NULL;
  1101. }
  1102. return ret;
  1103. }
  1104. /*
  1105. * Load an EFI image into memory.
  1106. *
  1107. * This function implements the LoadImage service.
  1108. * See the Unified Extensible Firmware Interface (UEFI) specification
  1109. * for details.
  1110. *
  1111. * @boot_policy true for request originating from the boot manager
  1112. * @parent_image the calles's image handle
  1113. * @file_path the path of the image to load
  1114. * @source_buffer memory location from which the image is installed
  1115. * @source_size size of the memory area from which the image is
  1116. * installed
  1117. * @image_handle handle for the newly installed image
  1118. * @return status code
  1119. */
  1120. static efi_status_t EFIAPI efi_load_image(bool boot_policy,
  1121. efi_handle_t parent_image,
  1122. struct efi_device_path *file_path,
  1123. void *source_buffer,
  1124. unsigned long source_size,
  1125. efi_handle_t *image_handle)
  1126. {
  1127. struct efi_loaded_image *info;
  1128. struct efi_object *obj;
  1129. EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
  1130. file_path, source_buffer, source_size, image_handle);
  1131. info = calloc(1, sizeof(*info));
  1132. obj = calloc(1, sizeof(*obj));
  1133. if (!source_buffer) {
  1134. struct efi_device_path *dp, *fp;
  1135. efi_status_t ret;
  1136. ret = efi_load_image_from_path(file_path, &source_buffer);
  1137. if (ret != EFI_SUCCESS) {
  1138. free(info);
  1139. free(obj);
  1140. return EFI_EXIT(ret);
  1141. }
  1142. /*
  1143. * split file_path which contains both the device and
  1144. * file parts:
  1145. */
  1146. efi_dp_split_file_path(file_path, &dp, &fp);
  1147. efi_setup_loaded_image(info, obj, dp, fp);
  1148. } else {
  1149. /* In this case, file_path is the "device" path, ie.
  1150. * something like a HARDWARE_DEVICE:MEMORY_MAPPED
  1151. */
  1152. efi_setup_loaded_image(info, obj, file_path, NULL);
  1153. }
  1154. info->reserved = efi_load_pe(source_buffer, info);
  1155. if (!info->reserved) {
  1156. free(info);
  1157. free(obj);
  1158. return EFI_EXIT(EFI_UNSUPPORTED);
  1159. }
  1160. *image_handle = info;
  1161. return EFI_EXIT(EFI_SUCCESS);
  1162. }
  1163. /*
  1164. * Call the entry point of an image.
  1165. *
  1166. * This function implements the StartImage service.
  1167. * See the Unified Extensible Firmware Interface (UEFI) specification
  1168. * for details.
  1169. *
  1170. * @image_handle handle of the image
  1171. * @exit_data_size size of the buffer
  1172. * @exit_data buffer to receive the exit data of the called image
  1173. * @return status code
  1174. */
  1175. static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
  1176. unsigned long *exit_data_size,
  1177. s16 **exit_data)
  1178. {
  1179. ulong (*entry)(void *image_handle, struct efi_system_table *st);
  1180. struct efi_loaded_image *info = image_handle;
  1181. EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
  1182. entry = info->reserved;
  1183. efi_is_direct_boot = false;
  1184. /* call the image! */
  1185. if (setjmp(&info->exit_jmp)) {
  1186. /* We returned from the child image */
  1187. return EFI_EXIT(info->exit_status);
  1188. }
  1189. __efi_nesting_dec();
  1190. __efi_exit_check();
  1191. entry(image_handle, &systab);
  1192. __efi_entry_check();
  1193. __efi_nesting_inc();
  1194. /* Should usually never get here */
  1195. return EFI_EXIT(EFI_SUCCESS);
  1196. }
  1197. /*
  1198. * Leave an EFI application or driver.
  1199. *
  1200. * This function implements the Exit service.
  1201. * See the Unified Extensible Firmware Interface (UEFI) specification
  1202. * for details.
  1203. *
  1204. * @image_handle handle of the application or driver that is exiting
  1205. * @exit_status status code
  1206. * @exit_data_size size of the buffer in bytes
  1207. * @exit_data buffer with data describing an error
  1208. * @return status code
  1209. */
  1210. static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
  1211. efi_status_t exit_status, unsigned long exit_data_size,
  1212. int16_t *exit_data)
  1213. {
  1214. struct efi_loaded_image *loaded_image_info = (void*)image_handle;
  1215. EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
  1216. exit_data_size, exit_data);
  1217. /* Make sure entry/exit counts for EFI world cross-overs match */
  1218. __efi_exit_check();
  1219. /*
  1220. * But longjmp out with the U-Boot gd, not the application's, as
  1221. * the other end is a setjmp call inside EFI context.
  1222. */
  1223. efi_restore_gd();
  1224. loaded_image_info->exit_status = exit_status;
  1225. longjmp(&loaded_image_info->exit_jmp, 1);
  1226. panic("EFI application exited");
  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. /* XXX Should persist EFI variables here */
  1286. board_quiesce_devices();
  1287. /* Fix up caches for EFI payloads if necessary */
  1288. efi_exit_caches();
  1289. /* This stops all lingering devices */
  1290. bootm_disable_interrupts();
  1291. /* Give the payload some time to boot */
  1292. WATCHDOG_RESET();
  1293. return EFI_EXIT(EFI_SUCCESS);
  1294. }
  1295. /*
  1296. * Get next value of the counter.
  1297. *
  1298. * This function implements the NextMonotonicCount service.
  1299. * See the Unified Extensible Firmware Interface (UEFI) specification
  1300. * for details.
  1301. *
  1302. * @count returned value of the counter
  1303. * @return status code
  1304. */
  1305. static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
  1306. {
  1307. static uint64_t mono = 0;
  1308. EFI_ENTRY("%p", count);
  1309. *count = mono++;
  1310. return EFI_EXIT(EFI_SUCCESS);
  1311. }
  1312. /*
  1313. * Sleep.
  1314. *
  1315. * This function implements the Stall sercive.
  1316. * See the Unified Extensible Firmware Interface (UEFI) specification
  1317. * for details.
  1318. *
  1319. * @microseconds period to sleep in microseconds
  1320. * @return status code
  1321. */
  1322. static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
  1323. {
  1324. EFI_ENTRY("%ld", microseconds);
  1325. udelay(microseconds);
  1326. return EFI_EXIT(EFI_SUCCESS);
  1327. }
  1328. /*
  1329. * Reset the watchdog timer.
  1330. *
  1331. * This function implements the WatchdogTimer service.
  1332. * See the Unified Extensible Firmware Interface (UEFI) specification
  1333. * for details.
  1334. *
  1335. * @timeout seconds before reset by watchdog
  1336. * @watchdog_code code to be logged when resetting
  1337. * @data_size size of buffer in bytes
  1338. * @watchdog_data buffer with data describing the reset reason
  1339. * @return status code
  1340. */
  1341. static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
  1342. uint64_t watchdog_code,
  1343. unsigned long data_size,
  1344. uint16_t *watchdog_data)
  1345. {
  1346. EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
  1347. data_size, watchdog_data);
  1348. return efi_unsupported(__func__);
  1349. }
  1350. /*
  1351. * Connect a controller to a driver.
  1352. *
  1353. * This function implements the ConnectController service.
  1354. * See the Unified Extensible Firmware Interface (UEFI) specification
  1355. * for details.
  1356. *
  1357. * @controller_handle handle of the controller
  1358. * @driver_image_handle handle of the driver
  1359. * @remain_device_path device path of a child controller
  1360. * @recursive true to connect all child controllers
  1361. * @return status code
  1362. */
  1363. static efi_status_t EFIAPI efi_connect_controller(
  1364. efi_handle_t controller_handle,
  1365. efi_handle_t *driver_image_handle,
  1366. struct efi_device_path *remain_device_path,
  1367. bool recursive)
  1368. {
  1369. EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
  1370. remain_device_path, recursive);
  1371. return EFI_EXIT(EFI_NOT_FOUND);
  1372. }
  1373. /*
  1374. * Disconnect a controller from a driver.
  1375. *
  1376. * This function implements the DisconnectController service.
  1377. * See the Unified Extensible Firmware Interface (UEFI) specification
  1378. * for details.
  1379. *
  1380. * @controller_handle handle of the controller
  1381. * @driver_image_handle handle of the driver
  1382. * @child_handle handle of the child to destroy
  1383. * @return status code
  1384. */
  1385. static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
  1386. void *driver_image_handle,
  1387. void *child_handle)
  1388. {
  1389. EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
  1390. child_handle);
  1391. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1392. }
  1393. /*
  1394. * Close a protocol.
  1395. *
  1396. * This function implements the CloseProtocol service.
  1397. * See the Unified Extensible Firmware Interface (UEFI) specification
  1398. * for details.
  1399. *
  1400. * @handle handle on which the protocol shall be closed
  1401. * @protocol GUID of the protocol to close
  1402. * @agent_handle handle of the driver
  1403. * @controller_handle handle of the controller
  1404. * @return status code
  1405. */
  1406. static efi_status_t EFIAPI efi_close_protocol(void *handle,
  1407. const efi_guid_t *protocol,
  1408. void *agent_handle,
  1409. void *controller_handle)
  1410. {
  1411. EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, agent_handle,
  1412. controller_handle);
  1413. return EFI_EXIT(EFI_NOT_FOUND);
  1414. }
  1415. /*
  1416. * Provide information about then open status of a protocol on a handle
  1417. *
  1418. * This function implements the OpenProtocolInformation service.
  1419. * See the Unified Extensible Firmware Interface (UEFI) specification
  1420. * for details.
  1421. *
  1422. * @handle handle for which the information shall be retrieved
  1423. * @protocol GUID of the protocol
  1424. * @entry_buffer buffer to receive the open protocol information
  1425. * @entry_count number of entries available in the buffer
  1426. * @return status code
  1427. */
  1428. static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
  1429. const efi_guid_t *protocol,
  1430. struct efi_open_protocol_info_entry **entry_buffer,
  1431. unsigned long *entry_count)
  1432. {
  1433. EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, entry_buffer,
  1434. entry_count);
  1435. return EFI_EXIT(EFI_NOT_FOUND);
  1436. }
  1437. /*
  1438. * Get protocols installed on a handle.
  1439. *
  1440. * This function implements the ProtocolsPerHandleService.
  1441. * See the Unified Extensible Firmware Interface (UEFI) specification
  1442. * for details.
  1443. *
  1444. * @handle handle for which the information is retrieved
  1445. * @protocol_buffer buffer with protocol GUIDs
  1446. * @protocol_buffer_count number of entries in the buffer
  1447. * @return status code
  1448. */
  1449. static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
  1450. efi_guid_t ***protocol_buffer,
  1451. unsigned long *protocol_buffer_count)
  1452. {
  1453. unsigned long buffer_size;
  1454. struct efi_object *efiobj;
  1455. unsigned long i, j;
  1456. struct list_head *lhandle;
  1457. efi_status_t r;
  1458. EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
  1459. protocol_buffer_count);
  1460. if (!handle || !protocol_buffer || !protocol_buffer_count)
  1461. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1462. *protocol_buffer = NULL;
  1463. *protocol_buffer_count = 0;
  1464. list_for_each(lhandle, &efi_obj_list) {
  1465. efiobj = list_entry(lhandle, struct efi_object, link);
  1466. if (efiobj->handle != handle)
  1467. continue;
  1468. /* Count protocols */
  1469. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  1470. if (efiobj->protocols[i].guid)
  1471. ++*protocol_buffer_count;
  1472. }
  1473. /* Copy guids */
  1474. if (*protocol_buffer_count) {
  1475. buffer_size = sizeof(efi_guid_t *) *
  1476. *protocol_buffer_count;
  1477. r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
  1478. buffer_size,
  1479. (void **)protocol_buffer);
  1480. if (r != EFI_SUCCESS)
  1481. return EFI_EXIT(r);
  1482. j = 0;
  1483. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); ++i) {
  1484. if (efiobj->protocols[i].guid) {
  1485. (*protocol_buffer)[j] = (void *)
  1486. efiobj->protocols[i].guid;
  1487. ++j;
  1488. }
  1489. }
  1490. }
  1491. break;
  1492. }
  1493. return EFI_EXIT(EFI_SUCCESS);
  1494. }
  1495. /*
  1496. * Locate handles implementing a protocol.
  1497. *
  1498. * This function implements the LocateHandleBuffer service.
  1499. * See the Unified Extensible Firmware Interface (UEFI) specification
  1500. * for details.
  1501. *
  1502. * @search_type selection criterion
  1503. * @protocol GUID of the protocol
  1504. * @search_key registration key
  1505. * @no_handles number of returned handles
  1506. * @buffer buffer with the returned handles
  1507. * @return status code
  1508. */
  1509. static efi_status_t EFIAPI efi_locate_handle_buffer(
  1510. enum efi_locate_search_type search_type,
  1511. const efi_guid_t *protocol, void *search_key,
  1512. unsigned long *no_handles, efi_handle_t **buffer)
  1513. {
  1514. efi_status_t r;
  1515. unsigned long buffer_size = 0;
  1516. EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key,
  1517. no_handles, buffer);
  1518. if (!no_handles || !buffer) {
  1519. r = EFI_INVALID_PARAMETER;
  1520. goto out;
  1521. }
  1522. *no_handles = 0;
  1523. *buffer = NULL;
  1524. r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
  1525. *buffer);
  1526. if (r != EFI_BUFFER_TOO_SMALL)
  1527. goto out;
  1528. r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
  1529. (void **)buffer);
  1530. if (r != EFI_SUCCESS)
  1531. goto out;
  1532. r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
  1533. *buffer);
  1534. if (r == EFI_SUCCESS)
  1535. *no_handles = buffer_size / sizeof(void *);
  1536. out:
  1537. return EFI_EXIT(r);
  1538. }
  1539. /*
  1540. * Find an interface implementing a protocol.
  1541. *
  1542. * This function implements the LocateProtocol service.
  1543. * See the Unified Extensible Firmware Interface (UEFI) specification
  1544. * for details.
  1545. *
  1546. * @protocol GUID of the protocol
  1547. * @registration registration key passed to the notification function
  1548. * @protocol_interface interface implementing the protocol
  1549. * @return status code
  1550. */
  1551. static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,
  1552. void *registration,
  1553. void **protocol_interface)
  1554. {
  1555. struct list_head *lhandle;
  1556. int i;
  1557. EFI_ENTRY("%pUl, %p, %p", protocol, registration, protocol_interface);
  1558. if (!protocol || !protocol_interface)
  1559. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1560. EFI_PRINT_GUID("protocol", protocol);
  1561. list_for_each(lhandle, &efi_obj_list) {
  1562. struct efi_object *efiobj;
  1563. efiobj = list_entry(lhandle, struct efi_object, link);
  1564. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  1565. struct efi_handler *handler = &efiobj->protocols[i];
  1566. if (!handler->guid)
  1567. continue;
  1568. if (!guidcmp(handler->guid, protocol)) {
  1569. *protocol_interface =
  1570. handler->protocol_interface;
  1571. return EFI_EXIT(EFI_SUCCESS);
  1572. }
  1573. }
  1574. }
  1575. *protocol_interface = NULL;
  1576. return EFI_EXIT(EFI_NOT_FOUND);
  1577. }
  1578. /*
  1579. * Install multiple protocol interfaces.
  1580. *
  1581. * This function implements the MultipleProtocolInterfaces service.
  1582. * See the Unified Extensible Firmware Interface (UEFI) specification
  1583. * for details.
  1584. *
  1585. * @handle handle on which the protocol interfaces shall be installed
  1586. * @... NULL terminated argument list with pairs of protocol GUIDS and
  1587. * interfaces
  1588. * @return status code
  1589. */
  1590. static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
  1591. void **handle, ...)
  1592. {
  1593. EFI_ENTRY("%p", handle);
  1594. va_list argptr;
  1595. const efi_guid_t *protocol;
  1596. void *protocol_interface;
  1597. efi_status_t r = EFI_SUCCESS;
  1598. int i = 0;
  1599. if (!handle)
  1600. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1601. va_start(argptr, handle);
  1602. for (;;) {
  1603. protocol = va_arg(argptr, efi_guid_t*);
  1604. if (!protocol)
  1605. break;
  1606. protocol_interface = va_arg(argptr, void*);
  1607. r = efi_install_protocol_interface(handle, protocol,
  1608. EFI_NATIVE_INTERFACE,
  1609. protocol_interface);
  1610. if (r != EFI_SUCCESS)
  1611. break;
  1612. i++;
  1613. }
  1614. va_end(argptr);
  1615. if (r == EFI_SUCCESS)
  1616. return EFI_EXIT(r);
  1617. /* If an error occured undo all changes. */
  1618. va_start(argptr, handle);
  1619. for (; i; --i) {
  1620. protocol = va_arg(argptr, efi_guid_t*);
  1621. protocol_interface = va_arg(argptr, void*);
  1622. efi_uninstall_protocol_interface(handle, protocol,
  1623. protocol_interface);
  1624. }
  1625. va_end(argptr);
  1626. return EFI_EXIT(r);
  1627. }
  1628. /*
  1629. * Uninstall multiple protocol interfaces.
  1630. *
  1631. * This function implements the UninstallMultipleProtocolInterfaces service.
  1632. * See the Unified Extensible Firmware Interface (UEFI) specification
  1633. * for details.
  1634. *
  1635. * @handle handle from which the protocol interfaces shall be removed
  1636. * @... NULL terminated argument list with pairs of protocol GUIDS and
  1637. * interfaces
  1638. * @return status code
  1639. */
  1640. static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
  1641. void *handle, ...)
  1642. {
  1643. EFI_ENTRY("%p", handle);
  1644. return EFI_EXIT(EFI_INVALID_PARAMETER);
  1645. }
  1646. /*
  1647. * Calculate cyclic redundancy code.
  1648. *
  1649. * This function implements the CalculateCrc32 service.
  1650. * See the Unified Extensible Firmware Interface (UEFI) specification
  1651. * for details.
  1652. *
  1653. * @data buffer with data
  1654. * @data_size size of buffer in bytes
  1655. * @crc32_p cyclic redundancy code
  1656. * @return status code
  1657. */
  1658. static efi_status_t EFIAPI efi_calculate_crc32(void *data,
  1659. unsigned long data_size,
  1660. uint32_t *crc32_p)
  1661. {
  1662. EFI_ENTRY("%p, %ld", data, data_size);
  1663. *crc32_p = crc32(0, data, data_size);
  1664. return EFI_EXIT(EFI_SUCCESS);
  1665. }
  1666. /*
  1667. * Copy memory.
  1668. *
  1669. * This function implements the CopyMem service.
  1670. * See the Unified Extensible Firmware Interface (UEFI) specification
  1671. * for details.
  1672. *
  1673. * @destination destination of the copy operation
  1674. * @source source of the copy operation
  1675. * @length number of bytes to copy
  1676. */
  1677. static void EFIAPI efi_copy_mem(void *destination, const void *source,
  1678. size_t length)
  1679. {
  1680. EFI_ENTRY("%p, %p, %ld", destination, source, (unsigned long)length);
  1681. memcpy(destination, source, length);
  1682. EFI_EXIT(EFI_SUCCESS);
  1683. }
  1684. /*
  1685. * Fill memory with a byte value.
  1686. *
  1687. * This function implements the SetMem service.
  1688. * See the Unified Extensible Firmware Interface (UEFI) specification
  1689. * for details.
  1690. *
  1691. * @buffer buffer to fill
  1692. * @size size of buffer in bytes
  1693. * @value byte to copy to the buffer
  1694. */
  1695. static void EFIAPI efi_set_mem(void *buffer, size_t size, uint8_t value)
  1696. {
  1697. EFI_ENTRY("%p, %ld, 0x%x", buffer, (unsigned long)size, value);
  1698. memset(buffer, value, size);
  1699. EFI_EXIT(EFI_SUCCESS);
  1700. }
  1701. /*
  1702. * Open protocol interface on a handle.
  1703. *
  1704. * This function implements the OpenProtocol interface.
  1705. * See the Unified Extensible Firmware Interface (UEFI) specification
  1706. * for details.
  1707. *
  1708. * @handle handle on which the protocol shall be opened
  1709. * @protocol GUID of the protocol
  1710. * @protocol_interface interface implementing the protocol
  1711. * @agent_handle handle of the driver
  1712. * @controller_handle handle of the controller
  1713. * @attributes attributes indicating how to open the protocol
  1714. * @return status code
  1715. */
  1716. static efi_status_t EFIAPI efi_open_protocol(
  1717. void *handle, const efi_guid_t *protocol,
  1718. void **protocol_interface, void *agent_handle,
  1719. void *controller_handle, uint32_t attributes)
  1720. {
  1721. struct list_head *lhandle;
  1722. int i;
  1723. efi_status_t r = EFI_INVALID_PARAMETER;
  1724. EFI_ENTRY("%p, %pUl, %p, %p, %p, 0x%x", handle, protocol,
  1725. protocol_interface, agent_handle, controller_handle,
  1726. attributes);
  1727. if (!handle || !protocol ||
  1728. (!protocol_interface && attributes !=
  1729. EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
  1730. goto out;
  1731. }
  1732. EFI_PRINT_GUID("protocol", protocol);
  1733. switch (attributes) {
  1734. case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
  1735. case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
  1736. case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
  1737. break;
  1738. case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
  1739. if (controller_handle == handle)
  1740. goto out;
  1741. case EFI_OPEN_PROTOCOL_BY_DRIVER:
  1742. case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
  1743. if (controller_handle == NULL)
  1744. goto out;
  1745. case EFI_OPEN_PROTOCOL_EXCLUSIVE:
  1746. if (agent_handle == NULL)
  1747. goto out;
  1748. break;
  1749. default:
  1750. goto out;
  1751. }
  1752. list_for_each(lhandle, &efi_obj_list) {
  1753. struct efi_object *efiobj;
  1754. efiobj = list_entry(lhandle, struct efi_object, link);
  1755. if (efiobj->handle != handle)
  1756. continue;
  1757. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  1758. struct efi_handler *handler = &efiobj->protocols[i];
  1759. const efi_guid_t *hprotocol = handler->guid;
  1760. if (!hprotocol)
  1761. continue;
  1762. if (!guidcmp(hprotocol, protocol)) {
  1763. if (attributes !=
  1764. EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
  1765. *protocol_interface =
  1766. handler->protocol_interface;
  1767. }
  1768. r = EFI_SUCCESS;
  1769. goto out;
  1770. }
  1771. }
  1772. goto unsupported;
  1773. }
  1774. unsupported:
  1775. r = EFI_UNSUPPORTED;
  1776. out:
  1777. return EFI_EXIT(r);
  1778. }
  1779. /*
  1780. * Get interface of a protocol on a handle.
  1781. *
  1782. * This function implements the HandleProtocol service.
  1783. * See the Unified Extensible Firmware Interface (UEFI) specification
  1784. * for details.
  1785. *
  1786. * @handle handle on which the protocol shall be opened
  1787. * @protocol GUID of the protocol
  1788. * @protocol_interface interface implementing the protocol
  1789. * @return status code
  1790. */
  1791. static efi_status_t EFIAPI efi_handle_protocol(void *handle,
  1792. const efi_guid_t *protocol,
  1793. void **protocol_interface)
  1794. {
  1795. return efi_open_protocol(handle, protocol, protocol_interface, NULL,
  1796. NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
  1797. }
  1798. static const struct efi_boot_services efi_boot_services = {
  1799. .hdr = {
  1800. .headersize = sizeof(struct efi_table_hdr),
  1801. },
  1802. .raise_tpl = efi_raise_tpl,
  1803. .restore_tpl = efi_restore_tpl,
  1804. .allocate_pages = efi_allocate_pages_ext,
  1805. .free_pages = efi_free_pages_ext,
  1806. .get_memory_map = efi_get_memory_map_ext,
  1807. .allocate_pool = efi_allocate_pool_ext,
  1808. .free_pool = efi_free_pool_ext,
  1809. .create_event = efi_create_event_ext,
  1810. .set_timer = efi_set_timer_ext,
  1811. .wait_for_event = efi_wait_for_event,
  1812. .signal_event = efi_signal_event_ext,
  1813. .close_event = efi_close_event,
  1814. .check_event = efi_check_event,
  1815. .install_protocol_interface = efi_install_protocol_interface_ext,
  1816. .reinstall_protocol_interface = efi_reinstall_protocol_interface,
  1817. .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext,
  1818. .handle_protocol = efi_handle_protocol,
  1819. .reserved = NULL,
  1820. .register_protocol_notify = efi_register_protocol_notify,
  1821. .locate_handle = efi_locate_handle_ext,
  1822. .locate_device_path = efi_locate_device_path,
  1823. .install_configuration_table = efi_install_configuration_table_ext,
  1824. .load_image = efi_load_image,
  1825. .start_image = efi_start_image,
  1826. .exit = efi_exit,
  1827. .unload_image = efi_unload_image,
  1828. .exit_boot_services = efi_exit_boot_services,
  1829. .get_next_monotonic_count = efi_get_next_monotonic_count,
  1830. .stall = efi_stall,
  1831. .set_watchdog_timer = efi_set_watchdog_timer,
  1832. .connect_controller = efi_connect_controller,
  1833. .disconnect_controller = efi_disconnect_controller,
  1834. .open_protocol = efi_open_protocol,
  1835. .close_protocol = efi_close_protocol,
  1836. .open_protocol_information = efi_open_protocol_information,
  1837. .protocols_per_handle = efi_protocols_per_handle,
  1838. .locate_handle_buffer = efi_locate_handle_buffer,
  1839. .locate_protocol = efi_locate_protocol,
  1840. .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
  1841. .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
  1842. .calculate_crc32 = efi_calculate_crc32,
  1843. .copy_mem = efi_copy_mem,
  1844. .set_mem = efi_set_mem,
  1845. };
  1846. static uint16_t __efi_runtime_data firmware_vendor[] =
  1847. { 'D','a','s',' ','U','-','b','o','o','t',0 };
  1848. struct efi_system_table __efi_runtime_data systab = {
  1849. .hdr = {
  1850. .signature = EFI_SYSTEM_TABLE_SIGNATURE,
  1851. .revision = 0x20005, /* 2.5 */
  1852. .headersize = sizeof(struct efi_table_hdr),
  1853. },
  1854. .fw_vendor = (long)firmware_vendor,
  1855. .con_in = (void*)&efi_con_in,
  1856. .con_out = (void*)&efi_con_out,
  1857. .std_err = (void*)&efi_con_out,
  1858. .runtime = (void*)&efi_runtime_services,
  1859. .boottime = (void*)&efi_boot_services,
  1860. .nr_tables = 0,
  1861. .tables = (void*)efi_conf_table,
  1862. };