efi.c 35 KB

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