efi_boottime.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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 <efi_loader.h>
  10. #include <malloc.h>
  11. #include <asm/global_data.h>
  12. #include <libfdt_env.h>
  13. #include <u-boot/crc.h>
  14. #include <bootm.h>
  15. #include <inttypes.h>
  16. #include <watchdog.h>
  17. DECLARE_GLOBAL_DATA_PTR;
  18. /* This list contains all the EFI objects our payload has access to */
  19. LIST_HEAD(efi_obj_list);
  20. /*
  21. * If we're running on nasty systems (32bit ARM booting into non-EFI Linux)
  22. * we need to do trickery with caches. Since we don't want to break the EFI
  23. * aware boot path, only apply hacks when loading exiting directly (breaking
  24. * direct Linux EFI booting along the way - oh well).
  25. */
  26. static bool efi_is_direct_boot = true;
  27. /*
  28. * EFI can pass arbitrary additional "tables" containing vendor specific
  29. * information to the payload. One such table is the FDT table which contains
  30. * a pointer to a flattened device tree blob.
  31. *
  32. * In most cases we want to pass an FDT to the payload, so reserve one slot of
  33. * config table space for it. The pointer gets populated by do_bootefi_exec().
  34. */
  35. static struct efi_configuration_table EFI_RUNTIME_DATA efi_conf_table[1];
  36. /*
  37. * The "gd" pointer lives in a register on ARM and AArch64 that we declare
  38. * fixed when compiling U-Boot. However, the payload does not know about that
  39. * restriction so we need to manually swap its and our view of that register on
  40. * EFI callback entry/exit.
  41. */
  42. static volatile void *efi_gd, *app_gd;
  43. /* Called from do_bootefi_exec() */
  44. void efi_save_gd(void)
  45. {
  46. efi_gd = gd;
  47. }
  48. /* Called on every callback entry */
  49. void efi_restore_gd(void)
  50. {
  51. /* Only restore if we're already in EFI context */
  52. if (!efi_gd)
  53. return;
  54. if (gd != efi_gd)
  55. app_gd = gd;
  56. gd = efi_gd;
  57. }
  58. /* Called on every callback exit */
  59. efi_status_t efi_exit_func(efi_status_t ret)
  60. {
  61. gd = app_gd;
  62. return ret;
  63. }
  64. static efi_status_t efi_unsupported(const char *funcname)
  65. {
  66. debug("EFI: App called into unimplemented function %s\n", funcname);
  67. return EFI_EXIT(EFI_UNSUPPORTED);
  68. }
  69. static int guidcmp(const efi_guid_t *g1, const efi_guid_t *g2)
  70. {
  71. return memcmp(g1, g2, sizeof(efi_guid_t));
  72. }
  73. static unsigned long EFIAPI efi_raise_tpl(unsigned long new_tpl)
  74. {
  75. EFI_ENTRY("0x%lx", new_tpl);
  76. return EFI_EXIT(0);
  77. }
  78. static void EFIAPI efi_restore_tpl(unsigned long old_tpl)
  79. {
  80. EFI_ENTRY("0x%lx", old_tpl);
  81. EFI_EXIT(efi_unsupported(__func__));
  82. }
  83. efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type,
  84. unsigned long pages,
  85. uint64_t *memory)
  86. {
  87. efi_status_t r;
  88. EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory);
  89. r = efi_allocate_pages(type, memory_type, pages, memory);
  90. return EFI_EXIT(r);
  91. }
  92. efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory, unsigned long pages)
  93. {
  94. efi_status_t r;
  95. EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages);
  96. r = efi_free_pages(memory, pages);
  97. return EFI_EXIT(r);
  98. }
  99. efi_status_t EFIAPI efi_get_memory_map_ext(unsigned long *memory_map_size,
  100. struct efi_mem_desc *memory_map,
  101. unsigned long *map_key,
  102. unsigned long *descriptor_size,
  103. uint32_t *descriptor_version)
  104. {
  105. efi_status_t r;
  106. EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map,
  107. map_key, descriptor_size, descriptor_version);
  108. r = efi_get_memory_map(memory_map_size, memory_map, map_key,
  109. descriptor_size, descriptor_version);
  110. return EFI_EXIT(r);
  111. }
  112. static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
  113. unsigned long size,
  114. void **buffer)
  115. {
  116. efi_status_t r;
  117. EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer);
  118. r = efi_allocate_pool(pool_type, size, buffer);
  119. return EFI_EXIT(r);
  120. }
  121. static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
  122. {
  123. efi_status_t r;
  124. EFI_ENTRY("%p", buffer);
  125. r = efi_free_pool(buffer);
  126. return EFI_EXIT(r);
  127. }
  128. /*
  129. * Our event capabilities are very limited. Only support a single
  130. * event to exist, so we don't need to maintain lists.
  131. */
  132. static struct {
  133. enum efi_event_type type;
  134. u32 trigger_type;
  135. u32 trigger_time;
  136. u64 trigger_next;
  137. unsigned long notify_tpl;
  138. void (*notify_function) (void *event, void *context);
  139. void *notify_context;
  140. } efi_event = {
  141. /* Disable timers on bootup */
  142. .trigger_next = -1ULL,
  143. };
  144. static efi_status_t EFIAPI efi_create_event(
  145. enum efi_event_type type, ulong notify_tpl,
  146. void (*notify_function) (void *event, void *context),
  147. void *notify_context, void **event)
  148. {
  149. EFI_ENTRY("%d, 0x%lx, %p, %p", type, notify_tpl, notify_function,
  150. notify_context);
  151. if (efi_event.notify_function) {
  152. /* We only support one event at a time */
  153. return EFI_EXIT(EFI_OUT_OF_RESOURCES);
  154. }
  155. efi_event.type = type;
  156. efi_event.notify_tpl = notify_tpl;
  157. efi_event.notify_function = notify_function;
  158. efi_event.notify_context = notify_context;
  159. *event = &efi_event;
  160. return EFI_EXIT(EFI_SUCCESS);
  161. }
  162. /*
  163. * Our timers have to work without interrupts, so we check whenever keyboard
  164. * input or disk accesses happen if enough time elapsed for it to fire.
  165. */
  166. void efi_timer_check(void)
  167. {
  168. u64 now = timer_get_us();
  169. if (now >= efi_event.trigger_next) {
  170. /* Triggering! */
  171. if (efi_event.trigger_type == EFI_TIMER_PERIODIC)
  172. efi_event.trigger_next += efi_event.trigger_time / 10;
  173. efi_event.notify_function(&efi_event, efi_event.notify_context);
  174. }
  175. WATCHDOG_RESET();
  176. }
  177. static efi_status_t EFIAPI efi_set_timer(void *event, int type,
  178. uint64_t trigger_time)
  179. {
  180. /* We don't have 64bit division available everywhere, so limit timer
  181. * distances to 32bit bits. */
  182. u32 trigger32 = trigger_time;
  183. EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time);
  184. if (trigger32 < trigger_time) {
  185. printf("WARNING: Truncating timer from %"PRIx64" to %x\n",
  186. trigger_time, trigger32);
  187. }
  188. if (event != &efi_event) {
  189. /* We only support one event at a time */
  190. return EFI_EXIT(EFI_INVALID_PARAMETER);
  191. }
  192. switch (type) {
  193. case EFI_TIMER_STOP:
  194. efi_event.trigger_next = -1ULL;
  195. break;
  196. case EFI_TIMER_PERIODIC:
  197. case EFI_TIMER_RELATIVE:
  198. efi_event.trigger_next = timer_get_us() + (trigger32 / 10);
  199. break;
  200. default:
  201. return EFI_EXIT(EFI_INVALID_PARAMETER);
  202. }
  203. efi_event.trigger_type = type;
  204. efi_event.trigger_time = trigger_time;
  205. return EFI_EXIT(EFI_SUCCESS);
  206. }
  207. static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events,
  208. void *event, unsigned long *index)
  209. {
  210. u64 now;
  211. EFI_ENTRY("%ld, %p, %p", num_events, event, index);
  212. now = timer_get_us();
  213. while (now < efi_event.trigger_next) { }
  214. efi_timer_check();
  215. return EFI_EXIT(EFI_SUCCESS);
  216. }
  217. static efi_status_t EFIAPI efi_signal_event(void *event)
  218. {
  219. EFI_ENTRY("%p", event);
  220. return EFI_EXIT(EFI_SUCCESS);
  221. }
  222. static efi_status_t EFIAPI efi_close_event(void *event)
  223. {
  224. EFI_ENTRY("%p", event);
  225. efi_event.trigger_next = -1ULL;
  226. return EFI_EXIT(EFI_SUCCESS);
  227. }
  228. static efi_status_t EFIAPI efi_check_event(void *event)
  229. {
  230. EFI_ENTRY("%p", event);
  231. return EFI_EXIT(EFI_NOT_READY);
  232. }
  233. static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
  234. efi_guid_t *protocol, int protocol_interface_type,
  235. void *protocol_interface)
  236. {
  237. EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type,
  238. protocol_interface);
  239. return EFI_EXIT(EFI_OUT_OF_RESOURCES);
  240. }
  241. static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
  242. efi_guid_t *protocol, void *old_interface,
  243. void *new_interface)
  244. {
  245. EFI_ENTRY("%p, %p, %p, %p", handle, protocol, old_interface,
  246. new_interface);
  247. return EFI_EXIT(EFI_ACCESS_DENIED);
  248. }
  249. static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle,
  250. efi_guid_t *protocol, void *protocol_interface)
  251. {
  252. EFI_ENTRY("%p, %p, %p", handle, protocol, protocol_interface);
  253. return EFI_EXIT(EFI_NOT_FOUND);
  254. }
  255. static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol,
  256. void *event,
  257. void **registration)
  258. {
  259. EFI_ENTRY("%p, %p, %p", protocol, event, registration);
  260. return EFI_EXIT(EFI_OUT_OF_RESOURCES);
  261. }
  262. static int efi_search(enum efi_locate_search_type search_type,
  263. efi_guid_t *protocol, void *search_key,
  264. struct efi_object *efiobj)
  265. {
  266. int i;
  267. switch (search_type) {
  268. case all_handles:
  269. return 0;
  270. case by_register_notify:
  271. return -1;
  272. case by_protocol:
  273. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  274. const efi_guid_t *guid = efiobj->protocols[i].guid;
  275. if (guid && !guidcmp(guid, protocol))
  276. return 0;
  277. }
  278. return -1;
  279. }
  280. return -1;
  281. }
  282. static efi_status_t EFIAPI efi_locate_handle(
  283. enum efi_locate_search_type search_type,
  284. efi_guid_t *protocol, void *search_key,
  285. unsigned long *buffer_size, efi_handle_t *buffer)
  286. {
  287. struct list_head *lhandle;
  288. unsigned long size = 0;
  289. EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
  290. buffer_size, buffer);
  291. /* Count how much space we need */
  292. list_for_each(lhandle, &efi_obj_list) {
  293. struct efi_object *efiobj;
  294. efiobj = list_entry(lhandle, struct efi_object, link);
  295. if (!efi_search(search_type, protocol, search_key, efiobj)) {
  296. size += sizeof(void*);
  297. }
  298. }
  299. if (*buffer_size < size) {
  300. *buffer_size = size;
  301. return EFI_EXIT(EFI_BUFFER_TOO_SMALL);
  302. }
  303. /* Then fill the array */
  304. list_for_each(lhandle, &efi_obj_list) {
  305. struct efi_object *efiobj;
  306. efiobj = list_entry(lhandle, struct efi_object, link);
  307. if (!efi_search(search_type, protocol, search_key, efiobj)) {
  308. *(buffer++) = efiobj->handle;
  309. }
  310. }
  311. *buffer_size = size;
  312. return EFI_EXIT(EFI_SUCCESS);
  313. }
  314. static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol,
  315. struct efi_device_path **device_path,
  316. efi_handle_t *device)
  317. {
  318. EFI_ENTRY("%p, %p, %p", protocol, device_path, device);
  319. return EFI_EXIT(EFI_NOT_FOUND);
  320. }
  321. static efi_status_t EFIAPI efi_install_configuration_table(efi_guid_t *guid,
  322. void *table)
  323. {
  324. int i;
  325. EFI_ENTRY("%p, %p", guid, table);
  326. /* Check for guid override */
  327. for (i = 0; i < systab.nr_tables; i++) {
  328. if (!guidcmp(guid, &efi_conf_table[i].guid)) {
  329. efi_conf_table[i].table = table;
  330. return EFI_EXIT(EFI_SUCCESS);
  331. }
  332. }
  333. /* No override, check for overflow */
  334. if (i >= ARRAY_SIZE(efi_conf_table))
  335. return EFI_EXIT(EFI_OUT_OF_RESOURCES);
  336. /* Add a new entry */
  337. memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid));
  338. efi_conf_table[i].table = table;
  339. systab.nr_tables = i;
  340. return EFI_EXIT(EFI_SUCCESS);
  341. }
  342. static efi_status_t EFIAPI efi_load_image(bool boot_policy,
  343. efi_handle_t parent_image,
  344. struct efi_device_path *file_path,
  345. void *source_buffer,
  346. unsigned long source_size,
  347. efi_handle_t *image_handle)
  348. {
  349. static struct efi_object loaded_image_info_obj = {
  350. .protocols = {
  351. {
  352. .guid = &efi_guid_loaded_image,
  353. .open = &efi_return_handle,
  354. },
  355. },
  356. };
  357. struct efi_loaded_image *info;
  358. struct efi_object *obj;
  359. EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
  360. file_path, source_buffer, source_size, image_handle);
  361. info = malloc(sizeof(*info));
  362. obj = malloc(sizeof(loaded_image_info_obj));
  363. memset(info, 0, sizeof(*info));
  364. memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj));
  365. obj->handle = info;
  366. info->file_path = file_path;
  367. info->reserved = efi_load_pe(source_buffer, info);
  368. if (!info->reserved) {
  369. free(info);
  370. free(obj);
  371. return EFI_EXIT(EFI_UNSUPPORTED);
  372. }
  373. *image_handle = info;
  374. list_add_tail(&obj->link, &efi_obj_list);
  375. return EFI_EXIT(EFI_SUCCESS);
  376. }
  377. static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
  378. unsigned long *exit_data_size,
  379. s16 **exit_data)
  380. {
  381. ulong (*entry)(void *image_handle, struct efi_system_table *st);
  382. struct efi_loaded_image *info = image_handle;
  383. EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
  384. entry = info->reserved;
  385. efi_is_direct_boot = false;
  386. /* call the image! */
  387. if (setjmp(&info->exit_jmp)) {
  388. /* We returned from the child image */
  389. return EFI_EXIT(info->exit_status);
  390. }
  391. entry(image_handle, &systab);
  392. /* Should usually never get here */
  393. return EFI_EXIT(EFI_SUCCESS);
  394. }
  395. static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
  396. efi_status_t exit_status, unsigned long exit_data_size,
  397. int16_t *exit_data)
  398. {
  399. struct efi_loaded_image *loaded_image_info = (void*)image_handle;
  400. EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
  401. exit_data_size, exit_data);
  402. loaded_image_info->exit_status = exit_status;
  403. longjmp(&loaded_image_info->exit_jmp, 1);
  404. panic("EFI application exited");
  405. }
  406. static struct efi_object *efi_search_obj(void *handle)
  407. {
  408. struct list_head *lhandle;
  409. list_for_each(lhandle, &efi_obj_list) {
  410. struct efi_object *efiobj;
  411. efiobj = list_entry(lhandle, struct efi_object, link);
  412. if (efiobj->handle == handle)
  413. return efiobj;
  414. }
  415. return NULL;
  416. }
  417. static efi_status_t EFIAPI efi_unload_image(void *image_handle)
  418. {
  419. struct efi_object *efiobj;
  420. EFI_ENTRY("%p", image_handle);
  421. efiobj = efi_search_obj(image_handle);
  422. if (efiobj)
  423. list_del(&efiobj->link);
  424. return EFI_EXIT(EFI_SUCCESS);
  425. }
  426. static void efi_exit_caches(void)
  427. {
  428. #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
  429. /*
  430. * Grub on 32bit ARM needs to have caches disabled before jumping into
  431. * a zImage, but does not know of all cache layers. Give it a hand.
  432. */
  433. if (efi_is_direct_boot)
  434. cleanup_before_linux();
  435. #endif
  436. }
  437. static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle,
  438. unsigned long map_key)
  439. {
  440. EFI_ENTRY("%p, %ld", image_handle, map_key);
  441. /* Fix up caches for EFI payloads if necessary */
  442. efi_exit_caches();
  443. /* This stops all lingering devices */
  444. bootm_disable_interrupts();
  445. /* Give the payload some time to boot */
  446. WATCHDOG_RESET();
  447. return EFI_EXIT(EFI_SUCCESS);
  448. }
  449. static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
  450. {
  451. static uint64_t mono = 0;
  452. EFI_ENTRY("%p", count);
  453. *count = mono++;
  454. return EFI_EXIT(EFI_SUCCESS);
  455. }
  456. static efi_status_t EFIAPI efi_stall(unsigned long microseconds)
  457. {
  458. EFI_ENTRY("%ld", microseconds);
  459. udelay(microseconds);
  460. return EFI_EXIT(EFI_SUCCESS);
  461. }
  462. static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
  463. uint64_t watchdog_code,
  464. unsigned long data_size,
  465. uint16_t *watchdog_data)
  466. {
  467. EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code,
  468. data_size, watchdog_data);
  469. return EFI_EXIT(efi_unsupported(__func__));
  470. }
  471. static efi_status_t EFIAPI efi_connect_controller(
  472. efi_handle_t controller_handle,
  473. efi_handle_t *driver_image_handle,
  474. struct efi_device_path *remain_device_path,
  475. bool recursive)
  476. {
  477. EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
  478. remain_device_path, recursive);
  479. return EFI_EXIT(EFI_NOT_FOUND);
  480. }
  481. static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
  482. void *driver_image_handle,
  483. void *child_handle)
  484. {
  485. EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
  486. child_handle);
  487. return EFI_EXIT(EFI_INVALID_PARAMETER);
  488. }
  489. static efi_status_t EFIAPI efi_close_protocol(void *handle,
  490. efi_guid_t *protocol,
  491. void *agent_handle,
  492. void *controller_handle)
  493. {
  494. EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle,
  495. controller_handle);
  496. return EFI_EXIT(EFI_NOT_FOUND);
  497. }
  498. static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle,
  499. efi_guid_t *protocol,
  500. struct efi_open_protocol_info_entry **entry_buffer,
  501. unsigned long *entry_count)
  502. {
  503. EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer,
  504. entry_count);
  505. return EFI_EXIT(EFI_NOT_FOUND);
  506. }
  507. static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,
  508. efi_guid_t ***protocol_buffer,
  509. unsigned long *protocol_buffer_count)
  510. {
  511. EFI_ENTRY("%p, %p, %p", handle, protocol_buffer,
  512. protocol_buffer_count);
  513. return EFI_EXIT(EFI_OUT_OF_RESOURCES);
  514. }
  515. static efi_status_t EFIAPI efi_locate_handle_buffer(
  516. enum efi_locate_search_type search_type,
  517. efi_guid_t *protocol, void *search_key,
  518. unsigned long *no_handles, efi_handle_t **buffer)
  519. {
  520. EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key,
  521. no_handles, buffer);
  522. return EFI_EXIT(EFI_NOT_FOUND);
  523. }
  524. static struct efi_class_map efi_class_maps[] = {
  525. {
  526. .guid = &efi_guid_console_control,
  527. .interface = &efi_console_control
  528. },
  529. };
  530. static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol,
  531. void *registration,
  532. void **protocol_interface)
  533. {
  534. int i;
  535. EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface);
  536. for (i = 0; i < ARRAY_SIZE(efi_class_maps); i++) {
  537. struct efi_class_map *curmap = &efi_class_maps[i];
  538. if (!guidcmp(protocol, curmap->guid)) {
  539. *protocol_interface = (void*)curmap->interface;
  540. return EFI_EXIT(EFI_SUCCESS);
  541. }
  542. }
  543. return EFI_EXIT(EFI_NOT_FOUND);
  544. }
  545. static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
  546. void **handle, ...)
  547. {
  548. EFI_ENTRY("%p", handle);
  549. return EFI_EXIT(EFI_OUT_OF_RESOURCES);
  550. }
  551. static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
  552. void *handle, ...)
  553. {
  554. EFI_ENTRY("%p", handle);
  555. return EFI_EXIT(EFI_INVALID_PARAMETER);
  556. }
  557. static efi_status_t EFIAPI efi_calculate_crc32(void *data,
  558. unsigned long data_size,
  559. uint32_t *crc32_p)
  560. {
  561. EFI_ENTRY("%p, %ld", data, data_size);
  562. *crc32_p = crc32(0, data, data_size);
  563. return EFI_EXIT(EFI_SUCCESS);
  564. }
  565. static void EFIAPI efi_copy_mem(void *destination, void *source,
  566. unsigned long length)
  567. {
  568. EFI_ENTRY("%p, %p, %ld", destination, source, length);
  569. memcpy(destination, source, length);
  570. }
  571. static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value)
  572. {
  573. EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value);
  574. memset(buffer, value, size);
  575. }
  576. static efi_status_t EFIAPI efi_open_protocol(
  577. void *handle, efi_guid_t *protocol,
  578. void **protocol_interface, void *agent_handle,
  579. void *controller_handle, uint32_t attributes)
  580. {
  581. struct list_head *lhandle;
  582. int i;
  583. efi_status_t r = EFI_UNSUPPORTED;
  584. EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol,
  585. protocol_interface, agent_handle, controller_handle,
  586. attributes);
  587. list_for_each(lhandle, &efi_obj_list) {
  588. struct efi_object *efiobj;
  589. efiobj = list_entry(lhandle, struct efi_object, link);
  590. if (efiobj->handle != handle)
  591. continue;
  592. for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
  593. struct efi_handler *handler = &efiobj->protocols[i];
  594. const efi_guid_t *hprotocol = handler->guid;
  595. if (!hprotocol)
  596. break;
  597. if (!guidcmp(hprotocol, protocol)) {
  598. r = handler->open(handle, protocol,
  599. protocol_interface, agent_handle,
  600. controller_handle, attributes);
  601. goto out;
  602. }
  603. }
  604. }
  605. out:
  606. return EFI_EXIT(r);
  607. }
  608. static efi_status_t EFIAPI efi_handle_protocol(void *handle,
  609. efi_guid_t *protocol,
  610. void **protocol_interface)
  611. {
  612. return efi_open_protocol(handle, protocol, protocol_interface,
  613. NULL, NULL, 0);
  614. }
  615. static const struct efi_boot_services efi_boot_services = {
  616. .hdr = {
  617. .headersize = sizeof(struct efi_table_hdr),
  618. },
  619. .raise_tpl = efi_raise_tpl,
  620. .restore_tpl = efi_restore_tpl,
  621. .allocate_pages = efi_allocate_pages_ext,
  622. .free_pages = efi_free_pages_ext,
  623. .get_memory_map = efi_get_memory_map_ext,
  624. .allocate_pool = efi_allocate_pool_ext,
  625. .free_pool = efi_free_pool_ext,
  626. .create_event = efi_create_event,
  627. .set_timer = efi_set_timer,
  628. .wait_for_event = efi_wait_for_event,
  629. .signal_event = efi_signal_event,
  630. .close_event = efi_close_event,
  631. .check_event = efi_check_event,
  632. .install_protocol_interface = efi_install_protocol_interface,
  633. .reinstall_protocol_interface = efi_reinstall_protocol_interface,
  634. .uninstall_protocol_interface = efi_uninstall_protocol_interface,
  635. .handle_protocol = efi_handle_protocol,
  636. .reserved = NULL,
  637. .register_protocol_notify = efi_register_protocol_notify,
  638. .locate_handle = efi_locate_handle,
  639. .locate_device_path = efi_locate_device_path,
  640. .install_configuration_table = efi_install_configuration_table,
  641. .load_image = efi_load_image,
  642. .start_image = efi_start_image,
  643. .exit = efi_exit,
  644. .unload_image = efi_unload_image,
  645. .exit_boot_services = efi_exit_boot_services,
  646. .get_next_monotonic_count = efi_get_next_monotonic_count,
  647. .stall = efi_stall,
  648. .set_watchdog_timer = efi_set_watchdog_timer,
  649. .connect_controller = efi_connect_controller,
  650. .disconnect_controller = efi_disconnect_controller,
  651. .open_protocol = efi_open_protocol,
  652. .close_protocol = efi_close_protocol,
  653. .open_protocol_information = efi_open_protocol_information,
  654. .protocols_per_handle = efi_protocols_per_handle,
  655. .locate_handle_buffer = efi_locate_handle_buffer,
  656. .locate_protocol = efi_locate_protocol,
  657. .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces,
  658. .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces,
  659. .calculate_crc32 = efi_calculate_crc32,
  660. .copy_mem = efi_copy_mem,
  661. .set_mem = efi_set_mem,
  662. };
  663. static uint16_t EFI_RUNTIME_DATA firmware_vendor[] =
  664. { 'D','a','s',' ','U','-','b','o','o','t',0 };
  665. struct efi_system_table EFI_RUNTIME_DATA systab = {
  666. .hdr = {
  667. .signature = EFI_SYSTEM_TABLE_SIGNATURE,
  668. .revision = 0x20005, /* 2.5 */
  669. .headersize = sizeof(struct efi_table_hdr),
  670. },
  671. .fw_vendor = (long)firmware_vendor,
  672. .con_in = (void*)&efi_con_in,
  673. .con_out = (void*)&efi_con_out,
  674. .std_err = (void*)&efi_con_out,
  675. .runtime = (void*)&efi_runtime_services,
  676. .boottime = (void*)&efi_boot_services,
  677. .nr_tables = 0,
  678. .tables = (void*)efi_conf_table,
  679. };