efi_boottime.c 54 KB

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