~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/platform/efi/efi.c

Version: ~ [ linux-5.8-rc4 ] ~ [ linux-5.7.7 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.50 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.131 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.187 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.229 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.229 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Common EFI (Extensible Firmware Interface) support functions
  3  * Based on Extensible Firmware Interface Specification version 1.0
  4  *
  5  * Copyright (C) 1999 VA Linux Systems
  6  * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
  7  * Copyright (C) 1999-2002 Hewlett-Packard Co.
  8  *      David Mosberger-Tang <davidm@hpl.hp.com>
  9  *      Stephane Eranian <eranian@hpl.hp.com>
 10  * Copyright (C) 2005-2008 Intel Co.
 11  *      Fenghua Yu <fenghua.yu@intel.com>
 12  *      Bibo Mao <bibo.mao@intel.com>
 13  *      Chandramouli Narayanan <mouli@linux.intel.com>
 14  *      Huang Ying <ying.huang@intel.com>
 15  * Copyright (C) 2013 SuSE Labs
 16  *      Borislav Petkov <bp@suse.de> - runtime services VA mapping
 17  *
 18  * Copied from efi_32.c to eliminate the duplicated code between EFI
 19  * 32/64 support code. --ying 2007-10-26
 20  *
 21  * All EFI Runtime Services are not implemented yet as EFI only
 22  * supports physical mode addressing on SoftSDV. This is to be fixed
 23  * in a future version.  --drummond 1999-07-20
 24  *
 25  * Implemented EFI runtime services and virtual mode calls.  --davidm
 26  *
 27  * Goutham Rao: <goutham.rao@intel.com>
 28  *      Skip non-WB memory and ignore empty memory ranges.
 29  */
 30 
 31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 32 
 33 #include <linux/kernel.h>
 34 #include <linux/init.h>
 35 #include <linux/efi.h>
 36 #include <linux/efi-bgrt.h>
 37 #include <linux/export.h>
 38 #include <linux/bootmem.h>
 39 #include <linux/slab.h>
 40 #include <linux/memblock.h>
 41 #include <linux/spinlock.h>
 42 #include <linux/uaccess.h>
 43 #include <linux/time.h>
 44 #include <linux/io.h>
 45 #include <linux/reboot.h>
 46 #include <linux/bcd.h>
 47 
 48 #include <asm/setup.h>
 49 #include <asm/efi.h>
 50 #include <asm/time.h>
 51 #include <asm/cacheflush.h>
 52 #include <asm/tlbflush.h>
 53 #include <asm/x86_init.h>
 54 #include <asm/rtc.h>
 55 #include <asm/uv/uv.h>
 56 
 57 #define EFI_DEBUG
 58 
 59 #define EFI_MIN_RESERVE 5120
 60 
 61 #define EFI_DUMMY_GUID \
 62         EFI_GUID(0x4424ac57, 0xbe4b, 0x47dd, 0x9e, 0x97, 0xed, 0x50, 0xf0, 0x9f, 0x92, 0xa9)
 63 
 64 static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 };
 65 
 66 struct efi_memory_map memmap;
 67 
 68 static struct efi efi_phys __initdata;
 69 static efi_system_table_t efi_systab __initdata;
 70 
 71 unsigned long x86_efi_facility;
 72 
 73 static __initdata efi_config_table_type_t arch_tables[] = {
 74 #ifdef CONFIG_X86_UV
 75         {UV_SYSTEM_TABLE_GUID, "UVsystab", &efi.uv_systab},
 76 #endif
 77         {NULL_GUID, NULL, NULL},
 78 };
 79 
 80 u64 efi_setup;          /* efi setup_data physical address */
 81 
 82 /*
 83  * Returns 1 if 'facility' is enabled, 0 otherwise.
 84  */
 85 int efi_enabled(int facility)
 86 {
 87         return test_bit(facility, &x86_efi_facility) != 0;
 88 }
 89 EXPORT_SYMBOL(efi_enabled);
 90 
 91 static bool __initdata disable_runtime = false;
 92 static int __init setup_noefi(char *arg)
 93 {
 94         disable_runtime = true;
 95         return 0;
 96 }
 97 early_param("noefi", setup_noefi);
 98 
 99 int add_efi_memmap;
