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