efi_boottime.c 21 KB

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