2 * Extensible Firmware Interface
4 * Based on Extensible Firmware Interface Specification version 0.9 April 30, 1999
6 * Copyright (C) 1999 VA Linux Systems
7 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
8 * Copyright (C) 1999-2003 Hewlett-Packard Co.
9 * David Mosberger-Tang <davidm@hpl.hp.com>
10 * Stephane Eranian <eranian@hpl.hp.com>
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
16 * Implemented EFI runtime services and virtual mode calls. --davidm
18 * Goutham Rao: <goutham.rao@intel.com>
19 * Skip non-WB memory and ignore empty memory ranges.
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/types.h>
26 #include <linux/time.h>
27 #include <linux/efi.h>
30 #include <asm/kregs.h>
31 #include <asm/meminit.h>
32 #include <asm/pgtable.h>
33 #include <asm/processor.h>
38 extern efi_status_t efi_call_phys (void *, ...);
42 static efi_runtime_services_t *runtime;
43 static unsigned long mem_limit = ~0UL, max_addr = ~0UL;
45 #define efi_call_virt(f, args...) (*(f))(args)
47 #define STUB_GET_TIME(prefix, adjust_arg) \
49 prefix##_get_time (efi_time_t *tm, efi_time_cap_t *tc) \
51 struct ia64_fpreg fr[6]; \
52 efi_time_cap_t *atc = NULL; \
56 atc = adjust_arg(tc); \
57 ia64_save_scratch_fpregs(fr); \
58 ret = efi_call_##prefix((efi_get_time_t *) __va(runtime->get_time), adjust_arg(tm), atc); \
59 ia64_load_scratch_fpregs(fr); \
63 #define STUB_SET_TIME(prefix, adjust_arg) \
65 prefix##_set_time (efi_time_t *tm) \
67 struct ia64_fpreg fr[6]; \
70 ia64_save_scratch_fpregs(fr); \
71 ret = efi_call_##prefix((efi_set_time_t *) __va(runtime->set_time), adjust_arg(tm)); \
72 ia64_load_scratch_fpregs(fr); \
76 #define STUB_GET_WAKEUP_TIME(prefix, adjust_arg) \
78 prefix##_get_wakeup_time (efi_bool_t *enabled, efi_bool_t *pending, efi_time_t *tm) \
80 struct ia64_fpreg fr[6]; \
83 ia64_save_scratch_fpregs(fr); \
84 ret = efi_call_##prefix((efi_get_wakeup_time_t *) __va(runtime->get_wakeup_time), \
85 adjust_arg(enabled), adjust_arg(pending), adjust_arg(tm)); \
86 ia64_load_scratch_fpregs(fr); \
90 #define STUB_SET_WAKEUP_TIME(prefix, adjust_arg) \
92 prefix##_set_wakeup_time (efi_bool_t enabled, efi_time_t *tm) \
94 struct ia64_fpreg fr[6]; \
95 efi_time_t *atm = NULL; \
99 atm = adjust_arg(tm); \
100 ia64_save_scratch_fpregs(fr); \
101 ret = efi_call_##prefix((efi_set_wakeup_time_t *) __va(runtime->set_wakeup_time), \
103 ia64_load_scratch_fpregs(fr); \
107 #define STUB_GET_VARIABLE(prefix, adjust_arg) \
108 static efi_status_t \
109 prefix##_get_variable (efi_char16_t *name, efi_guid_t *vendor, u32 *attr, \
110 unsigned long *data_size, void *data) \
112 struct ia64_fpreg fr[6]; \
117 aattr = adjust_arg(attr); \
118 ia64_save_scratch_fpregs(fr); \
119 ret = efi_call_##prefix((efi_get_variable_t *) __va(runtime->get_variable), \
120 adjust_arg(name), adjust_arg(vendor), aattr, \
121 adjust_arg(data_size), adjust_arg(data)); \
122 ia64_load_scratch_fpregs(fr); \
126 #define STUB_GET_NEXT_VARIABLE(prefix, adjust_arg) \
127 static efi_status_t \
128 prefix##_get_next_variable (unsigned long *name_size, efi_char16_t *name, efi_guid_t *vendor) \
130 struct ia64_fpreg fr[6]; \
133 ia64_save_scratch_fpregs(fr); \
134 ret = efi_call_##prefix((efi_get_next_variable_t *) __va(runtime->get_next_variable), \
135 adjust_arg(name_size), adjust_arg(name), adjust_arg(vendor)); \
136 ia64_load_scratch_fpregs(fr); \
140 #define STUB_SET_VARIABLE(prefix, adjust_arg) \
141 static efi_status_t \
142 prefix##_set_variable (efi_char16_t *name, efi_guid_t *vendor, unsigned long attr, \
143 unsigned long data_size, void *data) \
145 struct ia64_fpreg fr[6]; \
148 ia64_save_scratch_fpregs(fr); \
149 ret = efi_call_##prefix((efi_set_variable_t *) __va(runtime->set_variable), \
150 adjust_arg(name), adjust_arg(vendor), attr, data_size, \
152 ia64_load_scratch_fpregs(fr); \
156 #define STUB_GET_NEXT_HIGH_MONO_COUNT(prefix, adjust_arg) \
157 static efi_status_t \
158 prefix##_get_next_high_mono_count (u32 *count) \
160 struct ia64_fpreg fr[6]; \
163 ia64_save_scratch_fpregs(fr); \
164 ret = efi_call_##prefix((efi_get_next_high_mono_count_t *) \
165 __va(runtime->get_next_high_mono_count), adjust_arg(count)); \
166 ia64_load_scratch_fpregs(fr); \
170 #define STUB_RESET_SYSTEM(prefix, adjust_arg) \
172 prefix##_reset_system (int reset_type, efi_status_t status, \
173 unsigned long data_size, efi_char16_t *data) \
175 struct ia64_fpreg fr[6]; \
176 efi_char16_t *adata = NULL; \
179 adata = adjust_arg(data); \
181 ia64_save_scratch_fpregs(fr); \
182 efi_call_##prefix((efi_reset_system_t *) __va(runtime->reset_system), \
183 reset_type, status, data_size, adata); \
184 /* should not return, but just in case... */ \
185 ia64_load_scratch_fpregs(fr); \
188 #define phys_ptr(arg) ((__typeof__(arg)) ia64_tpa(arg))
190 STUB_GET_TIME(phys, phys_ptr)
191 STUB_SET_TIME(phys, phys_ptr)
192 STUB_GET_WAKEUP_TIME(phys, phys_ptr)
193 STUB_SET_WAKEUP_TIME(phys, phys_ptr)
194 STUB_GET_VARIABLE(phys, phys_ptr)
195 STUB_GET_NEXT_VARIABLE(phys, phys_ptr)
196 STUB_SET_VARIABLE(phys, phys_ptr)
197 STUB_GET_NEXT_HIGH_MONO_COUNT(phys, phys_ptr)
198 STUB_RESET_SYSTEM(phys, phys_ptr)
202 STUB_GET_TIME(virt, id)
203 STUB_SET_TIME(virt, id)
204 STUB_GET_WAKEUP_TIME(virt, id)
205 STUB_SET_WAKEUP_TIME(virt, id)
206 STUB_GET_VARIABLE(virt, id)
207 STUB_GET_NEXT_VARIABLE(virt, id)
208 STUB_SET_VARIABLE(virt, id)
209 STUB_GET_NEXT_HIGH_MONO_COUNT(virt, id)
210 STUB_RESET_SYSTEM(virt, id)
213 efi_gettimeofday (struct timespec *ts)
217 memset(ts, 0, sizeof(ts));
218 if ((*efi.get_time)(&tm, NULL) != EFI_SUCCESS)
221 ts->tv_sec = mktime(tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second);
222 ts->tv_nsec = tm.nanosecond;
226 is_available_memory (efi_memory_desc_t *md)
228 if (!(md->attribute & EFI_MEMORY_WB))
232 case EFI_LOADER_CODE:
233 case EFI_LOADER_DATA:
234 case EFI_BOOT_SERVICES_CODE:
235 case EFI_BOOT_SERVICES_DATA:
236 case EFI_CONVENTIONAL_MEMORY:
243 * Trim descriptor MD so its starts at address START_ADDR. If the descriptor covers
244 * memory that is normally available to the kernel, issue a warning that some memory
248 trim_bottom (efi_memory_desc_t *md, u64 start_addr)
250 u64 num_skipped_pages;
252 if (md->phys_addr >= start_addr || !md->num_pages)
255 num_skipped_pages = (start_addr - md->phys_addr) >> EFI_PAGE_SHIFT;
256 if (num_skipped_pages > md->num_pages)
257 num_skipped_pages = md->num_pages;
259 if (is_available_memory(md))
260 printk(KERN_NOTICE "efi.%s: ignoring %luKB of memory at 0x%lx due to granule hole "
261 "at 0x%lx\n", __FUNCTION__,
262 (num_skipped_pages << EFI_PAGE_SHIFT) >> 10,
263 md->phys_addr, start_addr - IA64_GRANULE_SIZE);
265 * NOTE: Don't set md->phys_addr to START_ADDR because that could cause the memory
266 * descriptor list to become unsorted. In such a case, md->num_pages will be
267 * zero, so the Right Thing will happen.
269 md->phys_addr += num_skipped_pages << EFI_PAGE_SHIFT;
270 md->num_pages -= num_skipped_pages;
274 trim_top (efi_memory_desc_t *md, u64 end_addr)
276 u64 num_dropped_pages, md_end_addr;
278 md_end_addr = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
280 if (md_end_addr <= end_addr || !md->num_pages)
283 num_dropped_pages = (md_end_addr - end_addr) >> EFI_PAGE_SHIFT;
284 if (num_dropped_pages > md->num_pages)
285 num_dropped_pages = md->num_pages;
287 if (is_available_memory(md))
288 printk(KERN_NOTICE "efi.%s: ignoring %luKB of memory at 0x%lx due to granule hole "
289 "at 0x%lx\n", __FUNCTION__,
290 (num_dropped_pages << EFI_PAGE_SHIFT) >> 10,
291 md->phys_addr, end_addr);
292 md->num_pages -= num_dropped_pages;
296 * Walks the EFI memory map and calls CALLBACK once for each EFI memory descriptor that
297 * has memory that is available for OS use.
300 efi_memmap_walk (efi_freemem_callback_t callback, void *arg)
307 void *efi_map_start, *efi_map_end, *p, *q;
308 efi_memory_desc_t *md, *check_md;
309 u64 efi_desc_size, start, end, granule_addr, last_granule_addr, first_non_wb_addr = 0;
310 unsigned long total_mem = 0;
312 efi_map_start = __va(ia64_boot_param->efi_memmap);
313 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
314 efi_desc_size = ia64_boot_param->efi_memdesc_size;
316 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
319 /* skip over non-WB memory descriptors; that's all we're interested in... */
320 if (!(md->attribute & EFI_MEMORY_WB))
324 * granule_addr is the base of md's first granule.
325 * [granule_addr - first_non_wb_addr) is guaranteed to
326 * be contiguous WB memory.
328 granule_addr = GRANULEROUNDDOWN(md->phys_addr);
329 first_non_wb_addr = max(first_non_wb_addr, granule_addr);
331 if (first_non_wb_addr < md->phys_addr) {
332 trim_bottom(md, granule_addr + IA64_GRANULE_SIZE);
333 granule_addr = GRANULEROUNDDOWN(md->phys_addr);
334 first_non_wb_addr = max(first_non_wb_addr, granule_addr);
337 for (q = p; q < efi_map_end; q += efi_desc_size) {
340 if ((check_md->attribute & EFI_MEMORY_WB) &&
341 (check_md->phys_addr == first_non_wb_addr))
342 first_non_wb_addr += check_md->num_pages << EFI_PAGE_SHIFT;
344 break; /* non-WB or hole */
347 last_granule_addr = GRANULEROUNDDOWN(first_non_wb_addr);
348 if (last_granule_addr < md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT))
349 trim_top(md, last_granule_addr);
351 if (is_available_memory(md)) {
352 if (md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) >= max_addr) {
353 if (md->phys_addr >= max_addr)
355 md->num_pages = (max_addr - md->phys_addr) >> EFI_PAGE_SHIFT;
356 first_non_wb_addr = max_addr;
359 if (total_mem >= mem_limit)
362 if (total_mem + (md->num_pages << EFI_PAGE_SHIFT) > mem_limit) {
363 unsigned long limit_addr = md->phys_addr;
365 limit_addr += mem_limit - total_mem;
366 limit_addr = GRANULEROUNDDOWN(limit_addr);
368 if (md->phys_addr > limit_addr)
371 md->num_pages = (limit_addr - md->phys_addr) >>
373 first_non_wb_addr = max_addr = md->phys_addr +
374 (md->num_pages << EFI_PAGE_SHIFT);
376 total_mem += (md->num_pages << EFI_PAGE_SHIFT);
378 if (md->num_pages == 0)
381 curr.start = PAGE_OFFSET + md->phys_addr;
382 curr.end = curr.start + (md->num_pages << EFI_PAGE_SHIFT);
388 if (curr.start < prev.start)
389 printk(KERN_ERR "Oops: EFI memory table not ordered!\n");
391 if (prev.end == curr.start) {
392 /* merge two consecutive memory ranges */
395 start = PAGE_ALIGN(prev.start);
396 end = prev.end & PAGE_MASK;
397 if ((end > start) && (*callback)(start, end, arg) < 0)
405 start = PAGE_ALIGN(prev.start);
406 end = prev.end & PAGE_MASK;
408 (*callback)(start, end, arg);
413 * Look for the PAL_CODE region reported by EFI and maps it using an
414 * ITR to enable safe PAL calls in virtual mode. See IA-64 Processor
415 * Abstraction Layer chapter 11 in ADAG
419 efi_get_pal_addr (void)
421 void *efi_map_start, *efi_map_end, *p;
422 efi_memory_desc_t *md;
424 int pal_code_count = 0;
427 efi_map_start = __va(ia64_boot_param->efi_memmap);
428 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
429 efi_desc_size = ia64_boot_param->efi_memdesc_size;
431 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
433 if (md->type != EFI_PAL_CODE)
436 if (++pal_code_count > 1) {
437 printk(KERN_ERR "Too many EFI Pal Code memory ranges, dropped @ %lx\n",
442 * The only ITLB entry in region 7 that is used is the one installed by
443 * __start(). That entry covers a 64MB range.
445 mask = ~((1 << KERNEL_TR_PAGE_SHIFT) - 1);
446 vaddr = PAGE_OFFSET + md->phys_addr;
449 * We must check that the PAL mapping won't overlap with the kernel
452 * PAL code is guaranteed to be aligned on a power of 2 between 4k and
453 * 256KB and that only one ITR is needed to map it. This implies that the
454 * PAL code is always aligned on its size, i.e., the closest matching page
455 * size supported by the TLB. Therefore PAL code is guaranteed never to
456 * cross a 64MB unless it is bigger than 64MB (very unlikely!). So for
457 * now the following test is enough to determine whether or not we need a
458 * dedicated ITR for the PAL code.
460 if ((vaddr & mask) == (KERNEL_START & mask)) {
461 printk(KERN_INFO "%s: no need to install ITR for PAL code\n",
466 if (md->num_pages << EFI_PAGE_SHIFT > IA64_GRANULE_SIZE)
467 panic("Woah! PAL code size bigger than a granule!");
470 mask = ~((1 << IA64_GRANULE_SHIFT) - 1);
472 printk(KERN_INFO "CPU %d: mapping PAL code [0x%lx-0x%lx) into [0x%lx-0x%lx)\n",
473 smp_processor_id(), md->phys_addr,
474 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
475 vaddr & mask, (vaddr & mask) + IA64_GRANULE_SIZE);
477 return __va(md->phys_addr);
479 printk(KERN_WARNING "%s: no PAL-code memory-descriptor found",
485 efi_map_pal_code (void)
487 void *pal_vaddr = efi_get_pal_addr ();
494 * Cannot write to CRx with PSR.ic=1
496 psr = ia64_clear_ic();
497 ia64_itr(0x1, IA64_TR_PALCODE, GRANULEROUNDDOWN((unsigned long) pal_vaddr),
498 pte_val(pfn_pte(__pa(pal_vaddr) >> PAGE_SHIFT, PAGE_KERNEL)),
500 ia64_set_psr(psr); /* restore psr */
507 void *efi_map_start, *efi_map_end;
508 efi_config_table_t *config_tables;
511 char *cp, *end, vendor[100] = "unknown";
512 extern char saved_command_line[];
515 /* it's too early to be able to use the standard kernel command line support... */
516 for (cp = saved_command_line; *cp; ) {
517 if (memcmp(cp, "mem=", 4) == 0) {
519 mem_limit = memparse(cp, &end);
523 } else if (memcmp(cp, "max_addr=", 9) == 0) {
525 max_addr = GRANULEROUNDDOWN(memparse(cp, &end));
530 while (*cp != ' ' && *cp)
536 if (max_addr != ~0UL)
537 printk(KERN_INFO "Ignoring memory above %luMB\n", max_addr >> 20);
539 efi.systab = __va(ia64_boot_param->efi_systab);
542 * Verify the EFI Table
544 if (efi.systab == NULL)
545 panic("Woah! Can't find EFI system table.\n");
546 if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
547 panic("Woah! EFI system table signature incorrect\n");
548 if ((efi.systab->hdr.revision ^ EFI_SYSTEM_TABLE_REVISION) >> 16 != 0)
549 printk(KERN_WARNING "Warning: EFI system table major version mismatch: "
550 "got %d.%02d, expected %d.%02d\n",
551 efi.systab->hdr.revision >> 16, efi.systab->hdr.revision & 0xffff,
552 EFI_SYSTEM_TABLE_REVISION >> 16, EFI_SYSTEM_TABLE_REVISION & 0xffff);
554 config_tables = __va(efi.systab->tables);
556 /* Show what we know for posterity */
557 c16 = __va(efi.systab->fw_vendor);
559 for (i = 0;i < (int) sizeof(vendor) && *c16; ++i)
564 printk(KERN_INFO "EFI v%u.%.02u by %s:",
565 efi.systab->hdr.revision >> 16, efi.systab->hdr.revision & 0xffff, vendor);
567 for (i = 0; i < (int) efi.systab->nr_tables; i++) {
568 if (efi_guidcmp(config_tables[i].guid, MPS_TABLE_GUID) == 0) {
569 efi.mps = __va(config_tables[i].table);
570 printk(" MPS=0x%lx", config_tables[i].table);
571 } else if (efi_guidcmp(config_tables[i].guid, ACPI_20_TABLE_GUID) == 0) {
572 efi.acpi20 = __va(config_tables[i].table);
573 printk(" ACPI 2.0=0x%lx", config_tables[i].table);
574 } else if (efi_guidcmp(config_tables[i].guid, ACPI_TABLE_GUID) == 0) {
575 efi.acpi = __va(config_tables[i].table);
576 printk(" ACPI=0x%lx", config_tables[i].table);
577 } else if (efi_guidcmp(config_tables[i].guid, SMBIOS_TABLE_GUID) == 0) {
578 efi.smbios = __va(config_tables[i].table);
579 printk(" SMBIOS=0x%lx", config_tables[i].table);
580 } else if (efi_guidcmp(config_tables[i].guid, SAL_SYSTEM_TABLE_GUID) == 0) {
581 efi.sal_systab = __va(config_tables[i].table);
582 printk(" SALsystab=0x%lx", config_tables[i].table);
583 } else if (efi_guidcmp(config_tables[i].guid, HCDP_TABLE_GUID) == 0) {
584 efi.hcdp = __va(config_tables[i].table);
585 printk(" HCDP=0x%lx", config_tables[i].table);
590 runtime = __va(efi.systab->runtime);
591 efi.get_time = phys_get_time;
592 efi.set_time = phys_set_time;
593 efi.get_wakeup_time = phys_get_wakeup_time;
594 efi.set_wakeup_time = phys_set_wakeup_time;
595 efi.get_variable = phys_get_variable;
596 efi.get_next_variable = phys_get_next_variable;
597 efi.set_variable = phys_set_variable;
598 efi.get_next_high_mono_count = phys_get_next_high_mono_count;
599 efi.reset_system = phys_reset_system;
601 efi_map_start = __va(ia64_boot_param->efi_memmap);
602 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
603 efi_desc_size = ia64_boot_param->efi_memdesc_size;
606 /* print EFI memory map: */
608 efi_memory_desc_t *md;
611 for (i = 0, p = efi_map_start; p < efi_map_end; ++i, p += efi_desc_size) {
613 printk("mem%02u: type=%u, attr=0x%lx, range=[0x%016lx-0x%016lx) (%luMB)\n",
614 i, md->type, md->attribute, md->phys_addr,
615 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
616 md->num_pages >> (20 - EFI_PAGE_SHIFT));
622 efi_enter_virtual_mode();
626 efi_enter_virtual_mode (void)
628 void *efi_map_start, *efi_map_end, *p;
629 efi_memory_desc_t *md;
633 efi_map_start = __va(ia64_boot_param->efi_memmap);
634 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
635 efi_desc_size = ia64_boot_param->efi_memdesc_size;
637 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
639 if (md->attribute & EFI_MEMORY_RUNTIME) {
641 * Some descriptors have multiple bits set, so the order of
642 * the tests is relevant.
644 if (md->attribute & EFI_MEMORY_WB) {
645 md->virt_addr = (u64) __va(md->phys_addr);
646 } else if (md->attribute & EFI_MEMORY_UC) {
647 md->virt_addr = (u64) ioremap(md->phys_addr, 0);
648 } else if (md->attribute & EFI_MEMORY_WC) {
650 md->virt_addr = ia64_remap(md->phys_addr, (_PAGE_A | _PAGE_P
656 printk(KERN_INFO "EFI_MEMORY_WC mapping\n");
657 md->virt_addr = (u64) ioremap(md->phys_addr, 0);
659 } else if (md->attribute & EFI_MEMORY_WT) {
661 md->virt_addr = ia64_remap(md->phys_addr, (_PAGE_A | _PAGE_P
662 | _PAGE_D | _PAGE_MA_WT
666 printk(KERN_INFO "EFI_MEMORY_WT mapping\n");
667 md->virt_addr = (u64) ioremap(md->phys_addr, 0);
673 status = efi_call_phys(__va(runtime->set_virtual_address_map),
674 ia64_boot_param->efi_memmap_size,
675 efi_desc_size, ia64_boot_param->efi_memdesc_version,
676 ia64_boot_param->efi_memmap);
677 if (status != EFI_SUCCESS) {
678 printk(KERN_WARNING "warning: unable to switch EFI into virtual mode "
679 "(status=%lu)\n", status);
684 * Now that EFI is in virtual mode, we call the EFI functions more efficiently:
686 efi.get_time = virt_get_time;
687 efi.set_time = virt_set_time;
688 efi.get_wakeup_time = virt_get_wakeup_time;
689 efi.set_wakeup_time = virt_set_wakeup_time;
690 efi.get_variable = virt_get_variable;
691 efi.get_next_variable = virt_get_next_variable;
692 efi.set_variable = virt_set_variable;
693 efi.get_next_high_mono_count = virt_get_next_high_mono_count;
694 efi.reset_system = virt_reset_system;
698 * Walk the EFI memory map looking for the I/O port range. There can only be one entry of
699 * this type, other I/O port ranges should be described via ACPI.
702 efi_get_iobase (void)
704 void *efi_map_start, *efi_map_end, *p;
705 efi_memory_desc_t *md;
708 efi_map_start = __va(ia64_boot_param->efi_memmap);
709 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
710 efi_desc_size = ia64_boot_param->efi_memdesc_size;
712 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
714 if (md->type == EFI_MEMORY_MAPPED_IO_PORT_SPACE) {
715 if (md->attribute & EFI_MEMORY_UC)
716 return md->phys_addr;
723 efi_mem_type (unsigned long phys_addr)
725 void *efi_map_start, *efi_map_end, *p;
726 efi_memory_desc_t *md;
729 efi_map_start = __va(ia64_boot_param->efi_memmap);
730 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
731 efi_desc_size = ia64_boot_param->efi_memdesc_size;
733 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
736 if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT))
743 efi_mem_attributes (unsigned long phys_addr)
745 void *efi_map_start, *efi_map_end, *p;
746 efi_memory_desc_t *md;
749 efi_map_start = __va(ia64_boot_param->efi_memmap);
750 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
751 efi_desc_size = ia64_boot_param->efi_memdesc_size;
753 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
756 if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT))
757 return md->attribute;
761 EXPORT_SYMBOL(efi_mem_attributes);
764 valid_phys_addr_range (unsigned long phys_addr, unsigned long *size)
766 void *efi_map_start, *efi_map_end, *p;
767 efi_memory_desc_t *md;
770 efi_map_start = __va(ia64_boot_param->efi_memmap);
771 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
772 efi_desc_size = ia64_boot_param->efi_memdesc_size;
774 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
777 if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT)) {
778 if (!(md->attribute & EFI_MEMORY_WB))
781 if (*size > md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - phys_addr)
782 *size = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - phys_addr;
790 efi_uart_console_only(void)
793 char *s, name[] = "ConOut";
794 efi_guid_t guid = EFI_GLOBAL_VARIABLE_GUID;
795 efi_char16_t *utf16, name_utf16[32];
796 unsigned char data[1024];
797 unsigned long size = sizeof(data);
798 struct efi_generic_dev_path *hdr, *end_addr;
801 /* Convert to UTF-16 */
805 *utf16++ = *s++ & 0x7f;
808 status = efi.get_variable(name_utf16, &guid, NULL, &size, data);
809 if (status != EFI_SUCCESS) {
810 printk(KERN_ERR "No EFI %s variable?\n", name);
814 hdr = (struct efi_generic_dev_path *) data;
815 end_addr = (struct efi_generic_dev_path *) ((u8 *) data + size);
816 while (hdr < end_addr) {
817 if (hdr->type == EFI_DEV_MSG &&
818 hdr->sub_type == EFI_DEV_MSG_UART)
820 else if (hdr->type == EFI_DEV_END_PATH ||
821 hdr->type == EFI_DEV_END_PATH2) {
824 if (hdr->sub_type == EFI_DEV_END_ENTIRE)
828 hdr = (struct efi_generic_dev_path *) ((u8 *) hdr + hdr->length);
830 printk(KERN_ERR "Malformed %s value\n", name);