efi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. * Extensible Firmware Interface
  3. *
  4. * Based on Extensible Firmware Interface Specification version 1.0
  5. *
  6. * Copyright (C) 1999 VA Linux Systems
  7. * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
  8. * Copyright (C) 1999-2002 Hewlett-Packard Co.
  9. * David Mosberger-Tang <davidm@hpl.hp.com>
  10. * Stephane Eranian <eranian@hpl.hp.com>
  11. *
  12. * All EFI Runtime Services are not implemented yet as EFI only
  13. * supports physical mode addressing on SoftSDV. This is to be fixed
  14. * in a future version. --drummond 1999-07-20
  15. *
  16. * Implemented EFI runtime services and virtual mode calls. --davidm
  17. *
  18. * Goutham Rao: <goutham.rao@intel.com>
  19. * Skip non-WB memory and ignore empty memory ranges.
  20. */
  21. #include <linux/config.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/mm.h>
  25. #include <linux/types.h>
  26. #include <linux/time.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/bootmem.h>
  29. #include <linux/ioport.h>
  30. #include <linux/module.h>
  31. #include <linux/efi.h>
  32. #include <linux/kexec.h>
  33. #include <asm/setup.h>
  34. #include <asm/io.h>
  35. #include <asm/page.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/processor.h>
  38. #include <asm/desc.h>
  39. #include <asm/tlbflush.h>
  40. #define EFI_DEBUG 0
  41. #define PFX "EFI: "
  42. extern efi_status_t asmlinkage efi_call_phys(void *, ...);
  43. struct efi efi;
  44. EXPORT_SYMBOL(efi);
  45. static struct efi efi_phys;
  46. struct efi_memory_map memmap;
  47. /*
  48. * We require an early boot_ioremap mapping mechanism initially
  49. */
  50. extern void * boot_ioremap(unsigned long, unsigned long);
  51. /*
  52. * To make EFI call EFI runtime service in physical addressing mode we need
  53. * prelog/epilog before/after the invocation to disable interrupt, to
  54. * claim EFI runtime service handler exclusively and to duplicate a memory in
  55. * low memory space say 0 - 3G.
  56. */
  57. static unsigned long efi_rt_eflags;
  58. static DEFINE_SPINLOCK(efi_rt_lock);
  59. static pgd_t efi_bak_pg_dir_pointer[2];
  60. static void efi_call_phys_prelog(void)
  61. {
  62. unsigned long cr4;
  63. unsigned long temp;
  64. struct Xgt_desc_struct *cpu_gdt_descr;
  65. spin_lock(&efi_rt_lock);
  66. local_irq_save(efi_rt_eflags);
  67. cpu_gdt_descr = &per_cpu(cpu_gdt_descr, 0);
  68. /*
  69. * If I don't have PSE, I should just duplicate two entries in page
  70. * directory. If I have PSE, I just need to duplicate one entry in
  71. * page directory.
  72. */
  73. cr4 = read_cr4();
  74. if (cr4 & X86_CR4_PSE) {
  75. efi_bak_pg_dir_pointer[0].pgd =
  76. swapper_pg_dir[pgd_index(0)].pgd;
  77. swapper_pg_dir[0].pgd =
  78. swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
  79. } else {
  80. efi_bak_pg_dir_pointer[0].pgd =
  81. swapper_pg_dir[pgd_index(0)].pgd;
  82. efi_bak_pg_dir_pointer[1].pgd =
  83. swapper_pg_dir[pgd_index(0x400000)].pgd;
  84. swapper_pg_dir[pgd_index(0)].pgd =
  85. swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
  86. temp = PAGE_OFFSET + 0x400000;
  87. swapper_pg_dir[pgd_index(0x400000)].pgd =
  88. swapper_pg_dir[pgd_index(temp)].pgd;
  89. }
  90. /*
  91. * After the lock is released, the original page table is restored.
  92. */
  93. local_flush_tlb();
  94. cpu_gdt_descr->address = __pa(cpu_gdt_descr->address);
  95. load_gdt(cpu_gdt_descr);
  96. }
  97. static void efi_call_phys_epilog(void)
  98. {
  99. unsigned long cr4;
  100. struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, 0);
  101. cpu_gdt_descr->address = (unsigned long)__va(cpu_gdt_descr->address);
  102. load_gdt(cpu_gdt_descr);
  103. cr4 = read_cr4();
  104. if (cr4 & X86_CR4_PSE) {
  105. swapper_pg_dir[pgd_index(0)].pgd =
  106. efi_bak_pg_dir_pointer[0].pgd;
  107. } else {
  108. swapper_pg_dir[pgd_index(0)].pgd =
  109. efi_bak_pg_dir_pointer[0].pgd;
  110. swapper_pg_dir[pgd_index(0x400000)].pgd =
  111. efi_bak_pg_dir_pointer[1].pgd;
  112. }
  113. /*
  114. * After the lock is released, the original page table is restored.
  115. */
  116. local_flush_tlb();
  117. local_irq_restore(efi_rt_eflags);
  118. spin_unlock(&efi_rt_lock);
  119. }
  120. static efi_status_t
  121. phys_efi_set_virtual_address_map(unsigned long memory_map_size,
  122. unsigned long descriptor_size,
  123. u32 descriptor_version,
  124. efi_memory_desc_t *virtual_map)
  125. {
  126. efi_status_t status;
  127. efi_call_phys_prelog();
  128. status = efi_call_phys(efi_phys.set_virtual_address_map,
  129. memory_map_size, descriptor_size,
  130. descriptor_version, virtual_map);
  131. efi_call_phys_epilog();
  132. return status;
  133. }
  134. static efi_status_t
  135. phys_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
  136. {
  137. efi_status_t status;
  138. efi_call_phys_prelog();
  139. status = efi_call_phys(efi_phys.get_time, tm, tc);
  140. efi_call_phys_epilog();
  141. return status;
  142. }
  143. inline int efi_set_rtc_mmss(unsigned long nowtime)
  144. {
  145. int real_seconds, real_minutes;
  146. efi_status_t status;
  147. efi_time_t eft;
  148. efi_time_cap_t cap;
  149. spin_lock(&efi_rt_lock);
  150. status = efi.get_time(&eft, &cap);
  151. spin_unlock(&efi_rt_lock);
  152. if (status != EFI_SUCCESS)
  153. panic("Ooops, efitime: can't read time!\n");
  154. real_seconds = nowtime % 60;
  155. real_minutes = nowtime / 60;
  156. if (((abs(real_minutes - eft.minute) + 15)/30) & 1)
  157. real_minutes += 30;
  158. real_minutes %= 60;
  159. eft.minute = real_minutes;
  160. eft.second = real_seconds;
  161. if (status != EFI_SUCCESS) {
  162. printk("Ooops: efitime: can't read time!\n");
  163. return -1;
  164. }
  165. return 0;
  166. }
  167. /*
  168. * This should only be used during kernel init and before runtime
  169. * services have been remapped, therefore, we'll need to call in physical
  170. * mode. Note, this call isn't used later, so mark it __init.
  171. */
  172. inline unsigned long __init efi_get_time(void)
  173. {
  174. efi_status_t status;
  175. efi_time_t eft;
  176. efi_time_cap_t cap;
  177. status = phys_efi_get_time(&eft, &cap);
  178. if (status != EFI_SUCCESS)
  179. printk("Oops: efitime: can't read time status: 0x%lx\n",status);
  180. return mktime(eft.year, eft.month, eft.day, eft.hour,
  181. eft.minute, eft.second);
  182. }
  183. int is_available_memory(efi_memory_desc_t * md)
  184. {
  185. if (!(md->attribute & EFI_MEMORY_WB))
  186. return 0;
  187. switch (md->type) {
  188. case EFI_LOADER_CODE:
  189. case EFI_LOADER_DATA:
  190. case EFI_BOOT_SERVICES_CODE:
  191. case EFI_BOOT_SERVICES_DATA:
  192. case EFI_CONVENTIONAL_MEMORY:
  193. return 1;
  194. }
  195. return 0;
  196. }
  197. /*
  198. * We need to map the EFI memory map again after paging_init().
  199. */
  200. void __init efi_map_memmap(void)
  201. {
  202. memmap.map = NULL;
  203. memmap.map = bt_ioremap((unsigned long) memmap.phys_map,
  204. (memmap.nr_map * memmap.desc_size));
  205. if (memmap.map == NULL)
  206. printk(KERN_ERR PFX "Could not remap the EFI memmap!\n");
  207. memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);
  208. }
  209. #if EFI_DEBUG
  210. static void __init print_efi_memmap(void)
  211. {
  212. efi_memory_desc_t *md;
  213. void *p;
  214. int i;
  215. for (p = memmap.map, i = 0; p < memmap.map_end; p += memmap.desc_size, i++) {
  216. md = p;
  217. printk(KERN_INFO "mem%02u: type=%u, attr=0x%llx, "
  218. "range=[0x%016llx-0x%016llx) (%lluMB)\n",
  219. i, md->type, md->attribute, md->phys_addr,
  220. md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
  221. (md->num_pages >> (20 - EFI_PAGE_SHIFT)));
  222. }
  223. }
  224. #endif /* EFI_DEBUG */
  225. /*
  226. * Walks the EFI memory map and calls CALLBACK once for each EFI
  227. * memory descriptor that has memory that is available for kernel use.
  228. */
  229. void efi_memmap_walk(efi_freemem_callback_t callback, void *arg)
  230. {
  231. int prev_valid = 0;
  232. struct range {
  233. unsigned long start;
  234. unsigned long end;
  235. } prev, curr;
  236. efi_memory_desc_t *md;
  237. unsigned long start, end;
  238. void *p;
  239. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  240. md = p;
  241. if ((md->num_pages == 0) || (!is_available_memory(md)))
  242. continue;
  243. curr.start = md->phys_addr;
  244. curr.end = curr.start + (md->num_pages << EFI_PAGE_SHIFT);
  245. if (!prev_valid) {
  246. prev = curr;
  247. prev_valid = 1;
  248. } else {
  249. if (curr.start < prev.start)
  250. printk(KERN_INFO PFX "Unordered memory map\n");
  251. if (prev.end == curr.start)
  252. prev.end = curr.end;
  253. else {
  254. start =
  255. (unsigned long) (PAGE_ALIGN(prev.start));
  256. end = (unsigned long) (prev.end & PAGE_MASK);
  257. if ((end > start)
  258. && (*callback) (start, end, arg) < 0)
  259. return;
  260. prev = curr;
  261. }
  262. }
  263. }
  264. if (prev_valid) {
  265. start = (unsigned long) PAGE_ALIGN(prev.start);
  266. end = (unsigned long) (prev.end & PAGE_MASK);
  267. if (end > start)
  268. (*callback) (start, end, arg);
  269. }
  270. }
  271. void __init efi_init(void)
  272. {
  273. efi_config_table_t *config_tables;
  274. efi_runtime_services_t *runtime;
  275. efi_char16_t *c16;
  276. char vendor[100] = "unknown";
  277. unsigned long num_config_tables;
  278. int i = 0;
  279. memset(&efi, 0, sizeof(efi) );
  280. memset(&efi_phys, 0, sizeof(efi_phys));
  281. efi_phys.systab = EFI_SYSTAB;
  282. memmap.phys_map = EFI_MEMMAP;
  283. memmap.nr_map = EFI_MEMMAP_SIZE/EFI_MEMDESC_SIZE;
  284. memmap.desc_version = EFI_MEMDESC_VERSION;
  285. memmap.desc_size = EFI_MEMDESC_SIZE;
  286. efi.systab = (efi_system_table_t *)
  287. boot_ioremap((unsigned long) efi_phys.systab,
  288. sizeof(efi_system_table_t));
  289. /*
  290. * Verify the EFI Table
  291. */
  292. if (efi.systab == NULL)
  293. printk(KERN_ERR PFX "Woah! Couldn't map the EFI system table.\n");
  294. if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
  295. printk(KERN_ERR PFX "Woah! EFI system table signature incorrect\n");
  296. if ((efi.systab->hdr.revision ^ EFI_SYSTEM_TABLE_REVISION) >> 16 != 0)
  297. printk(KERN_ERR PFX
  298. "Warning: EFI system table major version mismatch: "
  299. "got %d.%02d, expected %d.%02d\n",
  300. efi.systab->hdr.revision >> 16,
  301. efi.systab->hdr.revision & 0xffff,
  302. EFI_SYSTEM_TABLE_REVISION >> 16,
  303. EFI_SYSTEM_TABLE_REVISION & 0xffff);
  304. /*
  305. * Grab some details from the system table
  306. */
  307. num_config_tables = efi.systab->nr_tables;
  308. config_tables = (efi_config_table_t *)efi.systab->tables;
  309. runtime = efi.systab->runtime;
  310. /*
  311. * Show what we know for posterity
  312. */
  313. c16 = (efi_char16_t *) boot_ioremap(efi.systab->fw_vendor, 2);
  314. if (c16) {
  315. for (i = 0; i < sizeof(vendor) && *c16; ++i)
  316. vendor[i] = *c16++;
  317. vendor[i] = '\0';
  318. } else
  319. printk(KERN_ERR PFX "Could not map the firmware vendor!\n");
  320. printk(KERN_INFO PFX "EFI v%u.%.02u by %s \n",
  321. efi.systab->hdr.revision >> 16,
  322. efi.systab->hdr.revision & 0xffff, vendor);
  323. /*
  324. * Let's see what config tables the firmware passed to us.
  325. */
  326. config_tables = (efi_config_table_t *)
  327. boot_ioremap((unsigned long) config_tables,
  328. num_config_tables * sizeof(efi_config_table_t));
  329. if (config_tables == NULL)
  330. printk(KERN_ERR PFX "Could not map EFI Configuration Table!\n");
  331. for (i = 0; i < num_config_tables; i++) {
  332. if (efi_guidcmp(config_tables[i].guid, MPS_TABLE_GUID) == 0) {
  333. efi.mps = (void *)config_tables[i].table;
  334. printk(KERN_INFO " MPS=0x%lx ", config_tables[i].table);
  335. } else
  336. if (efi_guidcmp(config_tables[i].guid, ACPI_20_TABLE_GUID) == 0) {
  337. efi.acpi20 = __va(config_tables[i].table);
  338. printk(KERN_INFO " ACPI 2.0=0x%lx ", config_tables[i].table);
  339. } else
  340. if (efi_guidcmp(config_tables[i].guid, ACPI_TABLE_GUID) == 0) {
  341. efi.acpi = __va(config_tables[i].table);
  342. printk(KERN_INFO " ACPI=0x%lx ", config_tables[i].table);
  343. } else
  344. if (efi_guidcmp(config_tables[i].guid, SMBIOS_TABLE_GUID) == 0) {
  345. efi.smbios = (void *) config_tables[i].table;
  346. printk(KERN_INFO " SMBIOS=0x%lx ", config_tables[i].table);
  347. } else
  348. if (efi_guidcmp(config_tables[i].guid, HCDP_TABLE_GUID) == 0) {
  349. efi.hcdp = (void *)config_tables[i].table;
  350. printk(KERN_INFO " HCDP=0x%lx ", config_tables[i].table);
  351. } else
  352. if (efi_guidcmp(config_tables[i].guid, UGA_IO_PROTOCOL_GUID) == 0) {
  353. efi.uga = (void *)config_tables[i].table;
  354. printk(KERN_INFO " UGA=0x%lx ", config_tables[i].table);
  355. }
  356. }
  357. printk("\n");
  358. /*
  359. * Check out the runtime services table. We need to map
  360. * the runtime services table so that we can grab the physical
  361. * address of several of the EFI runtime functions, needed to
  362. * set the firmware into virtual mode.
  363. */
  364. runtime = (efi_runtime_services_t *) boot_ioremap((unsigned long)
  365. runtime,
  366. sizeof(efi_runtime_services_t));
  367. if (runtime != NULL) {
  368. /*
  369. * We will only need *early* access to the following
  370. * two EFI runtime services before set_virtual_address_map
  371. * is invoked.
  372. */
  373. efi_phys.get_time = (efi_get_time_t *) runtime->get_time;
  374. efi_phys.set_virtual_address_map =
  375. (efi_set_virtual_address_map_t *)
  376. runtime->set_virtual_address_map;
  377. } else
  378. printk(KERN_ERR PFX "Could not map the runtime service table!\n");
  379. /* Map the EFI memory map for use until paging_init() */
  380. memmap.map = boot_ioremap((unsigned long) EFI_MEMMAP, EFI_MEMMAP_SIZE);
  381. if (memmap.map == NULL)
  382. printk(KERN_ERR PFX "Could not map the EFI memory map!\n");
  383. memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);
  384. #if EFI_DEBUG
  385. print_efi_memmap();
  386. #endif
  387. }
  388. static inline void __init check_range_for_systab(efi_memory_desc_t *md)
  389. {
  390. if (((unsigned long)md->phys_addr <= (unsigned long)efi_phys.systab) &&
  391. ((unsigned long)efi_phys.systab < md->phys_addr +
  392. ((unsigned long)md->num_pages << EFI_PAGE_SHIFT))) {
  393. unsigned long addr;
  394. addr = md->virt_addr - md->phys_addr +
  395. (unsigned long)efi_phys.systab;
  396. efi.systab = (efi_system_table_t *)addr;
  397. }
  398. }
  399. /*
  400. * This function will switch the EFI runtime services to virtual mode.
  401. * Essentially, look through the EFI memmap and map every region that
  402. * has the runtime attribute bit set in its memory descriptor and update
  403. * that memory descriptor with the virtual address obtained from ioremap().
  404. * This enables the runtime services to be called without having to
  405. * thunk back into physical mode for every invocation.
  406. */
  407. void __init efi_enter_virtual_mode(void)
  408. {
  409. efi_memory_desc_t *md;
  410. efi_status_t status;
  411. void *p;
  412. efi.systab = NULL;
  413. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  414. md = p;
  415. if (!(md->attribute & EFI_MEMORY_RUNTIME))
  416. continue;
  417. md->virt_addr = (unsigned long)ioremap(md->phys_addr,
  418. md->num_pages << EFI_PAGE_SHIFT);
  419. if (!(unsigned long)md->virt_addr) {
  420. printk(KERN_ERR PFX "ioremap of 0x%lX failed\n",
  421. (unsigned long)md->phys_addr);
  422. }
  423. /* update the virtual address of the EFI system table */
  424. check_range_for_systab(md);
  425. }
  426. if (!efi.systab)
  427. BUG();
  428. status = phys_efi_set_virtual_address_map(
  429. memmap.desc_size * memmap.nr_map,
  430. memmap.desc_size,
  431. memmap.desc_version,
  432. memmap.phys_map);
  433. if (status != EFI_SUCCESS) {
  434. printk (KERN_ALERT "You are screwed! "
  435. "Unable to switch EFI into virtual mode "
  436. "(status=%lx)\n", status);
  437. panic("EFI call to SetVirtualAddressMap() failed!");
  438. }
  439. /*
  440. * Now that EFI is in virtual mode, update the function
  441. * pointers in the runtime service table to the new virtual addresses.
  442. */
  443. efi.get_time = (efi_get_time_t *) efi.systab->runtime->get_time;
  444. efi.set_time = (efi_set_time_t *) efi.systab->runtime->set_time;
  445. efi.get_wakeup_time = (efi_get_wakeup_time_t *)
  446. efi.systab->runtime->get_wakeup_time;
  447. efi.set_wakeup_time = (efi_set_wakeup_time_t *)
  448. efi.systab->runtime->set_wakeup_time;
  449. efi.get_variable = (efi_get_variable_t *)
  450. efi.systab->runtime->get_variable;
  451. efi.get_next_variable = (efi_get_next_variable_t *)
  452. efi.systab->runtime->get_next_variable;
  453. efi.set_variable = (efi_set_variable_t *)
  454. efi.systab->runtime->set_variable;
  455. efi.get_next_high_mono_count = (efi_get_next_high_mono_count_t *)
  456. efi.systab->runtime->get_next_high_mono_count;
  457. efi.reset_system = (efi_reset_system_t *)
  458. efi.systab->runtime->reset_system;
  459. }
  460. void __init
  461. efi_initialize_iomem_resources(struct resource *code_resource,
  462. struct resource *data_resource)
  463. {
  464. struct resource *res;
  465. efi_memory_desc_t *md;
  466. void *p;
  467. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  468. md = p;
  469. if ((md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT)) >
  470. 0x100000000ULL)
  471. continue;
  472. res = kzalloc(sizeof(struct resource), GFP_ATOMIC);
  473. switch (md->type) {
  474. case EFI_RESERVED_TYPE:
  475. res->name = "Reserved Memory";
  476. break;
  477. case EFI_LOADER_CODE:
  478. res->name = "Loader Code";
  479. break;
  480. case EFI_LOADER_DATA:
  481. res->name = "Loader Data";
  482. break;
  483. case EFI_BOOT_SERVICES_DATA:
  484. res->name = "BootServices Data";
  485. break;
  486. case EFI_BOOT_SERVICES_CODE:
  487. res->name = "BootServices Code";
  488. break;
  489. case EFI_RUNTIME_SERVICES_CODE:
  490. res->name = "Runtime Service Code";
  491. break;
  492. case EFI_RUNTIME_SERVICES_DATA:
  493. res->name = "Runtime Service Data";
  494. break;
  495. case EFI_CONVENTIONAL_MEMORY:
  496. res->name = "Conventional Memory";
  497. break;
  498. case EFI_UNUSABLE_MEMORY:
  499. res->name = "Unusable Memory";
  500. break;
  501. case EFI_ACPI_RECLAIM_MEMORY:
  502. res->name = "ACPI Reclaim";
  503. break;
  504. case EFI_ACPI_MEMORY_NVS:
  505. res->name = "ACPI NVS";
  506. break;
  507. case EFI_MEMORY_MAPPED_IO:
  508. res->name = "Memory Mapped IO";
  509. break;
  510. case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
  511. res->name = "Memory Mapped IO Port Space";
  512. break;
  513. default:
  514. res->name = "Reserved";
  515. break;
  516. }
  517. res->start = md->phys_addr;
  518. res->end = res->start + ((md->num_pages << EFI_PAGE_SHIFT) - 1);
  519. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  520. if (request_resource(&iomem_resource, res) < 0)
  521. printk(KERN_ERR PFX "Failed to allocate res %s : 0x%lx-0x%lx\n",
  522. res->name, res->start, res->end);
  523. /*
  524. * We don't know which region contains kernel data so we try
  525. * it repeatedly and let the resource manager test it.
  526. */
  527. if (md->type == EFI_CONVENTIONAL_MEMORY) {
  528. request_resource(res, code_resource);
  529. request_resource(res, data_resource);
  530. #ifdef CONFIG_KEXEC
  531. request_resource(res, &crashk_res);
  532. #endif
  533. }
  534. }
  535. }
  536. /*
  537. * Convenience functions to obtain memory types and attributes
  538. */
  539. u32 efi_mem_type(unsigned long phys_addr)
  540. {
  541. efi_memory_desc_t *md;
  542. void *p;
  543. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  544. md = p;
  545. if ((md->phys_addr <= phys_addr) && (phys_addr <
  546. (md->phys_addr + (md-> num_pages << EFI_PAGE_SHIFT)) ))
  547. return md->type;
  548. }
  549. return 0;
  550. }
  551. u64 efi_mem_attributes(unsigned long phys_addr)
  552. {
  553. efi_memory_desc_t *md;
  554. void *p;
  555. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  556. md = p;
  557. if ((md->phys_addr <= phys_addr) && (phys_addr <
  558. (md->phys_addr + (md-> num_pages << EFI_PAGE_SHIFT)) ))
  559. return md->attribute;
  560. }
  561. return 0;
  562. }