efi.c 18 KB

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