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