efi.c 35 KB

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