Tom Rini | 70df9d6 | 2018-05-07 17:02:21 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 2 | /* |
| 3 | * EFI application runtime services |
| 4 | * |
| 5 | * Copyright (c) 2016 Alexander Graf |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <dm.h> |
| 11 | #include <efi_loader.h> |
| 12 | #include <rtc.h> |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 13 | |
| 14 | /* For manual relocation support */ |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 17 | struct efi_runtime_mmio_list { |
| 18 | struct list_head link; |
| 19 | void **ptr; |
| 20 | u64 paddr; |
| 21 | u64 len; |
| 22 | }; |
| 23 | |
| 24 | /* This list contains all runtime available mmio regions */ |
| 25 | LIST_HEAD(efi_runtime_mmio); |
| 26 | |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 27 | static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void); |
| 28 | static efi_status_t __efi_runtime EFIAPI efi_device_error(void); |
| 29 | static efi_status_t __efi_runtime EFIAPI efi_invalid_parameter(void); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 30 | |
Simon Glass | fff89d4 | 2018-06-11 23:26:40 -0600 | [diff] [blame^] | 31 | /* |
| 32 | * TODO(sjg@chromium.org): These defines and structs should come from the elf |
| 33 | * header for each arch (or a generic header) rather than being repeated here. |
| 34 | */ |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 35 | #if defined(CONFIG_ARM64) |
| 36 | #define R_RELATIVE 1027 |
| 37 | #define R_MASK 0xffffffffULL |
| 38 | #define IS_RELA 1 |
| 39 | #elif defined(CONFIG_ARM) |
| 40 | #define R_RELATIVE 23 |
| 41 | #define R_MASK 0xffULL |
Simon Glass | cdfe696 | 2016-09-25 15:27:35 -0600 | [diff] [blame] | 42 | #elif defined(CONFIG_X86) |
| 43 | #include <asm/elf.h> |
| 44 | #define R_RELATIVE R_386_RELATIVE |
| 45 | #define R_MASK 0xffULL |
Rick Chen | 9677a37 | 2018-05-28 19:06:37 +0800 | [diff] [blame] | 46 | #elif defined(CONFIG_RISCV) |
| 47 | #include <elf.h> |
| 48 | #define R_RELATIVE R_RISCV_RELATIVE |
| 49 | #define R_MASK 0xffULL |
| 50 | #define IS_RELA 1 |
| 51 | |
| 52 | struct dyn_sym { |
| 53 | ulong foo1; |
| 54 | ulong addr; |
| 55 | u32 foo2; |
| 56 | u32 foo3; |
| 57 | }; |
| 58 | #ifdef CONFIG_CPU_RISCV_32 |
| 59 | #define R_ABSOLUTE R_RISCV_32 |
| 60 | #define SYM_INDEX 8 |
| 61 | #else |
| 62 | #define R_ABSOLUTE R_RISCV_64 |
| 63 | #define SYM_INDEX 32 |
| 64 | #endif |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 65 | #else |
| 66 | #error Need to add relocation awareness |
| 67 | #endif |
| 68 | |
| 69 | struct elf_rel { |
| 70 | ulong *offset; |
| 71 | ulong info; |
| 72 | }; |
| 73 | |
| 74 | struct elf_rela { |
| 75 | ulong *offset; |
| 76 | ulong info; |
| 77 | long addend; |
| 78 | }; |
| 79 | |
| 80 | /* |
| 81 | * EFI Runtime code lives in 2 stages. In the first stage, U-Boot and an EFI |
| 82 | * payload are running concurrently at the same time. In this mode, we can |
| 83 | * handle a good number of runtime callbacks |
| 84 | */ |
| 85 | |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 86 | static void EFIAPI efi_reset_system_boottime( |
| 87 | enum efi_reset_type reset_type, |
| 88 | efi_status_t reset_status, |
| 89 | unsigned long data_size, void *reset_data) |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 90 | { |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 91 | struct efi_event *evt; |
| 92 | |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 93 | EFI_ENTRY("%d %lx %lx %p", reset_type, reset_status, data_size, |
| 94 | reset_data); |
| 95 | |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 96 | /* Notify reset */ |
| 97 | list_for_each_entry(evt, &efi_events, link) { |
| 98 | if (evt->group && |
| 99 | !guidcmp(evt->group, |
| 100 | &efi_guid_event_group_reset_system)) { |
| 101 | efi_signal_event(evt, false); |
| 102 | break; |
| 103 | } |
| 104 | } |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 105 | switch (reset_type) { |
| 106 | case EFI_RESET_COLD: |
| 107 | case EFI_RESET_WARM: |
Heinrich Schuchardt | 450d4c8 | 2018-02-06 22:00:22 +0100 | [diff] [blame] | 108 | case EFI_RESET_PLATFORM_SPECIFIC: |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 109 | do_reset(NULL, 0, 0, NULL); |
| 110 | break; |
| 111 | case EFI_RESET_SHUTDOWN: |
| 112 | /* We don't have anything to map this to */ |
| 113 | break; |
| 114 | } |
| 115 | |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 116 | while (1) { } |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 119 | static efi_status_t EFIAPI efi_get_time_boottime( |
| 120 | struct efi_time *time, |
| 121 | struct efi_time_cap *capabilities) |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 122 | { |
| 123 | #if defined(CONFIG_CMD_DATE) && defined(CONFIG_DM_RTC) |
| 124 | struct rtc_time tm; |
| 125 | int r; |
| 126 | struct udevice *dev; |
| 127 | |
| 128 | EFI_ENTRY("%p %p", time, capabilities); |
| 129 | |
| 130 | r = uclass_get_device(UCLASS_RTC, 0, &dev); |
| 131 | if (r) |
| 132 | return EFI_EXIT(EFI_DEVICE_ERROR); |
| 133 | |
| 134 | r = dm_rtc_get(dev, &tm); |
| 135 | if (r) |
| 136 | return EFI_EXIT(EFI_DEVICE_ERROR); |
| 137 | |
| 138 | memset(time, 0, sizeof(*time)); |
| 139 | time->year = tm.tm_year; |
| 140 | time->month = tm.tm_mon; |
| 141 | time->day = tm.tm_mday; |
| 142 | time->hour = tm.tm_hour; |
| 143 | time->minute = tm.tm_min; |
| 144 | time->daylight = tm.tm_isdst; |
| 145 | |
| 146 | return EFI_EXIT(EFI_SUCCESS); |
| 147 | #else |
| 148 | return EFI_DEVICE_ERROR; |
| 149 | #endif |
| 150 | } |
| 151 | |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 152 | /* Boards may override the helpers below to implement RTS functionality */ |
| 153 | |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 154 | void __weak __efi_runtime EFIAPI efi_reset_system( |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 155 | enum efi_reset_type reset_type, |
| 156 | efi_status_t reset_status, |
| 157 | unsigned long data_size, void *reset_data) |
| 158 | { |
| 159 | /* Nothing we can do */ |
| 160 | while (1) { } |
| 161 | } |
| 162 | |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 163 | efi_status_t __weak efi_reset_system_init(void) |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 164 | { |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 165 | return EFI_SUCCESS; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 166 | } |
| 167 | |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 168 | efi_status_t __weak __efi_runtime EFIAPI efi_get_time( |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 169 | struct efi_time *time, |
| 170 | struct efi_time_cap *capabilities) |
| 171 | { |
| 172 | /* Nothing we can do */ |
| 173 | return EFI_DEVICE_ERROR; |
| 174 | } |
| 175 | |
Heinrich Schuchardt | 096db01 | 2018-03-03 15:29:00 +0100 | [diff] [blame] | 176 | efi_status_t __weak efi_get_time_init(void) |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 177 | { |
Heinrich Schuchardt | 096db01 | 2018-03-03 15:29:00 +0100 | [diff] [blame] | 178 | return EFI_SUCCESS; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 179 | } |
| 180 | |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 181 | struct efi_runtime_detach_list_struct { |
| 182 | void *ptr; |
| 183 | void *patchto; |
| 184 | }; |
| 185 | |
| 186 | static const struct efi_runtime_detach_list_struct efi_runtime_detach_list[] = { |
| 187 | { |
| 188 | /* do_reset is gone */ |
| 189 | .ptr = &efi_runtime_services.reset_system, |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 190 | .patchto = efi_reset_system, |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 191 | }, { |
| 192 | /* invalidate_*cache_all are gone */ |
| 193 | .ptr = &efi_runtime_services.set_virtual_address_map, |
| 194 | .patchto = &efi_invalid_parameter, |
| 195 | }, { |
| 196 | /* RTC accessors are gone */ |
| 197 | .ptr = &efi_runtime_services.get_time, |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 198 | .patchto = &efi_get_time, |
Alexander Graf | c59d360 | 2016-05-18 00:54:47 +0200 | [diff] [blame] | 199 | }, { |
| 200 | /* Clean up system table */ |
| 201 | .ptr = &systab.con_in, |
| 202 | .patchto = NULL, |
| 203 | }, { |
| 204 | /* Clean up system table */ |
| 205 | .ptr = &systab.con_out, |
| 206 | .patchto = NULL, |
| 207 | }, { |
| 208 | /* Clean up system table */ |
| 209 | .ptr = &systab.std_err, |
| 210 | .patchto = NULL, |
| 211 | }, { |
| 212 | /* Clean up system table */ |
| 213 | .ptr = &systab.boottime, |
| 214 | .patchto = NULL, |
Rob Clark | 15f3d74 | 2017-09-13 18:05:37 -0400 | [diff] [blame] | 215 | }, { |
| 216 | .ptr = &efi_runtime_services.get_variable, |
| 217 | .patchto = &efi_device_error, |
| 218 | }, { |
Heinrich Schuchardt | d6a6baa | 2018-05-17 07:57:05 +0200 | [diff] [blame] | 219 | .ptr = &efi_runtime_services.get_next_variable_name, |
Rob Clark | 15f3d74 | 2017-09-13 18:05:37 -0400 | [diff] [blame] | 220 | .patchto = &efi_device_error, |
| 221 | }, { |
| 222 | .ptr = &efi_runtime_services.set_variable, |
| 223 | .patchto = &efi_device_error, |
| 224 | } |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | static bool efi_runtime_tobedetached(void *p) |
| 228 | { |
| 229 | int i; |
| 230 | |
| 231 | for (i = 0; i < ARRAY_SIZE(efi_runtime_detach_list); i++) |
| 232 | if (efi_runtime_detach_list[i].ptr == p) |
| 233 | return true; |
| 234 | |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | static void efi_runtime_detach(ulong offset) |
| 239 | { |
| 240 | int i; |
| 241 | ulong patchoff = offset - (ulong)gd->relocaddr; |
| 242 | |
| 243 | for (i = 0; i < ARRAY_SIZE(efi_runtime_detach_list); i++) { |
| 244 | ulong patchto = (ulong)efi_runtime_detach_list[i].patchto; |
| 245 | ulong *p = efi_runtime_detach_list[i].ptr; |
| 246 | ulong newaddr = patchto ? (patchto + patchoff) : 0; |
| 247 | |
Alexander Graf | 62a6748 | 2016-06-02 11:38:27 +0200 | [diff] [blame] | 248 | debug("%s: Setting %p to %lx\n", __func__, p, newaddr); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 249 | *p = newaddr; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | /* Relocate EFI runtime to uboot_reloc_base = offset */ |
| 254 | void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map) |
| 255 | { |
| 256 | #ifdef IS_RELA |
| 257 | struct elf_rela *rel = (void*)&__efi_runtime_rel_start; |
| 258 | #else |
| 259 | struct elf_rel *rel = (void*)&__efi_runtime_rel_start; |
| 260 | static ulong lastoff = CONFIG_SYS_TEXT_BASE; |
| 261 | #endif |
| 262 | |
Alexander Graf | 62a6748 | 2016-06-02 11:38:27 +0200 | [diff] [blame] | 263 | debug("%s: Relocating to offset=%lx\n", __func__, offset); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 264 | for (; (ulong)rel < (ulong)&__efi_runtime_rel_stop; rel++) { |
| 265 | ulong base = CONFIG_SYS_TEXT_BASE; |
| 266 | ulong *p; |
| 267 | ulong newaddr; |
| 268 | |
| 269 | p = (void*)((ulong)rel->offset - base) + gd->relocaddr; |
| 270 | |
Rick Chen | 9677a37 | 2018-05-28 19:06:37 +0800 | [diff] [blame] | 271 | debug("%s: rel->info=%#lx *p=%#lx rel->offset=%p\n", __func__, rel->info, *p, rel->offset); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 272 | |
Rick Chen | 9677a37 | 2018-05-28 19:06:37 +0800 | [diff] [blame] | 273 | switch (rel->info & R_MASK) { |
| 274 | case R_RELATIVE: |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 275 | #ifdef IS_RELA |
| 276 | newaddr = rel->addend + offset - CONFIG_SYS_TEXT_BASE; |
| 277 | #else |
| 278 | newaddr = *p - lastoff + offset; |
| 279 | #endif |
Rick Chen | 9677a37 | 2018-05-28 19:06:37 +0800 | [diff] [blame] | 280 | break; |
| 281 | #ifdef R_ABSOLUTE |
| 282 | case R_ABSOLUTE: { |
| 283 | ulong symidx = rel->info >> SYM_INDEX; |
| 284 | extern struct dyn_sym __dyn_sym_start[]; |
| 285 | newaddr = __dyn_sym_start[symidx].addr + offset; |
| 286 | break; |
| 287 | } |
| 288 | #endif |
| 289 | default: |
| 290 | continue; |
| 291 | } |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 292 | |
| 293 | /* Check if the relocation is inside bounds */ |
| 294 | if (map && ((newaddr < map->virtual_start) || |
Heinrich Schuchardt | 9ebc47f | 2017-09-18 22:11:34 +0200 | [diff] [blame] | 295 | newaddr > (map->virtual_start + |
| 296 | (map->num_pages << EFI_PAGE_SHIFT)))) { |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 297 | if (!efi_runtime_tobedetached(p)) |
| 298 | printf("U-Boot EFI: Relocation at %p is out of " |
| 299 | "range (%lx)\n", p, newaddr); |
| 300 | continue; |
| 301 | } |
| 302 | |
Alexander Graf | 62a6748 | 2016-06-02 11:38:27 +0200 | [diff] [blame] | 303 | debug("%s: Setting %p to %lx\n", __func__, p, newaddr); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 304 | *p = newaddr; |
Alexander Graf | e570232 | 2016-04-11 23:20:39 +0200 | [diff] [blame] | 305 | flush_dcache_range((ulong)p & ~(EFI_CACHELINE_SIZE - 1), |
| 306 | ALIGN((ulong)&p[1], EFI_CACHELINE_SIZE)); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | #ifndef IS_RELA |
| 310 | lastoff = offset; |
| 311 | #endif |
| 312 | |
| 313 | invalidate_icache_all(); |
| 314 | } |
| 315 | |
| 316 | static efi_status_t EFIAPI efi_set_virtual_address_map( |
| 317 | unsigned long memory_map_size, |
| 318 | unsigned long descriptor_size, |
| 319 | uint32_t descriptor_version, |
| 320 | struct efi_mem_desc *virtmap) |
| 321 | { |
Heinrich Schuchardt | 9ebc47f | 2017-09-18 22:11:34 +0200 | [diff] [blame] | 322 | ulong runtime_start = (ulong)&__efi_runtime_start & |
| 323 | ~(ulong)EFI_PAGE_MASK; |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 324 | int n = memory_map_size / descriptor_size; |
| 325 | int i; |
| 326 | |
| 327 | EFI_ENTRY("%lx %lx %x %p", memory_map_size, descriptor_size, |
| 328 | descriptor_version, virtmap); |
| 329 | |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 330 | /* Rebind mmio pointers */ |
| 331 | for (i = 0; i < n; i++) { |
| 332 | struct efi_mem_desc *map = (void*)virtmap + |
| 333 | (descriptor_size * i); |
| 334 | struct list_head *lhandle; |
| 335 | efi_physical_addr_t map_start = map->physical_start; |
| 336 | efi_physical_addr_t map_len = map->num_pages << EFI_PAGE_SHIFT; |
| 337 | efi_physical_addr_t map_end = map_start + map_len; |
| 338 | |
| 339 | /* Adjust all mmio pointers in this region */ |
| 340 | list_for_each(lhandle, &efi_runtime_mmio) { |
| 341 | struct efi_runtime_mmio_list *lmmio; |
| 342 | |
| 343 | lmmio = list_entry(lhandle, |
| 344 | struct efi_runtime_mmio_list, |
| 345 | link); |
| 346 | if ((map_start <= lmmio->paddr) && |
| 347 | (map_end >= lmmio->paddr)) { |
| 348 | u64 off = map->virtual_start - map_start; |
| 349 | uintptr_t new_addr = lmmio->paddr + off; |
| 350 | *lmmio->ptr = (void *)new_addr; |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | /* Move the actual runtime code over */ |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 356 | for (i = 0; i < n; i++) { |
| 357 | struct efi_mem_desc *map; |
| 358 | |
| 359 | map = (void*)virtmap + (descriptor_size * i); |
| 360 | if (map->type == EFI_RUNTIME_SERVICES_CODE) { |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 361 | ulong new_offset = map->virtual_start - |
| 362 | (runtime_start - gd->relocaddr); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 363 | |
| 364 | efi_runtime_relocate(new_offset, map); |
| 365 | /* Once we're virtual, we can no longer handle |
| 366 | complex callbacks */ |
| 367 | efi_runtime_detach(new_offset); |
| 368 | return EFI_EXIT(EFI_SUCCESS); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 373 | } |
| 374 | |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 375 | efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len) |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 376 | { |
| 377 | struct efi_runtime_mmio_list *newmmio; |
xypron.glpk@gmx.de | 93fcc7f | 2017-08-11 21:19:37 +0200 | [diff] [blame] | 378 | u64 pages = (len + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT; |
Alexander Graf | 33a83a3 | 2018-03-15 15:08:16 +0100 | [diff] [blame] | 379 | uint64_t addr = *(uintptr_t *)mmio_ptr; |
| 380 | uint64_t retaddr; |
| 381 | |
| 382 | retaddr = efi_add_memory_map(addr, pages, EFI_MMAP_IO, false); |
| 383 | if (retaddr != addr) |
| 384 | return EFI_OUT_OF_RESOURCES; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 385 | |
| 386 | newmmio = calloc(1, sizeof(*newmmio)); |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 387 | if (!newmmio) |
| 388 | return EFI_OUT_OF_RESOURCES; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 389 | newmmio->ptr = mmio_ptr; |
| 390 | newmmio->paddr = *(uintptr_t *)mmio_ptr; |
| 391 | newmmio->len = len; |
| 392 | list_add_tail(&newmmio->link, &efi_runtime_mmio); |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 393 | |
Alexander Graf | 33a83a3 | 2018-03-15 15:08:16 +0100 | [diff] [blame] | 394 | return EFI_SUCCESS; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 395 | } |
| 396 | |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 397 | /* |
| 398 | * In the second stage, U-Boot has disappeared. To isolate our runtime code |
| 399 | * that at this point still exists from the rest, we put it into a special |
| 400 | * section. |
| 401 | * |
| 402 | * !!WARNING!! |
| 403 | * |
| 404 | * This means that we can not rely on any code outside of this file in any |
| 405 | * function or variable below this line. |
| 406 | * |
| 407 | * Please keep everything fully self-contained and annotated with |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 408 | * __efi_runtime and __efi_runtime_data markers. |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 409 | */ |
| 410 | |
| 411 | /* |
| 412 | * Relocate the EFI runtime stub to a different place. We need to call this |
| 413 | * the first time we expose the runtime interface to a user and on set virtual |
| 414 | * address map calls. |
| 415 | */ |
| 416 | |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 417 | static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void) |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 418 | { |
| 419 | return EFI_UNSUPPORTED; |
| 420 | } |
| 421 | |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 422 | static efi_status_t __efi_runtime EFIAPI efi_device_error(void) |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 423 | { |
| 424 | return EFI_DEVICE_ERROR; |
| 425 | } |
| 426 | |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 427 | static efi_status_t __efi_runtime EFIAPI efi_invalid_parameter(void) |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 428 | { |
| 429 | return EFI_INVALID_PARAMETER; |
| 430 | } |
| 431 | |
Heinrich Schuchardt | 897c072 | 2018-02-09 20:41:21 +0100 | [diff] [blame] | 432 | efi_status_t __efi_runtime EFIAPI efi_update_capsule( |
| 433 | struct efi_capsule_header **capsule_header_array, |
| 434 | efi_uintn_t capsule_count, |
| 435 | u64 scatter_gather_list) |
| 436 | { |
| 437 | return EFI_UNSUPPORTED; |
| 438 | } |
| 439 | |
| 440 | efi_status_t __efi_runtime EFIAPI efi_query_capsule_caps( |
| 441 | struct efi_capsule_header **capsule_header_array, |
| 442 | efi_uintn_t capsule_count, |
| 443 | u64 maximum_capsule_size, |
| 444 | u32 reset_type) |
| 445 | { |
| 446 | return EFI_UNSUPPORTED; |
| 447 | } |
| 448 | |
| 449 | efi_status_t __efi_runtime EFIAPI efi_query_variable_info( |
| 450 | u32 attributes, |
Heinrich Schuchardt | d6a6baa | 2018-05-17 07:57:05 +0200 | [diff] [blame] | 451 | u64 *maximum_variable_storage_size, |
| 452 | u64 *remaining_variable_storage_size, |
| 453 | u64 *maximum_variable_size) |
Heinrich Schuchardt | 897c072 | 2018-02-09 20:41:21 +0100 | [diff] [blame] | 454 | { |
| 455 | return EFI_UNSUPPORTED; |
| 456 | } |
| 457 | |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 458 | struct efi_runtime_services __efi_runtime_data efi_runtime_services = { |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 459 | .hdr = { |
| 460 | .signature = EFI_RUNTIME_SERVICES_SIGNATURE, |
| 461 | .revision = EFI_RUNTIME_SERVICES_REVISION, |
| 462 | .headersize = sizeof(struct efi_table_hdr), |
| 463 | }, |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 464 | .get_time = &efi_get_time_boottime, |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 465 | .set_time = (void *)&efi_device_error, |
| 466 | .get_wakeup_time = (void *)&efi_unimplemented, |
| 467 | .set_wakeup_time = (void *)&efi_unimplemented, |
| 468 | .set_virtual_address_map = &efi_set_virtual_address_map, |
| 469 | .convert_pointer = (void *)&efi_invalid_parameter, |
Rob Clark | 15f3d74 | 2017-09-13 18:05:37 -0400 | [diff] [blame] | 470 | .get_variable = efi_get_variable, |
Heinrich Schuchardt | d6a6baa | 2018-05-17 07:57:05 +0200 | [diff] [blame] | 471 | .get_next_variable_name = efi_get_next_variable_name, |
Rob Clark | 15f3d74 | 2017-09-13 18:05:37 -0400 | [diff] [blame] | 472 | .set_variable = efi_set_variable, |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 473 | .get_next_high_mono_count = (void *)&efi_device_error, |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 474 | .reset_system = &efi_reset_system_boottime, |
Heinrich Schuchardt | 897c072 | 2018-02-09 20:41:21 +0100 | [diff] [blame] | 475 | .update_capsule = efi_update_capsule, |
| 476 | .query_capsule_caps = efi_query_capsule_caps, |
| 477 | .query_variable_info = efi_query_variable_info, |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 478 | }; |