efi.c 19 KB

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