efi.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  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 timespec *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 = mktime(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. set_bit(EFI_SYSTEM_TABLES, &efi.flags);
  472. palo_phys = EFI_INVALID_TABLE_ADDR;
  473. if (efi_config_init(arch_tables) != 0)
  474. return;
  475. if (palo_phys != EFI_INVALID_TABLE_ADDR)
  476. handle_palo(palo_phys);
  477. runtime = __va(efi.systab->runtime);
  478. efi.get_time = phys_get_time;
  479. efi.set_time = phys_set_time;
  480. efi.get_wakeup_time = phys_get_wakeup_time;
  481. efi.set_wakeup_time = phys_set_wakeup_time;
  482. efi.get_variable = phys_get_variable;
  483. efi.get_next_variable = phys_get_next_variable;
  484. efi.set_variable = phys_set_variable;
  485. efi.get_next_high_mono_count = phys_get_next_high_mono_count;
  486. efi.reset_system = phys_reset_system;
  487. efi_map_start = __va(ia64_boot_param->efi_memmap);
  488. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  489. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  490. #if EFI_DEBUG
  491. /* print EFI memory map: */
  492. {
  493. efi_memory_desc_t *md;
  494. void *p;
  495. for (i = 0, p = efi_map_start; p < efi_map_end;
  496. ++i, p += efi_desc_size)
  497. {
  498. const char *unit;
  499. unsigned long size;
  500. char buf[64];
  501. md = p;
  502. size = md->num_pages << EFI_PAGE_SHIFT;
  503. if ((size >> 40) > 0) {
  504. size >>= 40;
  505. unit = "TB";
  506. } else if ((size >> 30) > 0) {
  507. size >>= 30;
  508. unit = "GB";
  509. } else if ((size >> 20) > 0) {
  510. size >>= 20;
  511. unit = "MB";
  512. } else {
  513. size >>= 10;
  514. unit = "KB";
  515. }
  516. printk("mem%02d: %s "
  517. "range=[0x%016lx-0x%016lx) (%4lu%s)\n",
  518. i, efi_md_typeattr_format(buf, sizeof(buf), md),
  519. md->phys_addr,
  520. md->phys_addr + efi_md_size(md), size, unit);
  521. }
  522. }
  523. #endif
  524. efi_map_pal_code();
  525. efi_enter_virtual_mode();
  526. }
  527. void
  528. efi_enter_virtual_mode (void)
  529. {
  530. void *efi_map_start, *efi_map_end, *p;
  531. efi_memory_desc_t *md;
  532. efi_status_t status;
  533. u64 efi_desc_size;
  534. efi_map_start = __va(ia64_boot_param->efi_memmap);
  535. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  536. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  537. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  538. md = p;
  539. if (md->attribute & EFI_MEMORY_RUNTIME) {
  540. /*
  541. * Some descriptors have multiple bits set, so the
  542. * order of the tests is relevant.
  543. */
  544. if (md->attribute & EFI_MEMORY_WB) {
  545. md->virt_addr = (u64) __va(md->phys_addr);
  546. } else if (md->attribute & EFI_MEMORY_UC) {
  547. md->virt_addr = (u64) ioremap(md->phys_addr, 0);
  548. } else if (md->attribute & EFI_MEMORY_WC) {
  549. #if 0
  550. md->virt_addr = ia64_remap(md->phys_addr,
  551. (_PAGE_A |
  552. _PAGE_P |
  553. _PAGE_D |
  554. _PAGE_MA_WC |
  555. _PAGE_PL_0 |
  556. _PAGE_AR_RW));
  557. #else
  558. printk(KERN_INFO "EFI_MEMORY_WC mapping\n");
  559. md->virt_addr = (u64) ioremap(md->phys_addr, 0);
  560. #endif
  561. } else if (md->attribute & EFI_MEMORY_WT) {
  562. #if 0
  563. md->virt_addr = ia64_remap(md->phys_addr,
  564. (_PAGE_A |
  565. _PAGE_P |
  566. _PAGE_D |
  567. _PAGE_MA_WT |
  568. _PAGE_PL_0 |
  569. _PAGE_AR_RW));
  570. #else
  571. printk(KERN_INFO "EFI_MEMORY_WT mapping\n");
  572. md->virt_addr = (u64) ioremap(md->phys_addr, 0);
  573. #endif
  574. }
  575. }
  576. }
  577. status = efi_call_phys(__va(runtime->set_virtual_address_map),
  578. ia64_boot_param->efi_memmap_size,
  579. efi_desc_size,
  580. ia64_boot_param->efi_memdesc_version,
  581. ia64_boot_param->efi_memmap);
  582. if (status != EFI_SUCCESS) {
  583. printk(KERN_WARNING "warning: unable to switch EFI into "
  584. "virtual mode (status=%lu)\n", status);
  585. return;
  586. }
  587. set_bit(EFI_RUNTIME_SERVICES, &efi.flags);
  588. /*
  589. * Now that EFI is in virtual mode, we call the EFI functions more
  590. * efficiently:
  591. */
  592. efi.get_time = virt_get_time;
  593. efi.set_time = virt_set_time;
  594. efi.get_wakeup_time = virt_get_wakeup_time;
  595. efi.set_wakeup_time = virt_set_wakeup_time;
  596. efi.get_variable = virt_get_variable;
  597. efi.get_next_variable = virt_get_next_variable;
  598. efi.set_variable = virt_set_variable;
  599. efi.get_next_high_mono_count = virt_get_next_high_mono_count;
  600. efi.reset_system = virt_reset_system;
  601. }
  602. /*
  603. * Walk the EFI memory map looking for the I/O port range. There can only be
  604. * one entry of this type, other I/O port ranges should be described via ACPI.
  605. */
  606. u64
  607. efi_get_iobase (void)
  608. {
  609. void *efi_map_start, *efi_map_end, *p;
  610. efi_memory_desc_t *md;
  611. u64 efi_desc_size;
  612. efi_map_start = __va(ia64_boot_param->efi_memmap);
  613. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  614. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  615. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  616. md = p;
  617. if (md->type == EFI_MEMORY_MAPPED_IO_PORT_SPACE) {
  618. if (md->attribute & EFI_MEMORY_UC)
  619. return md->phys_addr;
  620. }
  621. }
  622. return 0;
  623. }
  624. static struct kern_memdesc *
  625. kern_memory_descriptor (unsigned long phys_addr)
  626. {
  627. struct kern_memdesc *md;
  628. for (md = kern_memmap; md->start != ~0UL; md++) {
  629. if (phys_addr - md->start < (md->num_pages << EFI_PAGE_SHIFT))
  630. return md;
  631. }
  632. return NULL;
  633. }
  634. static efi_memory_desc_t *
  635. efi_memory_descriptor (unsigned long phys_addr)
  636. {
  637. void *efi_map_start, *efi_map_end, *p;
  638. efi_memory_desc_t *md;
  639. u64 efi_desc_size;
  640. efi_map_start = __va(ia64_boot_param->efi_memmap);
  641. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  642. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  643. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  644. md = p;
  645. if (phys_addr - md->phys_addr < efi_md_size(md))
  646. return md;
  647. }
  648. return NULL;
  649. }
  650. static int
  651. efi_memmap_intersects (unsigned long phys_addr, unsigned long size)
  652. {
  653. void *efi_map_start, *efi_map_end, *p;
  654. efi_memory_desc_t *md;
  655. u64 efi_desc_size;
  656. unsigned long end;
  657. efi_map_start = __va(ia64_boot_param->efi_memmap);
  658. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  659. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  660. end = phys_addr + size;
  661. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  662. md = p;
  663. if (md->phys_addr < end && efi_md_end(md) > phys_addr)
  664. return 1;
  665. }
  666. return 0;
  667. }
  668. u32
  669. efi_mem_type (unsigned long phys_addr)
  670. {
  671. efi_memory_desc_t *md = efi_memory_descriptor(phys_addr);
  672. if (md)
  673. return md->type;
  674. return 0;
  675. }
  676. u64
  677. efi_mem_attributes (unsigned long phys_addr)
  678. {
  679. efi_memory_desc_t *md = efi_memory_descriptor(phys_addr);
  680. if (md)
  681. return md->attribute;
  682. return 0;
  683. }
  684. EXPORT_SYMBOL(efi_mem_attributes);
  685. u64
  686. efi_mem_attribute (unsigned long phys_addr, unsigned long size)
  687. {
  688. unsigned long end = phys_addr + size;
  689. efi_memory_desc_t *md = efi_memory_descriptor(phys_addr);
  690. u64 attr;
  691. if (!md)
  692. return 0;
  693. /*
  694. * EFI_MEMORY_RUNTIME is not a memory attribute; it just tells
  695. * the kernel that firmware needs this region mapped.
  696. */
  697. attr = md->attribute & ~EFI_MEMORY_RUNTIME;
  698. do {
  699. unsigned long md_end = efi_md_end(md);
  700. if (end <= md_end)
  701. return attr;
  702. md = efi_memory_descriptor(md_end);
  703. if (!md || (md->attribute & ~EFI_MEMORY_RUNTIME) != attr)
  704. return 0;
  705. } while (md);
  706. return 0; /* never reached */
  707. }
  708. u64
  709. kern_mem_attribute (unsigned long phys_addr, unsigned long size)
  710. {
  711. unsigned long end = phys_addr + size;
  712. struct kern_memdesc *md;
  713. u64 attr;
  714. /*
  715. * This is a hack for ioremap calls before we set up kern_memmap.
  716. * Maybe we should do efi_memmap_init() earlier instead.
  717. */
  718. if (!kern_memmap) {
  719. attr = efi_mem_attribute(phys_addr, size);
  720. if (attr & EFI_MEMORY_WB)
  721. return EFI_MEMORY_WB;
  722. return 0;
  723. }
  724. md = kern_memory_descriptor(phys_addr);
  725. if (!md)
  726. return 0;
  727. attr = md->attribute;
  728. do {
  729. unsigned long md_end = kmd_end(md);
  730. if (end <= md_end)
  731. return attr;
  732. md = kern_memory_descriptor(md_end);
  733. if (!md || md->attribute != attr)
  734. return 0;
  735. } while (md);
  736. return 0; /* never reached */
  737. }
  738. EXPORT_SYMBOL(kern_mem_attribute);
  739. int
  740. valid_phys_addr_range (phys_addr_t phys_addr, unsigned long size)
  741. {
  742. u64 attr;
  743. /*
  744. * /dev/mem reads and writes use copy_to_user(), which implicitly
  745. * uses a granule-sized kernel identity mapping. It's really
  746. * only safe to do this for regions in kern_memmap. For more
  747. * details, see Documentation/ia64/aliasing.txt.
  748. */
  749. attr = kern_mem_attribute(phys_addr, size);
  750. if (attr & EFI_MEMORY_WB || attr & EFI_MEMORY_UC)
  751. return 1;
  752. return 0;
  753. }
  754. int
  755. valid_mmap_phys_addr_range (unsigned long pfn, unsigned long size)
  756. {
  757. unsigned long phys_addr = pfn << PAGE_SHIFT;
  758. u64 attr;
  759. attr = efi_mem_attribute(phys_addr, size);
  760. /*
  761. * /dev/mem mmap uses normal user pages, so we don't need the entire
  762. * granule, but the entire region we're mapping must support the same
  763. * attribute.
  764. */
  765. if (attr & EFI_MEMORY_WB || attr & EFI_MEMORY_UC)
  766. return 1;
  767. /*
  768. * Intel firmware doesn't tell us about all the MMIO regions, so
  769. * in general we have to allow mmap requests. But if EFI *does*
  770. * tell us about anything inside this region, we should deny it.
  771. * The user can always map a smaller region to avoid the overlap.
  772. */
  773. if (efi_memmap_intersects(phys_addr, size))
  774. return 0;
  775. return 1;
  776. }
  777. pgprot_t
  778. phys_mem_access_prot(struct file *file, unsigned long pfn, unsigned long size,
  779. pgprot_t vma_prot)
  780. {
  781. unsigned long phys_addr = pfn << PAGE_SHIFT;
  782. u64 attr;
  783. /*
  784. * For /dev/mem mmap, we use user mappings, but if the region is
  785. * in kern_memmap (and hence may be covered by a kernel mapping),
  786. * we must use the same attribute as the kernel mapping.
  787. */
  788. attr = kern_mem_attribute(phys_addr, size);
  789. if (attr & EFI_MEMORY_WB)
  790. return pgprot_cacheable(vma_prot);
  791. else if (attr & EFI_MEMORY_UC)
  792. return pgprot_noncached(vma_prot);
  793. /*
  794. * Some chipsets don't support UC access to memory. If
  795. * WB is supported, we prefer that.
  796. */
  797. if (efi_mem_attribute(phys_addr, size) & EFI_MEMORY_WB)
  798. return pgprot_cacheable(vma_prot);
  799. return pgprot_noncached(vma_prot);
  800. }
  801. int __init
  802. efi_uart_console_only(void)
  803. {
  804. efi_status_t status;
  805. char *s, name[] = "ConOut";
  806. efi_guid_t guid = EFI_GLOBAL_VARIABLE_GUID;
  807. efi_char16_t *utf16, name_utf16[32];
  808. unsigned char data[1024];
  809. unsigned long size = sizeof(data);
  810. struct efi_generic_dev_path *hdr, *end_addr;
  811. int uart = 0;
  812. /* Convert to UTF-16 */
  813. utf16 = name_utf16;
  814. s = name;
  815. while (*s)
  816. *utf16++ = *s++ & 0x7f;
  817. *utf16 = 0;
  818. status = efi.get_variable(name_utf16, &guid, NULL, &size, data);
  819. if (status != EFI_SUCCESS) {
  820. printk(KERN_ERR "No EFI %s variable?\n", name);
  821. return 0;
  822. }
  823. hdr = (struct efi_generic_dev_path *) data;
  824. end_addr = (struct efi_generic_dev_path *) ((u8 *) data + size);
  825. while (hdr < end_addr) {
  826. if (hdr->type == EFI_DEV_MSG &&
  827. hdr->sub_type == EFI_DEV_MSG_UART)
  828. uart = 1;
  829. else if (hdr->type == EFI_DEV_END_PATH ||
  830. hdr->type == EFI_DEV_END_PATH2) {
  831. if (!uart)
  832. return 0;
  833. if (hdr->sub_type == EFI_DEV_END_ENTIRE)
  834. return 1;
  835. uart = 0;
  836. }
  837. hdr = (struct efi_generic_dev_path *)((u8 *) hdr + hdr->length);
  838. }
  839. printk(KERN_ERR "Malformed %s value\n", name);
  840. return 0;
  841. }
  842. /*
  843. * Look for the first granule aligned memory descriptor memory
  844. * that is big enough to hold EFI memory map. Make sure this
  845. * descriptor is atleast granule sized so it does not get trimmed
  846. */
  847. struct kern_memdesc *
  848. find_memmap_space (void)
  849. {
  850. u64 contig_low=0, contig_high=0;
  851. u64 as = 0, ae;
  852. void *efi_map_start, *efi_map_end, *p, *q;
  853. efi_memory_desc_t *md, *pmd = NULL, *check_md;
  854. u64 space_needed, efi_desc_size;
  855. unsigned long total_mem = 0;
  856. efi_map_start = __va(ia64_boot_param->efi_memmap);
  857. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  858. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  859. /*
  860. * Worst case: we need 3 kernel descriptors for each efi descriptor
  861. * (if every entry has a WB part in the middle, and UC head and tail),
  862. * plus one for the end marker.
  863. */
  864. space_needed = sizeof(kern_memdesc_t) *
  865. (3 * (ia64_boot_param->efi_memmap_size/efi_desc_size) + 1);
  866. for (p = efi_map_start; p < efi_map_end; pmd = md, p += efi_desc_size) {
  867. md = p;
  868. if (!efi_wb(md)) {
  869. continue;
  870. }
  871. if (pmd == NULL || !efi_wb(pmd) ||
  872. efi_md_end(pmd) != md->phys_addr) {
  873. contig_low = GRANULEROUNDUP(md->phys_addr);
  874. contig_high = efi_md_end(md);
  875. for (q = p + efi_desc_size; q < efi_map_end;
  876. q += efi_desc_size) {
  877. check_md = q;
  878. if (!efi_wb(check_md))
  879. break;
  880. if (contig_high != check_md->phys_addr)
  881. break;
  882. contig_high = efi_md_end(check_md);
  883. }
  884. contig_high = GRANULEROUNDDOWN(contig_high);
  885. }
  886. if (!is_memory_available(md) || md->type == EFI_LOADER_DATA)
  887. continue;
  888. /* Round ends inward to granule boundaries */
  889. as = max(contig_low, md->phys_addr);
  890. ae = min(contig_high, efi_md_end(md));
  891. /* keep within max_addr= and min_addr= command line arg */
  892. as = max(as, min_addr);
  893. ae = min(ae, max_addr);
  894. if (ae <= as)
  895. continue;
  896. /* avoid going over mem= command line arg */
  897. if (total_mem + (ae - as) > mem_limit)
  898. ae -= total_mem + (ae - as) - mem_limit;
  899. if (ae <= as)
  900. continue;
  901. if (ae - as > space_needed)
  902. break;
  903. }
  904. if (p >= efi_map_end)
  905. panic("Can't allocate space for kernel memory descriptors");
  906. return __va(as);
  907. }
  908. /*
  909. * Walk the EFI memory map and gather all memory available for kernel
  910. * to use. We can allocate partial granules only if the unavailable
  911. * parts exist, and are WB.
  912. */
  913. unsigned long
  914. efi_memmap_init(u64 *s, u64 *e)
  915. {
  916. struct kern_memdesc *k, *prev = NULL;
  917. u64 contig_low=0, contig_high=0;
  918. u64 as, ae, lim;
  919. void *efi_map_start, *efi_map_end, *p, *q;
  920. efi_memory_desc_t *md, *pmd = NULL, *check_md;
  921. u64 efi_desc_size;
  922. unsigned long total_mem = 0;
  923. k = kern_memmap = find_memmap_space();
  924. efi_map_start = __va(ia64_boot_param->efi_memmap);
  925. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  926. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  927. for (p = efi_map_start; p < efi_map_end; pmd = md, p += efi_desc_size) {
  928. md = p;
  929. if (!efi_wb(md)) {
  930. if (efi_uc(md) &&
  931. (md->type == EFI_CONVENTIONAL_MEMORY ||
  932. md->type == EFI_BOOT_SERVICES_DATA)) {
  933. k->attribute = EFI_MEMORY_UC;
  934. k->start = md->phys_addr;
  935. k->num_pages = md->num_pages;
  936. k++;
  937. }
  938. continue;
  939. }
  940. if (pmd == NULL || !efi_wb(pmd) ||
  941. efi_md_end(pmd) != md->phys_addr) {
  942. contig_low = GRANULEROUNDUP(md->phys_addr);
  943. contig_high = efi_md_end(md);
  944. for (q = p + efi_desc_size; q < efi_map_end;
  945. q += efi_desc_size) {
  946. check_md = q;
  947. if (!efi_wb(check_md))
  948. break;
  949. if (contig_high != check_md->phys_addr)
  950. break;
  951. contig_high = efi_md_end(check_md);
  952. }
  953. contig_high = GRANULEROUNDDOWN(contig_high);
  954. }
  955. if (!is_memory_available(md))
  956. continue;
  957. /*
  958. * Round ends inward to granule boundaries
  959. * Give trimmings to uncached allocator
  960. */
  961. if (md->phys_addr < contig_low) {
  962. lim = min(efi_md_end(md), contig_low);
  963. if (efi_uc(md)) {
  964. if (k > kern_memmap &&
  965. (k-1)->attribute == EFI_MEMORY_UC &&
  966. kmd_end(k-1) == md->phys_addr) {
  967. (k-1)->num_pages +=
  968. (lim - md->phys_addr)
  969. >> EFI_PAGE_SHIFT;
  970. } else {
  971. k->attribute = EFI_MEMORY_UC;
  972. k->start = md->phys_addr;
  973. k->num_pages = (lim - md->phys_addr)
  974. >> EFI_PAGE_SHIFT;
  975. k++;
  976. }
  977. }
  978. as = contig_low;
  979. } else
  980. as = md->phys_addr;
  981. if (efi_md_end(md) > contig_high) {
  982. lim = max(md->phys_addr, contig_high);
  983. if (efi_uc(md)) {
  984. if (lim == md->phys_addr && k > kern_memmap &&
  985. (k-1)->attribute == EFI_MEMORY_UC &&
  986. kmd_end(k-1) == md->phys_addr) {
  987. (k-1)->num_pages += md->num_pages;
  988. } else {
  989. k->attribute = EFI_MEMORY_UC;
  990. k->start = lim;
  991. k->num_pages = (efi_md_end(md) - lim)
  992. >> EFI_PAGE_SHIFT;
  993. k++;
  994. }
  995. }
  996. ae = contig_high;
  997. } else
  998. ae = efi_md_end(md);
  999. /* keep within max_addr= and min_addr= command line arg */
  1000. as = max(as, min_addr);
  1001. ae = min(ae, max_addr);
  1002. if (ae <= as)
  1003. continue;
  1004. /* avoid going over mem= command line arg */
  1005. if (total_mem + (ae - as) > mem_limit)
  1006. ae -= total_mem + (ae - as) - mem_limit;
  1007. if (ae <= as)
  1008. continue;
  1009. if (prev && kmd_end(prev) == md->phys_addr) {
  1010. prev->num_pages += (ae - as) >> EFI_PAGE_SHIFT;
  1011. total_mem += ae - as;
  1012. continue;
  1013. }
  1014. k->attribute = EFI_MEMORY_WB;
  1015. k->start = as;
  1016. k->num_pages = (ae - as) >> EFI_PAGE_SHIFT;
  1017. total_mem += ae - as;
  1018. prev = k++;
  1019. }
  1020. k->start = ~0L; /* end-marker */
  1021. /* reserve the memory we are using for kern_memmap */
  1022. *s = (u64)kern_memmap;
  1023. *e = (u64)++k;
  1024. return total_mem;
  1025. }
  1026. void
  1027. efi_initialize_iomem_resources(struct resource *code_resource,
  1028. struct resource *data_resource,
  1029. struct resource *bss_resource)
  1030. {
  1031. struct resource *res;
  1032. void *efi_map_start, *efi_map_end, *p;
  1033. efi_memory_desc_t *md;
  1034. u64 efi_desc_size;
  1035. char *name;
  1036. unsigned long flags;
  1037. efi_map_start = __va(ia64_boot_param->efi_memmap);
  1038. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  1039. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  1040. res = NULL;
  1041. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  1042. md = p;
  1043. if (md->num_pages == 0) /* should not happen */
  1044. continue;
  1045. flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  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. break;
  1063. case EFI_ACPI_MEMORY_NVS:
  1064. name = "ACPI Non-volatile Storage";
  1065. break;
  1066. case EFI_UNUSABLE_MEMORY:
  1067. name = "reserved";
  1068. flags |= IORESOURCE_DISABLED;
  1069. break;
  1070. case EFI_PERSISTENT_MEMORY:
  1071. name = "Persistent Memory";
  1072. break;
  1073. case EFI_RESERVED_TYPE:
  1074. case EFI_RUNTIME_SERVICES_CODE:
  1075. case EFI_RUNTIME_SERVICES_DATA:
  1076. case EFI_ACPI_RECLAIM_MEMORY:
  1077. default:
  1078. name = "reserved";
  1079. break;
  1080. }
  1081. if ((res = kzalloc(sizeof(struct resource),
  1082. GFP_KERNEL)) == NULL) {
  1083. printk(KERN_ERR
  1084. "failed to allocate resource for iomem\n");
  1085. return;
  1086. }
  1087. res->name = name;
  1088. res->start = md->phys_addr;
  1089. res->end = md->phys_addr + efi_md_size(md) - 1;
  1090. res->flags = flags;
  1091. if (insert_resource(&iomem_resource, res) < 0)
  1092. kfree(res);
  1093. else {
  1094. /*
  1095. * We don't know which region contains
  1096. * kernel data so we try it repeatedly and
  1097. * let the resource manager test it.
  1098. */
  1099. insert_resource(res, code_resource);
  1100. insert_resource(res, data_resource);
  1101. insert_resource(res, bss_resource);
  1102. #ifdef CONFIG_KEXEC
  1103. insert_resource(res, &efi_memmap_res);
  1104. insert_resource(res, &boot_param_res);
  1105. if (crashk_res.end > crashk_res.start)
  1106. insert_resource(res, &crashk_res);
  1107. #endif
  1108. }
  1109. }
  1110. }
  1111. #ifdef CONFIG_KEXEC
  1112. /* find a block of memory aligned to 64M exclude reserved regions
  1113. rsvd_regions are sorted
  1114. */
  1115. unsigned long __init
  1116. kdump_find_rsvd_region (unsigned long size, struct rsvd_region *r, int n)
  1117. {
  1118. int i;
  1119. u64 start, end;
  1120. u64 alignment = 1UL << _PAGE_SIZE_64M;
  1121. void *efi_map_start, *efi_map_end, *p;
  1122. efi_memory_desc_t *md;
  1123. u64 efi_desc_size;
  1124. efi_map_start = __va(ia64_boot_param->efi_memmap);
  1125. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  1126. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  1127. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  1128. md = p;
  1129. if (!efi_wb(md))
  1130. continue;
  1131. start = ALIGN(md->phys_addr, alignment);
  1132. end = efi_md_end(md);
  1133. for (i = 0; i < n; i++) {
  1134. if (__pa(r[i].start) >= start && __pa(r[i].end) < end) {
  1135. if (__pa(r[i].start) > start + size)
  1136. return start;
  1137. start = ALIGN(__pa(r[i].end), alignment);
  1138. if (i < n-1 &&
  1139. __pa(r[i+1].start) < start + size)
  1140. continue;
  1141. else
  1142. break;
  1143. }
  1144. }
  1145. if (end > start + size)
  1146. return start;
  1147. }
  1148. printk(KERN_WARNING
  1149. "Cannot reserve 0x%lx byte of memory for crashdump\n", size);
  1150. return ~0UL;
  1151. }
  1152. #endif
  1153. #ifdef CONFIG_CRASH_DUMP
  1154. /* locate the size find a the descriptor at a certain address */
  1155. unsigned long __init
  1156. vmcore_find_descriptor_size (unsigned long address)
  1157. {
  1158. void *efi_map_start, *efi_map_end, *p;
  1159. efi_memory_desc_t *md;
  1160. u64 efi_desc_size;
  1161. unsigned long ret = 0;
  1162. efi_map_start = __va(ia64_boot_param->efi_memmap);
  1163. efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
  1164. efi_desc_size = ia64_boot_param->efi_memdesc_size;
  1165. for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
  1166. md = p;
  1167. if (efi_wb(md) && md->type == EFI_LOADER_DATA
  1168. && md->phys_addr == address) {
  1169. ret = efi_md_size(md);
  1170. break;
  1171. }
  1172. }
  1173. if (ret == 0)
  1174. printk(KERN_WARNING "Cannot locate EFI vmcore descriptor\n");
  1175. return ret;
  1176. }
  1177. #endif