efi_boottime.c 54 KB

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