efi.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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_virt2(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_virt1(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_virt3(get_wakeup_time,
  116. enabled, pending, tm);
  117. spin_unlock_irqrestore(&rtc_lock, flags);
  118. return status;
  119. }
  120. static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
  121. {
  122. unsigned long flags;
  123. efi_status_t status;
  124. spin_lock_irqsave(&rtc_lock, flags);
  125. status = efi_call_virt2(set_wakeup_time,
  126. enabled, tm);
  127. spin_unlock_irqrestore(&rtc_lock, flags);
  128. return status;
  129. }
  130. static efi_status_t virt_efi_get_variable(efi_char16_t *name,
  131. efi_guid_t *vendor,
  132. u32 *attr,
  133. unsigned long *data_size,
  134. void *data)
  135. {
  136. return efi_call_virt5(get_variable,
  137. name, vendor, attr,
  138. data_size, data);
  139. }
  140. static efi_status_t virt_efi_get_next_variable(unsigned long *name_size,
  141. efi_char16_t *name,
  142. efi_guid_t *vendor)
  143. {
  144. return efi_call_virt3(get_next_variable,
  145. name_size, name, vendor);
  146. }
  147. static efi_status_t virt_efi_set_variable(efi_char16_t *name,
  148. efi_guid_t *vendor,
  149. u32 attr,
  150. unsigned long data_size,
  151. void *data)
  152. {
  153. return efi_call_virt5(set_variable,
  154. name, vendor, attr,
  155. data_size, data);
  156. }
  157. static efi_status_t virt_efi_query_variable_info(u32 attr,
  158. u64 *storage_space,
  159. u64 *remaining_space,
  160. u64 *max_variable_size)
  161. {
  162. if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
  163. return EFI_UNSUPPORTED;
  164. return efi_call_virt4(query_variable_info, attr, storage_space,
  165. remaining_space, max_variable_size);
  166. }
  167. static efi_status_t virt_efi_get_next_high_mono_count(u32 *count)
  168. {
  169. return efi_call_virt1(get_next_high_mono_count, count);
  170. }
  171. static void virt_efi_reset_system(int reset_type,
  172. efi_status_t status,
  173. unsigned long data_size,
  174. efi_char16_t *data)
  175. {
  176. efi_call_virt4(reset_system, reset_type, status,
  177. data_size, data);
  178. }
  179. static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules,
  180. unsigned long count,
  181. unsigned long sg_list)
  182. {
  183. if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
  184. return EFI_UNSUPPORTED;
  185. return efi_call_virt3(update_capsule, capsules, count, sg_list);
  186. }
  187. static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules,
  188. unsigned long count,
  189. u64 *max_size,
  190. int *reset_type)
  191. {
  192. if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
  193. return EFI_UNSUPPORTED;
  194. return efi_call_virt4(query_capsule_caps, capsules, count, max_size,
  195. reset_type);
  196. }
  197. static efi_status_t __init phys_efi_set_virtual_address_map(
  198. unsigned long memory_map_size,
  199. unsigned long descriptor_size,
  200. u32 descriptor_version,
  201. efi_memory_desc_t *virtual_map)
  202. {
  203. efi_status_t status;
  204. efi_call_phys_prelog();
  205. status = efi_call_phys4(efi_phys.set_virtual_address_map,
  206. memory_map_size, descriptor_size,
  207. descriptor_version, virtual_map);
  208. efi_call_phys_epilog();
  209. return status;
  210. }
  211. int efi_set_rtc_mmss(const struct timespec *now)
  212. {
  213. unsigned long nowtime = now->tv_sec;
  214. efi_status_t status;
  215. efi_time_t eft;
  216. efi_time_cap_t cap;
  217. struct rtc_time tm;
  218. status = efi.get_time(&eft, &cap);
  219. if (status != EFI_SUCCESS) {
  220. pr_err("Oops: efitime: can't read time!\n");
  221. return -1;
  222. }
  223. rtc_time_to_tm(nowtime, &tm);
  224. if (!rtc_valid_tm(&tm)) {
  225. eft.year = tm.tm_year + 1900;
  226. eft.month = tm.tm_mon + 1;
  227. eft.day = tm.tm_mday;
  228. eft.minute = tm.tm_min;
  229. eft.second = tm.tm_sec;
  230. eft.nanosecond = 0;
  231. } else {
  232. pr_err("%s: Invalid EFI RTC value: write of %lx to EFI RTC failed\n",
  233. __func__, nowtime);
  234. return -1;
  235. }
  236. status = efi.set_time(&eft);
  237. if (status != EFI_SUCCESS) {
  238. pr_err("Oops: efitime: can't write time!\n");
  239. return -1;
  240. }
  241. return 0;
  242. }
  243. void efi_get_time(struct timespec *now)
  244. {
  245. efi_status_t status;
  246. efi_time_t eft;
  247. efi_time_cap_t cap;
  248. status = efi.get_time(&eft, &cap);
  249. if (status != EFI_SUCCESS)
  250. pr_err("Oops: efitime: can't read time!\n");
  251. now->tv_sec = mktime(eft.year, eft.month, eft.day, eft.hour,
  252. eft.minute, eft.second);
  253. now->tv_nsec = 0;
  254. }
  255. /*
  256. * Tell the kernel about the EFI memory map. This might include
  257. * more than the max 128 entries that can fit in the e820 legacy
  258. * (zeropage) memory map.
  259. */
  260. static void __init do_add_efi_memmap(void)
  261. {
  262. void *p;
  263. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  264. efi_memory_desc_t *md = p;
  265. unsigned long long start = md->phys_addr;
  266. unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
  267. int e820_type;
  268. switch (md->type) {
  269. case EFI_LOADER_CODE:
  270. case EFI_LOADER_DATA:
  271. case EFI_BOOT_SERVICES_CODE:
  272. case EFI_BOOT_SERVICES_DATA:
  273. case EFI_CONVENTIONAL_MEMORY:
  274. if (md->attribute & EFI_MEMORY_WB)
  275. e820_type = E820_RAM;
  276. else
  277. e820_type = E820_RESERVED;
  278. break;
  279. case EFI_ACPI_RECLAIM_MEMORY:
  280. e820_type = E820_ACPI;
  281. break;
  282. case EFI_ACPI_MEMORY_NVS:
  283. e820_type = E820_NVS;
  284. break;
  285. case EFI_UNUSABLE_MEMORY:
  286. e820_type = E820_UNUSABLE;
  287. break;
  288. default:
  289. /*
  290. * EFI_RESERVED_TYPE EFI_RUNTIME_SERVICES_CODE
  291. * EFI_RUNTIME_SERVICES_DATA EFI_MEMORY_MAPPED_IO
  292. * EFI_MEMORY_MAPPED_IO_PORT_SPACE EFI_PAL_CODE
  293. */
  294. e820_type = E820_RESERVED;
  295. break;
  296. }
  297. e820_add_region(start, size, e820_type);
  298. }
  299. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  300. }
  301. int __init efi_memblock_x86_reserve_range(void)
  302. {
  303. struct efi_info *e = &boot_params.efi_info;
  304. unsigned long pmap;
  305. #ifdef CONFIG_X86_32
  306. /* Can't handle data above 4GB at this time */
  307. if (e->efi_memmap_hi) {
  308. pr_err("Memory map is above 4GB, disabling EFI.\n");
  309. return -EINVAL;
  310. }
  311. pmap = e->efi_memmap;
  312. #else
  313. pmap = (e->efi_memmap | ((__u64)e->efi_memmap_hi << 32));
  314. #endif
  315. memmap.phys_map = (void *)pmap;
  316. memmap.nr_map = e->efi_memmap_size /
  317. e->efi_memdesc_size;
  318. memmap.desc_size = e->efi_memdesc_size;
  319. memmap.desc_version = e->efi_memdesc_version;
  320. memblock_reserve(pmap, memmap.nr_map * memmap.desc_size);
  321. efi.memmap = &memmap;
  322. return 0;
  323. }
  324. static void __init print_efi_memmap(void)
  325. {
  326. #ifdef EFI_DEBUG
  327. efi_memory_desc_t *md;
  328. void *p;
  329. int i;
  330. for (p = memmap.map, i = 0;
  331. p < memmap.map_end;
  332. p += memmap.desc_size, i++) {
  333. md = p;
  334. pr_info("mem%02u: type=%u, attr=0x%llx, range=[0x%016llx-0x%016llx) (%lluMB)\n",
  335. i, md->type, md->attribute, md->phys_addr,
  336. md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
  337. (md->num_pages >> (20 - EFI_PAGE_SHIFT)));
  338. }
  339. #endif /* EFI_DEBUG */
  340. }
  341. void __init efi_reserve_boot_services(void)
  342. {
  343. void *p;
  344. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  345. efi_memory_desc_t *md = p;
  346. u64 start = md->phys_addr;
  347. u64 size = md->num_pages << EFI_PAGE_SHIFT;
  348. if (md->type != EFI_BOOT_SERVICES_CODE &&
  349. md->type != EFI_BOOT_SERVICES_DATA)
  350. continue;
  351. /* Only reserve where possible:
  352. * - Not within any already allocated areas
  353. * - Not over any memory area (really needed, if above?)
  354. * - Not within any part of the kernel
  355. * - Not the bios reserved area
  356. */
  357. if ((start + size > __pa_symbol(_text)
  358. && start <= __pa_symbol(_end)) ||
  359. !e820_all_mapped(start, start+size, E820_RAM) ||
  360. memblock_is_region_reserved(start, size)) {
  361. /* Could not reserve, skip it */
  362. md->num_pages = 0;
  363. memblock_dbg("Could not reserve boot range [0x%010llx-0x%010llx]\n",
  364. start, start+size-1);
  365. } else
  366. memblock_reserve(start, size);
  367. }
  368. }
  369. void __init efi_unmap_memmap(void)
  370. {
  371. clear_bit(EFI_MEMMAP, &efi.flags);
  372. if (memmap.map) {
  373. early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size);
  374. memmap.map = NULL;
  375. }
  376. }
  377. void __init efi_free_boot_services(void)
  378. {
  379. void *p;
  380. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  381. efi_memory_desc_t *md = p;
  382. unsigned long long start = md->phys_addr;
  383. unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
  384. if (md->type != EFI_BOOT_SERVICES_CODE &&
  385. md->type != EFI_BOOT_SERVICES_DATA)
  386. continue;
  387. /* Could not reserve boot area */
  388. if (!size)
  389. continue;
  390. free_bootmem_late(start, size);
  391. }
  392. efi_unmap_memmap();
  393. }
  394. static int __init efi_systab_init(void *phys)
  395. {
  396. if (efi_enabled(EFI_64BIT)) {
  397. efi_system_table_64_t *systab64;
  398. struct efi_setup_data *data = NULL;
  399. u64 tmp = 0;
  400. if (efi_setup) {
  401. data = early_memremap(efi_setup, sizeof(*data));
  402. if (!data)
  403. return -ENOMEM;
  404. }
  405. systab64 = early_ioremap((unsigned long)phys,
  406. sizeof(*systab64));
  407. if (systab64 == NULL) {
  408. pr_err("Couldn't map the system table!\n");
  409. if (data)
  410. early_iounmap(data, sizeof(*data));
  411. return -ENOMEM;
  412. }
  413. efi_systab.hdr = systab64->hdr;
  414. efi_systab.fw_vendor = data ? (unsigned long)data->fw_vendor :
  415. systab64->fw_vendor;
  416. tmp |= data ? data->fw_vendor : systab64->fw_vendor;
  417. efi_systab.fw_revision = systab64->fw_revision;
  418. efi_systab.con_in_handle = systab64->con_in_handle;
  419. tmp |= systab64->con_in_handle;
  420. efi_systab.con_in = systab64->con_in;
  421. tmp |= systab64->con_in;
  422. efi_systab.con_out_handle = systab64->con_out_handle;
  423. tmp |= systab64->con_out_handle;
  424. efi_systab.con_out = systab64->con_out;
  425. tmp |= systab64->con_out;
  426. efi_systab.stderr_handle = systab64->stderr_handle;
  427. tmp |= systab64->stderr_handle;
  428. efi_systab.stderr = systab64->stderr;
  429. tmp |= systab64->stderr;
  430. efi_systab.runtime = data ?
  431. (void *)(unsigned long)data->runtime :
  432. (void *)(unsigned long)systab64->runtime;
  433. tmp |= data ? data->runtime : systab64->runtime;
  434. efi_systab.boottime = (void *)(unsigned long)systab64->boottime;
  435. tmp |= systab64->boottime;
  436. efi_systab.nr_tables = systab64->nr_tables;
  437. efi_systab.tables = data ? (unsigned long)data->tables :
  438. systab64->tables;
  439. tmp |= data ? data->tables : systab64->tables;
  440. early_iounmap(systab64, sizeof(*systab64));
  441. if (data)
  442. early_iounmap(data, sizeof(*data));
  443. #ifdef CONFIG_X86_32
  444. if (tmp >> 32) {
  445. pr_err("EFI data located above 4GB, disabling EFI.\n");
  446. return -EINVAL;
  447. }
  448. #endif
  449. } else {
  450. efi_system_table_32_t *systab32;
  451. systab32 = early_ioremap((unsigned long)phys,
  452. sizeof(*systab32));
  453. if (systab32 == NULL) {
  454. pr_err("Couldn't map the system table!\n");
  455. return -ENOMEM;
  456. }
  457. efi_systab.hdr = systab32->hdr;
  458. efi_systab.fw_vendor = systab32->fw_vendor;
  459. efi_systab.fw_revision = systab32->fw_revision;
  460. efi_systab.con_in_handle = systab32->con_in_handle;
  461. efi_systab.con_in = systab32->con_in;
  462. efi_systab.con_out_handle = systab32->con_out_handle;
  463. efi_systab.con_out = systab32->con_out;
  464. efi_systab.stderr_handle = systab32->stderr_handle;
  465. efi_systab.stderr = systab32->stderr;
  466. efi_systab.runtime = (void *)(unsigned long)systab32->runtime;
  467. efi_systab.boottime = (void *)(unsigned long)systab32->boottime;
  468. efi_systab.nr_tables = systab32->nr_tables;
  469. efi_systab.tables = systab32->tables;
  470. early_iounmap(systab32, sizeof(*systab32));
  471. }
  472. efi.systab = &efi_systab;
  473. /*
  474. * Verify the EFI Table
  475. */
  476. if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) {
  477. pr_err("System table signature incorrect!\n");
  478. return -EINVAL;
  479. }
  480. if ((efi.systab->hdr.revision >> 16) == 0)
  481. pr_err("Warning: System table version %d.%02d, expected 1.00 or greater!\n",
  482. efi.systab->hdr.revision >> 16,
  483. efi.systab->hdr.revision & 0xffff);
  484. set_bit(EFI_SYSTEM_TABLES, &efi.flags);
  485. return 0;
  486. }
  487. static int __init efi_runtime_init32(void)
  488. {
  489. efi_runtime_services_32_t *runtime;
  490. runtime = early_ioremap((unsigned long)efi.systab->runtime,
  491. sizeof(efi_runtime_services_32_t));
  492. if (!runtime) {
  493. pr_err("Could not map the runtime service table!\n");
  494. return -ENOMEM;
  495. }
  496. /*
  497. * We will only need *early* access to the following two
  498. * EFI runtime services before set_virtual_address_map
  499. * is invoked.
  500. */
  501. efi_phys.set_virtual_address_map =
  502. (efi_set_virtual_address_map_t *)
  503. (unsigned long)runtime->set_virtual_address_map;
  504. early_iounmap(runtime, sizeof(efi_runtime_services_32_t));
  505. return 0;
  506. }
  507. static int __init efi_runtime_init64(void)
  508. {
  509. efi_runtime_services_64_t *runtime;
  510. runtime = early_ioremap((unsigned long)efi.systab->runtime,
  511. sizeof(efi_runtime_services_64_t));
  512. if (!runtime) {
  513. pr_err("Could not map the runtime service table!\n");
  514. return -ENOMEM;
  515. }
  516. /*
  517. * We will only need *early* access to the following two
  518. * EFI runtime services before set_virtual_address_map
  519. * is invoked.
  520. */
  521. efi_phys.set_virtual_address_map =
  522. (efi_set_virtual_address_map_t *)
  523. (unsigned long)runtime->set_virtual_address_map;
  524. early_iounmap(runtime, sizeof(efi_runtime_services_64_t));
  525. return 0;
  526. }
  527. static int __init efi_runtime_init(void)
  528. {
  529. int rv;
  530. /*
  531. * Check out the runtime services table. We need to map
  532. * the runtime services table so that we can grab the physical
  533. * address of several of the EFI runtime functions, needed to
  534. * set the firmware into virtual mode.
  535. */
  536. if (efi_enabled(EFI_64BIT))
  537. rv = efi_runtime_init64();
  538. else
  539. rv = efi_runtime_init32();
  540. if (rv)
  541. return rv;
  542. set_bit(EFI_RUNTIME_SERVICES, &efi.flags);
  543. return 0;
  544. }
  545. static int __init efi_memmap_init(void)
  546. {
  547. /* Map the EFI memory map */
  548. memmap.map = early_ioremap((unsigned long)memmap.phys_map,
  549. memmap.nr_map * memmap.desc_size);
  550. if (memmap.map == NULL) {
  551. pr_err("Could not map the memory map!\n");
  552. return -ENOMEM;
  553. }
  554. memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);
  555. if (add_efi_memmap)
  556. do_add_efi_memmap();
  557. set_bit(EFI_MEMMAP, &efi.flags);
  558. return 0;
  559. }
  560. /*
  561. * A number of config table entries get remapped to virtual addresses
  562. * after entering EFI virtual mode. However, the kexec kernel requires
  563. * their physical addresses therefore we pass them via setup_data and
  564. * correct those entries to their respective physical addresses here.
  565. *
  566. * Currently only handles smbios which is necessary for some firmware
  567. * implementation.
  568. */
  569. static int __init efi_reuse_config(u64 tables, int nr_tables)
  570. {
  571. int i, sz, ret = 0;
  572. void *p, *tablep;
  573. struct efi_setup_data *data;
  574. if (!efi_setup)
  575. return 0;
  576. if (!efi_enabled(EFI_64BIT))
  577. return 0;
  578. data = early_memremap(efi_setup, sizeof(*data));
  579. if (!data) {
  580. ret = -ENOMEM;
  581. goto out;
  582. }
  583. if (!data->smbios)
  584. goto out_memremap;
  585. sz = sizeof(efi_config_table_64_t);
  586. p = tablep = early_memremap(tables, nr_tables * sz);
  587. if (!p) {
  588. pr_err("Could not map Configuration table!\n");
  589. ret = -ENOMEM;
  590. goto out_memremap;
  591. }
  592. for (i = 0; i < efi.systab->nr_tables; i++) {
  593. efi_guid_t guid;
  594. guid = ((efi_config_table_64_t *)p)->guid;
  595. if (!efi_guidcmp(guid, SMBIOS_TABLE_GUID))
  596. ((efi_config_table_64_t *)p)->table = data->smbios;
  597. p += sz;
  598. }
  599. early_iounmap(tablep, nr_tables * sz);
  600. out_memremap:
  601. early_iounmap(data, sizeof(*data));
  602. out:
  603. return ret;
  604. }
  605. void __init efi_init(void)
  606. {
  607. efi_char16_t *c16;
  608. char vendor[100] = "unknown";
  609. int i = 0;
  610. void *tmp;
  611. #ifdef CONFIG_X86_32
  612. if (boot_params.efi_info.efi_systab_hi ||
  613. boot_params.efi_info.efi_memmap_hi) {
  614. pr_info("Table located above 4GB, disabling EFI.\n");
  615. return;
  616. }
  617. efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab;
  618. #else
  619. efi_phys.systab = (efi_system_table_t *)
  620. (boot_params.efi_info.efi_systab |
  621. ((__u64)boot_params.efi_info.efi_systab_hi<<32));
  622. #endif
  623. if (efi_systab_init(efi_phys.systab))
  624. return;
  625. set_bit(EFI_SYSTEM_TABLES, &efi.flags);
  626. efi.config_table = (unsigned long)efi.systab->tables;
  627. efi.fw_vendor = (unsigned long)efi.systab->fw_vendor;
  628. efi.runtime = (unsigned long)efi.systab->runtime;
  629. /*
  630. * Show what we know for posterity
  631. */
  632. c16 = tmp = early_ioremap(efi.systab->fw_vendor, 2);
  633. if (c16) {
  634. for (i = 0; i < sizeof(vendor) - 1 && *c16; ++i)
  635. vendor[i] = *c16++;
  636. vendor[i] = '\0';
  637. } else
  638. pr_err("Could not map the firmware vendor!\n");
  639. early_iounmap(tmp, 2);
  640. pr_info("EFI v%u.%.02u by %s\n",
  641. efi.systab->hdr.revision >> 16,
  642. efi.systab->hdr.revision & 0xffff, vendor);
  643. if (efi_reuse_config(efi.systab->tables, efi.systab->nr_tables))
  644. return;
  645. if (efi_config_init(arch_tables))
  646. return;
  647. /*
  648. * Note: We currently don't support runtime services on an EFI
  649. * that doesn't match the kernel 32/64-bit mode.
  650. */
  651. if (!efi_runtime_supported())
  652. pr_info("No EFI runtime due to 32/64-bit mismatch with kernel\n");
  653. else {
  654. if (disable_runtime || efi_runtime_init())
  655. return;
  656. }
  657. if (efi_memmap_init())
  658. return;
  659. set_bit(EFI_MEMMAP, &efi.flags);
  660. print_efi_memmap();
  661. }
  662. void __init efi_late_init(void)
  663. {
  664. efi_bgrt_init();
  665. }
  666. void __init efi_set_executable(efi_memory_desc_t *md, bool executable)
  667. {
  668. u64 addr, npages;
  669. addr = md->virt_addr;
  670. npages = md->num_pages;
  671. memrange_efi_to_native(&addr, &npages);
  672. if (executable)
  673. set_memory_x(addr, npages);
  674. else
  675. set_memory_nx(addr, npages);
  676. }
  677. void __init runtime_code_page_mkexec(void)
  678. {
  679. efi_memory_desc_t *md;
  680. void *p;
  681. /* Make EFI runtime service code area executable */
  682. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  683. md = p;
  684. if (md->type != EFI_RUNTIME_SERVICES_CODE)
  685. continue;
  686. efi_set_executable(md, true);
  687. }
  688. }
  689. void efi_memory_uc(u64 addr, unsigned long size)
  690. {
  691. unsigned long page_shift = 1UL << EFI_PAGE_SHIFT;
  692. u64 npages;
  693. npages = round_up(size, page_shift) / page_shift;
  694. memrange_efi_to_native(&addr, &npages);
  695. set_memory_uc(addr, npages);
  696. }
  697. void __init old_map_region(efi_memory_desc_t *md)
  698. {
  699. u64 start_pfn, end_pfn, end;
  700. unsigned long size;
  701. void *va;
  702. start_pfn = PFN_DOWN(md->phys_addr);
  703. size = md->num_pages << PAGE_SHIFT;
  704. end = md->phys_addr + size;
  705. end_pfn = PFN_UP(end);
  706. if (pfn_range_is_mapped(start_pfn, end_pfn)) {
  707. va = __va(md->phys_addr);
  708. if (!(md->attribute & EFI_MEMORY_WB))
  709. efi_memory_uc((u64)(unsigned long)va, size);
  710. } else
  711. va = efi_ioremap(md->phys_addr, size,
  712. md->type, md->attribute);
  713. md->virt_addr = (u64) (unsigned long) va;
  714. if (!va)
  715. pr_err("ioremap of 0x%llX failed!\n",
  716. (unsigned long long)md->phys_addr);
  717. }
  718. static void native_runtime_setup(void)
  719. {
  720. efi.get_time = virt_efi_get_time;
  721. efi.set_time = virt_efi_set_time;
  722. efi.get_wakeup_time = virt_efi_get_wakeup_time;
  723. efi.set_wakeup_time = virt_efi_set_wakeup_time;
  724. efi.get_variable = virt_efi_get_variable;
  725. efi.get_next_variable = virt_efi_get_next_variable;
  726. efi.set_variable = virt_efi_set_variable;
  727. efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count;
  728. efi.reset_system = virt_efi_reset_system;
  729. efi.query_variable_info = virt_efi_query_variable_info;
  730. efi.update_capsule = virt_efi_update_capsule;
  731. efi.query_capsule_caps = virt_efi_query_capsule_caps;
  732. }
  733. /* Merge contiguous regions of the same type and attribute */
  734. static void __init efi_merge_regions(void)
  735. {
  736. void *p;
  737. efi_memory_desc_t *md, *prev_md = NULL;
  738. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  739. u64 prev_size;
  740. md = p;
  741. if (!prev_md) {
  742. prev_md = md;
  743. continue;
  744. }
  745. if (prev_md->type != md->type ||
  746. prev_md->attribute != md->attribute) {
  747. prev_md = md;
  748. continue;
  749. }
  750. prev_size = prev_md->num_pages << EFI_PAGE_SHIFT;
  751. if (md->phys_addr == (prev_md->phys_addr + prev_size)) {
  752. prev_md->num_pages += md->num_pages;
  753. md->type = EFI_RESERVED_TYPE;
  754. md->attribute = 0;
  755. continue;
  756. }
  757. prev_md = md;
  758. }
  759. }
  760. static void __init get_systab_virt_addr(efi_memory_desc_t *md)
  761. {
  762. unsigned long size;
  763. u64 end, systab;
  764. size = md->num_pages << EFI_PAGE_SHIFT;
  765. end = md->phys_addr + size;
  766. systab = (u64)(unsigned long)efi_phys.systab;
  767. if (md->phys_addr <= systab && systab < end) {
  768. systab += md->virt_addr - md->phys_addr;
  769. efi.systab = (efi_system_table_t *)(unsigned long)systab;
  770. }
  771. }
  772. static void __init save_runtime_map(void)
  773. {
  774. #ifdef CONFIG_KEXEC
  775. efi_memory_desc_t *md;
  776. void *tmp, *p, *q = NULL;
  777. int count = 0;
  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. }