efi_boottime.c 21 KB

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