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