efi_boottime.c 21 KB

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