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[2]; 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_ext(int pool_type, 134 unsigned long size, 135 void **buffer) 136 { 137 efi_status_t r; 138 139 EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer); 140 r = efi_allocate_pool(pool_type, size, buffer); 141 return EFI_EXIT(r); 142 } 143 144 static efi_status_t EFIAPI efi_free_pool_ext(void *buffer) 145 { 146 efi_status_t r; 147 148 EFI_ENTRY("%p", buffer); 149 r = efi_free_pool(buffer); 150 return EFI_EXIT(r); 151 } 152 153 /* 154 * Our event capabilities are very limited. Only support a single 155 * event to exist, so we don't need to maintain lists. 156 */ 157 static struct { 158 enum efi_event_type type; 159 u32 trigger_type; 160 u32 trigger_time; 161 u64 trigger_next; 162 unsigned long notify_tpl; 163 void (EFIAPI *notify_function) (void *event, void *context); 164 void *notify_context; 165 } efi_event = { 166 /* Disable timers on bootup */ 167 .trigger_next = -1ULL, 168 }; 169 170 static efi_status_t EFIAPI efi_create_event( 171 enum efi_event_type type, ulong notify_tpl, 172 void (EFIAPI *notify_function) (void *event, 173 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 efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table) 381 { 382 int i; 383 384 /* Check for guid override */ 385 for (i = 0; i < systab.nr_tables; i++) { 386 if (!guidcmp(guid, &efi_conf_table[i].guid)) { 387 efi_conf_table[i].table = table; 388 return EFI_SUCCESS; 389 } 390 } 391 392 /* No override, check for overflow */ 393 if (i >= ARRAY_SIZE(efi_conf_table)) 394 return EFI_OUT_OF_RESOURCES; 395 396 /* Add a new entry */ 397 memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid)); 398 efi_conf_table[i].table = table; 399 systab.nr_tables = i + 1; 400 401 return EFI_SUCCESS; 402 } 403 404 static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid, 405 void *table) 406 { 407 EFI_ENTRY("%p, %p", guid, table); 408 return EFI_EXIT(efi_install_configuration_table(guid, table)); 409 } 410 411 static efi_status_t EFIAPI efi_load_image(bool boot_policy, 412 efi_handle_t parent_image, 413 struct efi_device_path *file_path, 414 void *source_buffer, 415 unsigned long source_size, 416 efi_handle_t *image_handle) 417 { 418 static struct efi_object loaded_image_info_obj = { 419 .protocols = { 420 { 421 .guid = &efi_guid_loaded_image, 422 .open = &efi_return_handle, 423 }, 424 }, 425 }; 426 struct efi_loaded_image *info; 427 struct efi_object *obj; 428 429 EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image, 430 file_path, source_buffer, source_size, image_handle); 431 info = malloc(sizeof(*info)); 432 obj = malloc(sizeof(loaded_image_info_obj)); 433 memset(info, 0, sizeof(*info)); 434 memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj)); 435 obj->handle = info; 436 info->file_path = file_path; 437 info->reserved = efi_load_pe(source_buffer, info); 438 if (!info->reserved) { 439 free(info); 440 free(obj); 441 return EFI_EXIT(EFI_UNSUPPORTED); 442 } 443 444 *image_handle = info; 445 list_add_tail(&obj->link, &efi_obj_list); 446 447 return EFI_EXIT(EFI_SUCCESS); 448 } 449 450 static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, 451 unsigned long *exit_data_size, 452 s16 **exit_data) 453 { 454 ulong (*entry)(void *image_handle, struct efi_system_table *st); 455 struct efi_loaded_image *info = image_handle; 456 457 EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data); 458 entry = info->reserved; 459 460 efi_is_direct_boot = false; 461 462 /* call the image! */ 463 if (setjmp(&info->exit_jmp)) { 464 /* We returned from the child image */ 465 return EFI_EXIT(info->exit_status); 466 } 467 468 entry(image_handle, &systab); 469 470 /* Should usually never get here */ 471 return EFI_EXIT(EFI_SUCCESS); 472 } 473 474 static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle, 475 efi_status_t exit_status, unsigned long exit_data_size, 476 int16_t *exit_data) 477 { 478 struct efi_loaded_image *loaded_image_info = (void*)image_handle; 479 480 EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status, 481 exit_data_size, exit_data); 482 483 loaded_image_info->exit_status = exit_status; 484 longjmp(&loaded_image_info->exit_jmp, 1); 485 486 panic("EFI application exited"); 487 } 488 489 static struct efi_object *efi_search_obj(void *handle) 490 { 491 struct list_head *lhandle; 492 493 list_for_each(lhandle, &efi_obj_list) { 494 struct efi_object *efiobj; 495 efiobj = list_entry(lhandle, struct efi_object, link); 496 if (efiobj->handle == handle) 497 return efiobj; 498 } 499 500 return NULL; 501 } 502 503 static efi_status_t EFIAPI efi_unload_image(void *image_handle) 504 { 505 struct efi_object *efiobj; 506 507 EFI_ENTRY("%p", image_handle); 508 efiobj = efi_search_obj(image_handle); 509 if (efiobj) 510 list_del(&efiobj->link); 511 512 return EFI_EXIT(EFI_SUCCESS); 513 } 514 515 static void efi_exit_caches(void) 516 { 517 #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64) 518 /* 519 * Grub on 32bit ARM needs to have caches disabled before jumping into 520 * a zImage, but does not know of all cache layers. Give it a hand. 521 */ 522 if (efi_is_direct_boot) 523 cleanup_before_linux(); 524 #endif 525 } 526 527 static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle, 528 unsigned long map_key) 529 { 530 EFI_ENTRY("%p, %ld", image_handle, map_key); 531 532 /* Fix up caches for EFI payloads if necessary */ 533 efi_exit_caches(); 534 535 /* This stops all lingering devices */ 536 bootm_disable_interrupts(); 537 538 /* Give the payload some time to boot */ 539 WATCHDOG_RESET(); 540 541 return EFI_EXIT(EFI_SUCCESS); 542 } 543 544 static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count) 545 { 546 static uint64_t mono = 0; 547 EFI_ENTRY("%p", count); 548 *count = mono++; 549 return EFI_EXIT(EFI_SUCCESS); 550 } 551 552 static efi_status_t EFIAPI efi_stall(unsigned long microseconds) 553 { 554 EFI_ENTRY("%ld", microseconds); 555 udelay(microseconds); 556 return EFI_EXIT(EFI_SUCCESS); 557 } 558 559 static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout, 560 uint64_t watchdog_code, 561 unsigned long data_size, 562 uint16_t *watchdog_data) 563 { 564 EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code, 565 data_size, watchdog_data); 566 return EFI_EXIT(efi_unsupported(__func__)); 567 } 568 569 static efi_status_t EFIAPI efi_connect_controller( 570 efi_handle_t controller_handle, 571 efi_handle_t *driver_image_handle, 572 struct efi_device_path *remain_device_path, 573 bool recursive) 574 { 575 EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle, 576 remain_device_path, recursive); 577 return EFI_EXIT(EFI_NOT_FOUND); 578 } 579 580 static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle, 581 void *driver_image_handle, 582 void *child_handle) 583 { 584 EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle, 585 child_handle); 586 return EFI_EXIT(EFI_INVALID_PARAMETER); 587 } 588 589 static efi_status_t EFIAPI efi_close_protocol(void *handle, 590 efi_guid_t *protocol, 591 void *agent_handle, 592 void *controller_handle) 593 { 594 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle, 595 controller_handle); 596 return EFI_EXIT(EFI_NOT_FOUND); 597 } 598 599 static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle, 600 efi_guid_t *protocol, 601 struct efi_open_protocol_info_entry **entry_buffer, 602 unsigned long *entry_count) 603 { 604 EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer, 605 entry_count); 606 return EFI_EXIT(EFI_NOT_FOUND); 607 } 608 609 static efi_status_t EFIAPI efi_protocols_per_handle(void *handle, 610 efi_guid_t ***protocol_buffer, 611 unsigned long *protocol_buffer_count) 612 { 613 EFI_ENTRY("%p, %p, %p", handle, protocol_buffer, 614 protocol_buffer_count); 615 return EFI_EXIT(EFI_OUT_OF_RESOURCES); 616 } 617 618 static efi_status_t EFIAPI efi_locate_handle_buffer( 619 enum efi_locate_search_type search_type, 620 efi_guid_t *protocol, void *search_key, 621 unsigned long *no_handles, efi_handle_t **buffer) 622 { 623 EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key, 624 no_handles, buffer); 625 return EFI_EXIT(EFI_NOT_FOUND); 626 } 627 628 static struct efi_class_map efi_class_maps[] = { 629 { 630 .guid = &efi_guid_console_control, 631 .interface = &efi_console_control 632 }, 633 }; 634 635 static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol, 636 void *registration, 637 void **protocol_interface) 638 { 639 int i; 640 641 EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface); 642 for (i = 0; i < ARRAY_SIZE(efi_class_maps); i++) { 643 struct efi_class_map *curmap = &efi_class_maps[i]; 644 if (!guidcmp(protocol, curmap->guid)) { 645 *protocol_interface = (void*)curmap->interface; 646 return EFI_EXIT(EFI_SUCCESS); 647 } 648 } 649 650 return EFI_EXIT(EFI_NOT_FOUND); 651 } 652 653 static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces( 654 void **handle, ...) 655 { 656 EFI_ENTRY("%p", handle); 657 return EFI_EXIT(EFI_OUT_OF_RESOURCES); 658 } 659 660 static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces( 661 void *handle, ...) 662 { 663 EFI_ENTRY("%p", handle); 664 return EFI_EXIT(EFI_INVALID_PARAMETER); 665 } 666 667 static efi_status_t EFIAPI efi_calculate_crc32(void *data, 668 unsigned long data_size, 669 uint32_t *crc32_p) 670 { 671 EFI_ENTRY("%p, %ld", data, data_size); 672 *crc32_p = crc32(0, data, data_size); 673 return EFI_EXIT(EFI_SUCCESS); 674 } 675 676 static void EFIAPI efi_copy_mem(void *destination, void *source, 677 unsigned long length) 678 { 679 EFI_ENTRY("%p, %p, %ld", destination, source, length); 680 memcpy(destination, source, length); 681 } 682 683 static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value) 684 { 685 EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value); 686 memset(buffer, value, size); 687 } 688 689 static efi_status_t EFIAPI efi_open_protocol( 690 void *handle, efi_guid_t *protocol, 691 void **protocol_interface, void *agent_handle, 692 void *controller_handle, uint32_t attributes) 693 { 694 struct list_head *lhandle; 695 int i; 696 efi_status_t r = EFI_UNSUPPORTED; 697 698 EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol, 699 protocol_interface, agent_handle, controller_handle, 700 attributes); 701 list_for_each(lhandle, &efi_obj_list) { 702 struct efi_object *efiobj; 703 efiobj = list_entry(lhandle, struct efi_object, link); 704 705 if (efiobj->handle != handle) 706 continue; 707 708 for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 709 struct efi_handler *handler = &efiobj->protocols[i]; 710 const efi_guid_t *hprotocol = handler->guid; 711 if (!hprotocol) 712 break; 713 if (!guidcmp(hprotocol, protocol)) { 714 r = handler->open(handle, protocol, 715 protocol_interface, agent_handle, 716 controller_handle, attributes); 717 goto out; 718 } 719 } 720 } 721 722 out: 723 return EFI_EXIT(r); 724 } 725 726 static efi_status_t EFIAPI efi_handle_protocol(void *handle, 727 efi_guid_t *protocol, 728 void **protocol_interface) 729 { 730 return efi_open_protocol(handle, protocol, protocol_interface, 731 NULL, NULL, 0); 732 } 733 734 static const struct efi_boot_services efi_boot_services = { 735 .hdr = { 736 .headersize = sizeof(struct efi_table_hdr), 737 }, 738 .raise_tpl = efi_raise_tpl, 739 .restore_tpl = efi_restore_tpl, 740 .allocate_pages = efi_allocate_pages_ext, 741 .free_pages = efi_free_pages_ext, 742 .get_memory_map = efi_get_memory_map_ext, 743 .allocate_pool = efi_allocate_pool_ext, 744 .free_pool = efi_free_pool_ext, 745 .create_event = efi_create_event, 746 .set_timer = efi_set_timer, 747 .wait_for_event = efi_wait_for_event, 748 .signal_event = efi_signal_event, 749 .close_event = efi_close_event, 750 .check_event = efi_check_event, 751 .install_protocol_interface = efi_install_protocol_interface, 752 .reinstall_protocol_interface = efi_reinstall_protocol_interface, 753 .uninstall_protocol_interface = efi_uninstall_protocol_interface, 754 .handle_protocol = efi_handle_protocol, 755 .reserved = NULL, 756 .register_protocol_notify = efi_register_protocol_notify, 757 .locate_handle = efi_locate_handle, 758 .locate_device_path = efi_locate_device_path, 759 .install_configuration_table = efi_install_configuration_table_ext, 760 .load_image = efi_load_image, 761 .start_image = efi_start_image, 762 .exit = efi_exit, 763 .unload_image = efi_unload_image, 764 .exit_boot_services = efi_exit_boot_services, 765 .get_next_monotonic_count = efi_get_next_monotonic_count, 766 .stall = efi_stall, 767 .set_watchdog_timer = efi_set_watchdog_timer, 768 .connect_controller = efi_connect_controller, 769 .disconnect_controller = efi_disconnect_controller, 770 .open_protocol = efi_open_protocol, 771 .close_protocol = efi_close_protocol, 772 .open_protocol_information = efi_open_protocol_information, 773 .protocols_per_handle = efi_protocols_per_handle, 774 .locate_handle_buffer = efi_locate_handle_buffer, 775 .locate_protocol = efi_locate_protocol, 776 .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces, 777 .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces, 778 .calculate_crc32 = efi_calculate_crc32, 779 .copy_mem = efi_copy_mem, 780 .set_mem = efi_set_mem, 781 }; 782 783 784 static uint16_t EFI_RUNTIME_DATA firmware_vendor[] = 785 { 'D','a','s',' ','U','-','b','o','o','t',0 }; 786 787 struct efi_system_table EFI_RUNTIME_DATA systab = { 788 .hdr = { 789 .signature = EFI_SYSTEM_TABLE_SIGNATURE, 790 .revision = 0x20005, /* 2.5 */ 791 .headersize = sizeof(struct efi_table_hdr), 792 }, 793 .fw_vendor = (long)firmware_vendor, 794 .con_in = (void*)&efi_con_in, 795 .con_out = (void*)&efi_con_out, 796 .std_err = (void*)&efi_con_out, 797 .runtime = (void*)&efi_runtime_services, 798 .boottime = (void*)&efi_boot_services, 799 .nr_tables = 0, 800 .tables = (void*)efi_conf_table, 801 }; 802