1 // SPDX-License-Identifier: GPL-2.0+
3 * EFI application runtime services
5 * Copyright (c) 2016 Alexander Graf
12 #include <efi_loader.h>
13 #include <efi_variable.h>
17 #include <asm/global_data.h>
18 #include <u-boot/crc.h>
19 #include <asm/sections.h>
21 /* For manual relocation support */
22 DECLARE_GLOBAL_DATA_PTR;
24 /* GUID of the runtime properties table */
25 static const efi_guid_t efi_rt_properties_table_guid =
26 EFI_RT_PROPERTIES_TABLE_GUID;
28 struct efi_runtime_mmio_list {
29 struct list_head link;
35 /* This list contains all runtime available mmio regions */
36 static LIST_HEAD(efi_runtime_mmio);
38 static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void);
42 * header for each architecture (or a generic header) rather than being repeated
45 #if defined(__aarch64__)
46 #define R_RELATIVE R_AARCH64_RELATIVE
47 #define R_MASK 0xffffffffULL
49 #elif defined(__arm__)
50 #define R_RELATIVE R_ARM_RELATIVE
51 #define R_MASK 0xffULL
52 #elif defined(__i386__)
53 #define R_RELATIVE R_386_RELATIVE
54 #define R_MASK 0xffULL
55 #elif defined(__x86_64__)
56 #define R_RELATIVE R_X86_64_RELATIVE
57 #define R_MASK 0xffffffffULL
59 #elif defined(__riscv)
60 #define R_RELATIVE R_RISCV_RELATIVE
61 #define R_MASK 0xffULL
70 #if (__riscv_xlen == 32)
71 #define R_ABSOLUTE R_RISCV_32
73 #elif (__riscv_xlen == 64)
74 #define R_ABSOLUTE R_RISCV_64
77 #error unknown riscv target
80 #error Need to add relocation awareness
94 static __efi_runtime_data struct efi_mem_desc *efi_virtmap;
95 static __efi_runtime_data efi_uintn_t efi_descriptor_count;
96 static __efi_runtime_data efi_uintn_t efi_descriptor_size;
99 * EFI runtime code lives in two stages. In the first stage, U-Boot and an EFI
100 * payload are running concurrently at the same time. In this mode, we can
101 * handle a good number of runtime callbacks
105 * efi_init_runtime_supported() - create runtime properties table
107 * Create a configuration table specifying which services are available at
110 * Return: status code
112 efi_status_t efi_init_runtime_supported(void)
114 const efi_guid_t efi_guid_efi_rt_var_file = U_BOOT_EFI_RT_VAR_FILE_GUID;
116 struct efi_rt_properties_table *rt_table;
118 ret = efi_allocate_pool(EFI_RUNTIME_SERVICES_DATA,
119 sizeof(struct efi_rt_properties_table),
121 if (ret != EFI_SUCCESS)
124 rt_table->version = EFI_RT_PROPERTIES_TABLE_VERSION;
125 rt_table->length = sizeof(struct efi_rt_properties_table);
126 rt_table->runtime_services_supported =
127 EFI_RT_SUPPORTED_GET_VARIABLE |
128 EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME |
129 EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP |
130 EFI_RT_SUPPORTED_CONVERT_POINTER;
132 if (IS_ENABLED(CONFIG_EFI_RT_VOLATILE_STORE)) {
133 ret = efi_set_variable_int(u"RTStorageVolatile",
134 &efi_guid_efi_rt_var_file,
135 EFI_VARIABLE_BOOTSERVICE_ACCESS |
136 EFI_VARIABLE_RUNTIME_ACCESS |
137 EFI_VARIABLE_READ_ONLY,
138 sizeof(EFI_VAR_FILE_NAME),
139 EFI_VAR_FILE_NAME, false);
140 if (ret != EFI_SUCCESS) {
141 log_err("Failed to set RTStorageVolatile\n");
144 rt_table->runtime_services_supported |= EFI_RT_SUPPORTED_SET_VARIABLE;
148 * This value must be synced with efi_runtime_detach_list
149 * as well as efi_runtime_services.
151 #ifdef CONFIG_EFI_HAVE_RUNTIME_RESET
152 rt_table->runtime_services_supported |= EFI_RT_SUPPORTED_RESET_SYSTEM;
155 ret = efi_install_configuration_table(&efi_rt_properties_table_guid,
161 * efi_memcpy_runtime() - copy memory area
163 * At runtime memcpy() is not available.
165 * Overlapping memory areas can be copied safely if src >= dest.
167 * @dest: destination buffer
168 * @src: source buffer
169 * @n: number of bytes to copy
170 * Return: pointer to destination buffer
172 void __efi_runtime efi_memcpy_runtime(void *dest, const void *src, size_t n)
182 * efi_update_table_header_crc32() - Update crc32 in table header
186 void __efi_runtime efi_update_table_header_crc32(struct efi_table_hdr *table)
189 table->crc32 = crc32(0, (const unsigned char *)table,
194 * efi_reset_system_boottime() - reset system at boot time
196 * This function implements the ResetSystem() runtime service before
197 * SetVirtualAddressMap() is called.
199 * See the Unified Extensible Firmware Interface (UEFI) specification for
202 * @reset_type: type of reset to perform
203 * @reset_status: status code for the reset
204 * @data_size: size of reset_data
205 * @reset_data: information about the reset
207 static void EFIAPI efi_reset_system_boottime(
208 enum efi_reset_type reset_type,
209 efi_status_t reset_status,
210 unsigned long data_size, void *reset_data)
212 struct efi_event *evt;
214 EFI_ENTRY("%d %lx %lx %p", reset_type, reset_status, data_size,
218 list_for_each_entry(evt, &efi_events, link) {
221 &efi_guid_event_group_reset_system)) {
222 efi_signal_event(evt);
226 switch (reset_type) {
229 case EFI_RESET_PLATFORM_SPECIFIC:
230 do_reset(NULL, 0, 0, NULL);
232 case EFI_RESET_SHUTDOWN:
233 #ifdef CONFIG_CMD_POWEROFF
234 do_poweroff(NULL, 0, 0, NULL);
243 * efi_get_time_boottime() - get current time at boot time
245 * This function implements the GetTime runtime service before
246 * SetVirtualAddressMap() is called.
248 * See the Unified Extensible Firmware Interface (UEFI) specification
251 * @time: pointer to structure to receive current time
252 * @capabilities: pointer to structure to receive RTC properties
253 * Returns: status code
255 static efi_status_t EFIAPI efi_get_time_boottime(
256 struct efi_time *time,
257 struct efi_time_cap *capabilities)
259 #ifdef CONFIG_EFI_GET_TIME
260 efi_status_t ret = EFI_SUCCESS;
264 EFI_ENTRY("%p %p", time, capabilities);
267 ret = EFI_INVALID_PARAMETER;
270 if (uclass_get_device(UCLASS_RTC, 0, &dev) ||
271 dm_rtc_get(dev, &tm)) {
272 ret = EFI_UNSUPPORTED;
275 if (dm_rtc_get(dev, &tm)) {
276 ret = EFI_DEVICE_ERROR;
280 memset(time, 0, sizeof(*time));
281 time->year = tm.tm_year;
282 time->month = tm.tm_mon;
283 time->day = tm.tm_mday;
284 time->hour = tm.tm_hour;
285 time->minute = tm.tm_min;
286 time->second = tm.tm_sec;
289 EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT;
290 else if (!tm.tm_isdst)
291 time->daylight = EFI_TIME_ADJUST_DAYLIGHT;
294 time->timezone = EFI_UNSPECIFIED_TIMEZONE;
297 /* Set reasonable dummy values */
298 capabilities->resolution = 1; /* 1 Hz */
299 capabilities->accuracy = 100000000; /* 100 ppm */
300 capabilities->sets_to_zero = false;
303 return EFI_EXIT(ret);
305 EFI_ENTRY("%p %p", time, capabilities);
306 return EFI_EXIT(EFI_UNSUPPORTED);
310 #ifdef CONFIG_EFI_SET_TIME
313 * efi_validate_time() - checks if timestamp is valid
315 * @time: timestamp to validate
316 * Returns: 0 if timestamp is valid, 1 otherwise
318 static int efi_validate_time(struct efi_time *time)
321 time->year < 1900 || time->year > 9999 ||
322 !time->month || time->month > 12 || !time->day ||
323 time->day > rtc_month_days(time->month - 1, time->year) ||
324 time->hour > 23 || time->minute > 59 || time->second > 59 ||
325 time->nanosecond > 999999999 ||
327 ~(EFI_TIME_IN_DAYLIGHT | EFI_TIME_ADJUST_DAYLIGHT) ||
328 ((time->timezone < -1440 || time->timezone > 1440) &&
329 time->timezone != EFI_UNSPECIFIED_TIMEZONE));
335 * efi_set_time_boottime() - set current time
337 * This function implements the SetTime() runtime service before
338 * SetVirtualAddressMap() is called.
340 * See the Unified Extensible Firmware Interface (UEFI) specification
343 * @time: pointer to structure to with current time
344 * Returns: status code
346 static efi_status_t EFIAPI efi_set_time_boottime(struct efi_time *time)
348 #ifdef CONFIG_EFI_SET_TIME
349 efi_status_t ret = EFI_SUCCESS;
353 EFI_ENTRY("%p", time);
355 if (efi_validate_time(time)) {
356 ret = EFI_INVALID_PARAMETER;
360 if (uclass_get_device(UCLASS_RTC, 0, &dev)) {
361 ret = EFI_UNSUPPORTED;
365 memset(&tm, 0, sizeof(tm));
366 tm.tm_year = time->year;
367 tm.tm_mon = time->month;
368 tm.tm_mday = time->day;
369 tm.tm_hour = time->hour;
370 tm.tm_min = time->minute;
371 tm.tm_sec = time->second;
372 switch (time->daylight) {
373 case EFI_TIME_ADJUST_DAYLIGHT:
376 case EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT:
383 /* Calculate day of week */
384 rtc_calc_weekday(&tm);
386 if (dm_rtc_set(dev, &tm))
387 ret = EFI_DEVICE_ERROR;
389 return EFI_EXIT(ret);
391 EFI_ENTRY("%p", time);
392 return EFI_EXIT(EFI_UNSUPPORTED);
396 * efi_reset_system() - reset system
398 * This function implements the ResetSystem() runtime service after
399 * SetVirtualAddressMap() is called. As this placeholder cannot reset the
400 * system it simply return to the caller.
402 * Boards may override the helpers below to implement reset functionality.
404 * See the Unified Extensible Firmware Interface (UEFI) specification for
407 * @reset_type: type of reset to perform
408 * @reset_status: status code for the reset
409 * @data_size: size of reset_data
410 * @reset_data: information about the reset
412 void __weak __efi_runtime EFIAPI efi_reset_system(
413 enum efi_reset_type reset_type,
414 efi_status_t reset_status,
415 unsigned long data_size, void *reset_data)
421 * efi_reset_system_init() - initialize the reset driver
423 * Boards may override this function to initialize the reset driver.
425 efi_status_t __weak efi_reset_system_init(void)
431 * efi_get_time() - get current time
433 * This function implements the GetTime runtime service after
434 * SetVirtualAddressMap() is called. As the U-Boot driver are not available
435 * anymore only an error code is returned.
437 * See the Unified Extensible Firmware Interface (UEFI) specification
440 * @time: pointer to structure to receive current time
441 * @capabilities: pointer to structure to receive RTC properties
442 * Returns: status code
444 efi_status_t __weak __efi_runtime EFIAPI efi_get_time(
445 struct efi_time *time,
446 struct efi_time_cap *capabilities)
448 return EFI_UNSUPPORTED;
452 * efi_set_time() - set current time
454 * This function implements the SetTime runtime service after
455 * SetVirtualAddressMap() is called. As the U-Boot driver are not available
456 * anymore only an error code is returned.
458 * See the Unified Extensible Firmware Interface (UEFI) specification
461 * @time: pointer to structure to with current time
462 * Returns: status code
464 efi_status_t __weak __efi_runtime EFIAPI efi_set_time(struct efi_time *time)
466 return EFI_UNSUPPORTED;
470 * efi_update_capsule_unsupported() - process information from operating system
472 * This function implements the UpdateCapsule() runtime service.
474 * See the Unified Extensible Firmware Interface (UEFI) specification for
477 * @capsule_header_array: pointer to array of virtual pointers
478 * @capsule_count: number of pointers in capsule_header_array
479 * @scatter_gather_list: pointer to array of physical pointers
480 * Returns: status code
482 static efi_status_t __efi_runtime EFIAPI efi_update_capsule_unsupported(
483 struct efi_capsule_header **capsule_header_array,
484 efi_uintn_t capsule_count,
485 u64 scatter_gather_list)
487 return EFI_UNSUPPORTED;
491 * efi_query_capsule_caps_unsupported() - check if capsule is supported
493 * This function implements the QueryCapsuleCapabilities() runtime service.
495 * See the Unified Extensible Firmware Interface (UEFI) specification for
498 * @capsule_header_array: pointer to array of virtual pointers
499 * @capsule_count: number of pointers in capsule_header_array
500 * @maximum_capsule_size: maximum capsule size
501 * @reset_type: type of reset needed for capsule update
502 * Returns: status code
504 static efi_status_t __efi_runtime EFIAPI efi_query_capsule_caps_unsupported(
505 struct efi_capsule_header **capsule_header_array,
506 efi_uintn_t capsule_count,
507 u64 *maximum_capsule_size,
510 return EFI_UNSUPPORTED;
514 * efi_is_runtime_service_pointer() - check if pointer points to runtime table
516 * @p: pointer to check
517 * Return: true if the pointer points to a service function pointer in the
520 static bool efi_is_runtime_service_pointer(void *p)
522 return (p >= (void *)&efi_runtime_services.get_time &&
523 p <= (void *)&efi_runtime_services.query_variable_info) ||
524 p == (void *)&efi_events.prev ||
525 p == (void *)&efi_events.next;
529 * efi_runtime_detach() - detach unimplemented runtime functions
531 void efi_runtime_detach(void)
533 efi_runtime_services.reset_system = efi_reset_system;
534 efi_runtime_services.get_time = efi_get_time;
535 efi_runtime_services.set_time = efi_set_time;
536 if (IS_ENABLED(CONFIG_EFI_RUNTIME_UPDATE_CAPSULE)) {
537 /* won't support at runtime */
538 efi_runtime_services.update_capsule =
539 efi_update_capsule_unsupported;
540 efi_runtime_services.query_capsule_caps =
541 efi_query_capsule_caps_unsupported;
545 efi_update_table_header_crc32(&efi_runtime_services.hdr);
549 * efi_set_virtual_address_map_runtime() - change from physical to virtual
552 * This function implements the SetVirtualAddressMap() runtime service after
553 * it is first called.
555 * See the Unified Extensible Firmware Interface (UEFI) specification for
558 * @memory_map_size: size of the virtual map
559 * @descriptor_size: size of an entry in the map
560 * @descriptor_version: version of the map entries
561 * @virtmap: virtual address mapping information
562 * Return: status code EFI_UNSUPPORTED
564 static __efi_runtime efi_status_t EFIAPI efi_set_virtual_address_map_runtime(
565 efi_uintn_t memory_map_size,
566 efi_uintn_t descriptor_size,
567 uint32_t descriptor_version,
568 struct efi_mem_desc *virtmap)
570 return EFI_UNSUPPORTED;
574 * efi_convert_pointer_runtime() - convert from physical to virtual pointer
576 * This function implements the ConvertPointer() runtime service after
577 * the first call to SetVirtualAddressMap().
579 * See the Unified Extensible Firmware Interface (UEFI) specification for
582 * @debug_disposition: indicates if pointer may be converted to NULL
583 * @address: pointer to be converted
584 * Return: status code EFI_UNSUPPORTED
586 static __efi_runtime efi_status_t EFIAPI efi_convert_pointer_runtime(
587 efi_uintn_t debug_disposition, void **address)
589 return EFI_UNSUPPORTED;
593 * efi_convert_pointer() - convert from physical to virtual pointer
595 * This function implements the ConvertPointer() runtime service until
596 * the first call to SetVirtualAddressMap().
598 * See the Unified Extensible Firmware Interface (UEFI) specification for
601 * @debug_disposition: indicates if pointer may be converted to NULL
602 * @address: pointer to be converted
603 * Return: status code
605 __efi_runtime efi_status_t EFIAPI
606 efi_convert_pointer(efi_uintn_t debug_disposition, void **address)
608 efi_physical_addr_t addr;
610 efi_status_t ret = EFI_NOT_FOUND;
613 ret = EFI_UNSUPPORTED;
618 ret = EFI_INVALID_PARAMETER;
622 if (debug_disposition & EFI_OPTIONAL_PTR)
625 return EFI_INVALID_PARAMETER;
628 addr = (uintptr_t)*address;
629 for (i = 0; i < efi_descriptor_count; i++) {
630 struct efi_mem_desc *map = (void *)efi_virtmap +
631 (efi_descriptor_size * i);
633 if (addr >= map->physical_start &&
634 (addr < map->physical_start
635 + (map->num_pages << EFI_PAGE_SHIFT))) {
636 *address = (void *)(uintptr_t)
637 (addr + map->virtual_start -
638 map->physical_start);
649 static __efi_runtime void efi_relocate_runtime_table(ulong offset)
654 /* Relocate the runtime services pointers */
655 patchoff = offset - gd->relocaddr;
656 for (pos = (void **)&efi_runtime_services.get_time;
657 pos <= (void **)&efi_runtime_services.query_variable_info; ++pos) {
663 * The entry for SetVirtualAddress() must point to a physical address.
664 * After the first execution the service must return EFI_UNSUPPORTED.
666 efi_runtime_services.set_virtual_address_map =
667 &efi_set_virtual_address_map_runtime;
670 * The entry for ConvertPointer() must point to a physical address.
671 * The service is not usable after SetVirtualAddress().
673 efi_runtime_services.convert_pointer = &efi_convert_pointer_runtime;
676 * TODO: Update UEFI variable RuntimeServicesSupported removing flags
677 * EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP and
678 * EFI_RT_SUPPORTED_CONVERT_POINTER as required by the UEFI spec 2.8.
682 efi_update_table_header_crc32(&efi_runtime_services.hdr);
685 /* Relocate EFI runtime to uboot_reloc_base = offset */
686 void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map)
689 struct elf_rela *rel = (void *)__efi_runtime_rel_start;
691 struct elf_rel *rel = (void *)__efi_runtime_rel_start;
692 static ulong lastoff = CONFIG_TEXT_BASE;
695 debug("%s: Relocating to offset=%lx\n", __func__, offset);
696 for (; (uintptr_t)rel < (uintptr_t)__efi_runtime_rel_stop; rel++) {
697 ulong base = CONFIG_TEXT_BASE;
701 p = (void*)((ulong)rel->offset - base) + gd->relocaddr;
704 * The runtime services table is updated in
705 * efi_relocate_runtime_table()
707 if (map && efi_is_runtime_service_pointer(p))
710 debug("%s: rel->info=%#lx *p=%#lx rel->offset=%p\n", __func__,
711 rel->info, *p, rel->offset);
713 switch (rel->info & R_MASK) {
716 newaddr = rel->addend + offset - CONFIG_TEXT_BASE;
718 newaddr = *p - lastoff + offset;
723 ulong symidx = rel->info >> SYM_INDEX;
724 extern struct dyn_sym __dyn_sym_start[];
725 newaddr = __dyn_sym_start[symidx].addr + offset;
727 newaddr -= CONFIG_TEXT_BASE;
733 printf("%s: Unknown relocation type %llx\n",
734 __func__, rel->info & R_MASK);
738 /* Check if the relocation is inside bounds */
739 if (map && ((newaddr < map->virtual_start) ||
740 newaddr > (map->virtual_start +
741 (map->num_pages << EFI_PAGE_SHIFT)))) {
742 printf("%s: Relocation at %p is out of range (%lx)\n",
743 __func__, p, newaddr);
747 debug("%s: Setting %p to %lx\n", __func__, p, newaddr);
749 flush_dcache_range((ulong)p & ~(EFI_CACHELINE_SIZE - 1),
750 ALIGN((ulong)&p[1], EFI_CACHELINE_SIZE));
757 invalidate_icache_all();
761 * efi_set_virtual_address_map() - change from physical to virtual mapping
763 * This function implements the SetVirtualAddressMap() runtime service.
765 * See the Unified Extensible Firmware Interface (UEFI) specification for
768 * @memory_map_size: size of the virtual map
769 * @descriptor_size: size of an entry in the map
770 * @descriptor_version: version of the map entries
771 * @virtmap: virtual address mapping information
772 * Return: status code
774 static efi_status_t EFIAPI efi_set_virtual_address_map(
775 efi_uintn_t memory_map_size,
776 efi_uintn_t descriptor_size,
777 uint32_t descriptor_version,
778 struct efi_mem_desc *virtmap)
780 efi_uintn_t n = memory_map_size / descriptor_size;
782 efi_status_t ret = EFI_INVALID_PARAMETER;
783 int rt_code_sections = 0;
784 struct efi_event *event;
786 EFI_ENTRY("%zx %zx %x %p", memory_map_size, descriptor_size,
787 descriptor_version, virtmap);
789 if (descriptor_version != EFI_MEMORY_DESCRIPTOR_VERSION ||
790 descriptor_size < sizeof(struct efi_mem_desc))
793 efi_virtmap = virtmap;
794 efi_descriptor_size = descriptor_size;
795 efi_descriptor_count = n;
799 * Further down we are cheating. While really we should implement
800 * SetVirtualAddressMap() events and ConvertPointer() to allow
801 * dynamically loaded drivers to expose runtime services, we don't
804 * So let's ensure we see exactly one single runtime section, as
805 * that is the built-in one. If we see more (or less), someone must
806 * have tried adding or removing to that which we don't support yet.
807 * In that case, let's better fail rather than expose broken runtime
810 for (i = 0; i < n; i++) {
811 struct efi_mem_desc *map = (void*)virtmap +
812 (descriptor_size * i);
814 if (map->type == EFI_RUNTIME_SERVICES_CODE)
818 if (rt_code_sections != 1) {
820 * We expose exactly one single runtime code section, so
821 * something is definitely going wrong.
826 /* Notify EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE */
827 list_for_each_entry(event, &efi_events, link) {
828 if (event->notify_function)
829 EFI_CALL_VOID(event->notify_function(
830 event, event->notify_context));
833 /* Rebind mmio pointers */
834 for (i = 0; i < n; i++) {
835 struct efi_mem_desc *map = (void*)virtmap +
836 (descriptor_size * i);
837 struct list_head *lhandle;
838 efi_physical_addr_t map_start = map->physical_start;
839 efi_physical_addr_t map_len = map->num_pages << EFI_PAGE_SHIFT;
840 efi_physical_addr_t map_end = map_start + map_len;
841 u64 off = map->virtual_start - map_start;
843 /* Adjust all mmio pointers in this region */
844 list_for_each(lhandle, &efi_runtime_mmio) {
845 struct efi_runtime_mmio_list *lmmio;
847 lmmio = list_entry(lhandle,
848 struct efi_runtime_mmio_list,
850 if ((map_start <= lmmio->paddr) &&
851 (map_end >= lmmio->paddr)) {
852 uintptr_t new_addr = lmmio->paddr + off;
853 *lmmio->ptr = (void *)new_addr;
856 if ((map_start <= (uintptr_t)systab.tables) &&
857 (map_end >= (uintptr_t)systab.tables)) {
858 char *ptr = (char *)systab.tables;
861 systab.tables = (struct efi_configuration_table *)ptr;
865 /* Relocate the runtime. See TODO above */
866 for (i = 0; i < n; i++) {
867 struct efi_mem_desc *map;
869 map = (void*)virtmap + (descriptor_size * i);
870 if (map->type == EFI_RUNTIME_SERVICES_CODE) {
871 ulong new_offset = map->virtual_start -
872 map->physical_start + gd->relocaddr;
874 efi_relocate_runtime_table(new_offset);
875 efi_runtime_relocate(new_offset, map);
882 return EFI_EXIT(ret);
886 * efi_add_runtime_mmio() - add memory-mapped IO region
888 * This function adds a memory-mapped IO region to the memory map to make it
889 * available at runtime.
891 * @mmio_ptr: pointer to a pointer to the start of the memory-mapped
893 * @len: size of the memory-mapped IO region
894 * Returns: status code
896 efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len)
898 struct efi_runtime_mmio_list *newmmio;
899 uint64_t addr = *(uintptr_t *)mmio_ptr;
902 ret = efi_add_memory_map(addr, len, EFI_MMAP_IO);
903 if (ret != EFI_SUCCESS)
904 return EFI_OUT_OF_RESOURCES;
906 newmmio = calloc(1, sizeof(*newmmio));
908 return EFI_OUT_OF_RESOURCES;
909 newmmio->ptr = mmio_ptr;
910 newmmio->paddr = *(uintptr_t *)mmio_ptr;
912 list_add_tail(&newmmio->link, &efi_runtime_mmio);
918 * In the second stage, U-Boot has disappeared. To isolate our runtime code
919 * that at this point still exists from the rest, we put it into a special
924 * This means that we can not rely on any code outside of this file in any
925 * function or variable below this line.
927 * Please keep everything fully self-contained and annotated with
928 * __efi_runtime and __efi_runtime_data markers.
932 * Relocate the EFI runtime stub to a different place. We need to call this
933 * the first time we expose the runtime interface to a user and on set virtual
938 * efi_unimplemented() - replacement function, returns EFI_UNSUPPORTED
940 * This function is used after SetVirtualAddressMap() is called as replacement
941 * for services that are not available anymore due to constraints of the U-Boot
944 * Return: EFI_UNSUPPORTED
946 static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void)
948 return EFI_UNSUPPORTED;
951 struct efi_runtime_services __efi_runtime_data efi_runtime_services = {
953 .signature = EFI_RUNTIME_SERVICES_SIGNATURE,
954 .revision = EFI_SPECIFICATION_VERSION,
955 .headersize = sizeof(struct efi_runtime_services),
957 .get_time = &efi_get_time_boottime,
958 .set_time = &efi_set_time_boottime,
959 .get_wakeup_time = (void *)&efi_unimplemented,
960 .set_wakeup_time = (void *)&efi_unimplemented,
961 .set_virtual_address_map = &efi_set_virtual_address_map,
962 .convert_pointer = efi_convert_pointer,
963 .get_variable = efi_get_variable,
964 .get_next_variable_name = efi_get_next_variable_name,
965 .set_variable = efi_set_variable,
966 .get_next_high_mono_count = (void *)&efi_unimplemented,
967 .reset_system = &efi_reset_system_boottime,
968 #ifdef CONFIG_EFI_RUNTIME_UPDATE_CAPSULE
969 .update_capsule = efi_update_capsule,
970 .query_capsule_caps = efi_query_capsule_caps,
972 .update_capsule = efi_update_capsule_unsupported,
973 .query_capsule_caps = efi_query_capsule_caps_unsupported,
975 .query_variable_info = efi_query_variable_info,