blob: b19cdac959b2de86de8ffc40d8d58ac0e2821deb [file] [log] [blame]
Huang, Ying5b836832008-01-30 13:31:19 +01001/*
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#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/mm.h>
21#include <linux/types.h>
22#include <linux/spinlock.h>
23#include <linux/bootmem.h>
24#include <linux/ioport.h>
25#include <linux/module.h>
26#include <linux/efi.h>
27#include <linux/uaccess.h>
28#include <linux/io.h>
29#include <linux/reboot.h>
David Howells0d01ff22013-04-11 23:51:01 +010030#include <linux/slab.h>
Huang, Ying5b836832008-01-30 13:31:19 +010031
32#include <asm/setup.h>
33#include <asm/page.h>
34#include <asm/e820.h>
35#include <asm/pgtable.h>
36#include <asm/tlbflush.h>
Huang, Ying5b836832008-01-30 13:31:19 +010037#include <asm/proto.h>
38#include <asm/efi.h>
Huang, Ying4de0d4a2008-02-13 17:22:41 +080039#include <asm/cacheflush.h>
Brian Gerst3819cd42009-01-23 11:03:29 +090040#include <asm/fixmap.h>
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010041#include <asm/realmode.h>
Matt Fleming4f9dbcf2014-01-10 18:48:30 +000042#include <asm/time.h>
Huang, Ying5b836832008-01-30 13:31:19 +010043
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010044/*
45 * We allocate runtime services regions bottom-up, starting from -4G, i.e.
46 * 0xffff_ffff_0000_0000 and limit EFI VA mapping space to 64G.
47 */
Mathias Krause8266e312014-09-21 17:26:54 +020048static u64 efi_va = EFI_VA_START;
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010049
Matt Flemingc9f2a9a2015-11-27 21:09:33 +000050struct efi_scratch efi_scratch;
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010051
Matthew Garrett9cd2b072011-05-05 15:19:43 -040052static void __init early_code_mapping_set_exec(int executable)
Huang, Ying5b836832008-01-30 13:31:19 +010053{
54 efi_memory_desc_t *md;
55 void *p;
56
Huang, Yinga2172e22008-01-30 13:33:55 +010057 if (!(__supported_pte_mask & _PAGE_NX))
58 return;
59
Matthew Garrett916f6762011-05-25 09:53:13 -040060 /* Make EFI service code area executable */
Huang, Ying5b836832008-01-30 13:31:19 +010061 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
62 md = p;
Matthew Garrett916f6762011-05-25 09:53:13 -040063 if (md->type == EFI_RUNTIME_SERVICES_CODE ||
64 md->type == EFI_BOOT_SERVICES_CODE)
Matthew Garrett9cd2b072011-05-05 15:19:43 -040065 efi_set_executable(md, executable);
Huang, Ying5b836832008-01-30 13:31:19 +010066 }
67}
68
Ingo Molnar744937b2015-03-03 07:48:50 +010069pgd_t * __init efi_call_phys_prolog(void)
Huang, Ying5b836832008-01-30 13:31:19 +010070{
71 unsigned long vaddress;
Ingo Molnar744937b2015-03-03 07:48:50 +010072 pgd_t *save_pgd;
73
Nathan Zimmerb8f2c212013-01-08 09:02:43 -060074 int pgd;
75 int n_pgds;
Huang, Ying5b836832008-01-30 13:31:19 +010076
Matt Flemingc9f2a9a2015-11-27 21:09:33 +000077 if (!efi_enabled(EFI_OLD_MEMMAP)) {
78 save_pgd = (pgd_t *)read_cr3();
79 write_cr3((unsigned long)efi_scratch.efi_pgt);
80 goto out;
81 }
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +010082
Matthew Garrett9cd2b072011-05-05 15:19:43 -040083 early_code_mapping_set_exec(1);
Nathan Zimmerb8f2c212013-01-08 09:02:43 -060084
85 n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT), PGDIR_SIZE);
86 save_pgd = kmalloc(n_pgds * sizeof(pgd_t), GFP_KERNEL);
87
88 for (pgd = 0; pgd < n_pgds; pgd++) {
89 save_pgd[pgd] = *pgd_offset_k(pgd * PGDIR_SIZE);
90 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
91 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
92 }
Matt Flemingc9f2a9a2015-11-27 21:09:33 +000093out:
Huang, Ying5b836832008-01-30 13:31:19 +010094 __flush_tlb_all();
Ingo Molnar744937b2015-03-03 07:48:50 +010095
96 return save_pgd;
Huang, Ying5b836832008-01-30 13:31:19 +010097}
98
Ingo Molnar744937b2015-03-03 07:48:50 +010099void __init efi_call_phys_epilog(pgd_t *save_pgd)
Huang, Ying5b836832008-01-30 13:31:19 +0100100{
101 /*
102 * After the lock is released, the original page table is restored.
103 */
Ingo Molnar744937b2015-03-03 07:48:50 +0100104 int pgd_idx;
105 int nr_pgds;
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100106
Matt Flemingc9f2a9a2015-11-27 21:09:33 +0000107 if (!efi_enabled(EFI_OLD_MEMMAP)) {
108 write_cr3((unsigned long)save_pgd);
109 __flush_tlb_all();
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100110 return;
Matt Flemingc9f2a9a2015-11-27 21:09:33 +0000111 }
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100112
Ingo Molnar744937b2015-03-03 07:48:50 +0100113 nr_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT) , PGDIR_SIZE);
114
115 for (pgd_idx = 0; pgd_idx < nr_pgds; pgd_idx++)
116 set_pgd(pgd_offset_k(pgd_idx * PGDIR_SIZE), save_pgd[pgd_idx]);
117
Nathan Zimmerb8f2c212013-01-08 09:02:43 -0600118 kfree(save_pgd);
Ingo Molnar744937b2015-03-03 07:48:50 +0100119
Huang, Ying5b836832008-01-30 13:31:19 +0100120 __flush_tlb_all();
Matthew Garrett9cd2b072011-05-05 15:19:43 -0400121 early_code_mapping_set_exec(0);
Huang, Ying5b836832008-01-30 13:31:19 +0100122}
Keith Packarde1ad7832011-12-11 16:12:42 -0800123
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100124/*
125 * Add low kernel mappings for passing arguments to EFI functions.
126 */
127void efi_sync_low_kernel_mappings(void)
128{
129 unsigned num_pgds;
130 pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
131
132 if (efi_enabled(EFI_OLD_MEMMAP))
133 return;
134
135 num_pgds = pgd_index(MODULES_END - 1) - pgd_index(PAGE_OFFSET);
136
137 memcpy(pgd + pgd_index(PAGE_OFFSET),
138 init_mm.pgd + pgd_index(PAGE_OFFSET),
139 sizeof(pgd_t) * num_pgds);
140}
141
Mathias Krause4e78eb052014-09-07 19:42:17 +0200142int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100143{
Matt Flemingedc3b912015-11-27 21:09:31 +0000144 unsigned long pfn, text;
Matt Flemingb61a76f2015-11-27 21:09:32 +0000145 efi_memory_desc_t *md;
Matt Fleming4f9dbcf2014-01-10 18:48:30 +0000146 struct page *page;
Matt Fleming994448f2014-03-05 18:15:37 +0000147 unsigned npages;
Borislav Petkovb7b898a2014-01-18 12:48:17 +0100148 pgd_t *pgd;
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100149
Borislav Petkovb7b898a2014-01-18 12:48:17 +0100150 if (efi_enabled(EFI_OLD_MEMMAP))
151 return 0;
152
153 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
154 pgd = __va(efi_scratch.efi_pgt);
155
156 /*
157 * It can happen that the physical address of new_memmap lands in memory
158 * which is not mapped in the EFI page table. Therefore we need to go
159 * and ident-map those pages containing the map before calling
160 * phys_efi_set_virtual_address_map().
161 */
Matt Flemingedc3b912015-11-27 21:09:31 +0000162 pfn = pa_memmap >> PAGE_SHIFT;
163 if (kernel_map_pages_in_pgd(pgd, pfn, pa_memmap, num_pages, _PAGE_NX)) {
Borislav Petkovb7b898a2014-01-18 12:48:17 +0100164 pr_err("Error ident-mapping new memmap (0x%lx)!\n", pa_memmap);
165 return 1;
166 }
167
168 efi_scratch.use_pgd = true;
169
Matt Fleming4f9dbcf2014-01-10 18:48:30 +0000170 /*
171 * When making calls to the firmware everything needs to be 1:1
172 * mapped and addressable with 32-bit pointers. Map the kernel
173 * text and allocate a new stack because we can't rely on the
174 * stack pointer being < 4GB.
175 */
176 if (!IS_ENABLED(CONFIG_EFI_MIXED))
Matt Fleming994448f2014-03-05 18:15:37 +0000177 return 0;
Matt Fleming4f9dbcf2014-01-10 18:48:30 +0000178
Matt Flemingb61a76f2015-11-27 21:09:32 +0000179 /*
180 * Map all of RAM so that we can access arguments in the 1:1
181 * mapping when making EFI runtime calls.
182 */
183 for_each_efi_memory_desc(&memmap, md) {
184 if (md->type != EFI_CONVENTIONAL_MEMORY &&
185 md->type != EFI_LOADER_DATA &&
186 md->type != EFI_LOADER_CODE)
187 continue;
188
189 pfn = md->phys_addr >> PAGE_SHIFT;
190 npages = md->num_pages;
191
192 if (kernel_map_pages_in_pgd(pgd, pfn, md->phys_addr, npages, 0)) {
193 pr_err("Failed to map 1:1 memory\n");
194 return 1;
195 }
196 }
197
Matt Fleming4f9dbcf2014-01-10 18:48:30 +0000198 page = alloc_page(GFP_KERNEL|__GFP_DMA32);
199 if (!page)
200 panic("Unable to allocate EFI runtime stack < 4GB\n");
201
202 efi_scratch.phys_stack = virt_to_phys(page_address(page));
203 efi_scratch.phys_stack += PAGE_SIZE; /* stack grows down */
204
205 npages = (_end - _text) >> PAGE_SHIFT;
206 text = __pa(_text);
Matt Flemingedc3b912015-11-27 21:09:31 +0000207 pfn = text >> PAGE_SHIFT;
Matt Fleming4f9dbcf2014-01-10 18:48:30 +0000208
Matt Flemingedc3b912015-11-27 21:09:31 +0000209 if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, 0)) {
Matt Fleming4f9dbcf2014-01-10 18:48:30 +0000210 pr_err("Failed to map kernel text 1:1\n");
Matt Fleming994448f2014-03-05 18:15:37 +0000211 return 1;
Matt Fleming4f9dbcf2014-01-10 18:48:30 +0000212 }
Borislav Petkovb7b898a2014-01-18 12:48:17 +0100213
214 return 0;
215}
216
Mathias Krause4e78eb052014-09-07 19:42:17 +0200217void __init efi_cleanup_page_tables(unsigned long pa_memmap, unsigned num_pages)
Borislav Petkovb7b898a2014-01-18 12:48:17 +0100218{
219 pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
220
221 kernel_unmap_pages_in_pgd(pgd, pa_memmap, num_pages);
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100222}
223
224static void __init __map_region(efi_memory_desc_t *md, u64 va)
225{
226 pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
Matt Flemingedc3b912015-11-27 21:09:31 +0000227 unsigned long flags = 0;
228 unsigned long pfn;
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100229
230 if (!(md->attribute & EFI_MEMORY_WB))
Matt Flemingedc3b912015-11-27 21:09:31 +0000231 flags |= _PAGE_PCD;
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100232
Matt Flemingedc3b912015-11-27 21:09:31 +0000233 pfn = md->phys_addr >> PAGE_SHIFT;
234 if (kernel_map_pages_in_pgd(pgd, pfn, va, md->num_pages, flags))
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100235 pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
236 md->phys_addr, va);
237}
238
239void __init efi_map_region(efi_memory_desc_t *md)
240{
241 unsigned long size = md->num_pages << PAGE_SHIFT;
242 u64 pa = md->phys_addr;
243
244 if (efi_enabled(EFI_OLD_MEMMAP))
245 return old_map_region(md);
246
247 /*
248 * Make sure the 1:1 mappings are present as a catch-all for b0rked
249 * firmware which doesn't update all internal pointers after switching
250 * to virtual mode and would otherwise crap on us.
251 */
252 __map_region(md, md->phys_addr);
253
Matt Fleming4f9dbcf2014-01-10 18:48:30 +0000254 /*
255 * Enforce the 1:1 mapping as the default virtual address when
256 * booting in EFI mixed mode, because even though we may be
257 * running a 64-bit kernel, the firmware may only be 32-bit.
258 */
259 if (!efi_is_native () && IS_ENABLED(CONFIG_EFI_MIXED)) {
260 md->virt_addr = md->phys_addr;
261 return;
262 }
263
Borislav Petkovd2f7cbe2013-10-31 17:25:08 +0100264 efi_va -= size;
265
266 /* Is PA 2M-aligned? */
267 if (!(pa & (PMD_SIZE - 1))) {
268 efi_va &= PMD_MASK;
269 } else {
270 u64 pa_offset = pa & (PMD_SIZE - 1);
271 u64 prev_va = efi_va;
272
273 /* get us the same offset within this 2M page */
274 efi_va = (efi_va & PMD_MASK) + pa_offset;
275
276 if (efi_va > prev_va)
277 efi_va -= PMD_SIZE;
278 }
279
280 if (efi_va < EFI_VA_END) {
281 pr_warn(FW_WARN "VA address range overflow!\n");
282 return;
283 }
284
285 /* Do the VA map */
286 __map_region(md, efi_va);
287 md->virt_addr = efi_va;
288}
289
Dave Young3b266492013-12-20 18:02:14 +0800290/*
291 * kexec kernel will use efi_map_region_fixed to map efi runtime memory ranges.
292 * md->virt_addr is the original virtual address which had been mapped in kexec
293 * 1st kernel.
294 */
295void __init efi_map_region_fixed(efi_memory_desc_t *md)
296{
297 __map_region(md, md->virt_addr);
298}
299
Keith Packarde1ad7832011-12-11 16:12:42 -0800300void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
Matt Fleming3e8fa262012-10-19 13:25:46 +0100301 u32 type, u64 attribute)
Keith Packarde1ad7832011-12-11 16:12:42 -0800302{
303 unsigned long last_map_pfn;
304
305 if (type == EFI_MEMORY_MAPPED_IO)
306 return ioremap(phys_addr, size);
307
308 last_map_pfn = init_memory_mapping(phys_addr, phys_addr + size);
309 if ((last_map_pfn << PAGE_SHIFT) < phys_addr + size) {
310 unsigned long top = last_map_pfn << PAGE_SHIFT;
Matt Fleming3e8fa262012-10-19 13:25:46 +0100311 efi_ioremap(top, size - (top - phys_addr), type, attribute);
Keith Packarde1ad7832011-12-11 16:12:42 -0800312 }
313
Matt Fleming3e8fa262012-10-19 13:25:46 +0100314 if (!(attribute & EFI_MEMORY_WB))
315 efi_memory_uc((u64)(unsigned long)__va(phys_addr), size);
316
Keith Packarde1ad7832011-12-11 16:12:42 -0800317 return (void __iomem *)__va(phys_addr);
318}
Dave Young1fec0532013-12-20 18:02:19 +0800319
320void __init parse_efi_setup(u64 phys_addr, u32 data_len)
321{
322 efi_setup = phys_addr + sizeof(struct setup_data);
Dave Young1fec0532013-12-20 18:02:19 +0800323}
Borislav Petkovc55d0162014-02-14 08:24:24 +0100324
325void __init efi_runtime_mkexec(void)
326{
327 if (!efi_enabled(EFI_OLD_MEMMAP))
328 return;
329
330 if (__supported_pte_mask & _PAGE_NX)
331 runtime_code_page_mkexec();
332}
Borislav Petkov11cc8512014-01-18 12:48:15 +0100333
334void __init efi_dump_pagetable(void)
335{
336#ifdef CONFIG_EFI_PGT_DUMP
337 pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
338
339 ptdump_walk_pgd_level(NULL, pgd);
340#endif
341}
Matt Fleming994448f2014-03-05 18:15:37 +0000342
Matt Fleming4f9dbcf2014-01-10 18:48:30 +0000343#ifdef CONFIG_EFI_MIXED
344extern efi_status_t efi64_thunk(u32, ...);
345
346#define runtime_service32(func) \
347({ \
348 u32 table = (u32)(unsigned long)efi.systab; \
349 u32 *rt, *___f; \
350 \
351 rt = (u32 *)(table + offsetof(efi_system_table_32_t, runtime)); \
352 ___f = (u32 *)(*rt + offsetof(efi_runtime_services_32_t, func)); \
353 *___f; \
354})
355
356/*
357 * Switch to the EFI page tables early so that we can access the 1:1
358 * runtime services mappings which are not mapped in any other page
359 * tables. This function must be called before runtime_service32().
360 *
361 * Also, disable interrupts because the IDT points to 64-bit handlers,
362 * which aren't going to function correctly when we switch to 32-bit.
363 */
364#define efi_thunk(f, ...) \
365({ \
366 efi_status_t __s; \
367 unsigned long flags; \
368 u32 func; \
369 \
370 efi_sync_low_kernel_mappings(); \
371 local_irq_save(flags); \
372 \
373 efi_scratch.prev_cr3 = read_cr3(); \
374 write_cr3((unsigned long)efi_scratch.efi_pgt); \
375 __flush_tlb_all(); \
376 \
377 func = runtime_service32(f); \
378 __s = efi64_thunk(func, __VA_ARGS__); \
379 \
380 write_cr3(efi_scratch.prev_cr3); \
381 __flush_tlb_all(); \
382 local_irq_restore(flags); \
383 \
384 __s; \
385})
386
387efi_status_t efi_thunk_set_virtual_address_map(
388 void *phys_set_virtual_address_map,
389 unsigned long memory_map_size,
390 unsigned long descriptor_size,
391 u32 descriptor_version,
392 efi_memory_desc_t *virtual_map)
393{
394 efi_status_t status;
395 unsigned long flags;
396 u32 func;
397
398 efi_sync_low_kernel_mappings();
399 local_irq_save(flags);
400
401 efi_scratch.prev_cr3 = read_cr3();
402 write_cr3((unsigned long)efi_scratch.efi_pgt);
403 __flush_tlb_all();
404
405 func = (u32)(unsigned long)phys_set_virtual_address_map;
406 status = efi64_thunk(func, memory_map_size, descriptor_size,
407 descriptor_version, virtual_map);
408
409 write_cr3(efi_scratch.prev_cr3);
410 __flush_tlb_all();
411 local_irq_restore(flags);
412
413 return status;
414}
415
416static efi_status_t efi_thunk_get_time(efi_time_t *tm, efi_time_cap_t *tc)
417{
418 efi_status_t status;
419 u32 phys_tm, phys_tc;
420
421 spin_lock(&rtc_lock);
422
423 phys_tm = virt_to_phys(tm);
424 phys_tc = virt_to_phys(tc);
425
426 status = efi_thunk(get_time, phys_tm, phys_tc);
427
428 spin_unlock(&rtc_lock);
429
430 return status;
431}
432
433static efi_status_t efi_thunk_set_time(efi_time_t *tm)
434{
435 efi_status_t status;
436 u32 phys_tm;
437
438 spin_lock(&rtc_lock);
439
440 phys_tm = virt_to_phys(tm);
441
442 status = efi_thunk(set_time, phys_tm);
443
444 spin_unlock(&rtc_lock);
445
446 return status;
447}
448
449static efi_status_t
450efi_thunk_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
451 efi_time_t *tm)
452{
453 efi_status_t status;
454 u32 phys_enabled, phys_pending, phys_tm;
455
456 spin_lock(&rtc_lock);
457
458 phys_enabled = virt_to_phys(enabled);
459 phys_pending = virt_to_phys(pending);
460 phys_tm = virt_to_phys(tm);
461
462 status = efi_thunk(get_wakeup_time, phys_enabled,
463 phys_pending, phys_tm);
464
465 spin_unlock(&rtc_lock);
466
467 return status;
468}
469
470static efi_status_t
471efi_thunk_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
472{
473 efi_status_t status;
474 u32 phys_tm;
475
476 spin_lock(&rtc_lock);
477
478 phys_tm = virt_to_phys(tm);
479
480 status = efi_thunk(set_wakeup_time, enabled, phys_tm);
481
482 spin_unlock(&rtc_lock);
483
484 return status;
485}
486
487
488static efi_status_t
489efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor,
490 u32 *attr, unsigned long *data_size, void *data)
491{
492 efi_status_t status;
493 u32 phys_name, phys_vendor, phys_attr;
494 u32 phys_data_size, phys_data;
495
496 phys_data_size = virt_to_phys(data_size);
497 phys_vendor = virt_to_phys(vendor);
498 phys_name = virt_to_phys(name);
499 phys_attr = virt_to_phys(attr);
500 phys_data = virt_to_phys(data);
501
502 status = efi_thunk(get_variable, phys_name, phys_vendor,
503 phys_attr, phys_data_size, phys_data);
504
505 return status;
506}
507
508static efi_status_t
509efi_thunk_set_variable(efi_char16_t *name, efi_guid_t *vendor,
510 u32 attr, unsigned long data_size, void *data)
511{
512 u32 phys_name, phys_vendor, phys_data;
513 efi_status_t status;
514
515 phys_name = virt_to_phys(name);
516 phys_vendor = virt_to_phys(vendor);
517 phys_data = virt_to_phys(data);
518
519 /* If data_size is > sizeof(u32) we've got problems */
520 status = efi_thunk(set_variable, phys_name, phys_vendor,
521 attr, data_size, phys_data);
522
523 return status;
524}
525
526static efi_status_t
527efi_thunk_get_next_variable(unsigned long *name_size,
528 efi_char16_t *name,
529 efi_guid_t *vendor)
530{
531 efi_status_t status;
532 u32 phys_name_size, phys_name, phys_vendor;
533
534 phys_name_size = virt_to_phys(name_size);
535 phys_vendor = virt_to_phys(vendor);
536 phys_name = virt_to_phys(name);
537
538 status = efi_thunk(get_next_variable, phys_name_size,
539 phys_name, phys_vendor);
540
541 return status;
542}
543
544static efi_status_t
545efi_thunk_get_next_high_mono_count(u32 *count)
546{
547 efi_status_t status;
548 u32 phys_count;
549
550 phys_count = virt_to_phys(count);
551 status = efi_thunk(get_next_high_mono_count, phys_count);
552
553 return status;
554}
555
556static void
557efi_thunk_reset_system(int reset_type, efi_status_t status,
558 unsigned long data_size, efi_char16_t *data)
559{
560 u32 phys_data;
561
562 phys_data = virt_to_phys(data);
563
564 efi_thunk(reset_system, reset_type, status, data_size, phys_data);
565}
566
567static efi_status_t
568efi_thunk_update_capsule(efi_capsule_header_t **capsules,
569 unsigned long count, unsigned long sg_list)
570{
571 /*
572 * To properly support this function we would need to repackage
573 * 'capsules' because the firmware doesn't understand 64-bit
574 * pointers.
575 */
576 return EFI_UNSUPPORTED;
577}
578
579static efi_status_t
580efi_thunk_query_variable_info(u32 attr, u64 *storage_space,
581 u64 *remaining_space,
582 u64 *max_variable_size)
583{
584 efi_status_t status;
585 u32 phys_storage, phys_remaining, phys_max;
586
587 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
588 return EFI_UNSUPPORTED;
589
590 phys_storage = virt_to_phys(storage_space);
591 phys_remaining = virt_to_phys(remaining_space);
592 phys_max = virt_to_phys(max_variable_size);
593
Matt Fleming9a110402014-03-16 17:46:46 +0000594 status = efi_thunk(query_variable_info, attr, phys_storage,
Matt Fleming4f9dbcf2014-01-10 18:48:30 +0000595 phys_remaining, phys_max);
596
597 return status;
598}
599
600static efi_status_t
601efi_thunk_query_capsule_caps(efi_capsule_header_t **capsules,
602 unsigned long count, u64 *max_size,
603 int *reset_type)
604{
605 /*
606 * To properly support this function we would need to repackage
607 * 'capsules' because the firmware doesn't understand 64-bit
608 * pointers.
609 */
610 return EFI_UNSUPPORTED;
611}
612
613void efi_thunk_runtime_setup(void)
614{
615 efi.get_time = efi_thunk_get_time;
616 efi.set_time = efi_thunk_set_time;
617 efi.get_wakeup_time = efi_thunk_get_wakeup_time;
618 efi.set_wakeup_time = efi_thunk_set_wakeup_time;
619 efi.get_variable = efi_thunk_get_variable;
620 efi.get_next_variable = efi_thunk_get_next_variable;
621 efi.set_variable = efi_thunk_set_variable;
622 efi.get_next_high_mono_count = efi_thunk_get_next_high_mono_count;
623 efi.reset_system = efi_thunk_reset_system;
624 efi.query_variable_info = efi_thunk_query_variable_info;
625 efi.update_capsule = efi_thunk_update_capsule;
626 efi.query_capsule_caps = efi_thunk_query_capsule_caps;
627}
628#endif /* CONFIG_EFI_MIXED */