efi.c 17 KB

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