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