efi_boottime.c 21 KB

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