efi.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. /*
  2. * Extensible Firmware Interface
  3. *
  4. * Based on Extensible Firmware Interface Specification version 0.9 April 30, 1999
  5. *
  6. * Copyright (C) 1999 VA Linux Systems
  7. * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
  8. * Copyright (C) 1999-2003 Hewlett-Packard Co.
  9. * David Mosberger-Tang <davidm@hpl.hp.com>
  10. * Stephane Eranian <eranian@hpl.hp.com>
  11. * (c) Copyright 2006 Hewlett-Packard Development Company, L.P.
  12. * Bjorn Helgaas <bjorn.helgaas@hp.com>
  13. *
  14. * All EFI Runtime Services are not implemented yet as EFI only
  15. * supports physical mode addressing on SoftSDV. This is to be fixed
  16. * in a future version. --drummond 1999-07-20
  17. *
  18. * Implemented EFI runtime services and virtual mode calls. --davidm
  19. *
  20. * Goutham Rao: <goutham.rao@intel.com>
  21. * Skip non-WB memory and ignore empty memory ranges.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/bootmem.h>
  25. #include <linux/kernel.h>
  26. #include <linux/init.h>
  27. #include <linux/types.h>
  28. #include <linux/time.h>
  29. #include <linux/efi.h>
  30. #include <linux/kexec.h>
  31. #include <asm/io.h>
  32. #include <asm/kregs.h>
  33. #include <asm/meminit.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/processor.h>
  36. #include <asm/mca.h>
  37. #define EFI_DEBUG 0
  38. extern efi_status_t efi_call_phys (void *, ...);
  39. struct efi efi;
  40. EXPORT_SYMBOL(efi);
  41. static efi_runtime_services_t *runtime;
  42. static unsigned long mem_limit = ~0UL, max_addr = ~0UL, min_addr = 0UL;
  43. #define efi_call_virt(f, args...) (*(f))(args)
  44. #define STUB_GET_TIME(prefix, adjust_arg) \
  45. static efi_status_t \
  46. prefix##_get_time (efi_time_t *tm, efi_time_cap_t *tc) \
  47. { \
  48. struct ia64_fpreg fr[6]; \
  49. efi_time_cap_t *atc = NULL; \
  50. efi_status_t ret; \
  51. \
  52. if (tc) \
  53. atc = adjust_arg(tc); \
  54. ia64_save_scratch_fpregs(fr); \
  55. ret = efi_call_##prefix((efi_get_time_t *) __va(runtime->get_time), adjust_arg(tm), atc); \
  56. ia64_load_scratch_fpregs(fr); \
  57. return ret; \
  58. }
  59. #define STUB_SET_TIME(prefix, adjust_arg) \
  60. static efi_status_t \
  61. prefix##_set_time (efi_time_t *tm) \
  62. { \
  63. struct ia64_fpreg fr[6]; \
  64. efi_status_t ret; \
  65. \
  66. ia64_save_scratch_fpregs(fr); \
  67. ret = efi_call_##prefix((efi_set_time_t *) __va(runtime->set_time), adjust_arg(tm)); \
  68. ia64_load_scratch_fpregs(fr); \
  69. return ret; \
  70. }
  71. #define STUB_GET_WAKEUP_TIME(prefix, adjust_arg) \
  72. static efi_status_t \
  73. prefix##_get_wakeup_time (efi_bool_t *enabled, efi_bool_t *pending, efi_time_t *tm) \
  74. { \
  75. struct ia64_fpreg fr[6]; \
  76. efi_status_t ret; \
  77. \
  78. ia64_save_scratch_fpregs(fr); \
  79. ret = efi_call_##prefix((efi_get_wakeup_time_t *) __va(runtime->get_wakeup_time), \
  80. adjust_arg(enabled), adjust_arg(pending), adjust_arg(tm)); \
  81. ia64_load_scratch_fpregs(fr); \
  82. return ret; \
  83. }
  84. #define STUB_SET_WAKEUP_TIME(prefix, adjust_arg) \
  85. static efi_status_t \
  86. prefix##_set_wakeup_time (efi_bool_t enabled, efi_time_t *tm) \
  87. { \
  88. struct ia64_fpreg fr[6]; \
  89. efi_time_t *atm = NULL; \
  90. efi_status_t ret; \
  91. \
  92. if (tm) \
  93. atm = adjust_arg(tm); \
  94. ia64_save_scratch_fpregs(fr); \
  95. ret = efi_call_##prefix((efi_set_wakeup_time_t *) __va(runtime->set_wakeup_time), \
  96. enabled, atm); \
  97. ia64_load_scratch_fpregs(fr); \
  98. return ret; \
  99. }
  100. #define STUB_GET_VARIABLE(prefix, adjust_arg) \
  101. static efi_status_t \
  102. prefix##_get_variable (efi_char16_t *name, efi_guid_t *vendor, u32 *attr, \
  103. unsigned long *data_size, void *data) \
  104. { \
  105. struct ia64_fpreg fr[6]; \
  106. u32 *aattr = NULL; \
  107. efi_status_t ret; \
  108. \
  109. if (attr) \
  110. aattr = adjust_arg(attr); \
  111. ia64_save_scratch_fpregs(fr); \
  112. ret = efi_call_##prefix((efi_get_variable_t *) __va(runtime->get_variable), \
  113. adjust_arg(name), adjust_arg(vendor), aattr, \
  114. adjust_arg(data_size), adjust_arg(data)); \
  115. ia64_load_scratch_fpregs(fr); \
  116. return ret; \
  117. }
  118. #define STUB_GET_NEXT_VARIABLE(prefix, adjust_arg) \
  119. static efi_status_t \
  120. prefix##_get_next_variable (unsigned long *name_size, efi_char16_t *name, efi_guid_t *vendor) \
  121. { \
  122. struct ia64_fpreg fr[6]; \
  123. efi_status_t ret; \
  124. \
  125. ia64_save_scratch_fpregs(fr); \
  126. ret = efi_call_##prefix((efi_get_next_variable_t *) __va(runtime->get_next_variable), \
  127. adjust_arg(name_size), adjust_arg(name), adjust_arg(vendor)); \
  128. ia64_load_scratch_fpregs(fr); \
  129. return ret; \
  130. }
  131. #define STUB_SET_VARIABLE(prefix, adjust_arg) \
  132. static efi_status_t \
  133. prefix##_set_variable (efi_char16_t *name, efi_guid_t *vendor, unsigned long attr, \
  134. unsigned long data_size, void *data) \
  135. { \
  136. struct ia64_fpreg fr[6]; \
  137. efi_status_t ret; \
  138. \
  139. ia64_save_scratch_fpregs(fr); \
  140. ret = efi_call_##prefix((efi_set_variable_t *) __va(runtime->set_variable), \
  141. adjust_arg(name), adjust_arg(vendor), attr, data_size, \
  142. adjust_arg(data)); \
  143. ia64_load_scratch_fpregs(fr); \
  144. return ret; \
  145. }
  146. #define STUB_GET_NEXT_HIGH_MONO_COUNT(prefix, adjust_arg) \
  147. static efi_status_t \
  148. prefix##_get_next_high_mono_count (u32 *count) \
  149. { \
  150. struct ia64_fpreg fr[6]; \
  151. efi_status_t ret; \
  152. \
  153. ia64_save_scratch_fpregs(fr); \
  154. ret = efi_call_##prefix((efi_get_next_high_mono_count_t *) \
  155. __va(runtime->get_next_high_mono_count), adjust_arg(count)); \
  156. ia64_load_scratch_fpregs(fr); \
  157. return ret; \
  158. }
  159. #define STUB_RESET_SYSTEM(prefix, adjust_arg) \
  160. static void \
  161. prefix##_reset_system (int reset_type, efi_status_t status, \
  162. unsigned long data_size, efi_char16_t *data) \
  163. { \
  164. struct ia64_fpreg fr[6]; \
  165. efi_char16_t *adata = NULL; \
  166. \
  167. if (data) \
  168. adata = adjust_arg(data); \
  169. \
  170. ia64_save_scratch_fpregs(fr); \
  171. efi_call_##prefix((efi_reset_system_t *) __va(runtime->reset_system), \
  172. reset_type, status, data_size, adata); \
  173. /* should not return, but just in case... */ \
  174. ia64_load_scratch_fpregs(fr); \
  175. }
  176. #define phys_ptr(arg) ((__typeof__(arg)) ia64_tpa(arg))
  177. STUB_GET_TIME(phys, phys_ptr)
  178. STUB_SET_TIME(phys, phys_ptr)
  179. STUB_GET_WAKEUP_TIME(phys, phys_ptr)
  180. STUB_SET_WAKEUP_TIME(phys, phys_ptr)
  181. STUB_GET_VARIABLE(phys, phys_ptr)
  182. STUB_GET_NEXT_VARIABLE(phys, phys_ptr)
  183. STUB_SET_VARIABLE(phys, phys_ptr)
  184. STUB_GET_NEXT_HIGH_MONO_COUNT(phys, phys_ptr)
  185. STUB_RESET_SYSTEM(phys, phys_ptr)
  186. #define id(arg) arg
  187. STUB_GET_TIME(virt, id)
  188. STUB_SET_TIME(virt, id)
  189. STUB_GET_WAKEUP_TIME(virt, id)
  190. STUB_SET_WAKEUP_TIME(virt, id)
  191. STUB_GET_VARIABLE(virt, id)
  192. STUB_GET_NEXT_VARIABLE(virt, id)
  193. STUB_SET_VARIABLE(virt, id)
  194. STUB_GET_NEXT_HIGH_MONO_COUNT(virt, id)
  195. STUB_RESET_SYSTEM(virt, id)
  196. void
  197. efi_gettimeofday (struct timespec *ts)
  198. {
  199. efi_time_t tm;
  200. memset(ts, 0, sizeof(ts));
  201. if ((*efi.get_time)(&tm, NULL) != EFI_SUCCESS)
  202. return;
  203. ts->tv_sec = mktime(tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second);
  204. ts->tv_nsec = tm.nanosecond;
  205. }
  206. static int
  207. is_memory_available (efi_memory_desc_t *md)
  208. {
  209. if (!(md->attribute & EFI_MEMORY_WB))
  210. return 0;
  211. switch (md->type) {
  212. case EFI_LOADER_CODE:
  213. case EFI_LOADER_DATA:
  214. case EFI_BOOT_SERVICES_CODE:
  215. case EFI_BOOT_SERVICES_DATA:
  216. case EFI_CONVENTIONAL_MEMORY:
  217. return 1;
  218. }
  219. return 0;
  220. }
  221. typedef struct kern_memdesc {
  222. u64 attribute;
  223. u64 start;
  224. u64 num_pages;
  225. } kern_memdesc_t;
  226. static kern_memdesc_t *kern_memmap;
  227. #define efi_md_size(md) (md->num_pages << EFI_PAGE_SHIFT)
  228. static inline u64
  229. kmd_end(kern_memdesc_t *kmd)
  230. {
  231. return (kmd->start + (kmd->num_pages << EFI_PAGE_SHIFT));
  232. }
  233. static inline u64
  234. efi_md_end(efi_memory_desc_t *md)
  235. {
  236. return (md->phys_addr + efi_md_size(md));
  237. }
  238. static inline int
  239. efi_wb(efi_memory_desc_t *md)
  240. {
  241. return (md->attribute & EFI_MEMORY_WB);
  242. }
  243. static inline int
  244. efi_uc(efi_memory_desc_t *md)
  245. {
  246. return (md->attribute & EFI_MEMORY_UC);
  247. }
  248. static void
  249. walk (efi_freemem_callback_t callback, void *arg, u64 attr)
  250. {
  251. kern_memdesc_t *k;
  252. u64 start, end, voff;
  253. voff = (attr == EFI_MEMORY_WB) ? PAGE_OFFSET : __IA64_UNCACHED_OFFSET;
  254. for (k = kern_memmap; k->start != ~0UL; k++) {
  255. if (k->attribute != attr)
  256. continue;
  257. start = PAGE_ALIGN(k->start);
  258. end = (k->start + (k->num_pages << EFI_PAGE_SHIFT)) & PAGE_MASK;
  259. if (start < end)
  260. if ((*callback)(start + voff, end + voff, arg) < 0)
  261. return;
  262. }
  263. }
  264. /*
  265. * Walks the EFI memory map and calls CALLBACK once for each EFI memory descriptor that
  266. * has memory that is available for OS use.
  267. */
  268. void
  269. efi_memmap_walk (efi_freemem_callback_t callback, void *arg)
  270. {
  271. walk(callback, arg, EFI_MEMORY_WB);
  272. }
  273. /*
  274. * Walks the EFI memory map and calls CALLBACK once for each EFI memory descriptor that
  275. * has memory that is available for uncached allocator.
  276. */
  277. void
  278. efi_memmap_walk_uc (efi_freemem_callback_t callback, void *arg)
  279. {
  280. walk(callback, arg, EFI_MEMORY_UC);
  281. }
  282. /*
  283. * Look for the PAL_CODE region reported by EFI and maps it using an
  284. * ITR to enable safe PAL calls in virtual mode. See IA-64 Processor
  285. * Abstraction Layer chapter 11 in ADAG
  286. */
  287. void *
  288. efi_get_pal_addr (void)
  289. {
  290. void *efi_map_start, *efi_map_end, *p;
  291. efi_memory_desc_t *md;
  292. u64 efi_desc_size;
  293. int pal_code_count = 0;
  294. u64 vaddr, mask;
  295. efi_map_start = __va(ia64_boot_param->efi_memmap);
  296. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  297. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  298. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  299. md = p;
  300. if (md->type != EFI_PAL_CODE)
  301. continue;
  302. if (++pal_code_count > 1) {
  303. printk(KERN_ERR "Too many EFI Pal Code memory ranges, dropped @ %lx\n",
  304. md->phys_addr);
  305. continue;
  306. }
  307. /*
  308. * The only ITLB entry in region 7 that is used is the one installed by
  309. * __start(). That entry covers a 64MB range.
  310. */
  311. mask = ~((1 << KERNEL_TR_PAGE_SHIFT) - 1);
  312. vaddr = PAGE_OFFSET + md->phys_addr;
  313. /*
  314. * We must check that the PAL mapping won't overlap with the kernel
  315. * mapping.
  316. *
  317. * PAL code is guaranteed to be aligned on a power of 2 between 4k and
  318. * 256KB and that only one ITR is needed to map it. This implies that the
  319. * PAL code is always aligned on its size, i.e., the closest matching page
  320. * size supported by the TLB. Therefore PAL code is guaranteed never to
  321. * cross a 64MB unless it is bigger than 64MB (very unlikely!). So for
  322. * now the following test is enough to determine whether or not we need a
  323. * dedicated ITR for the PAL code.
  324. */
  325. if ((vaddr & mask) == (KERNEL_START & mask)) {
  326. printk(KERN_INFO "%s: no need to install ITR for PAL code\n",
  327. __FUNCTION__);
  328. continue;
  329. }
  330. if (md->num_pages << EFI_PAGE_SHIFT > IA64_GRANULE_SIZE)
  331. panic("Woah! PAL code size bigger than a granule!");
  332. #if EFI_DEBUG
  333. mask = ~((1 << IA64_GRANULE_SHIFT) - 1);
  334. printk(KERN_INFO "CPU %d: mapping PAL code [0x%lx-0x%lx) into [0x%lx-0x%lx)\n",
  335. smp_processor_id(), md->phys_addr,
  336. md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
  337. vaddr & mask, (vaddr & mask) + IA64_GRANULE_SIZE);
  338. #endif
  339. return __va(md->phys_addr);
  340. }
  341. printk(KERN_WARNING "%s: no PAL-code memory-descriptor found\n",
  342. __FUNCTION__);
  343. return NULL;
  344. }
  345. void
  346. efi_map_pal_code (void)
  347. {
  348. void *pal_vaddr = efi_get_pal_addr ();
  349. u64 psr;
  350. if (!pal_vaddr)
  351. return;
  352. /*
  353. * Cannot write to CRx with PSR.ic=1
  354. */
  355. psr = ia64_clear_ic();
  356. ia64_itr(0x1, IA64_TR_PALCODE, GRANULEROUNDDOWN((unsigned long) pal_vaddr),
  357. pte_val(pfn_pte(__pa(pal_vaddr) >> PAGE_SHIFT, PAGE_KERNEL)),
  358. IA64_GRANULE_SHIFT);
  359. ia64_set_psr(psr); /* restore psr */
  360. ia64_srlz_i();
  361. }
  362. void __init
  363. efi_init (void)
  364. {
  365. void *efi_map_start, *efi_map_end;
  366. efi_config_table_t *config_tables;
  367. efi_char16_t *c16;
  368. u64 efi_desc_size;
  369. char *cp, vendor[100] = "unknown";
  370. int i;
  371. /* it's too early to be able to use the standard kernel command line support... */
  372. for (cp = boot_command_line; *cp; ) {
  373. if (memcmp(cp, "mem=", 4) == 0) {
  374. mem_limit = memparse(cp + 4, &cp);
  375. } else if (memcmp(cp, "max_addr=", 9) == 0) {
  376. max_addr = GRANULEROUNDDOWN(memparse(cp + 9, &cp));
  377. } else if (memcmp(cp, "min_addr=", 9) == 0) {
  378. min_addr = GRANULEROUNDDOWN(memparse(cp + 9, &cp));
  379. } else {
  380. while (*cp != ' ' && *cp)
  381. ++cp;
  382. while (*cp == ' ')
  383. ++cp;
  384. }
  385. }
  386. if (min_addr != 0UL)
  387. printk(KERN_INFO "Ignoring memory below %luMB\n", min_addr >> 20);
  388. if (max_addr != ~0UL)
  389. printk(KERN_INFO "Ignoring memory above %luMB\n", max_addr >> 20);
  390. efi.systab = __va(ia64_boot_param->efi_systab);
  391. /*
  392. * Verify the EFI Table
  393. */
  394. if (efi.systab == NULL)
  395. panic("Woah! Can't find EFI system table.\n");
  396. if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
  397. panic("Woah! EFI system table signature incorrect\n");
  398. if ((efi.systab->hdr.revision ^ EFI_SYSTEM_TABLE_REVISION) >> 16 != 0)
  399. printk(KERN_WARNING "Warning: EFI system table major version mismatch: "
  400. "got %d.%02d, expected %d.%02d\n",
  401. efi.systab->hdr.revision >> 16, efi.systab->hdr.revision & 0xffff,
  402. EFI_SYSTEM_TABLE_REVISION >> 16, EFI_SYSTEM_TABLE_REVISION & 0xffff);
  403. config_tables = __va(efi.systab->tables);
  404. /* Show what we know for posterity */
  405. c16 = __va(efi.systab->fw_vendor);
  406. if (c16) {
  407. for (i = 0;i < (int) sizeof(vendor) - 1 && *c16; ++i)
  408. vendor[i] = *c16++;
  409. vendor[i] = '\0';
  410. }
  411. printk(KERN_INFO "EFI v%u.%.02u by %s:",
  412. efi.systab->hdr.revision >> 16, efi.systab->hdr.revision & 0xffff, vendor);
  413. efi.mps = EFI_INVALID_TABLE_ADDR;
  414. efi.acpi = EFI_INVALID_TABLE_ADDR;
  415. efi.acpi20 = EFI_INVALID_TABLE_ADDR;
  416. efi.smbios = EFI_INVALID_TABLE_ADDR;
  417. efi.sal_systab = EFI_INVALID_TABLE_ADDR;
  418. efi.boot_info = EFI_INVALID_TABLE_ADDR;
  419. efi.hcdp = EFI_INVALID_TABLE_ADDR;
  420. efi.uga = EFI_INVALID_TABLE_ADDR;
  421. for (i = 0; i < (int) efi.systab->nr_tables; i++) {
  422. if (efi_guidcmp(config_tables[i].guid, MPS_TABLE_GUID) == 0) {
  423. efi.mps = config_tables[i].table;
  424. printk(" MPS=0x%lx", config_tables[i].table);
  425. } else if (efi_guidcmp(config_tables[i].guid, ACPI_20_TABLE_GUID) == 0) {
  426. efi.acpi20 = config_tables[i].table;
  427. printk(" ACPI 2.0=0x%lx", config_tables[i].table);
  428. } else if (efi_guidcmp(config_tables[i].guid, ACPI_TABLE_GUID) == 0) {
  429. efi.acpi = config_tables[i].table;
  430. printk(" ACPI=0x%lx", config_tables[i].table);
  431. } else if (efi_guidcmp(config_tables[i].guid, SMBIOS_TABLE_GUID) == 0) {
  432. efi.smbios = config_tables[i].table;
  433. printk(" SMBIOS=0x%lx", config_tables[i].table);
  434. } else if (efi_guidcmp(config_tables[i].guid, SAL_SYSTEM_TABLE_GUID) == 0) {
  435. efi.sal_systab = config_tables[i].table;
  436. printk(" SALsystab=0x%lx", config_tables[i].table);
  437. } else if (efi_guidcmp(config_tables[i].guid, HCDP_TABLE_GUID) == 0) {
  438. efi.hcdp = config_tables[i].table;
  439. printk(" HCDP=0x%lx", config_tables[i].table);
  440. }
  441. }
  442. printk("\n");
  443. runtime = __va(efi.systab->runtime);
  444. efi.get_time = phys_get_time;
  445. efi.set_time = phys_set_time;
  446. efi.get_wakeup_time = phys_get_wakeup_time;
  447. efi.set_wakeup_time = phys_set_wakeup_time;
  448. efi.get_variable = phys_get_variable;
  449. efi.get_next_variable = phys_get_next_variable;
  450. efi.set_variable = phys_set_variable;
  451. efi.get_next_high_mono_count = phys_get_next_high_mono_count;
  452. efi.reset_system = phys_reset_system;
  453. efi_map_start = __va(ia64_boot_param->efi_memmap);
  454. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  455. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  456. #if EFI_DEBUG
  457. /* print EFI memory map: */
  458. {
  459. efi_memory_desc_t *md;
  460. void *p;
  461. for (i = 0, p = efi_map_start; p < efi_map_end; ++i, p += efi_desc_size) {
  462. md = p;
  463. printk("mem%02u: type=%u, attr=0x%lx, range=[0x%016lx-0x%016lx) (%luMB)\n",
  464. i, md->type, md->attribute, md->phys_addr,
  465. md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
  466. md->num_pages >> (20 - EFI_PAGE_SHIFT));
  467. }
  468. }
  469. #endif
  470. efi_map_pal_code();
  471. efi_enter_virtual_mode();
  472. }
  473. void
  474. efi_enter_virtual_mode (void)
  475. {
  476. void *efi_map_start, *efi_map_end, *p;
  477. efi_memory_desc_t *md;
  478. efi_status_t status;
  479. u64 efi_desc_size;
  480. efi_map_start = __va(ia64_boot_param->efi_memmap);
  481. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  482. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  483. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  484. md = p;
  485. if (md->attribute & EFI_MEMORY_RUNTIME) {
  486. /*
  487. * Some descriptors have multiple bits set, so the order of
  488. * the tests is relevant.
  489. */
  490. if (md->attribute & EFI_MEMORY_WB) {
  491. md->virt_addr = (u64) __va(md->phys_addr);
  492. } else if (md->attribute & EFI_MEMORY_UC) {
  493. md->virt_addr = (u64) ioremap(md->phys_addr, 0);
  494. } else if (md->attribute & EFI_MEMORY_WC) {
  495. #if 0
  496. md->virt_addr = ia64_remap(md->phys_addr, (_PAGE_A | _PAGE_P
  497. | _PAGE_D
  498. | _PAGE_MA_WC
  499. | _PAGE_PL_0
  500. | _PAGE_AR_RW));
  501. #else
  502. printk(KERN_INFO "EFI_MEMORY_WC mapping\n");
  503. md->virt_addr = (u64) ioremap(md->phys_addr, 0);
  504. #endif
  505. } else if (md->attribute & EFI_MEMORY_WT) {
  506. #if 0
  507. md->virt_addr = ia64_remap(md->phys_addr, (_PAGE_A | _PAGE_P
  508. | _PAGE_D | _PAGE_MA_WT
  509. | _PAGE_PL_0
  510. | _PAGE_AR_RW));
  511. #else
  512. printk(KERN_INFO "EFI_MEMORY_WT mapping\n");
  513. md->virt_addr = (u64) ioremap(md->phys_addr, 0);
  514. #endif
  515. }
  516. }
  517. }
  518. status = efi_call_phys(__va(runtime->set_virtual_address_map),
  519. ia64_boot_param->efi_memmap_size,
  520. efi_desc_size, ia64_boot_param->efi_memdesc_version,
  521. ia64_boot_param->efi_memmap);
  522. if (status != EFI_SUCCESS) {
  523. printk(KERN_WARNING "warning: unable to switch EFI into virtual mode "
  524. "(status=%lu)\n", status);
  525. return;
  526. }
  527. /*
  528. * Now that EFI is in virtual mode, we call the EFI functions more efficiently:
  529. */
  530. efi.get_time = virt_get_time;
  531. efi.set_time = virt_set_time;
  532. efi.get_wakeup_time = virt_get_wakeup_time;
  533. efi.set_wakeup_time = virt_set_wakeup_time;
  534. efi.get_variable = virt_get_variable;
  535. efi.get_next_variable = virt_get_next_variable;
  536. efi.set_variable = virt_set_variable;
  537. efi.get_next_high_mono_count = virt_get_next_high_mono_count;
  538. efi.reset_system = virt_reset_system;
  539. }
  540. /*
  541. * Walk the EFI memory map looking for the I/O port range. There can only be one entry of
  542. * this type, other I/O port ranges should be described via ACPI.
  543. */
  544. u64
  545. efi_get_iobase (void)
  546. {
  547. void *efi_map_start, *efi_map_end, *p;
  548. efi_memory_desc_t *md;
  549. u64 efi_desc_size;
  550. efi_map_start = __va(ia64_boot_param->efi_memmap);
  551. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  552. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  553. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  554. md = p;
  555. if (md->type == EFI_MEMORY_MAPPED_IO_PORT_SPACE) {
  556. if (md->attribute & EFI_MEMORY_UC)
  557. return md->phys_addr;
  558. }
  559. }
  560. return 0;
  561. }
  562. static struct kern_memdesc *
  563. kern_memory_descriptor (unsigned long phys_addr)
  564. {
  565. struct kern_memdesc *md;
  566. for (md = kern_memmap; md->start != ~0UL; md++) {
  567. if (phys_addr - md->start < (md->num_pages << EFI_PAGE_SHIFT))
  568. return md;
  569. }
  570. return NULL;
  571. }
  572. static efi_memory_desc_t *
  573. efi_memory_descriptor (unsigned long phys_addr)
  574. {
  575. void *efi_map_start, *efi_map_end, *p;
  576. efi_memory_desc_t *md;
  577. u64 efi_desc_size;
  578. efi_map_start = __va(ia64_boot_param->efi_memmap);
  579. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  580. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  581. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  582. md = p;
  583. if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT))
  584. return md;
  585. }
  586. return NULL;
  587. }
  588. u32
  589. efi_mem_type (unsigned long phys_addr)
  590. {
  591. efi_memory_desc_t *md = efi_memory_descriptor(phys_addr);
  592. if (md)
  593. return md->type;
  594. return 0;
  595. }
  596. u64
  597. efi_mem_attributes (unsigned long phys_addr)
  598. {
  599. efi_memory_desc_t *md = efi_memory_descriptor(phys_addr);
  600. if (md)
  601. return md->attribute;
  602. return 0;
  603. }
  604. EXPORT_SYMBOL(efi_mem_attributes);
  605. u64
  606. efi_mem_attribute (unsigned long phys_addr, unsigned long size)
  607. {
  608. unsigned long end = phys_addr + size;
  609. efi_memory_desc_t *md = efi_memory_descriptor(phys_addr);
  610. u64 attr;
  611. if (!md)
  612. return 0;
  613. /*
  614. * EFI_MEMORY_RUNTIME is not a memory attribute; it just tells
  615. * the kernel that firmware needs this region mapped.
  616. */
  617. attr = md->attribute & ~EFI_MEMORY_RUNTIME;
  618. do {
  619. unsigned long md_end = efi_md_end(md);
  620. if (end <= md_end)
  621. return attr;
  622. md = efi_memory_descriptor(md_end);
  623. if (!md || (md->attribute & ~EFI_MEMORY_RUNTIME) != attr)
  624. return 0;
  625. } while (md);
  626. return 0;
  627. }
  628. u64
  629. kern_mem_attribute (unsigned long phys_addr, unsigned long size)
  630. {
  631. unsigned long end = phys_addr + size;
  632. struct kern_memdesc *md;
  633. u64 attr;
  634. /*
  635. * This is a hack for ioremap calls before we set up kern_memmap.
  636. * Maybe we should do efi_memmap_init() earlier instead.
  637. */
  638. if (!kern_memmap) {
  639. attr = efi_mem_attribute(phys_addr, size);
  640. if (attr & EFI_MEMORY_WB)
  641. return EFI_MEMORY_WB;
  642. return 0;
  643. }
  644. md = kern_memory_descriptor(phys_addr);
  645. if (!md)
  646. return 0;
  647. attr = md->attribute;
  648. do {
  649. unsigned long md_end = kmd_end(md);
  650. if (end <= md_end)
  651. return attr;
  652. md = kern_memory_descriptor(md_end);
  653. if (!md || md->attribute != attr)
  654. return 0;
  655. } while (md);
  656. return 0;
  657. }
  658. EXPORT_SYMBOL(kern_mem_attribute);
  659. int
  660. valid_phys_addr_range (unsigned long phys_addr, unsigned long size)
  661. {
  662. u64 attr;
  663. /*
  664. * /dev/mem reads and writes use copy_to_user(), which implicitly
  665. * uses a granule-sized kernel identity mapping. It's really
  666. * only safe to do this for regions in kern_memmap. For more
  667. * details, see Documentation/ia64/aliasing.txt.
  668. */
  669. attr = kern_mem_attribute(phys_addr, size);
  670. if (attr & EFI_MEMORY_WB || attr & EFI_MEMORY_UC)
  671. return 1;
  672. return 0;
  673. }
  674. int
  675. valid_mmap_phys_addr_range (unsigned long pfn, unsigned long size)
  676. {
  677. /*
  678. * MMIO regions are often missing from the EFI memory map.
  679. * We must allow mmap of them for programs like X, so we
  680. * currently can't do any useful validation.
  681. */
  682. return 1;
  683. }
  684. pgprot_t
  685. phys_mem_access_prot(struct file *file, unsigned long pfn, unsigned long size,
  686. pgprot_t vma_prot)
  687. {
  688. unsigned long phys_addr = pfn << PAGE_SHIFT;
  689. u64 attr;
  690. /*
  691. * For /dev/mem mmap, we use user mappings, but if the region is
  692. * in kern_memmap (and hence may be covered by a kernel mapping),
  693. * we must use the same attribute as the kernel mapping.
  694. */
  695. attr = kern_mem_attribute(phys_addr, size);
  696. if (attr & EFI_MEMORY_WB)
  697. return pgprot_cacheable(vma_prot);
  698. else if (attr & EFI_MEMORY_UC)
  699. return pgprot_noncached(vma_prot);
  700. /*
  701. * Some chipsets don't support UC access to memory. If
  702. * WB is supported, we prefer that.
  703. */
  704. if (efi_mem_attribute(phys_addr, size) & EFI_MEMORY_WB)
  705. return pgprot_cacheable(vma_prot);
  706. return pgprot_noncached(vma_prot);
  707. }
  708. int __init
  709. efi_uart_console_only(void)
  710. {
  711. efi_status_t status;
  712. char *s, name[] = "ConOut";
  713. efi_guid_t guid = EFI_GLOBAL_VARIABLE_GUID;
  714. efi_char16_t *utf16, name_utf16[32];
  715. unsigned char data[1024];
  716. unsigned long size = sizeof(data);
  717. struct efi_generic_dev_path *hdr, *end_addr;
  718. int uart = 0;
  719. /* Convert to UTF-16 */
  720. utf16 = name_utf16;
  721. s = name;
  722. while (*s)
  723. *utf16++ = *s++ & 0x7f;
  724. *utf16 = 0;
  725. status = efi.get_variable(name_utf16, &guid, NULL, &size, data);
  726. if (status != EFI_SUCCESS) {
  727. printk(KERN_ERR "No EFI %s variable?\n", name);
  728. return 0;
  729. }
  730. hdr = (struct efi_generic_dev_path *) data;
  731. end_addr = (struct efi_generic_dev_path *) ((u8 *) data + size);
  732. while (hdr < end_addr) {
  733. if (hdr->type == EFI_DEV_MSG &&
  734. hdr->sub_type == EFI_DEV_MSG_UART)
  735. uart = 1;
  736. else if (hdr->type == EFI_DEV_END_PATH ||
  737. hdr->type == EFI_DEV_END_PATH2) {
  738. if (!uart)
  739. return 0;
  740. if (hdr->sub_type == EFI_DEV_END_ENTIRE)
  741. return 1;
  742. uart = 0;
  743. }
  744. hdr = (struct efi_generic_dev_path *) ((u8 *) hdr + hdr->length);
  745. }
  746. printk(KERN_ERR "Malformed %s value\n", name);
  747. return 0;
  748. }
  749. /*
  750. * Look for the first granule aligned memory descriptor memory
  751. * that is big enough to hold EFI memory map. Make sure this
  752. * descriptor is atleast granule sized so it does not get trimmed
  753. */
  754. struct kern_memdesc *
  755. find_memmap_space (void)
  756. {
  757. u64 contig_low=0, contig_high=0;
  758. u64 as = 0, ae;
  759. void *efi_map_start, *efi_map_end, *p, *q;
  760. efi_memory_desc_t *md, *pmd = NULL, *check_md;
  761. u64 space_needed, efi_desc_size;
  762. unsigned long total_mem = 0;
  763. efi_map_start = __va(ia64_boot_param->efi_memmap);
  764. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  765. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  766. /*
  767. * Worst case: we need 3 kernel descriptors for each efi descriptor
  768. * (if every entry has a WB part in the middle, and UC head and tail),
  769. * plus one for the end marker.
  770. */
  771. space_needed = sizeof(kern_memdesc_t) *
  772. (3 * (ia64_boot_param->efi_memmap_size/efi_desc_size) + 1);
  773. for (p = efi_map_start; p < efi_map_end; pmd = md, p += efi_desc_size) {
  774. md = p;
  775. if (!efi_wb(md)) {
  776. continue;
  777. }
  778. if (pmd == NULL || !efi_wb(pmd) || efi_md_end(pmd) != md->phys_addr) {
  779. contig_low = GRANULEROUNDUP(md->phys_addr);
  780. contig_high = efi_md_end(md);
  781. for (q = p + efi_desc_size; q < efi_map_end; q += efi_desc_size) {
  782. check_md = q;
  783. if (!efi_wb(check_md))
  784. break;
  785. if (contig_high != check_md->phys_addr)
  786. break;
  787. contig_high = efi_md_end(check_md);
  788. }
  789. contig_high = GRANULEROUNDDOWN(contig_high);
  790. }
  791. if (!is_memory_available(md) || md->type == EFI_LOADER_DATA)
  792. continue;
  793. /* Round ends inward to granule boundaries */
  794. as = max(contig_low, md->phys_addr);
  795. ae = min(contig_high, efi_md_end(md));
  796. /* keep within max_addr= and min_addr= command line arg */
  797. as = max(as, min_addr);
  798. ae = min(ae, max_addr);
  799. if (ae <= as)
  800. continue;
  801. /* avoid going over mem= command line arg */
  802. if (total_mem + (ae - as) > mem_limit)
  803. ae -= total_mem + (ae - as) - mem_limit;
  804. if (ae <= as)
  805. continue;
  806. if (ae - as > space_needed)
  807. break;
  808. }
  809. if (p >= efi_map_end)
  810. panic("Can't allocate space for kernel memory descriptors");
  811. return __va(as);
  812. }
  813. /*
  814. * Walk the EFI memory map and gather all memory available for kernel
  815. * to use. We can allocate partial granules only if the unavailable
  816. * parts exist, and are WB.
  817. */
  818. void
  819. efi_memmap_init(unsigned long *s, unsigned long *e)
  820. {
  821. struct kern_memdesc *k, *prev = NULL;
  822. u64 contig_low=0, contig_high=0;
  823. u64 as, ae, lim;
  824. void *efi_map_start, *efi_map_end, *p, *q;
  825. efi_memory_desc_t *md, *pmd = NULL, *check_md;
  826. u64 efi_desc_size;
  827. unsigned long total_mem = 0;
  828. k = kern_memmap = find_memmap_space();
  829. efi_map_start = __va(ia64_boot_param->efi_memmap);
  830. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  831. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  832. for (p = efi_map_start; p < efi_map_end; pmd = md, p += efi_desc_size) {
  833. md = p;
  834. if (!efi_wb(md)) {
  835. if (efi_uc(md) && (md->type == EFI_CONVENTIONAL_MEMORY ||
  836. md->type == EFI_BOOT_SERVICES_DATA)) {
  837. k->attribute = EFI_MEMORY_UC;
  838. k->start = md->phys_addr;
  839. k->num_pages = md->num_pages;
  840. k++;
  841. }
  842. continue;
  843. }
  844. if (pmd == NULL || !efi_wb(pmd) || efi_md_end(pmd) != md->phys_addr) {
  845. contig_low = GRANULEROUNDUP(md->phys_addr);
  846. contig_high = efi_md_end(md);
  847. for (q = p + efi_desc_size; q < efi_map_end; q += efi_desc_size) {
  848. check_md = q;
  849. if (!efi_wb(check_md))
  850. break;
  851. if (contig_high != check_md->phys_addr)
  852. break;
  853. contig_high = efi_md_end(check_md);
  854. }
  855. contig_high = GRANULEROUNDDOWN(contig_high);
  856. }
  857. if (!is_memory_available(md))
  858. continue;
  859. #ifdef CONFIG_CRASH_DUMP
  860. /* saved_max_pfn should ignore max_addr= command line arg */
  861. if (saved_max_pfn < (efi_md_end(md) >> PAGE_SHIFT))
  862. saved_max_pfn = (efi_md_end(md) >> PAGE_SHIFT);
  863. #endif
  864. /*
  865. * Round ends inward to granule boundaries
  866. * Give trimmings to uncached allocator
  867. */
  868. if (md->phys_addr < contig_low) {
  869. lim = min(efi_md_end(md), contig_low);
  870. if (efi_uc(md)) {
  871. if (k > kern_memmap && (k-1)->attribute == EFI_MEMORY_UC &&
  872. kmd_end(k-1) == md->phys_addr) {
  873. (k-1)->num_pages += (lim - md->phys_addr) >> EFI_PAGE_SHIFT;
  874. } else {
  875. k->attribute = EFI_MEMORY_UC;
  876. k->start = md->phys_addr;
  877. k->num_pages = (lim - md->phys_addr) >> EFI_PAGE_SHIFT;
  878. k++;
  879. }
  880. }
  881. as = contig_low;
  882. } else
  883. as = md->phys_addr;
  884. if (efi_md_end(md) > contig_high) {
  885. lim = max(md->phys_addr, contig_high);
  886. if (efi_uc(md)) {
  887. if (lim == md->phys_addr && k > kern_memmap &&
  888. (k-1)->attribute == EFI_MEMORY_UC &&
  889. kmd_end(k-1) == md->phys_addr) {
  890. (k-1)->num_pages += md->num_pages;
  891. } else {
  892. k->attribute = EFI_MEMORY_UC;
  893. k->start = lim;
  894. k->num_pages = (efi_md_end(md) - lim) >> EFI_PAGE_SHIFT;
  895. k++;
  896. }
  897. }
  898. ae = contig_high;
  899. } else
  900. ae = efi_md_end(md);
  901. /* keep within max_addr= and min_addr= command line arg */
  902. as = max(as, min_addr);
  903. ae = min(ae, max_addr);
  904. if (ae <= as)
  905. continue;
  906. /* avoid going over mem= command line arg */
  907. if (total_mem + (ae - as) > mem_limit)
  908. ae -= total_mem + (ae - as) - mem_limit;
  909. if (ae <= as)
  910. continue;
  911. if (prev && kmd_end(prev) == md->phys_addr) {
  912. prev->num_pages += (ae - as) >> EFI_PAGE_SHIFT;
  913. total_mem += ae - as;
  914. continue;
  915. }
  916. k->attribute = EFI_MEMORY_WB;
  917. k->start = as;
  918. k->num_pages = (ae - as) >> EFI_PAGE_SHIFT;
  919. total_mem += ae - as;
  920. prev = k++;
  921. }
  922. k->start = ~0L; /* end-marker */
  923. /* reserve the memory we are using for kern_memmap */
  924. *s = (u64)kern_memmap;
  925. *e = (u64)++k;
  926. }
  927. void
  928. efi_initialize_iomem_resources(struct resource *code_resource,
  929. struct resource *data_resource)
  930. {
  931. struct resource *res;
  932. void *efi_map_start, *efi_map_end, *p;
  933. efi_memory_desc_t *md;
  934. u64 efi_desc_size;
  935. char *name;
  936. unsigned long flags;
  937. efi_map_start = __va(ia64_boot_param->efi_memmap);
  938. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  939. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  940. res = NULL;
  941. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  942. md = p;
  943. if (md->num_pages == 0) /* should not happen */
  944. continue;
  945. flags = IORESOURCE_MEM;
  946. switch (md->type) {
  947. case EFI_MEMORY_MAPPED_IO:
  948. case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
  949. continue;
  950. case EFI_LOADER_CODE:
  951. case EFI_LOADER_DATA:
  952. case EFI_BOOT_SERVICES_DATA:
  953. case EFI_BOOT_SERVICES_CODE:
  954. case EFI_CONVENTIONAL_MEMORY:
  955. if (md->attribute & EFI_MEMORY_WP) {
  956. name = "System ROM";
  957. flags |= IORESOURCE_READONLY;
  958. } else {
  959. name = "System RAM";
  960. }
  961. break;
  962. case EFI_ACPI_MEMORY_NVS:
  963. name = "ACPI Non-volatile Storage";
  964. flags |= IORESOURCE_BUSY;
  965. break;
  966. case EFI_UNUSABLE_MEMORY:
  967. name = "reserved";
  968. flags |= IORESOURCE_BUSY | IORESOURCE_DISABLED;
  969. break;
  970. case EFI_RESERVED_TYPE:
  971. case EFI_RUNTIME_SERVICES_CODE:
  972. case EFI_RUNTIME_SERVICES_DATA:
  973. case EFI_ACPI_RECLAIM_MEMORY:
  974. default:
  975. name = "reserved";
  976. flags |= IORESOURCE_BUSY;
  977. break;
  978. }
  979. if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) {
  980. printk(KERN_ERR "failed to alocate resource for iomem\n");
  981. return;
  982. }
  983. res->name = name;
  984. res->start = md->phys_addr;
  985. res->end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - 1;
  986. res->flags = flags;
  987. if (insert_resource(&iomem_resource, res) < 0)
  988. kfree(res);
  989. else {
  990. /*
  991. * We don't know which region contains
  992. * kernel data so we try it repeatedly and
  993. * let the resource manager test it.
  994. */
  995. insert_resource(res, code_resource);
  996. insert_resource(res, data_resource);
  997. #ifdef CONFIG_KEXEC
  998. insert_resource(res, &efi_memmap_res);
  999. insert_resource(res, &boot_param_res);
  1000. if (crashk_res.end > crashk_res.start)
  1001. insert_resource(res, &crashk_res);
  1002. #endif
  1003. }
  1004. }
  1005. }
  1006. #ifdef CONFIG_KEXEC
  1007. /* find a block of memory aligned to 64M exclude reserved regions
  1008. rsvd_regions are sorted
  1009. */
  1010. unsigned long __init
  1011. kdump_find_rsvd_region (unsigned long size,
  1012. struct rsvd_region *r, int n)
  1013. {
  1014. int i;
  1015. u64 start, end;
  1016. u64 alignment = 1UL << _PAGE_SIZE_64M;
  1017. void *efi_map_start, *efi_map_end, *p;
  1018. efi_memory_desc_t *md;
  1019. u64 efi_desc_size;
  1020. efi_map_start = __va(ia64_boot_param->efi_memmap);
  1021. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  1022. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  1023. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  1024. md = p;
  1025. if (!efi_wb(md))
  1026. continue;
  1027. start = ALIGN(md->phys_addr, alignment);
  1028. end = efi_md_end(md);
  1029. for (i = 0; i < n; i++) {
  1030. if (__pa(r[i].start) >= start && __pa(r[i].end) < end) {
  1031. if (__pa(r[i].start) > start + size)
  1032. return start;
  1033. start = ALIGN(__pa(r[i].end), alignment);
  1034. if (i < n-1 && __pa(r[i+1].start) < start + size)
  1035. continue;
  1036. else
  1037. break;
  1038. }
  1039. }
  1040. if (end > start + size)
  1041. return start;
  1042. }
  1043. printk(KERN_WARNING "Cannot reserve 0x%lx byte of memory for crashdump\n",
  1044. size);
  1045. return ~0UL;
  1046. }
  1047. #endif
  1048. #ifdef CONFIG_PROC_VMCORE
  1049. /* locate the size find a the descriptor at a certain address */
  1050. unsigned long
  1051. vmcore_find_descriptor_size (unsigned long address)
  1052. {
  1053. void *efi_map_start, *efi_map_end, *p;
  1054. efi_memory_desc_t *md;
  1055. u64 efi_desc_size;
  1056. unsigned long ret = 0;
  1057. efi_map_start = __va(ia64_boot_param->efi_memmap);
  1058. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  1059. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  1060. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  1061. md = p;
  1062. if (efi_wb(md) && md->type == EFI_LOADER_DATA
  1063. && md->phys_addr == address) {
  1064. ret = efi_md_size(md);
  1065. break;
  1066. }
  1067. }
  1068. if (ret == 0)
  1069. printk(KERN_WARNING "Cannot locate EFI vmcore descriptor\n");
  1070. return ret;
  1071. }
  1072. #endif