efi.c 33 KB

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