]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/x86/platform/efi/efi_64.c
x86/efi: Consolidate region mapping logic
[mirror_ubuntu-artful-kernel.git] / arch / x86 / platform / efi / efi_64.c
CommitLineData
5b83683f
HY
1/*
2 * x86_64 specific EFI support functions
3 * Based on Extensible Firmware Interface Specification version 1.0
4 *
5 * Copyright (C) 2005-2008 Intel Co.
6 * Fenghua Yu <fenghua.yu@intel.com>
7 * Bibo Mao <bibo.mao@intel.com>
8 * Chandramouli Narayanan <mouli@linux.intel.com>
9 * Huang Ying <ying.huang@intel.com>
10 *
11 * Code to convert EFI to E820 map has been implemented in elilo bootloader
12 * based on a EFI patch by Edgar Hucek. Based on the E820 map, the page table
13 * is setup appropriately for EFI runtime code.
14 * - mouli 06/14/2007.
15 *
16 */
17
26d7f65f
MF
18#define pr_fmt(fmt) "efi: " fmt
19
5b83683f
HY
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/mm.h>
23#include <linux/types.h>
24#include <linux/spinlock.h>
25#include <linux/bootmem.h>
26#include <linux/ioport.h>
cc3ae7b0 27#include <linux/init.h>
5ab788d7 28#include <linux/mc146818rtc.h>
5b83683f
HY
29#include <linux/efi.h>
30#include <linux/uaccess.h>
31#include <linux/io.h>
32#include <linux/reboot.h>
0d01ff25 33#include <linux/slab.h>
5b83683f
HY
34
35#include <asm/setup.h>
36#include <asm/page.h>
37#include <asm/e820.h>
38#include <asm/pgtable.h>
39#include <asm/tlbflush.h>
5b83683f
HY
40#include <asm/proto.h>
41#include <asm/efi.h>
4de0d4a6 42#include <asm/cacheflush.h>
3819cd48 43#include <asm/fixmap.h>
d2f7cbe7 44#include <asm/realmode.h>
4f9dbcfc 45#include <asm/time.h>
67a9108e 46#include <asm/pgalloc.h>
5b83683f 47
d2f7cbe7
BP
48/*
49 * We allocate runtime services regions bottom-up, starting from -4G, i.e.
50 * 0xffff_ffff_0000_0000 and limit EFI VA mapping space to 64G.
51 */
8266e31e 52static u64 efi_va = EFI_VA_START;
d2f7cbe7 53
c9f2a9a6 54struct efi_scratch efi_scratch;
d2f7cbe7 55
9cd2b07c 56static void __init early_code_mapping_set_exec(int executable)
5b83683f
HY
57{
58 efi_memory_desc_t *md;
5b83683f 59
a2172e25
HY
60 if (!(__supported_pte_mask & _PAGE_NX))
61 return;
62
916f676f 63 /* Make EFI service code area executable */
78ce248f 64 for_each_efi_memory_desc(md) {
916f676f
MG
65 if (md->type == EFI_RUNTIME_SERVICES_CODE ||
66 md->type == EFI_BOOT_SERVICES_CODE)
9cd2b07c 67 efi_set_executable(md, executable);
5b83683f
HY
68 }
69}
70
744937b0 71pgd_t * __init efi_call_phys_prolog(void)
5b83683f
HY
72{
73 unsigned long vaddress;
744937b0
IM
74 pgd_t *save_pgd;
75
b8f2c21d
NZ
76 int pgd;
77 int n_pgds;
5b83683f 78
c9f2a9a6
MF
79 if (!efi_enabled(EFI_OLD_MEMMAP)) {
80 save_pgd = (pgd_t *)read_cr3();
81 write_cr3((unsigned long)efi_scratch.efi_pgt);
82 goto out;
83 }
d2f7cbe7 84
9cd2b07c 85 early_code_mapping_set_exec(1);
b8f2c21d
NZ
86
87 n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT), PGDIR_SIZE);
88 save_pgd = kmalloc(n_pgds * sizeof(pgd_t), GFP_KERNEL);
89
90 for (pgd = 0; pgd < n_pgds; pgd++) {
91 save_pgd[pgd] = *pgd_offset_k(pgd * PGDIR_SIZE);
92 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
93 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
94 }
c9f2a9a6 95out:
5b83683f 96 __flush_tlb_all();
744937b0
IM
97
98 return save_pgd;
5b83683f
HY
99}
100
744937b0 101void __init efi_call_phys_epilog(pgd_t *save_pgd)
5b83683f
HY
102{
103 /*
104 * After the lock is released, the original page table is restored.
105 */
744937b0
IM
106 int pgd_idx;
107 int nr_pgds;
d2f7cbe7 108
c9f2a9a6
MF
109 if (!efi_enabled(EFI_OLD_MEMMAP)) {
110 write_cr3((unsigned long)save_pgd);
111 __flush_tlb_all();
d2f7cbe7 112 return;
c9f2a9a6 113 }
d2f7cbe7 114
744937b0
IM
115 nr_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT) , PGDIR_SIZE);
116
117 for (pgd_idx = 0; pgd_idx < nr_pgds; pgd_idx++)
118 set_pgd(pgd_offset_k(pgd_idx * PGDIR_SIZE), save_pgd[pgd_idx]);
119
b8f2c21d 120 kfree(save_pgd);
744937b0 121
5b83683f 122 __flush_tlb_all();
9cd2b07c 123 early_code_mapping_set_exec(0);
5b83683f 124}
e1ad783b 125
67a9108e
MF
126static pgd_t *efi_pgd;
127
128/*
129 * We need our own copy of the higher levels of the page tables
130 * because we want to avoid inserting EFI region mappings (EFI_VA_END
131 * to EFI_VA_START) into the standard kernel page tables. Everything
132 * else can be shared, see efi_sync_low_kernel_mappings().
133 */
134int __init efi_alloc_page_tables(void)
135{
136 pgd_t *pgd;
137 pud_t *pud;
138 gfp_t gfp_mask;
139
140 if (efi_enabled(EFI_OLD_MEMMAP))
141 return 0;
142
f58f230a 143 gfp_mask = GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO;
67a9108e
MF
144 efi_pgd = (pgd_t *)__get_free_page(gfp_mask);
145 if (!efi_pgd)
146 return -ENOMEM;
147
148 pgd = efi_pgd + pgd_index(EFI_VA_END);
149
150 pud = pud_alloc_one(NULL, 0);
151 if (!pud) {
152 free_page((unsigned long)efi_pgd);
153 return -ENOMEM;
154 }
155
156 pgd_populate(NULL, pgd, pud);
157
158 return 0;
159}
160
d2f7cbe7
BP
161/*
162 * Add low kernel mappings for passing arguments to EFI functions.
163 */
164void efi_sync_low_kernel_mappings(void)
165{
67a9108e
MF
166 unsigned num_entries;
167 pgd_t *pgd_k, *pgd_efi;
168 pud_t *pud_k, *pud_efi;
d2f7cbe7
BP
169
170 if (efi_enabled(EFI_OLD_MEMMAP))
171 return;
172
67a9108e
MF
173 /*
174 * We can share all PGD entries apart from the one entry that
175 * covers the EFI runtime mapping space.
176 *
177 * Make sure the EFI runtime region mappings are guaranteed to
178 * only span a single PGD entry and that the entry also maps
179 * other important kernel regions.
180 */
181 BUILD_BUG_ON(pgd_index(EFI_VA_END) != pgd_index(MODULES_END));
182 BUILD_BUG_ON((EFI_VA_START & PGDIR_MASK) !=
183 (EFI_VA_END & PGDIR_MASK));
184
185 pgd_efi = efi_pgd + pgd_index(PAGE_OFFSET);
186 pgd_k = pgd_offset_k(PAGE_OFFSET);
187
188 num_entries = pgd_index(EFI_VA_END) - pgd_index(PAGE_OFFSET);
189 memcpy(pgd_efi, pgd_k, sizeof(pgd_t) * num_entries);
d2f7cbe7 190
67a9108e
MF
191 /*
192 * We share all the PUD entries apart from those that map the
193 * EFI regions. Copy around them.
194 */
195 BUILD_BUG_ON((EFI_VA_START & ~PUD_MASK) != 0);
196 BUILD_BUG_ON((EFI_VA_END & ~PUD_MASK) != 0);
197
198 pgd_efi = efi_pgd + pgd_index(EFI_VA_END);
199 pud_efi = pud_offset(pgd_efi, 0);
200
201 pgd_k = pgd_offset_k(EFI_VA_END);
202 pud_k = pud_offset(pgd_k, 0);
203
204 num_entries = pud_index(EFI_VA_END);
205 memcpy(pud_efi, pud_k, sizeof(pud_t) * num_entries);
206
207 pud_efi = pud_offset(pgd_efi, EFI_VA_START);
208 pud_k = pud_offset(pgd_k, EFI_VA_START);
209
210 num_entries = PTRS_PER_PUD - pud_index(EFI_VA_START);
211 memcpy(pud_efi, pud_k, sizeof(pud_t) * num_entries);
d2f7cbe7
BP
212}
213
4e78eb05 214int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
d2f7cbe7 215{
edc3b912 216 unsigned long pfn, text;
4f9dbcfc 217 struct page *page;
994448f1 218 unsigned npages;
b7b898ae
BP
219 pgd_t *pgd;
220
221 if (efi_enabled(EFI_OLD_MEMMAP))
222 return 0;
223
67a9108e
MF
224 efi_scratch.efi_pgt = (pgd_t *)__pa(efi_pgd);
225 pgd = efi_pgd;
d2f7cbe7 226
b7b898ae
BP
227 /*
228 * It can happen that the physical address of new_memmap lands in memory
229 * which is not mapped in the EFI page table. Therefore we need to go
230 * and ident-map those pages containing the map before calling
231 * phys_efi_set_virtual_address_map().
232 */
edc3b912 233 pfn = pa_memmap >> PAGE_SHIFT;
15f003d2 234 if (kernel_map_pages_in_pgd(pgd, pfn, pa_memmap, num_pages, _PAGE_NX | _PAGE_RW)) {
b7b898ae
BP
235 pr_err("Error ident-mapping new memmap (0x%lx)!\n", pa_memmap);
236 return 1;
237 }
238
239 efi_scratch.use_pgd = true;
240
4f9dbcfc
MF
241 /*
242 * When making calls to the firmware everything needs to be 1:1
243 * mapped and addressable with 32-bit pointers. Map the kernel
244 * text and allocate a new stack because we can't rely on the
245 * stack pointer being < 4GB.
246 */
247 if (!IS_ENABLED(CONFIG_EFI_MIXED))
994448f1 248 return 0;
4f9dbcfc
MF
249
250 page = alloc_page(GFP_KERNEL|__GFP_DMA32);
251 if (!page)
252 panic("Unable to allocate EFI runtime stack < 4GB\n");
253
254 efi_scratch.phys_stack = virt_to_phys(page_address(page));
255 efi_scratch.phys_stack += PAGE_SIZE; /* stack grows down */
256
2ad510dc 257 npages = (_etext - _text) >> PAGE_SHIFT;
4f9dbcfc 258 text = __pa(_text);
edc3b912 259 pfn = text >> PAGE_SHIFT;
4f9dbcfc 260
15f003d2 261 if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, _PAGE_RW)) {
4f9dbcfc 262 pr_err("Failed to map kernel text 1:1\n");
994448f1 263 return 1;
4f9dbcfc 264 }
b7b898ae
BP
265
266 return 0;
267}
268
d2f7cbe7
BP
269static void __init __map_region(efi_memory_desc_t *md, u64 va)
270{
15f003d2 271 unsigned long flags = _PAGE_RW;
edc3b912 272 unsigned long pfn;
67a9108e 273 pgd_t *pgd = efi_pgd;
d2f7cbe7
BP
274
275 if (!(md->attribute & EFI_MEMORY_WB))
edc3b912 276 flags |= _PAGE_PCD;
d2f7cbe7 277
edc3b912
MF
278 pfn = md->phys_addr >> PAGE_SHIFT;
279 if (kernel_map_pages_in_pgd(pgd, pfn, va, md->num_pages, flags))
d2f7cbe7
BP
280 pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
281 md->phys_addr, va);
282}
283
284void __init efi_map_region(efi_memory_desc_t *md)
285{
286 unsigned long size = md->num_pages << PAGE_SHIFT;
287 u64 pa = md->phys_addr;
288
289 if (efi_enabled(EFI_OLD_MEMMAP))
290 return old_map_region(md);
291
292 /*
293 * Make sure the 1:1 mappings are present as a catch-all for b0rked
294 * firmware which doesn't update all internal pointers after switching
295 * to virtual mode and would otherwise crap on us.
296 */
297 __map_region(md, md->phys_addr);
298
4f9dbcfc
MF
299 /*
300 * Enforce the 1:1 mapping as the default virtual address when
301 * booting in EFI mixed mode, because even though we may be
302 * running a 64-bit kernel, the firmware may only be 32-bit.
303 */
304 if (!efi_is_native () && IS_ENABLED(CONFIG_EFI_MIXED)) {
305 md->virt_addr = md->phys_addr;
306 return;
307 }
308
d2f7cbe7
BP
309 efi_va -= size;
310
311 /* Is PA 2M-aligned? */
312 if (!(pa & (PMD_SIZE - 1))) {
313 efi_va &= PMD_MASK;
314 } else {
315 u64 pa_offset = pa & (PMD_SIZE - 1);
316 u64 prev_va = efi_va;
317
318 /* get us the same offset within this 2M page */
319 efi_va = (efi_va & PMD_MASK) + pa_offset;
320
321 if (efi_va > prev_va)
322 efi_va -= PMD_SIZE;
323 }
324
325 if (efi_va < EFI_VA_END) {
326 pr_warn(FW_WARN "VA address range overflow!\n");
327 return;
328 }
329
330 /* Do the VA map */
331 __map_region(md, efi_va);
332 md->virt_addr = efi_va;
333}
334
3b266496
DY
335/*
336 * kexec kernel will use efi_map_region_fixed to map efi runtime memory ranges.
337 * md->virt_addr is the original virtual address which had been mapped in kexec
338 * 1st kernel.
339 */
340void __init efi_map_region_fixed(efi_memory_desc_t *md)
341{
342 __map_region(md, md->virt_addr);
343}
344
e1ad783b 345void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
3e8fa263 346 u32 type, u64 attribute)
e1ad783b
KP
347{
348 unsigned long last_map_pfn;
349
350 if (type == EFI_MEMORY_MAPPED_IO)
351 return ioremap(phys_addr, size);
352
353 last_map_pfn = init_memory_mapping(phys_addr, phys_addr + size);
354 if ((last_map_pfn << PAGE_SHIFT) < phys_addr + size) {
355 unsigned long top = last_map_pfn << PAGE_SHIFT;
3e8fa263 356 efi_ioremap(top, size - (top - phys_addr), type, attribute);
e1ad783b
KP
357 }
358
3e8fa263
MF
359 if (!(attribute & EFI_MEMORY_WB))
360 efi_memory_uc((u64)(unsigned long)__va(phys_addr), size);
361
e1ad783b
KP
362 return (void __iomem *)__va(phys_addr);
363}
1fec0533
DY
364
365void __init parse_efi_setup(u64 phys_addr, u32 data_len)
366{
367 efi_setup = phys_addr + sizeof(struct setup_data);
1fec0533 368}
c55d016f 369
6d0cc887 370void __init efi_runtime_update_mappings(void)
c55d016f 371{
6d0cc887
SP
372 unsigned long pfn;
373 pgd_t *pgd = efi_pgd;
374 efi_memory_desc_t *md;
6d0cc887
SP
375
376 if (efi_enabled(EFI_OLD_MEMMAP)) {
377 if (__supported_pte_mask & _PAGE_NX)
378 runtime_code_page_mkexec();
379 return;
380 }
381
382 if (!efi_enabled(EFI_NX_PE_DATA))
c55d016f
BP
383 return;
384
78ce248f 385 for_each_efi_memory_desc(md) {
6d0cc887 386 unsigned long pf = 0;
6d0cc887
SP
387
388 if (!(md->attribute & EFI_MEMORY_RUNTIME))
389 continue;
390
391 if (!(md->attribute & EFI_MEMORY_WB))
392 pf |= _PAGE_PCD;
393
394 if ((md->attribute & EFI_MEMORY_XP) ||
395 (md->type == EFI_RUNTIME_SERVICES_DATA))
396 pf |= _PAGE_NX;
397
398 if (!(md->attribute & EFI_MEMORY_RO) &&
399 (md->type != EFI_RUNTIME_SERVICES_CODE))
400 pf |= _PAGE_RW;
401
402 /* Update the 1:1 mapping */
403 pfn = md->phys_addr >> PAGE_SHIFT;
404 if (kernel_map_pages_in_pgd(pgd, pfn, md->phys_addr, md->num_pages, pf))
405 pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
406 md->phys_addr, md->virt_addr);
407
408 if (kernel_map_pages_in_pgd(pgd, pfn, md->virt_addr, md->num_pages, pf))
409 pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
410 md->phys_addr, md->virt_addr);
411 }
c55d016f 412}
11cc8512
BP
413
414void __init efi_dump_pagetable(void)
415{
416#ifdef CONFIG_EFI_PGT_DUMP
67a9108e 417 ptdump_walk_pgd_level(NULL, efi_pgd);
11cc8512
BP
418#endif
419}
994448f1 420
4f9dbcfc
MF
421#ifdef CONFIG_EFI_MIXED
422extern efi_status_t efi64_thunk(u32, ...);
423
424#define runtime_service32(func) \
425({ \
426 u32 table = (u32)(unsigned long)efi.systab; \
427 u32 *rt, *___f; \
428 \
429 rt = (u32 *)(table + offsetof(efi_system_table_32_t, runtime)); \
430 ___f = (u32 *)(*rt + offsetof(efi_runtime_services_32_t, func)); \
431 *___f; \
432})
433
434/*
435 * Switch to the EFI page tables early so that we can access the 1:1
436 * runtime services mappings which are not mapped in any other page
437 * tables. This function must be called before runtime_service32().
438 *
439 * Also, disable interrupts because the IDT points to 64-bit handlers,
440 * which aren't going to function correctly when we switch to 32-bit.
441 */
442#define efi_thunk(f, ...) \
443({ \
444 efi_status_t __s; \
21f86625
AT
445 unsigned long __flags; \
446 u32 __func; \
4f9dbcfc 447 \
21f86625
AT
448 local_irq_save(__flags); \
449 arch_efi_call_virt_setup(); \
4f9dbcfc 450 \
21f86625
AT
451 __func = runtime_service32(f); \
452 __s = efi64_thunk(__func, __VA_ARGS__); \
4f9dbcfc 453 \
21f86625
AT
454 arch_efi_call_virt_teardown(); \
455 local_irq_restore(__flags); \
4f9dbcfc
MF
456 \
457 __s; \
458})
459
460efi_status_t efi_thunk_set_virtual_address_map(
461 void *phys_set_virtual_address_map,
462 unsigned long memory_map_size,
463 unsigned long descriptor_size,
464 u32 descriptor_version,
465 efi_memory_desc_t *virtual_map)
466{
467 efi_status_t status;
468 unsigned long flags;
469 u32 func;
470
471 efi_sync_low_kernel_mappings();
472 local_irq_save(flags);
473
474 efi_scratch.prev_cr3 = read_cr3();
475 write_cr3((unsigned long)efi_scratch.efi_pgt);
476 __flush_tlb_all();
477
478 func = (u32)(unsigned long)phys_set_virtual_address_map;
479 status = efi64_thunk(func, memory_map_size, descriptor_size,
480 descriptor_version, virtual_map);
481
482 write_cr3(efi_scratch.prev_cr3);
483 __flush_tlb_all();
484 local_irq_restore(flags);
485
486 return status;
487}
488
489static efi_status_t efi_thunk_get_time(efi_time_t *tm, efi_time_cap_t *tc)
490{
491 efi_status_t status;
492 u32 phys_tm, phys_tc;
493
494 spin_lock(&rtc_lock);
495
496 phys_tm = virt_to_phys(tm);
497 phys_tc = virt_to_phys(tc);
498
499 status = efi_thunk(get_time, phys_tm, phys_tc);
500
501 spin_unlock(&rtc_lock);
502
503 return status;
504}
505
506static efi_status_t efi_thunk_set_time(efi_time_t *tm)
507{
508 efi_status_t status;
509 u32 phys_tm;
510
511 spin_lock(&rtc_lock);
512
513 phys_tm = virt_to_phys(tm);
514
515 status = efi_thunk(set_time, phys_tm);
516
517 spin_unlock(&rtc_lock);
518
519 return status;
520}
521
522static efi_status_t
523efi_thunk_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
524 efi_time_t *tm)
525{
526 efi_status_t status;
527 u32 phys_enabled, phys_pending, phys_tm;
528
529 spin_lock(&rtc_lock);
530
531 phys_enabled = virt_to_phys(enabled);
532 phys_pending = virt_to_phys(pending);
533 phys_tm = virt_to_phys(tm);
534
535 status = efi_thunk(get_wakeup_time, phys_enabled,
536 phys_pending, phys_tm);
537
538 spin_unlock(&rtc_lock);
539
540 return status;
541}
542
543static efi_status_t
544efi_thunk_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
545{
546 efi_status_t status;
547 u32 phys_tm;
548
549 spin_lock(&rtc_lock);
550
551 phys_tm = virt_to_phys(tm);
552
553 status = efi_thunk(set_wakeup_time, enabled, phys_tm);
554
555 spin_unlock(&rtc_lock);
556
557 return status;
558}
559
560
561static efi_status_t
562efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor,
563 u32 *attr, unsigned long *data_size, void *data)
564{
565 efi_status_t status;
566 u32 phys_name, phys_vendor, phys_attr;
567 u32 phys_data_size, phys_data;
568
569 phys_data_size = virt_to_phys(data_size);
570 phys_vendor = virt_to_phys(vendor);
571 phys_name = virt_to_phys(name);
572 phys_attr = virt_to_phys(attr);
573 phys_data = virt_to_phys(data);
574
575 status = efi_thunk(get_variable, phys_name, phys_vendor,
576 phys_attr, phys_data_size, phys_data);
577
578 return status;
579}
580
581static efi_status_t
582efi_thunk_set_variable(efi_char16_t *name, efi_guid_t *vendor,
583 u32 attr, unsigned long data_size, void *data)
584{
585 u32 phys_name, phys_vendor, phys_data;
586 efi_status_t status;
587
588 phys_name = virt_to_phys(name);
589 phys_vendor = virt_to_phys(vendor);
590 phys_data = virt_to_phys(data);
591
592 /* If data_size is > sizeof(u32) we've got problems */
593 status = efi_thunk(set_variable, phys_name, phys_vendor,
594 attr, data_size, phys_data);
595
596 return status;
597}
598
599static efi_status_t
600efi_thunk_get_next_variable(unsigned long *name_size,
601 efi_char16_t *name,
602 efi_guid_t *vendor)
603{
604 efi_status_t status;
605 u32 phys_name_size, phys_name, phys_vendor;
606
607 phys_name_size = virt_to_phys(name_size);
608 phys_vendor = virt_to_phys(vendor);
609 phys_name = virt_to_phys(name);
610
611 status = efi_thunk(get_next_variable, phys_name_size,
612 phys_name, phys_vendor);
613
614 return status;
615}
616
617static efi_status_t
618efi_thunk_get_next_high_mono_count(u32 *count)
619{
620 efi_status_t status;
621 u32 phys_count;
622
623 phys_count = virt_to_phys(count);
624 status = efi_thunk(get_next_high_mono_count, phys_count);
625
626 return status;
627}
628
629static void
630efi_thunk_reset_system(int reset_type, efi_status_t status,
631 unsigned long data_size, efi_char16_t *data)
632{
633 u32 phys_data;
634
635 phys_data = virt_to_phys(data);
636
637 efi_thunk(reset_system, reset_type, status, data_size, phys_data);
638}
639
640static efi_status_t
641efi_thunk_update_capsule(efi_capsule_header_t **capsules,
642 unsigned long count, unsigned long sg_list)
643{
644 /*
645 * To properly support this function we would need to repackage
646 * 'capsules' because the firmware doesn't understand 64-bit
647 * pointers.
648 */
649 return EFI_UNSUPPORTED;
650}
651
652static efi_status_t
653efi_thunk_query_variable_info(u32 attr, u64 *storage_space,
654 u64 *remaining_space,
655 u64 *max_variable_size)
656{
657 efi_status_t status;
658 u32 phys_storage, phys_remaining, phys_max;
659
660 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
661 return EFI_UNSUPPORTED;
662
663 phys_storage = virt_to_phys(storage_space);
664 phys_remaining = virt_to_phys(remaining_space);
665 phys_max = virt_to_phys(max_variable_size);
666
9a11040f 667 status = efi_thunk(query_variable_info, attr, phys_storage,
4f9dbcfc
MF
668 phys_remaining, phys_max);
669
670 return status;
671}
672
673static efi_status_t
674efi_thunk_query_capsule_caps(efi_capsule_header_t **capsules,
675 unsigned long count, u64 *max_size,
676 int *reset_type)
677{
678 /*
679 * To properly support this function we would need to repackage
680 * 'capsules' because the firmware doesn't understand 64-bit
681 * pointers.
682 */
683 return EFI_UNSUPPORTED;
684}
685
686void efi_thunk_runtime_setup(void)
687{
688 efi.get_time = efi_thunk_get_time;
689 efi.set_time = efi_thunk_set_time;
690 efi.get_wakeup_time = efi_thunk_get_wakeup_time;
691 efi.set_wakeup_time = efi_thunk_set_wakeup_time;
692 efi.get_variable = efi_thunk_get_variable;
693 efi.get_next_variable = efi_thunk_get_next_variable;
694 efi.set_variable = efi_thunk_set_variable;
695 efi.get_next_high_mono_count = efi_thunk_get_next_high_mono_count;
696 efi.reset_system = efi_thunk_reset_system;
697 efi.query_variable_info = efi_thunk_query_variable_info;
698 efi.update_capsule = efi_thunk_update_capsule;
699 efi.query_capsule_caps = efi_thunk_query_capsule_caps;
700}
701#endif /* CONFIG_EFI_MIXED */