efi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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 gdt_descr;
  64. spin_lock(&efi_rt_lock);
  65. local_irq_save(efi_rt_eflags);
  66. /*
  67. * If I don't have PSE, I should just duplicate two entries in page
  68. * directory. If I have PSE, I just need to duplicate one entry in
  69. * page directory.
  70. */
  71. cr4 = read_cr4();
  72. if (cr4 & X86_CR4_PSE) {
  73. efi_bak_pg_dir_pointer[0].pgd =
  74. swapper_pg_dir[pgd_index(0)].pgd;
  75. swapper_pg_dir[0].pgd =
  76. swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
  77. } else {
  78. efi_bak_pg_dir_pointer[0].pgd =
  79. swapper_pg_dir[pgd_index(0)].pgd;
  80. efi_bak_pg_dir_pointer[1].pgd =
  81. swapper_pg_dir[pgd_index(0x400000)].pgd;
  82. swapper_pg_dir[pgd_index(0)].pgd =
  83. swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
  84. temp = PAGE_OFFSET + 0x400000;
  85. swapper_pg_dir[pgd_index(0x400000)].pgd =
  86. swapper_pg_dir[pgd_index(temp)].pgd;
  87. }
  88. /*
  89. * After the lock is released, the original page table is restored.
  90. */
  91. local_flush_tlb();
  92. gdt_descr.address = __pa(get_cpu_gdt_table(0));
  93. gdt_descr.size = GDT_SIZE - 1;
  94. load_gdt(&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 gdt_descr;
  100. gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
  101. gdt_descr.size = GDT_SIZE - 1;
  102. load_gdt(&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 is used during kernel init before runtime
  169. * services have been remapped and also during suspend, therefore,
  170. * we'll need to call both in physical and virtual modes.
  171. */
  172. inline unsigned long efi_get_time(void)
  173. {
  174. efi_status_t status;
  175. efi_time_t eft;
  176. efi_time_cap_t cap;
  177. if (efi.get_time) {
  178. /* if we are in virtual mode use remapped function */
  179. status = efi.get_time(&eft, &cap);
  180. } else {
  181. /* we are in physical mode */
  182. status = phys_efi_get_time(&eft, &cap);
  183. }
  184. if (status != EFI_SUCCESS)
  185. printk("Oops: efitime: can't read time status: 0x%lx\n",status);
  186. return mktime(eft.year, eft.month, eft.day, eft.hour,
  187. eft.minute, eft.second);
  188. }
  189. int is_available_memory(efi_memory_desc_t * md)
  190. {
  191. if (!(md->attribute & EFI_MEMORY_WB))
  192. return 0;
  193. switch (md->type) {
  194. case EFI_LOADER_CODE:
  195. case EFI_LOADER_DATA:
  196. case EFI_BOOT_SERVICES_CODE:
  197. case EFI_BOOT_SERVICES_DATA:
  198. case EFI_CONVENTIONAL_MEMORY:
  199. return 1;
  200. }
  201. return 0;
  202. }
  203. /*
  204. * We need to map the EFI memory map again after paging_init().
  205. */
  206. void __init efi_map_memmap(void)
  207. {
  208. memmap.map = NULL;
  209. memmap.map = bt_ioremap((unsigned long) memmap.phys_map,
  210. (memmap.nr_map * memmap.desc_size));
  211. if (memmap.map == NULL)
  212. printk(KERN_ERR PFX "Could not remap the EFI memmap!\n");
  213. memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);
  214. }
  215. #if EFI_DEBUG
  216. static void __init print_efi_memmap(void)
  217. {
  218. efi_memory_desc_t *md;
  219. void *p;
  220. int i;
  221. for (p = memmap.map, i = 0; p < memmap.map_end; p += memmap.desc_size, i++) {
  222. md = p;
  223. printk(KERN_INFO "mem%02u: type=%u, attr=0x%llx, "
  224. "range=[0x%016llx-0x%016llx) (%lluMB)\n",
  225. i, md->type, md->attribute, md->phys_addr,
  226. md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
  227. (md->num_pages >> (20 - EFI_PAGE_SHIFT)));
  228. }
  229. }
  230. #endif /* EFI_DEBUG */
  231. /*
  232. * Walks the EFI memory map and calls CALLBACK once for each EFI
  233. * memory descriptor that has memory that is available for kernel use.
  234. */
  235. void efi_memmap_walk(efi_freemem_callback_t callback, void *arg)
  236. {
  237. int prev_valid = 0;
  238. struct range {
  239. unsigned long start;
  240. unsigned long end;
  241. } uninitialized_var(prev), curr;
  242. efi_memory_desc_t *md;
  243. unsigned long start, end;
  244. void *p;
  245. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  246. md = p;
  247. if ((md->num_pages == 0) || (!is_available_memory(md)))
  248. continue;
  249. curr.start = md->phys_addr;
  250. curr.end = curr.start + (md->num_pages << EFI_PAGE_SHIFT);
  251. if (!prev_valid) {
  252. prev = curr;
  253. prev_valid = 1;
  254. } else {
  255. if (curr.start < prev.start)
  256. printk(KERN_INFO PFX "Unordered memory map\n");
  257. if (prev.end == curr.start)
  258. prev.end = curr.end;
  259. else {
  260. start =
  261. (unsigned long) (PAGE_ALIGN(prev.start));
  262. end = (unsigned long) (prev.end & PAGE_MASK);
  263. if ((end > start)
  264. && (*callback) (start, end, arg) < 0)
  265. return;
  266. prev = curr;
  267. }
  268. }
  269. }
  270. if (prev_valid) {
  271. start = (unsigned long) PAGE_ALIGN(prev.start);
  272. end = (unsigned long) (prev.end & PAGE_MASK);
  273. if (end > start)
  274. (*callback) (start, end, arg);
  275. }
  276. }
  277. void __init efi_init(void)
  278. {
  279. efi_config_table_t *config_tables;
  280. efi_runtime_services_t *runtime;
  281. efi_char16_t *c16;
  282. char vendor[100] = "unknown";
  283. unsigned long num_config_tables;
  284. int i = 0;
  285. memset(&efi, 0, sizeof(efi) );
  286. memset(&efi_phys, 0, sizeof(efi_phys));
  287. efi_phys.systab = EFI_SYSTAB;
  288. memmap.phys_map = EFI_MEMMAP;
  289. memmap.nr_map = EFI_MEMMAP_SIZE/EFI_MEMDESC_SIZE;
  290. memmap.desc_version = EFI_MEMDESC_VERSION;
  291. memmap.desc_size = EFI_MEMDESC_SIZE;
  292. efi.systab = (efi_system_table_t *)
  293. boot_ioremap((unsigned long) efi_phys.systab,
  294. sizeof(efi_system_table_t));
  295. /*
  296. * Verify the EFI Table
  297. */
  298. if (efi.systab == NULL)
  299. printk(KERN_ERR PFX "Woah! Couldn't map the EFI system table.\n");
  300. if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
  301. printk(KERN_ERR PFX "Woah! EFI system table signature incorrect\n");
  302. if ((efi.systab->hdr.revision >> 16) == 0)
  303. printk(KERN_ERR PFX "Warning: EFI system table version "
  304. "%d.%02d, expected 1.00 or greater\n",
  305. efi.systab->hdr.revision >> 16,
  306. efi.systab->hdr.revision & 0xffff);
  307. /*
  308. * Grab some details from the system table
  309. */
  310. num_config_tables = efi.systab->nr_tables;
  311. config_tables = (efi_config_table_t *)efi.systab->tables;
  312. runtime = efi.systab->runtime;
  313. /*
  314. * Show what we know for posterity
  315. */
  316. c16 = (efi_char16_t *) boot_ioremap(efi.systab->fw_vendor, 2);
  317. if (c16) {
  318. for (i = 0; i < (sizeof(vendor) - 1) && *c16; ++i)
  319. vendor[i] = *c16++;
  320. vendor[i] = '\0';
  321. } else
  322. printk(KERN_ERR PFX "Could not map the firmware vendor!\n");
  323. printk(KERN_INFO PFX "EFI v%u.%.02u by %s \n",
  324. efi.systab->hdr.revision >> 16,
  325. efi.systab->hdr.revision & 0xffff, vendor);
  326. /*
  327. * Let's see what config tables the firmware passed to us.
  328. */
  329. config_tables = (efi_config_table_t *)
  330. boot_ioremap((unsigned long) config_tables,
  331. num_config_tables * sizeof(efi_config_table_t));
  332. if (config_tables == NULL)
  333. printk(KERN_ERR PFX "Could not map EFI Configuration Table!\n");
  334. efi.mps = EFI_INVALID_TABLE_ADDR;
  335. efi.acpi = EFI_INVALID_TABLE_ADDR;
  336. efi.acpi20 = EFI_INVALID_TABLE_ADDR;
  337. efi.smbios = EFI_INVALID_TABLE_ADDR;
  338. efi.sal_systab = EFI_INVALID_TABLE_ADDR;
  339. efi.boot_info = EFI_INVALID_TABLE_ADDR;
  340. efi.hcdp = EFI_INVALID_TABLE_ADDR;
  341. efi.uga = EFI_INVALID_TABLE_ADDR;
  342. for (i = 0; i < num_config_tables; i++) {
  343. if (efi_guidcmp(config_tables[i].guid, MPS_TABLE_GUID) == 0) {
  344. efi.mps = config_tables[i].table;
  345. printk(KERN_INFO " MPS=0x%lx ", config_tables[i].table);
  346. } else
  347. if (efi_guidcmp(config_tables[i].guid, ACPI_20_TABLE_GUID) == 0) {
  348. efi.acpi20 = config_tables[i].table;
  349. printk(KERN_INFO " ACPI 2.0=0x%lx ", config_tables[i].table);
  350. } else
  351. if (efi_guidcmp(config_tables[i].guid, ACPI_TABLE_GUID) == 0) {
  352. efi.acpi = config_tables[i].table;
  353. printk(KERN_INFO " ACPI=0x%lx ", config_tables[i].table);
  354. } else
  355. if (efi_guidcmp(config_tables[i].guid, SMBIOS_TABLE_GUID) == 0) {
  356. efi.smbios = config_tables[i].table;
  357. printk(KERN_INFO " SMBIOS=0x%lx ", config_tables[i].table);
  358. } else
  359. if (efi_guidcmp(config_tables[i].guid, HCDP_TABLE_GUID) == 0) {
  360. efi.hcdp = config_tables[i].table;
  361. printk(KERN_INFO " HCDP=0x%lx ", config_tables[i].table);
  362. } else
  363. if (efi_guidcmp(config_tables[i].guid, UGA_IO_PROTOCOL_GUID) == 0) {
  364. efi.uga = config_tables[i].table;
  365. printk(KERN_INFO " UGA=0x%lx ", config_tables[i].table);
  366. }
  367. }
  368. printk("\n");
  369. /*
  370. * Check out the runtime services table. We need to map
  371. * the runtime services table so that we can grab the physical
  372. * address of several of the EFI runtime functions, needed to
  373. * set the firmware into virtual mode.
  374. */
  375. runtime = (efi_runtime_services_t *) boot_ioremap((unsigned long)
  376. runtime,
  377. sizeof(efi_runtime_services_t));
  378. if (runtime != NULL) {
  379. /*
  380. * We will only need *early* access to the following
  381. * two EFI runtime services before set_virtual_address_map
  382. * is invoked.
  383. */
  384. efi_phys.get_time = (efi_get_time_t *) runtime->get_time;
  385. efi_phys.set_virtual_address_map =
  386. (efi_set_virtual_address_map_t *)
  387. runtime->set_virtual_address_map;
  388. } else
  389. printk(KERN_ERR PFX "Could not map the runtime service table!\n");
  390. /* Map the EFI memory map for use until paging_init() */
  391. memmap.map = boot_ioremap((unsigned long) EFI_MEMMAP, EFI_MEMMAP_SIZE);
  392. if (memmap.map == NULL)
  393. printk(KERN_ERR PFX "Could not map the EFI memory map!\n");
  394. memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);
  395. #if EFI_DEBUG
  396. print_efi_memmap();
  397. #endif
  398. }
  399. static inline void __init check_range_for_systab(efi_memory_desc_t *md)
  400. {
  401. if (((unsigned long)md->phys_addr <= (unsigned long)efi_phys.systab) &&
  402. ((unsigned long)efi_phys.systab < md->phys_addr +
  403. ((unsigned long)md->num_pages << EFI_PAGE_SHIFT))) {
  404. unsigned long addr;
  405. addr = md->virt_addr - md->phys_addr +
  406. (unsigned long)efi_phys.systab;
  407. efi.systab = (efi_system_table_t *)addr;
  408. }
  409. }
  410. /*
  411. * Wrap all the virtual calls in a way that forces the parameters on the stack.
  412. */
  413. #define efi_call_virt(f, args...) \
  414. ((efi_##f##_t __attribute__((regparm(0)))*)efi.systab->runtime->f)(args)
  415. static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
  416. {
  417. return efi_call_virt(get_time, tm, tc);
  418. }
  419. static efi_status_t virt_efi_set_time (efi_time_t *tm)
  420. {
  421. return efi_call_virt(set_time, tm);
  422. }
  423. static efi_status_t virt_efi_get_wakeup_time (efi_bool_t *enabled,
  424. efi_bool_t *pending,
  425. efi_time_t *tm)
  426. {
  427. return efi_call_virt(get_wakeup_time, enabled, pending, tm);
  428. }
  429. static efi_status_t virt_efi_set_wakeup_time (efi_bool_t enabled,
  430. efi_time_t *tm)
  431. {
  432. return efi_call_virt(set_wakeup_time, enabled, tm);
  433. }
  434. static efi_status_t virt_efi_get_variable (efi_char16_t *name,
  435. efi_guid_t *vendor, u32 *attr,
  436. unsigned long *data_size, void *data)
  437. {
  438. return efi_call_virt(get_variable, name, vendor, attr, data_size, data);
  439. }
  440. static efi_status_t virt_efi_get_next_variable (unsigned long *name_size,
  441. efi_char16_t *name,
  442. efi_guid_t *vendor)
  443. {
  444. return efi_call_virt(get_next_variable, name_size, name, vendor);
  445. }
  446. static efi_status_t virt_efi_set_variable (efi_char16_t *name,
  447. efi_guid_t *vendor,
  448. unsigned long attr,
  449. unsigned long data_size, void *data)
  450. {
  451. return efi_call_virt(set_variable, name, vendor, attr, data_size, data);
  452. }
  453. static efi_status_t virt_efi_get_next_high_mono_count (u32 *count)
  454. {
  455. return efi_call_virt(get_next_high_mono_count, count);
  456. }
  457. static void virt_efi_reset_system (int reset_type, efi_status_t status,
  458. unsigned long data_size,
  459. efi_char16_t *data)
  460. {
  461. efi_call_virt(reset_system, reset_type, status, data_size, data);
  462. }
  463. /*
  464. * This function will switch the EFI runtime services to virtual mode.
  465. * Essentially, look through the EFI memmap and map every region that
  466. * has the runtime attribute bit set in its memory descriptor and update
  467. * that memory descriptor with the virtual address obtained from ioremap().
  468. * This enables the runtime services to be called without having to
  469. * thunk back into physical mode for every invocation.
  470. */
  471. void __init efi_enter_virtual_mode(void)
  472. {
  473. efi_memory_desc_t *md;
  474. efi_status_t status;
  475. void *p;
  476. efi.systab = NULL;
  477. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  478. md = p;
  479. if (!(md->attribute & EFI_MEMORY_RUNTIME))
  480. continue;
  481. md->virt_addr = (unsigned long)ioremap(md->phys_addr,
  482. md->num_pages << EFI_PAGE_SHIFT);
  483. if (!(unsigned long)md->virt_addr) {
  484. printk(KERN_ERR PFX "ioremap of 0x%lX failed\n",
  485. (unsigned long)md->phys_addr);
  486. }
  487. /* update the virtual address of the EFI system table */
  488. check_range_for_systab(md);
  489. }
  490. BUG_ON(!efi.systab);
  491. status = phys_efi_set_virtual_address_map(
  492. memmap.desc_size * memmap.nr_map,
  493. memmap.desc_size,
  494. memmap.desc_version,
  495. memmap.phys_map);
  496. if (status != EFI_SUCCESS) {
  497. printk (KERN_ALERT "You are screwed! "
  498. "Unable to switch EFI into virtual mode "
  499. "(status=%lx)\n", status);
  500. panic("EFI call to SetVirtualAddressMap() failed!");
  501. }
  502. /*
  503. * Now that EFI is in virtual mode, update the function
  504. * pointers in the runtime service table to the new virtual addresses.
  505. */
  506. efi.get_time = virt_efi_get_time;
  507. efi.set_time = virt_efi_set_time;
  508. efi.get_wakeup_time = virt_efi_get_wakeup_time;
  509. efi.set_wakeup_time = virt_efi_set_wakeup_time;
  510. efi.get_variable = virt_efi_get_variable;
  511. efi.get_next_variable = virt_efi_get_next_variable;
  512. efi.set_variable = virt_efi_set_variable;
  513. efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count;
  514. efi.reset_system = virt_efi_reset_system;
  515. }
  516. void __init
  517. efi_initialize_iomem_resources(struct resource *code_resource,
  518. struct resource *data_resource)
  519. {
  520. struct resource *res;
  521. efi_memory_desc_t *md;
  522. void *p;
  523. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  524. md = p;
  525. if ((md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT)) >
  526. 0x100000000ULL)
  527. continue;
  528. res = kzalloc(sizeof(struct resource), GFP_ATOMIC);
  529. switch (md->type) {
  530. case EFI_RESERVED_TYPE:
  531. res->name = "Reserved Memory";
  532. break;
  533. case EFI_LOADER_CODE:
  534. res->name = "Loader Code";
  535. break;
  536. case EFI_LOADER_DATA:
  537. res->name = "Loader Data";
  538. break;
  539. case EFI_BOOT_SERVICES_DATA:
  540. res->name = "BootServices Data";
  541. break;
  542. case EFI_BOOT_SERVICES_CODE:
  543. res->name = "BootServices Code";
  544. break;
  545. case EFI_RUNTIME_SERVICES_CODE:
  546. res->name = "Runtime Service Code";
  547. break;
  548. case EFI_RUNTIME_SERVICES_DATA:
  549. res->name = "Runtime Service Data";
  550. break;
  551. case EFI_CONVENTIONAL_MEMORY:
  552. res->name = "Conventional Memory";
  553. break;
  554. case EFI_UNUSABLE_MEMORY:
  555. res->name = "Unusable Memory";
  556. break;
  557. case EFI_ACPI_RECLAIM_MEMORY:
  558. res->name = "ACPI Reclaim";
  559. break;
  560. case EFI_ACPI_MEMORY_NVS:
  561. res->name = "ACPI NVS";
  562. break;
  563. case EFI_MEMORY_MAPPED_IO:
  564. res->name = "Memory Mapped IO";
  565. break;
  566. case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
  567. res->name = "Memory Mapped IO Port Space";
  568. break;
  569. default:
  570. res->name = "Reserved";
  571. break;
  572. }
  573. res->start = md->phys_addr;
  574. res->end = res->start + ((md->num_pages << EFI_PAGE_SHIFT) - 1);
  575. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  576. if (request_resource(&iomem_resource, res) < 0)
  577. printk(KERN_ERR PFX "Failed to allocate res %s : "
  578. "0x%llx-0x%llx\n", res->name,
  579. (unsigned long long)res->start,
  580. (unsigned long long)res->end);
  581. /*
  582. * We don't know which region contains kernel data so we try
  583. * it repeatedly and let the resource manager test it.
  584. */
  585. if (md->type == EFI_CONVENTIONAL_MEMORY) {
  586. request_resource(res, code_resource);
  587. request_resource(res, data_resource);
  588. #ifdef CONFIG_KEXEC
  589. request_resource(res, &crashk_res);
  590. #endif
  591. }
  592. }
  593. }
  594. /*
  595. * Convenience functions to obtain memory types and attributes
  596. */
  597. u32 efi_mem_type(unsigned long phys_addr)
  598. {
  599. efi_memory_desc_t *md;
  600. void *p;
  601. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  602. md = p;
  603. if ((md->phys_addr <= phys_addr) && (phys_addr <
  604. (md->phys_addr + (md-> num_pages << EFI_PAGE_SHIFT)) ))
  605. return md->type;
  606. }
  607. return 0;
  608. }
  609. u64 efi_mem_attributes(unsigned long phys_addr)
  610. {
  611. efi_memory_desc_t *md;
  612. void *p;
  613. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  614. md = p;
  615. if ((md->phys_addr <= phys_addr) && (phys_addr <
  616. (md->phys_addr + (md-> num_pages << EFI_PAGE_SHIFT)) ))
  617. return md->attribute;
  618. }
  619. return 0;
  620. }