100 EXPORT_SYMBOL(add_efi_memmap);
101 
102 static int __init setup_add_efi_memmap(char *arg)
103 {
104         add_efi_memmap = 1;
105         return 0;
106 }
107 early_param("add_efi_memmap", setup_add_efi_memmap);
108 
109 static bool efi_no_storage_paranoia;
110 
111 static int __init setup_storage_paranoia(char *arg)
112 {
113         efi_no_storage_paranoia = true;
114         return 0;
115 }
116 early_param("efi_no_storage_paranoia", setup_storage_paranoia);
117 
118 static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
119 {
120         unsigned long flags;
121         efi_status_t status;
122 
123         spin_lock_irqsave(&rtc_lock, flags);
124         status = efi_call_virt2(get_time, tm, tc);
125         spin_unlock_irqrestore(&rtc_lock, flags);
126         return status;
127 }
128 
129 static efi_status_t virt_efi_set_time(efi_time_t *tm)
130 {
131         unsigned long flags;
132         efi_status_t status;
133 
134         spin_lock_irqsave(&rtc_lock, flags);
135         status = efi_call_virt1(set_time, tm);
136         spin_unlock_irqrestore(&rtc_lock, flags);
137         return status;
138 }
139 
140 static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled,
141                                              efi_bool_t *pending,
142                                              efi_time_t *tm)
143 {
144         unsigned long flags;
145         efi_status_t status;
146 
147         spin_lock_irqsave(&rtc_lock, flags);
148         status = efi_call_virt3(get_wakeup_time,
149                                 enabled, pending, tm);
150         spin_unlock_irqrestore(&rtc_lock, flags);
151         return status;
152 }
153 
154 static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
155 {
156         unsigned long flags;
157         efi_status_t status;
158 
159         spin_lock_irqsave(&rtc_lock, flags);
160         status = efi_call_virt2(set_wakeup_time,
161                                 enabled, tm);
162         spin_unlock_irqrestore(&rtc_lock, flags);
163         return status;
164 }
165 
166 static efi_status_t virt_efi_get_variable(efi_char16_t *name,
167                                           efi_guid_t *vendor,
168                                           u32 *attr,
169                                           unsigned long *data_size,
170                                           void *data)
171 {
172         return efi_call_virt5(get_variable,
173                               name, vendor, attr,
174                               data_size, data);
175 }
176 
177 static efi_status_t virt_efi_get_next_variable(unsigned long *name_size,
178                                                efi_char16_t *name,
179                                                efi_guid_t *vendor)
180 {
181         return efi_call_virt3(get_next_variable,
182                               name_size, name, vendor);
183 }
184 
185 static efi_status_t virt_efi_set_variable(efi_char16_t *name,
186                                           efi_guid_t *vendor,
187                                           u32 attr,
188                                           unsigned long data_size,
189                                           void *data)
190 {
191         return efi_call_virt5(set_variable,
192                               name, vendor, attr,
193                               data_size, data);
194 }
195 
196 static efi_status_t virt_efi_query_variable_info(u32 attr,
197                                                  u64 *storage_space,
198                                                  u64 *remaining_space,
199                                                  u64 *max_variable_size)
200 {
201         if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
202                 return EFI_UNSUPPORTED;
203 
204         return efi_call_virt4(query_variable_info, attr, storage_space,
205                               remaining_space, max_variable_size);
206 }
207 
208 static efi_status_t virt_efi_get_next_high_mono_count(u32 *count)
209 {
210         return efi_call_virt1(get_next_high_mono_count, count);
211 }
212 
213 static void virt_efi_reset_system(int reset_type,
214                                   efi_status_t status,
215                                   unsigned long data_size,
216                                   efi_char16_t *data)
217 {
218         efi_call_virt4(reset_system, reset_type, status,
219                        data_size, data);
220 }
221 
222 static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules,
223                                             unsigned long count,
224                                             unsigned long sg_list)
225 {
226         if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
227                 return EFI_UNSUPPORTED;
228 
229         return efi_call_virt3(update_capsule, capsules, count, sg_list);
230 }
231 
232 static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules,
233                                                 unsigned long count,
234                                                 u64 *max_size,
235                                                 int *reset_type)
236 {
237         if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
238                 return EFI_UNSUPPORTED;
239 
240         return efi_call_virt4(query_capsule_caps, capsules, count, max_size,
241                               reset_type);
242 }
243 
244 static efi_status_t __init phys_efi_set_virtual_address_map(
245         unsigned long memory_map_size,
246         unsigned long descriptor_size,
247         u32 descriptor_version,
248         efi_memory_desc_t *virtual_map)
249 {
250         efi_status_t status;
251         unsigned long flags;
252 
253         efi_call_phys_prelog();
254 
255         /* Disable interrupts around EFI calls: */
256         local_irq_save(flags);
257         status = efi_call_phys4(efi_phys.set_virtual_address_map,
258                                 memory_map_size, descriptor_size,
259                                 descriptor_version, virtual_map);
260         local_irq_restore(flags);
261 
262         efi_call_phys_epilog();
263 
264         return status;
265 }
266 
267 static efi_status_t __init phys_efi_get_time(efi_time_t *tm,
268                                              efi_time_cap_t *tc)
269 {
270         unsigned long flags;
271         efi_status_t status;
272 
273         spin_lock_irqsave(&rtc_lock, flags);
274         efi_call_phys_prelog();
275         status = efi_call_phys2(efi_phys.get_time, virt_to_phys(tm),
276                                 virt_to_phys(tc));
277         efi_call_phys_epilog();
278         spin_unlock_irqrestore(&rtc_lock, flags);
279         return status;
280 }
281 
282 int efi_set_rtc_mmss(const struct timespec *now)
283 {
284         unsigned long nowtime = now->tv_sec;
285         efi_status_t    status;
286         efi_time_t      eft;
287         efi_time_cap_t  cap;
288         struct rtc_time tm;
289 
290         status = efi.get_time(&eft, &cap);
291         if (status != EFI_SUCCESS) {
292                 pr_err("Oops: efitime: can't read time!\n");
293                 return -1;
294         }
295 
296         rtc_time_to_tm(nowtime, &tm);
297         if (!rtc_valid_tm(&tm)) {
298                 eft.year = tm.tm_year + 1900;
299                 eft.month = tm.tm_mon + 1;
300                 eft.day = tm.tm_mday;
301                 eft.minute = tm.tm_min;
302                 eft.second = tm.tm_sec;
303                 eft.nanosecond = 0;
304         } else {
305                 printk(KERN_ERR
306                        "%s: Invalid EFI RTC value: write of %lx to EFI RTC failed\n",
307                        __FUNCTION__, nowtime);
308                 return -1;
309         }
310 
311         status = efi.set_time(&eft);
312         if (status != EFI_SUCCESS) {
313                 pr_err("Oops: efitime: can't write time!\n");
314                 return -1;
315         }
316         return 0;
317 }
318 
319 void efi_get_time(struct timespec *now)
320 {
321         efi_status_t status;
322         efi_time_t eft;
323         efi_time_cap_t cap;
324 
325         status = efi.get_time(&eft, &cap);
326         if (status != EFI_SUCCESS)
327                 pr_err("Oops: efitime: can't read time!\n");
328 
329         now->tv_sec = mktime(eft.year, eft.month, eft.day, eft.hour,
330                              eft.minute, eft.second);
331         now->tv_nsec = 0;
332 }
333 
334 /*
335  * Tell the kernel about the EFI memory map.  This might include
336  * more than the max 128 entries that can fit in the e820 legacy
337  * (zeropage) memory map.
338  */
339 
340 static void __init do_add_efi_memmap(void)
341 {
342         void *p;
343 
344         for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
345                 efi_memory_desc_t *md = p;
346                 unsigned long long start = md->phys_addr;
347                 unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
348                 int e820_type;
349 
350                 switch (md->type) {
351                 case EFI_LOADER_CODE:
352                 case EFI_LOADER_DATA:
353                 case EFI_BOOT_SERVICES_CODE:
354                 case EFI_BOOT_SERVICES_DATA:
355                 case EFI_CONVENTIONAL_MEMORY:
356                         if (md->attribute & EFI_MEMORY_WB)
357                                 e820_type = E820_RAM;
358                         else
359                                 e820_type = E820_RESERVED;
360                         break;
361                 case EFI_ACPI_RECLAIM_MEMORY:
362                         e820_type = E820_ACPI;
363                         break;
364                 case EFI_ACPI_MEMORY_NVS:
365                         e820_type = E820_NVS;
366                         break;
367                 case EFI_UNUSABLE_MEMORY:
368                         e820_type = E820_UNUSABLE;
369                         break;
370                 default:
371                         /*
372                          * EFI_RESERVED_TYPE EFI_RUNTIME_SERVICES_CODE
373                          * EFI_RUNTIME_SERVICES_DATA EFI_MEMORY_MAPPED_IO
374                          * EFI_MEMORY_MAPPED_IO_PORT_SPACE EFI_PAL_CODE
375                          */
376                         e820_type = E820_RESERVED;
377                         break;
378                 }
379                 e820_add_region(start, size, e820_type);
380         }
381         sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
382 }
383 
384 int __init efi_memblock_x86_reserve_range(void)
385 {
386         struct efi_info *e = &boot_params.efi_info;
387         unsigned long pmap;
388 
389 #ifdef CONFIG_X86_32
390         /* Can't handle data above 4GB at this time */
391         if (e->efi_memmap_hi) {
392                 pr_err("Memory map is above 4GB, disabling EFI.\n");
393                 return -EINVAL;
394         }
395         pmap =  e->efi_memmap;
396 #else
397         pmap = (e->efi_memmap | ((__u64)e->efi_memmap_hi << 32));
398 #endif
399         memmap.phys_map         = (void *)pmap;
400         memmap.nr_map           = e->efi_memmap_size /
401                                   e->efi_memdesc_size;
402         memmap.desc_size        = e->efi_memdesc_size;
403         memmap.desc_version     = e->efi_memdesc_version;
404 
405         memblock_reserve(pmap, memmap.nr_map * memmap.desc_size);
406 
407         efi.memmap = &memmap;
408 
409         return 0;
410 }
411 
412 static void __init print_efi_memmap(void)
413 {
414 #ifdef EFI_DEBUG
415         efi_memory_desc_t *md;
416         void *p;
417         int i;
418 
419         for (p = memmap.map, i = 0;
420              p < memmap.map_end;
421              p += memmap.desc_size, i++) {
422                 md = p;
423                 pr_info("mem%02u: type=%u, attr=0x%llx, "
424                         "range=[0x%016llx-0x%016llx) (%lluMB)\n",
425                         i, md->type, md->attribute, md->phys_addr,
426                         md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
427                         (md->num_pages >> (20 - EFI_PAGE_SHIFT)));
428         }
429 #endif  /*  EFI_DEBUG  */
430 }
431 
432 void __init efi_reserve_boot_services(void)
433 {
434         void *p;
435 
436         for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
437                 efi_memory_desc_t *md = p;
438                 u64 start = md->phys_addr;
439                 u64 size = md->num_pages << EFI_PAGE_SHIFT;
440 
441                 if (md->type != EFI_BOOT_SERVICES_CODE &&
442                     md->type != EFI_BOOT_SERVICES_DATA)
443                         continue;
444                 /* Only reserve where possible:
445                  * - Not within any already allocated areas
446                  * - Not over any memory area (really needed, if above?)
447                  * - Not within any part of the kernel
448                  * - Not the bios reserved area
449                 */
450                 if ((start + size > __pa_symbol(_text)
451                                 && start <= __pa_symbol(_end)) ||
452                         !e820_all_mapped(start, start+size, E820_RAM) ||
453                         memblock_is_region_reserved(start, size)) {
454                         /* Could not reserve, skip it */
455                         md->num_pages = 0;
456                         memblock_dbg("Could not reserve boot range "
457                                         "[0x%010llx-0x%010llx]\n",
458                                                 start, start+size-1);
459                 } else
460                         memblock_reserve(start, size);
461         }
462 }
463 
464 void __init efi_unmap_memmap(void)
465 {
466         clear_bit(EFI_MEMMAP, &x86_efi_facility);
467         if (memmap.map) {
468                 early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size);
469                 memmap.map = NULL;
470         }
471 }
472 
473 void __init efi_free_boot_services(void)
474 {
475         void *p;
476 
477         if (!efi_is_native())
478                 return;
479 
480         for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
481                 efi_memory_desc_t *md = p;
482                 unsigned long long start = md->phys_addr;
483                 unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
484 
485                 if (md->type != EFI_BOOT_SERVICES_CODE &&
486                     md->type != EFI_BOOT_SERVICES_DATA)
487                         continue;
488 
489                 /* Could not reserve boot area */
490                 if (!size)
491                         continue;
492 
493                 free_bootmem_late(start, size);
494         }
495 
496         efi_unmap_memmap();
497 }
498 
499 static int __init efi_systab_init(void *phys)
500 {
501         if (efi_enabled(EFI_64BIT)) {
502                 efi_system_table_64_t *systab64;
503                 struct efi_setup_data *data = NULL;
504                 u64 tmp = 0;
505 
506                 if (efi_setup) {
507                         data = early_memremap(efi_setup, sizeof(*data));
508                         if (!data)
509                                 return -ENOMEM;
510                 }
511                 systab64 = early_ioremap((unsigned long)phys,
512                                          sizeof(*systab64));
513                 if (systab64 == NULL) {
514                         pr_err("Couldn't map the system table!\n");
515                         if (data)
516                                 early_iounmap(data, sizeof(*data));
517                         return -ENOMEM;
518                 }
519 
520                 efi_systab.hdr = systab64->hdr;
521                 efi_systab.fw_vendor = data ? (unsigned long)data->fw_vendor :
522                                               systab64->fw_vendor;
523                 tmp |= data ? data->fw_vendor : systab64->fw_vendor;
524                 efi_systab.fw_revision = systab64->fw_revision;
525                 efi_systab.con_in_handle = systab64->con_in_handle;
526                 tmp |= systab64->con_in_handle;
527                 efi_systab.con_in = systab64->con_in;
528                 tmp |= systab64->con_in;
529                 efi_systab.con_out_handle = systab64->con_out_handle;
530                 tmp |= systab64->con_out_handle;
531                 efi_systab.con_out = systab64->con_out;
532                 tmp |= systab64->con_out;
533                 efi_systab.stderr_handle = systab64->stderr_handle;
534                 tmp |= systab64->stderr_handle;
535                 efi_systab.stderr = systab64->stderr;
536                 tmp |= systab64->stderr;
537                 efi_systab.runtime = data ?
538                                      (void *)(unsigned long)data->runtime :
539                                      (void *)(unsigned long)systab64->runtime;
540                 tmp |= data ? data->runtime : systab64->runtime;
541                 efi_systab.boottime = (void *)(unsigned long)systab64->boottime;
542                 tmp |= systab64->boottime;
543                 efi_systab.nr_tables = systab64->nr_tables;
544                 efi_systab.tables = data ? (unsigned long)data->tables :
545                                            systab64->tables;
546                 tmp |= data ? data->tables : systab64->tables;
547 
548                 early_iounmap(systab64, sizeof(*systab64));
549                 if (data)
550                         early_iounmap(data, sizeof(*data));
551 #ifdef CONFIG_X86_32
552                 if (tmp >> 32) {
553                         pr_err("EFI data located above 4GB, disabling EFI.\n");
554                         return -EINVAL;
555                 }
556 #endif
557         } else {
558                 efi_system_table_32_t *systab32;
559 
560                 systab32 = early_ioremap((unsigned long)phys,
561                                          sizeof(*systab32));
562                 if (systab32 == NULL) {
563                         pr_err("Couldn't map the system table!\n");
564                         return -ENOMEM;
565                 }
566 
567                 efi_systab.hdr = systab32->hdr;
568                 efi_systab.fw_vendor = systab32->fw_vendor;
569                 efi_systab.fw_revision = systab32->fw_revision;
570                 efi_systab.con_in_handle = systab32->con_in_handle;
571                 efi_systab.con_in = systab32->con_in;
572                 efi_systab.con_out_handle = systab32->con_out_handle;
573                 efi_systab.con_out = systab32->con_out;
574                 efi_systab.stderr_handle = systab32->stderr_handle;
575                 efi_systab.stderr = systab32->stderr;
576                 efi_systab.runtime = (void *)(unsigned long)systab32->runtime;
577                 efi_systab.boottime = (void *)(unsigned long)systab32->boottime;
578                 efi_systab.nr_tables = systab32->nr_tables;
579                 efi_systab.tables = systab32->tables;
580 
581                 early_iounmap(systab32, sizeof(*systab32));
582         }
583 
584         efi.systab = &efi_systab;
585 
586         /*
587          * Verify the EFI Table
588          */
589         if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) {
590                 pr_err("System table signature incorrect!\n");
591                 return -EINVAL;
592         }
593         if ((efi.systab->hdr.revision >> 16) == 0)
594                 pr_err("Warning: System table version "
595                        "%d.%02d, expected 1.00 or greater!\n",
596                        efi.systab->hdr.revision >> 16,
597                        efi.systab->hdr.revision & 0xffff);
598 
599         return 0;
600 }
601 
602 static int __init efi_runtime_init(void)
603 {
604         efi_runtime_services_t *runtime;
605 
606         /*
607          * Check out the runtime services table. We need to map
608          * the runtime services table so that we can grab the physical
609          * address of several of the EFI runtime functions, needed to
610          * set the firmware into virtual mode.
611          */
612         runtime = early_ioremap((unsigned long)efi.systab->runtime,
613                                 sizeof(efi_runtime_services_t));
614         if (!runtime) {
615                 pr_err("Could not map the runtime service table!\n");
616                 return -ENOMEM;
617         }
618         /*
619          * We will only need *early* access to the following
620          * two EFI runtime services before set_virtual_address_map
621          * is invoked.
622          */
623         efi_phys.get_time = (efi_get_time_t *)runtime->get_time;
624         efi_phys.set_virtual_address_map =
625                 (efi_set_virtual_address_map_t *)
626                 runtime->set_virtual_address_map;
627         /*
628          * Make efi_get_time can be called before entering
629          * virtual mode.
630          */
631         efi.get_time = phys_efi_get_time;
632         early_iounmap(runtime, sizeof(efi_runtime_services_t));
633 
634         return 0;
635 }
636 
637 static int __init efi_memmap_init(void)
638 {
639         /* Map the EFI memory map */
640         memmap.map = early_ioremap((unsigned long)memmap.phys_map,
641                                    memmap.nr_map * memmap.desc_size);
642         if (memmap.map == NULL) {
643                 pr_err("Could not map the memory map!\n");
644                 return -ENOMEM;
645         }
646         memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);
647 
648         if (add_efi_memmap)
649                 do_add_efi_memmap();
650 
651         return 0;
652 }
653 
654 /*
655  * A number of config table entries get remapped to virtual addresses
656  * after entering EFI virtual mode. However, the kexec kernel requires
657  * their physical addresses therefore we pass them via setup_data and
658  * correct those entries to their respective physical addresses here.
659  *
660  * Currently only handles smbios which is necessary for some firmware
661  * implementation.
662  */
663 static int __init efi_reuse_config(u64 tables, int nr_tables)
664 {
665         int i, sz, ret = 0;
666         void *p, *tablep;
667         struct efi_setup_data *data;
668 
669         if (!efi_setup)
670                 return 0;
671 
672         if (!efi_enabled(EFI_64BIT))
673                 return 0;
674 
675         data = early_memremap(efi_setup, sizeof(*data));
676         if (!data) {
677                 ret = -ENOMEM;
678                 goto out;
679         }
680 
681         if (!data->smbios)
682                 goto out_memremap;
683 
684         sz = sizeof(efi_config_table_64_t);
685 
686         p = tablep = early_memremap(tables, nr_tables * sz);
687         if (!p) {
688                 pr_err("Could not map Configuration table!\n");
689                 ret = -ENOMEM;
690                 goto out_memremap;
691         }
692 
693         for (i = 0; i < efi.systab->nr_tables; i++) {
694                 efi_guid_t guid;
695 
696                 guid = ((efi_config_table_64_t *)p)->guid;
697 
698                 if (!efi_guidcmp(guid, SMBIOS_TABLE_GUID))
699                         ((efi_config_table_64_t *)p)->table = data->smbios;
700                 p += sz;
701         }
702         early_iounmap(tablep, nr_tables * sz);
703 
704 out_memremap:
705         early_iounmap(data, sizeof(*data));
706 out:
707         return ret;
708 }
709 
710 void __init efi_init(void)
711 {
712         efi_char16_t *c16;
713         char vendor[100] = "unknown";
714         int i = 0;
715         void *tmp;
716 
717 #ifdef CONFIG_X86_32
718         if (boot_params.efi_info.efi_systab_hi ||
719             boot_params.efi_info.efi_memmap_hi) {
720                 pr_info("Table located above 4GB, disabling EFI.\n");
721                 return;
722         }
723         efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab;
724 #else
725         efi_phys.systab = (efi_system_table_t *)
726                           (boot_params.efi_info.efi_systab |
727                           ((__u64)boot_params.efi_info.efi_systab_hi<<32));
728 #endif
729 
730         if (efi_systab_init(efi_phys.systab))
731                 return;
732 
733         set_bit(EFI_SYSTEM_TABLES, &x86_efi_facility);
734 
735         efi.config_table = (unsigned long)efi.systab->tables;
736         efi.fw_vendor    = (unsigned long)efi.systab->fw_vendor;
737         efi.runtime      = (unsigned long)efi.systab->runtime;
738 
739         /*
740          * Show what we know for posterity
741          */
742         c16 = tmp = early_ioremap(efi.systab->fw_vendor, 2);
743         if (c16) {
744                 for (i = 0; i < sizeof(vendor) - 1 && *c16; ++i)
745                         vendor[i] = *c16++;
746                 vendor[i] = '\0';
747         } else
748                 pr_err("Could not map the firmware vendor!\n");
749         early_iounmap(tmp, 2);
750 
751         pr_info("EFI v%u.%.02u by %s\n",
752                 efi.systab->hdr.revision >> 16,
753                 efi.systab->hdr.revision & 0xffff, vendor);
754 
755         if (efi_reuse_config(efi.systab->tables, efi.systab->nr_tables))
756                 return;
757 
758         if (efi_config_init(arch_tables))
759                 return;
760 
761         set_bit(EFI_CONFIG_TABLES, &x86_efi_facility);
762 
763         /*
764          * Note: We currently don't support runtime services on an EFI
765          * that doesn't match the kernel 32/64-bit mode.
766          */
767 
768         if (!efi_is_native())
769                 pr_info("No EFI runtime due to 32/64-bit mismatch with kernel\n");
770         else {
771                 if (disable_runtime || efi_runtime_init())
772                         return;
773                 set_bit(EFI_RUNTIME_SERVICES, &x86_efi_facility);
774         }
775         if (efi_memmap_init())
776                 return;
777 
778         set_bit(EFI_MEMMAP, &x86_efi_facility);
779 
780         print_efi_memmap();
781 }
782 
783 void __init efi_late_init(void)
784 {
785         efi_bgrt_init();
786 }
787 
788 void __init efi_set_executable(efi_memory_desc_t *md, bool executable)
789 {
790         u64 addr, npages;
791 
792         addr = md->virt_addr;
793         npages = md->num_pages;
794 
795         memrange_efi_to_native(&addr, &npages);
796 
797         if (executable)
798                 set_memory_x(addr, npages);
799         else
800                 set_memory_nx(addr, npages);
801 }
802 
803 void __init runtime_code_page_mkexec(void)
804 {
805         efi_memory_desc_t *md;
806         void *p;
807 
808         /* Make EFI runtime service code area executable */
809         for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
810                 md = p;
811 
812                 if (md->type != EFI_RUNTIME_SERVICES_CODE)
813                         continue;
814 
815                 efi_set_executable(md, true);
816         }
817 }
818 
819 void efi_memory_uc(u64 addr, unsigned long size)
820 {
821         unsigned long page_shift = 1UL << EFI_PAGE_SHIFT;
822         u64 npages;
823 
824         npages = round_up(size, page_shift) / page_shift;
825         memrange_efi_to_native(&addr, &npages);
826         set_memory_uc(addr, npages);
827 }
828 
829 void __init old_map_region(efi_memory_desc_t *md)
830 {
831         u64 start_pfn, end_pfn, end;
832         unsigned long size;
833         void *va;
834 
835         start_pfn = PFN_DOWN(md->phys_addr);
836         size      = md->num_pages << PAGE_SHIFT;
837         end       = md->phys_addr + size;
838         end_pfn   = PFN_UP(end);
839 
840         if (pfn_range_is_mapped(start_pfn, end_pfn)) {
841                 va = __va(md->phys_addr);
842 
843                 if (!(md->attribute & EFI_MEMORY_WB))
844                         efi_memory_uc((u64)(unsigned long)va, size);
845         } else
846                 va = efi_ioremap(md->phys_addr, size,
847                                  md->type, md->attribute);
848 
849         md->virt_addr = (u64) (unsigned long) va;
850         if (!va)
851                 pr_err("ioremap of 0x%llX failed!\n",
852                        (unsigned long long)md->phys_addr);
853 }
854 
855 /* Merge contiguous regions of the same type and attribute */
856 static void __init efi_merge_regions(void)
857 {
858         void *p;
859         efi_memory_desc_t *md, *prev_md = NULL;
860 
861         for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
862                 u64 prev_size;
863                 md = p;
864 
865                 if (!prev_md) {
866                         prev_md = md;
867                         continue;
868                 }
869 
870                 if (prev_md->type != md->type ||
871                     prev_md->attribute != md->attribute) {
872                         prev_md = md;
873                         continue;
874                 }
875 
876                 prev_size = prev_md->num_pages << EFI_PAGE_SHIFT;
877 
878                 if (md->phys_addr == (prev_md->phys_addr + prev_size)) {
879                         prev_md->num_pages += md->num_pages;
880                         md->type = EFI_RESERVED_TYPE;
881                         md->attribute = 0;
882                         continue;
883                 }
884                 prev_md = md;
885         }
886 }
887 
888 static void __init get_systab_virt_addr(efi_memory_desc_t *md)
889 {
890         unsigned long size;
891         u64 end, systab;
892 
893         size = md->num_pages << EFI_PAGE_SHIFT;
894         end = md->phys_addr + size;
895         systab = (u64)(unsigned long)efi_phys.systab;
896         if (md->phys_addr <= systab && systab < end) {
897                 systab += md->virt_addr - md->phys_addr;
898                 efi.systab = (efi_system_table_t *)(unsigned long)systab;
899         }
900 }
901 
902 static int __init save_runtime_map(void)
903 {
904         efi_memory_desc_t *md;
905         void *tmp, *p, *q = NULL;
906         int count = 0;
907 
908         for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
909                 md = p;
910 
911                 if (!(md->attribute & EFI_MEMORY_RUNTIME) ||
912                     (md->type == EFI_BOOT_SERVICES_CODE) ||
913                     (md->type == EFI_BOOT_SERVICES_DATA))
914                         continue;
915                 tmp = krealloc(q, (count + 1) * memmap.desc_size, GFP_KERNEL);
916                 if (!tmp)
917                         goto out;
918                 q = tmp;
919 
920                 memcpy(q + count * memmap.desc_size, md, memmap.desc_size);
921                 count++;
922         }
923 
924         efi_runtime_map_setup(q, count, memmap.desc_size);
925 
926         return 0;
927 out:
928         kfree(q);
929         return -ENOMEM;
930 }
931 
932 /*
933  * Map efi regions which were passed via setup_data. The virt_addr is a fixed
934  * addr which was used in first kernel of a kexec boot.
935  */
936 static void __init efi_map_regions_fixed(void)
937 {
938         void *p;
939         efi_memory_desc_t *md;
940 
941         for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
942                 md = p;
943                 efi_map_region_fixed(md); /* FIXME: add error handling */
944                 get_systab_virt_addr(md);
945         }
946 
947 }
948 
949 static void *realloc_pages(void *old_memmap, int old_shift)
950 {
951         void *ret;
952 
953         ret = (void *)__get_free_pages(GFP_KERNEL, old_shift + 1);
954         if (!ret)
955                 goto out;
956 
957         /*
958          * A first-time allocation doesn't have anything to copy.
959          */
960         if (!old_memmap)
961                 return ret;
962 
963         memcpy(ret, old_memmap, PAGE_SIZE << old_shift);
964 
965 out:
966         free_pages((unsigned long)old_memmap, old_shift);
967         return ret;
968 }
969 
970 /*
971  * Iterate the EFI memory map in reverse order because the regions
972  * will be mapped top-down. The end result is the same as if we had
973  * mapped things forward, but doesn't require us to change the
974  * existing implementation of efi_map_region().
975  */
976 static inline void *efi_map_next_entry_reverse(void *entry)
977 {
978         /* Initial call */
979         if (!entry)
980                 return memmap.map_end - memmap.desc_size;
981 
982         entry -= memmap.desc_size;
983         if (entry < memmap.map)
984                 return NULL;
985 
986         return entry;
987 }
988 
989 /*
990  * efi_map_next_entry - Return the next EFI memory map descriptor
991  * @entry: Previous EFI memory map descriptor
992  *
993  * This is a helper function to iterate over the EFI memory map, which
994  * we do in different orders depending on the current configuration.
995  *
996  * To begin traversing the memory map @entry must be %NULL.
997  *
998  * Returns %NULL when we reach the end of the memory map.
999  */
1000 static void *efi_map_next_entry(void *entry)
1001 {
1002         if (!efi_enabled(EFI_OLD_MEMMAP) && efi_enabled(EFI_64BIT)) {
1003                 /*
1004                  * Starting in UEFI v2.5 the EFI_PROPERTIES_TABLE
1005                  * config table feature requires us to map all entries
1006                  * in the same order as they appear in the EFI memory
1007                  * map. That is to say, entry N must have a lower
1008                  * virtual address than entry N+1. This is because the
1009                  * firmware toolchain leaves relative references in
1010                  * the code/data sections, which are split and become
1011                  * separate EFI memory regions. Mapping things
1012                  * out-of-order leads to the firmware accessing
1013                  * unmapped addresses.
1014                  *
1015                  * Since we need to map things this way whether or not
1016                  * the kernel actually makes use of
1017                  * EFI_PROPERTIES_TABLE, let's just switch to this
1018                  * scheme by default for 64-bit.
1019                  */
1020                 return efi_map_next_entry_reverse(entry);
1021         }
1022 
1023         /* Initial call */
1024         if (!entry)
1025                 return memmap.map;
1026 
1027         entry += memmap.desc_size;
1028         if (entry >= memmap.map_end)
1029                 return NULL;
1030 
1031         return entry;
1032 }
1033 
1034 /*
1035  * Map the efi memory ranges of the runtime services and update new_mmap with
1036  * virtual addresses.
1037  */
1038 static void * __init efi_map_regions(int *count, int *pg_shift)
1039 {
1040         void *p, *new_memmap = NULL;
1041         unsigned long left = 0;
1042         efi_memory_desc_t *md;
1043 
1044         p = NULL;
1045         while ((p = efi_map_next_entry(p))) {
1046                 md = p;
1047                 if (!(md->attribute & EFI_MEMORY_RUNTIME)) {
1048 #ifdef CONFIG_X86_64
1049                         if (md->type != EFI_BOOT_SERVICES_CODE &&
1050                             md->type != EFI_BOOT_SERVICES_DATA)
1051 #endif
1052                                 continue;
1053                 }
1054 
1055                 efi_map_region(md);
1056                 get_systab_virt_addr(md);
1057 
1058                 if (left < memmap.desc_size) {
1059                         new_memmap = realloc_pages(new_memmap, *pg_shift);
1060                         if (!new_memmap)
1061                                 return NULL;
1062 
1063                         left += PAGE_SIZE << *pg_shift;
1064                         (*pg_shift)++;
1065                 }
1066 
1067                 memcpy(new_memmap + (*count * memmap.desc_size), md,
1068                        memmap.desc_size);
1069 
1070                 left -= memmap.desc_size;
1071                 (*count)++;
1072         }
1073 
1074         return new_memmap;
1075 }
1076 
1077 /*
1078  * This function will switch the EFI runtime services to virtual mode.
1079  * Essentially, we look through the EFI memmap and map every region that
1080  * has the runtime attribute bit set in its memory descriptor into the
1081  * ->trampoline_pgd page table using a top-down VA allocation scheme.
1082  *
1083  * The old method which used to update that memory descriptor with the
1084  * virtual address obtained from ioremap() is still supported when the
1085  * kernel is booted with efi=old_map on its command line. Same old
1086  * method enabled the runtime services to be called without having to
1087  * thunk back into physical mode for every invocation.
1088  *
1089  * The new method does a pagetable switch in a preemption-safe manner
1090  * so that we're in a different address space when calling a runtime
1091  * function. For function arguments passing we do copy the PGDs of the
1092  * kernel page table into ->trampoline_pgd prior to each call.
1093  *
1094  * Specially for kexec boot, efi runtime maps in previous kernel should
1095  * be passed in via setup_data. In that case runtime ranges will be mapped
1096  * to the same virtual addresses as the first kernel.
1097  */
1098 void __init efi_enter_virtual_mode(void)
1099 {
1100         int err, count = 0, pg_shift = 0;
1101         void *new_memmap = NULL;
1102         efi_status_t status;
1103 
1104         efi.systab = NULL;
1105 
1106         /*
1107          * We don't do virtual mode, since we don't do runtime services, on
1108          * non-native EFI
1109          */
1110         if (!efi_is_native()) {
1111                 efi_unmap_memmap();
1112                 return;
1113         }
1114 
1115         if (efi_setup) {
1116                 efi_map_regions_fixed();
1117         } else {
1118                 efi_merge_regions();
1119                 new_memmap = efi_map_regions(&count, &pg_shift);
1120                 if (!new_memmap) {
1121                         pr_err("Error reallocating memory, EFI runtime non-functional!\n");
1122                         return;
1123                 }
1124 
1125                 err = save_runtime_map();
1126                 if (err)
1127                         pr_err("Error saving runtime map, efi runtime on kexec non-functional!!\n");
1128         }
1129 
1130         BUG_ON(!efi.systab);
1131 
1132         if (!efi_setup) {
1133                 if (efi_setup_page_tables(__pa(new_memmap), 1 << pg_shift))
1134                         return;
1135         }
1136 
1137         efi_sync_low_kernel_mappings();
1138 
1139         if (!efi_setup) {
1140                 status = phys_efi_set_virtual_address_map(
1141                         memmap.desc_size * count,
1142                         memmap.desc_size,
1143                         memmap.desc_version,
1144                         (efi_memory_desc_t *)__pa(new_memmap));
1145 
1146                 if (status != EFI_SUCCESS) {
1147                         pr_alert("Unable to switch EFI into virtual mode (status=%lx)!\n",
1148                                  status);
1149                         panic("EFI call to SetVirtualAddressMap() failed!");
1150                 }
1151         }
1152 
1153         /*
1154          * Now that EFI is in virtual mode, update the function
1155          * pointers in the runtime service table to the new virtual addresses.
1156          *
1157          * Call EFI services through wrapper functions.
1158          */
1159         efi.runtime_version = efi_systab.hdr.revision;
1160         efi.get_time = virt_efi_get_time;
1161         efi.set_time = virt_efi_set_time;
1162         efi.get_wakeup_time = virt_efi_get_wakeup_time;
1163         efi.set_wakeup_time = virt_efi_set_wakeup_time;
1164         efi.get_variable = virt_efi_get_variable;
1165         efi.get_next_variable = virt_efi_get_next_variable;
1166         efi.set_variable = virt_efi_set_variable;
1167         efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count;
1168         efi.reset_system = virt_efi_reset_system;
1169         efi.set_virtual_address_map = NULL;
1170         efi.query_variable_info = virt_efi_query_variable_info;
1171         efi.update_capsule = virt_efi_update_capsule;
1172         efi.query_capsule_caps = virt_efi_query_capsule_caps;
1173 
1174         efi_runtime_mkexec();
1175 
1176 
1177         /*
1178          * We mapped the descriptor array into the EFI pagetable above but we're
1179          * not unmapping it here. Here's why:
1180          *
1181          * We're copying select PGDs from the kernel page table to the EFI page
1182          * table and when we do so and make changes to those PGDs like unmapping
1183          * stuff from them, those changes appear in the kernel page table and we
1184          * go boom.
1185          *
1186          * From setup_real_mode():
1187          *
1188          * ...
1189          * trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
1190          *
1191          * In this particular case, our allocation is in PGD 0 of the EFI page
1192          * table but we've copied that PGD from PGD[272] of the EFI page table:
1193          *
1194          *      pgd_index(__PAGE_OFFSET = 0xffff880000000000) = 272
1195          *
1196          * where the direct memory mapping in kernel space is.
1197          *
1198          * new_memmap's VA comes from that direct mapping and thus clearing it,
1199          * it would get cleared in the kernel page table too.
1200          *
1201          * efi_cleanup_page_tables(__pa(new_memmap), 1 << pg_shift);
1202          */
1203         if (!efi_setup)
1204                 free_pages((unsigned long)new_memmap, pg_shift);
1205 
1206         /* clean DUMMY object */
1207         efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID,
1208                          EFI_VARIABLE_NON_VOLATILE |
1209                          EFI_VARIABLE_BOOTSERVICE_ACCESS |
1210                          EFI_VARIABLE_RUNTIME_ACCESS,
1211                          0, NULL);
1212 }
1213 
1214 /*
1215  * Convenience functions to obtain memory types and attributes
1216  */
1217 u32 efi_mem_type(unsigned long phys_addr)
1218 {
1219         efi_memory_desc_t *md;
1220         void *p;
1221 
1222         if (!efi_enabled(EFI_MEMMAP))
1223                 return 0;
1224 
1225         for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
1226                 md = p;
1227                 if ((md->phys_addr <= phys_addr) &&
1228                     (phys_addr < (md->phys_addr +
1229                                   (md->num_pages << EFI_PAGE_SHIFT))))
1230                         return md->type;
1231         }
1232         return 0;
1233 }
1234 
1235 u64 efi_mem_attributes(unsigned long phys_addr)
1236 {
1237         efi_memory_desc_t *md;
1238         void *p;
1239 
1240         for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
1241                 md = p;
1242                 if ((md->phys_addr <= phys_addr) &&
1243                     (phys_addr < (md->phys_addr +
1244                                   (md->num_pages << EFI_PAGE_SHIFT))))
1245                         return md->attribute;
1246         }
1247         return 0;
1248 }
1249 
1250 /*
1251  * Some firmware has serious problems when using more than 50% of the EFI
1252  * variable store, i.e. it triggers bugs that can brick machines. Ensure that
1253  * we never use more than this safe limit.
1254  *
1255  * Return EFI_SUCCESS if it is safe to write 'size' bytes to the variable
1256  * store.
1257  */
1258 efi_status_t efi_query_variable_store(u32 attributes, unsigned long size)
1259 {
1260         efi_status_t status;
1261         u64 storage_size, remaining_size, max_size;
1262 
1263         if (!(attributes & EFI_VARIABLE_NON_VOLATILE))
1264                 return 0;
1265 
1266         status = efi.query_variable_info(attributes, &storage_size,
1267                                          &remaining_size, &max_size);
1268         if (status != EFI_SUCCESS)
1269                 return status;
1270 
1271         /*
1272          * Some firmware implementations refuse to boot if there's insufficient
1273          * space in the variable store. We account for that by refusing the
1274          * write if permitting it would reduce the available space to under
1275          * 5KB. This figure was provided by Samsung, so should be safe.
1276          */
1277         if ((remaining_size - size < EFI_MIN_RESERVE) &&
1278                 !efi_no_storage_paranoia) {
1279 
1280                 /*
1281                  * Triggering garbage collection may require that the firmware
1282                  * generate a real EFI_OUT_OF_RESOURCES error. We can force
1283                  * that by attempting to use more space than is available.
1284                  */
1285                 unsigned long dummy_size = remaining_size + 1024;
1286                 void *dummy = kzalloc(dummy_size, GFP_ATOMIC);
1287 
1288                 if (!dummy)
1289                         return EFI_OUT_OF_RESOURCES;
1290 
1291                 status = efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID,
1292                                           EFI_VARIABLE_NON_VOLATILE |
1293                                           EFI_VARIABLE_BOOTSERVICE_ACCESS |
1294                                           EFI_VARIABLE_RUNTIME_ACCESS,
1295                                           dummy_size, dummy);
1296 
1297                 if (status == EFI_SUCCESS) {
1298                         /*
1299                          * This should have failed, so if it didn't make sure
1300                          * that we delete it...
1301                          */
1302                         efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID,
1303                                          EFI_VARIABLE_NON_VOLATILE |
1304                                          EFI_VARIABLE_BOOTSERVICE_ACCESS |
1305                                          EFI_VARIABLE_RUNTIME_ACCESS,
1306                                          0, dummy);
1307                 }
1308 
1309                 kfree(dummy);
1310 
1311                 /*
1312                  * The runtime code may now have triggered a garbage collection
1313                  * run, so check the variable info again
1314                  */
1315                 status = efi.query_variable_info(attributes, &storage_size,
1316                                                  &remaining_size, &max_size);
1317 
1318                 if (status != EFI_SUCCESS)
1319                         return status;
1320 
1321                 /*
1322                  * There still isn't enough room, so return an error
1323                  */
1324                 if (remaining_size - size < EFI_MIN_RESERVE)
1325                         return EFI_OUT_OF_RESOURCES;
1326         }
1327 
1328         return EFI_SUCCESS;
1329 }
1330 EXPORT_SYMBOL_GPL(efi_query_variable_store);
1331 
1332 static int __init parse_efi_cmdline(char *str)
1333 {
1334         if (*str == '=')
1335                 str++;
1336 
1337         if (!strncmp(str, "old_map", 7))
1338                 set_bit(EFI_OLD_MEMMAP, &x86_efi_facility);
1339 
1340         return 0;
1341 }
1342 early_param("efi", parse_efi_cmdline);
1343 
1344 void __init efi_apply_memmap_quirks(void)
1345 {
1346         /*
1347          * Once setup is done earlier, unmap the EFI memory map on mismatched
1348          * firmware/kernel architectures since there is no support for runtime
1349          * services.
1350          */
1351         if (!efi_is_native()) {
1352                 pr_info("efi: Setup done, disabling due to 32/64-bit mismatch\n");
1353                 efi_unmap_memmap();
1354         }
1355 
1356         /*
1357          * UV doesn't support the new EFI pagetable mapping yet.
1358          */
1359         if (is_uv_system())
1360                 set_bit(EFI_OLD_MEMMAP, &x86_efi_facility);
1361 }
1362 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp