Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[deliverable/linux.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>
5b83683f
HY
28#include <linux/efi.h>
29#include <linux/uaccess.h>
30#include <linux/io.h>
31#include <linux/reboot.h>
0d01ff25 32#include <linux/slab.h>
5b83683f
HY
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>
5b83683f
HY
39#include <asm/proto.h>
40#include <asm/efi.h>
4de0d4a6 41#include <asm/cacheflush.h>
3819cd48 42#include <asm/fixmap.h>
d2f7cbe7 43#include <asm/realmode.h>
4f9dbcfc 44#include <asm/time.h>
67a9108e 45#include <asm/pgalloc.h>
5b83683f 46
d2f7cbe7
BP
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 */
8266e31e 51static u64 efi_va = EFI_VA_START;
d2f7cbe7 52
c9f2a9a6 53struct efi_scratch efi_scratch;
d2f7cbe7 54
9cd2b07c 55static void __init early_code_mapping_set_exec(int executable)
5b83683f
HY
56{
57 efi_memory_desc_t *md;
5b83683f 58
a2172e25
HY
59 if (!(__supported_pte_mask & _PAGE_NX))
60 return;
61
916f676f 62 /* Make EFI service code area executable */
78ce248f 63 for_each_efi_memory_desc(md) {
916f676f
MG
64 if (md->type == EFI_RUNTIME_SERVICES_CODE ||
65 md->type == EFI_BOOT_SERVICES_CODE)
9cd2b07c 66 efi_set_executable(md, executable);
5b83683f
HY
67 }
68}
69
744937b0 70pgd_t * __init efi_call_phys_prolog(void)
5b83683f
HY
71{
72 unsigned long vaddress;
744937b0
IM
73 pgd_t *save_pgd;
74
b8f2c21d
NZ
75 int pgd;
76 int n_pgds;
5b83683f 77
c9f2a9a6
MF
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 }
d2f7cbe7 83
9cd2b07c 84 early_code_mapping_set_exec(1);
b8f2c21d
NZ
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 }
c9f2a9a6 94out:
5b83683f 95 __flush_tlb_all();
744937b0
IM
96
97 return save_pgd;
5b83683f
HY
98}
99
744937b0 100void __init efi_call_phys_epilog(pgd_t *save_pgd)
5b83683f
HY
101{
102 /*
103 * After the lock is released, the original page table is restored.
104 */
744937b0
IM
105 int pgd_idx;
106 int nr_pgds;
d2f7cbe7 107
c9f2a9a6
MF
108 if (!efi_enabled(EFI_OLD_MEMMAP)) {
109 write_cr3((unsigned long)save_pgd);
110 __flush_tlb_all();
d2f7cbe7 111 return;
c9f2a9a6 112 }
d2f7cbe7 113
744937b0
IM
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
b8f2c21d 119 kfree(save_pgd);
744937b0 120
5b83683f 121 __flush_tlb_all();
9cd2b07c 122 early_code_mapping_set_exec(0);
5b83683f 123}
e1ad783b 124
67a9108e
MF
125static 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 */
133int __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
f58f230a 142 gfp_mask = GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO;
67a9108e
MF
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
d2f7cbe7
BP
160/*
161 * Add low kernel mappings for passing arguments to EFI functions.
162 */
163void efi_sync_low_kernel_mappings(void)
164{
67a9108e
MF
165 unsigned num_entries;
166 pgd_t *pgd_k, *pgd_efi;
167 pud_t *pud_k, *pud_efi;
d2f7cbe7
BP
168
169 if (efi_enabled(EFI_OLD_MEMMAP))
170 return;
171
67a9108e
MF
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);
d2f7cbe7 189
67a9108e
MF
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);
d2f7cbe7
BP
211}
212
4e78eb05 213int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
d2f7cbe7 214{
edc3b912 215 unsigned long pfn, text;
b61a76f8 216 efi_memory_desc_t *md;
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 249
b61a76f8
MF
250 /*
251 * Map all of RAM so that we can access arguments in the 1:1
252 * mapping when making EFI runtime calls.
253 */
78ce248f 254 for_each_efi_memory_desc(md) {
b61a76f8
MF
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
15f003d2 263 if (kernel_map_pages_in_pgd(pgd, pfn, md->phys_addr, npages, _PAGE_RW)) {
b61a76f8
MF
264 pr_err("Failed to map 1:1 memory\n");
265 return 1;
266 }
267 }
268
4f9dbcfc
MF
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
2ad510dc 276 npages = (_etext - _text) >> PAGE_SHIFT;
4f9dbcfc 277 text = __pa(_text);
edc3b912 278 pfn = text >> PAGE_SHIFT;
4f9dbcfc 279
15f003d2 280 if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, _PAGE_RW)) {
4f9dbcfc 281 pr_err("Failed to map kernel text 1:1\n");
994448f1 282 return 1;
4f9dbcfc 283 }
b7b898ae
BP
284
285 return 0;
286}
287
d2f7cbe7
BP
288static void __init __map_region(efi_memory_desc_t *md, u64 va)
289{
15f003d2 290 unsigned long flags = _PAGE_RW;
edc3b912 291 unsigned long pfn;
67a9108e 292 pgd_t *pgd = efi_pgd;
d2f7cbe7
BP
293
294 if (!(md->attribute & EFI_MEMORY_WB))
edc3b912 295 flags |= _PAGE_PCD;
d2f7cbe7 296
edc3b912
MF
297 pfn = md->phys_addr >> PAGE_SHIFT;
298 if (kernel_map_pages_in_pgd(pgd, pfn, va, md->num_pages, flags))
d2f7cbe7
BP
299 pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
300 md->phys_addr, va);
301}
302
303void __init efi_map_region(efi_memory_desc_t *md)
304{
305 unsigned long size = md->num_pages << PAGE_SHIFT;
306 u64 pa = md->phys_addr;
307
308 if (efi_enabled(EFI_OLD_MEMMAP))
309 return old_map_region(md);
310
311 /*
312 * Make sure the 1:1 mappings are present as a catch-all for b0rked
313 * firmware which doesn't update all internal pointers after switching
314 * to virtual mode and would otherwise crap on us.
315 */
316 __map_region(md, md->phys_addr);
317
4f9dbcfc
MF
318 /*
319 * Enforce the 1:1 mapping as the default virtual address when
320 * booting in EFI mixed mode, because even though we may be
321 * running a 64-bit kernel, the firmware may only be 32-bit.
322 */
323 if (!efi_is_native () && IS_ENABLED(CONFIG_EFI_MIXED)) {
324 md->virt_addr = md->phys_addr;
325 return;
326 }
327
d2f7cbe7
BP
328 efi_va -= size;
329
330 /* Is PA 2M-aligned? */
331 if (!(pa & (PMD_SIZE - 1))) {
332 efi_va &= PMD_MASK;
333 } else {
334 u64 pa_offset = pa & (PMD_SIZE - 1);
335 u64 prev_va = efi_va;
336
337 /* get us the same offset within this 2M page */
338 efi_va = (efi_va & PMD_MASK) + pa_offset;
339
340 if (efi_va > prev_va)
341 efi_va -= PMD_SIZE;
342 }
343
344 if (efi_va < EFI_VA_END) {
345 pr_warn(FW_WARN "VA address range overflow!\n");
346 return;
347 }
348
349 /* Do the VA map */
350 __map_region(md, efi_va);
351 md->virt_addr = efi_va;
352}
353
3b266496
DY
354/*
355 * kexec kernel will use efi_map_region_fixed to map efi runtime memory ranges.
356 * md->virt_addr is the original virtual address which had been mapped in kexec
357 * 1st kernel.
358 */
359void __init efi_map_region_fixed(efi_memory_desc_t *md)
360{
361 __map_region(md, md->virt_addr);
362}
363
e1ad783b 364void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
3e8fa263 365 u32 type, u64 attribute)
e1ad783b
KP
366{
367 unsigned long last_map_pfn;
368
369 if (type == EFI_MEMORY_MAPPED_IO)
370 return ioremap(phys_addr, size);
371
372 last_map_pfn = init_memory_mapping(phys_addr, phys_addr + size);
373 if ((last_map_pfn << PAGE_SHIFT) < phys_addr + size) {
374 unsigned long top = last_map_pfn << PAGE_SHIFT;
3e8fa263 375 efi_ioremap(top, size - (top - phys_addr), type, attribute);
e1ad783b
KP
376 }
377
3e8fa263
MF
378 if (!(attribute & EFI_MEMORY_WB))
379 efi_memory_uc((u64)(unsigned long)__va(phys_addr), size);
380
e1ad783b
KP
381 return (void __iomem *)__va(phys_addr);
382}
1fec0533
DY
383
384void __init parse_efi_setup(u64 phys_addr, u32 data_len)
385{
386 efi_setup = phys_addr + sizeof(struct setup_data);
1fec0533 387}
c55d016f 388
6d0cc887 389void __init efi_runtime_update_mappings(void)
c55d016f 390{
6d0cc887
SP
391 unsigned long pfn;
392 pgd_t *pgd = efi_pgd;
393 efi_memory_desc_t *md;
6d0cc887
SP
394
395 if (efi_enabled(EFI_OLD_MEMMAP)) {
396 if (__supported_pte_mask & _PAGE_NX)
397 runtime_code_page_mkexec();
398 return;
399 }
400
401 if (!efi_enabled(EFI_NX_PE_DATA))
c55d016f
BP
402 return;
403
78ce248f 404 for_each_efi_memory_desc(md) {
6d0cc887 405 unsigned long pf = 0;
6d0cc887
SP
406
407 if (!(md->attribute & EFI_MEMORY_RUNTIME))
408 continue;
409
410 if (!(md->attribute & EFI_MEMORY_WB))
411 pf |= _PAGE_PCD;
412
413 if ((md->attribute & EFI_MEMORY_XP) ||
414 (md->type == EFI_RUNTIME_SERVICES_DATA))
415 pf |= _PAGE_NX;
416
417 if (!(md->attribute & EFI_MEMORY_RO) &&
418 (md->type != EFI_RUNTIME_SERVICES_CODE))
419 pf |= _PAGE_RW;
420
421 /* Update the 1:1 mapping */
422 pfn = md->phys_addr >> PAGE_SHIFT;
423 if (kernel_map_pages_in_pgd(pgd, pfn, md->phys_addr, md->num_pages, pf))
424 pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
425 md->phys_addr, md->virt_addr);
426
427 if (kernel_map_pages_in_pgd(pgd, pfn, md->virt_addr, md->num_pages, pf))
428 pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
429 md->phys_addr, md->virt_addr);
430 }
c55d016f 431}
11cc8512
BP
432
433void __init efi_dump_pagetable(void)
434{
435#ifdef CONFIG_EFI_PGT_DUMP
67a9108e 436 ptdump_walk_pgd_level(NULL, efi_pgd);
11cc8512
BP
437#endif
438}
994448f1 439
4f9dbcfc
MF
440#ifdef CONFIG_EFI_MIXED
441extern efi_status_t efi64_thunk(u32, ...);
442
443#define runtime_service32(func) \
444({ \
445 u32 table = (u32)(unsigned long)efi.systab; \
446 u32 *rt, *___f; \
447 \
448 rt = (u32 *)(table + offsetof(efi_system_table_32_t, runtime)); \
449 ___f = (u32 *)(*rt + offsetof(efi_runtime_services_32_t, func)); \
450 *___f; \
451})
452
453/*
454 * Switch to the EFI page tables early so that we can access the 1:1
455 * runtime services mappings which are not mapped in any other page
456 * tables. This function must be called before runtime_service32().
457 *
458 * Also, disable interrupts because the IDT points to 64-bit handlers,
459 * which aren't going to function correctly when we switch to 32-bit.
460 */
461#define efi_thunk(f, ...) \
462({ \
463 efi_status_t __s; \
21f86625
AT
464 unsigned long __flags; \
465 u32 __func; \
4f9dbcfc 466 \
21f86625
AT
467 local_irq_save(__flags); \
468 arch_efi_call_virt_setup(); \
4f9dbcfc 469 \
21f86625
AT
470 __func = runtime_service32(f); \
471 __s = efi64_thunk(__func, __VA_ARGS__); \
4f9dbcfc 472 \
21f86625
AT
473 arch_efi_call_virt_teardown(); \
474 local_irq_restore(__flags); \
4f9dbcfc
MF
475 \
476 __s; \
477})
478
479efi_status_t efi_thunk_set_virtual_address_map(
480 void *phys_set_virtual_address_map,
481 unsigned long memory_map_size,
482 unsigned long descriptor_size,
483 u32 descriptor_version,
484 efi_memory_desc_t *virtual_map)
485{
486 efi_status_t status;
487 unsigned long flags;
488 u32 func;
489
490 efi_sync_low_kernel_mappings();
491 local_irq_save(flags);
492
493 efi_scratch.prev_cr3 = read_cr3();
494 write_cr3((unsigned long)efi_scratch.efi_pgt);
495 __flush_tlb_all();
496
497 func = (u32)(unsigned long)phys_set_virtual_address_map;
498 status = efi64_thunk(func, memory_map_size, descriptor_size,
499 descriptor_version, virtual_map);
500
501 write_cr3(efi_scratch.prev_cr3);
502 __flush_tlb_all();
503 local_irq_restore(flags);
504
505 return status;
506}
507
508static efi_status_t efi_thunk_get_time(efi_time_t *tm, efi_time_cap_t *tc)
509{
510 efi_status_t status;
511 u32 phys_tm, phys_tc;
512
513 spin_lock(&rtc_lock);
514
515 phys_tm = virt_to_phys(tm);
516 phys_tc = virt_to_phys(tc);
517
518 status = efi_thunk(get_time, phys_tm, phys_tc);
519
520 spin_unlock(&rtc_lock);
521
522 return status;
523}
524
525static efi_status_t efi_thunk_set_time(efi_time_t *tm)
526{
527 efi_status_t status;
528 u32 phys_tm;
529
530 spin_lock(&rtc_lock);
531
532 phys_tm = virt_to_phys(tm);
533
534 status = efi_thunk(set_time, phys_tm);
535
536 spin_unlock(&rtc_lock);
537
538 return status;
539}
540
541static efi_status_t
542efi_thunk_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
543 efi_time_t *tm)
544{
545 efi_status_t status;
546 u32 phys_enabled, phys_pending, phys_tm;
547
548 spin_lock(&rtc_lock);
549
550 phys_enabled = virt_to_phys(enabled);
551 phys_pending = virt_to_phys(pending);
552 phys_tm = virt_to_phys(tm);
553
554 status = efi_thunk(get_wakeup_time, phys_enabled,
555 phys_pending, phys_tm);
556
557 spin_unlock(&rtc_lock);
558
559 return status;
560}
561
562static efi_status_t
563efi_thunk_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
564{
565 efi_status_t status;
566 u32 phys_tm;
567
568 spin_lock(&rtc_lock);
569
570 phys_tm = virt_to_phys(tm);
571
572 status = efi_thunk(set_wakeup_time, enabled, phys_tm);
573
574 spin_unlock(&rtc_lock);
575
576 return status;
577}
578
579
580static efi_status_t
581efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor,
582 u32 *attr, unsigned long *data_size, void *data)
583{
584 efi_status_t status;
585 u32 phys_name, phys_vendor, phys_attr;
586 u32 phys_data_size, phys_data;
587
588 phys_data_size = virt_to_phys(data_size);
589 phys_vendor = virt_to_phys(vendor);
590 phys_name = virt_to_phys(name);
591 phys_attr = virt_to_phys(attr);
592 phys_data = virt_to_phys(data);
593
594 status = efi_thunk(get_variable, phys_name, phys_vendor,
595 phys_attr, phys_data_size, phys_data);
596
597 return status;
598}
599
600static efi_status_t
601efi_thunk_set_variable(efi_char16_t *name, efi_guid_t *vendor,
602 u32 attr, unsigned long data_size, void *data)
603{
604 u32 phys_name, phys_vendor, phys_data;
605 efi_status_t status;
606
607 phys_name = virt_to_phys(name);
608 phys_vendor = virt_to_phys(vendor);
609 phys_data = virt_to_phys(data);
610
611 /* If data_size is > sizeof(u32) we've got problems */
612 status = efi_thunk(set_variable, phys_name, phys_vendor,
613 attr, data_size, phys_data);
614
615 return status;
616}
617
618static efi_status_t
619efi_thunk_get_next_variable(unsigned long *name_size,
620 efi_char16_t *name,
621 efi_guid_t *vendor)
622{
623 efi_status_t status;
624 u32 phys_name_size, phys_name, phys_vendor;
625
626 phys_name_size = virt_to_phys(name_size);
627 phys_vendor = virt_to_phys(vendor);
628 phys_name = virt_to_phys(name);
629
630 status = efi_thunk(get_next_variable, phys_name_size,
631 phys_name, phys_vendor);
632
633 return status;
634}
635
636static efi_status_t
637efi_thunk_get_next_high_mono_count(u32 *count)
638{
639 efi_status_t status;
640 u32 phys_count;
641
642 phys_count = virt_to_phys(count);
643 status = efi_thunk(get_next_high_mono_count, phys_count);
644
645 return status;
646}
647
648static void
649efi_thunk_reset_system(int reset_type, efi_status_t status,
650 unsigned long data_size, efi_char16_t *data)
651{
652 u32 phys_data;
653
654 phys_data = virt_to_phys(data);
655
656 efi_thunk(reset_system, reset_type, status, data_size, phys_data);
657}
658
659static efi_status_t
660efi_thunk_update_capsule(efi_capsule_header_t **capsules,
661 unsigned long count, unsigned long sg_list)
662{
663 /*
664 * To properly support this function we would need to repackage
665 * 'capsules' because the firmware doesn't understand 64-bit
666 * pointers.
667 */
668 return EFI_UNSUPPORTED;
669}
670
671static efi_status_t
672efi_thunk_query_variable_info(u32 attr, u64 *storage_space,
673 u64 *remaining_space,
674 u64 *max_variable_size)
675{
676 efi_status_t status;
677 u32 phys_storage, phys_remaining, phys_max;
678
679 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
680 return EFI_UNSUPPORTED;
681
682 phys_storage = virt_to_phys(storage_space);
683 phys_remaining = virt_to_phys(remaining_space);
684 phys_max = virt_to_phys(max_variable_size);
685
9a11040f 686 status = efi_thunk(query_variable_info, attr, phys_storage,
4f9dbcfc
MF
687 phys_remaining, phys_max);
688
689 return status;
690}
691
692static efi_status_t
693efi_thunk_query_capsule_caps(efi_capsule_header_t **capsules,
694 unsigned long count, u64 *max_size,
695 int *reset_type)
696{
697 /*
698 * To properly support this function we would need to repackage
699 * 'capsules' because the firmware doesn't understand 64-bit
700 * pointers.
701 */
702 return EFI_UNSUPPORTED;
703}
704
705void efi_thunk_runtime_setup(void)
706{
707 efi.get_time = efi_thunk_get_time;
708 efi.set_time = efi_thunk_set_time;
709 efi.get_wakeup_time = efi_thunk_get_wakeup_time;
710 efi.set_wakeup_time = efi_thunk_set_wakeup_time;
711 efi.get_variable = efi_thunk_get_variable;
712 efi.get_next_variable = efi_thunk_get_next_variable;
713 efi.set_variable = efi_thunk_set_variable;
714 efi.get_next_high_mono_count = efi_thunk_get_next_high_mono_count;
715 efi.reset_system = efi_thunk_reset_system;
716 efi.query_variable_info = efi_thunk_query_variable_info;
717 efi.update_capsule = efi_thunk_update_capsule;
718 efi.query_capsule_caps = efi_thunk_query_capsule_caps;
719}
720#endif /* CONFIG_EFI_MIXED */
This page took 0.534067 seconds and 5 git commands to generate.