enable kexec
[linux-2.6.git] / arch / ia64 / kernel / efi.c
index 13572d1..e1e7d91 100644 (file)
@@ -39,22 +39,24 @@ extern efi_status_t efi_call_phys (void *, ...);
 struct efi efi;
 EXPORT_SYMBOL(efi);
 static efi_runtime_services_t *runtime;
-static unsigned long mem_limit = ~0UL;
+static unsigned long mem_limit = ~0UL, max_addr = ~0UL;
 
 #define efi_call_virt(f, args...)      (*(f))(args)
 
-#define STUB_GET_TIME(prefix, adjust_arg)                                                      \
-static efi_status_t                                                                            \
-prefix##_get_time (efi_time_t *tm, efi_time_cap_t *tc)                                         \
-{                                                                                              \
-       struct ia64_fpreg fr[6];                                                                \
-       efi_status_t ret;                                                                       \
-                                                                                               \
-       ia64_save_scratch_fpregs(fr);                                                           \
-       ret = efi_call_##prefix((efi_get_time_t *) __va(runtime->get_time), adjust_arg(tm),     \
-                               adjust_arg(tc));                                                \
-       ia64_load_scratch_fpregs(fr);                                                           \
-       return ret;                                                                             \
+#define STUB_GET_TIME(prefix, adjust_arg)                                                        \
+static efi_status_t                                                                              \
+prefix##_get_time (efi_time_t *tm, efi_time_cap_t *tc)                                           \
+{                                                                                                \
+       struct ia64_fpreg fr[6];                                                                  \
+       efi_time_cap_t *atc = 0;                                                                  \
+       efi_status_t ret;                                                                         \
+                                                                                                 \
+       if (tc)                                                                                   \
+               atc = adjust_arg(tc);                                                             \
+       ia64_save_scratch_fpregs(fr);                                                             \
+       ret = efi_call_##prefix((efi_get_time_t *) __va(runtime->get_time), adjust_arg(tm), atc); \
+       ia64_load_scratch_fpregs(fr);                                                             \
+       return ret;                                                                               \
 }
 
 #define STUB_SET_TIME(prefix, adjust_arg)                                                      \
@@ -89,11 +91,14 @@ static efi_status_t                                                                         \
 prefix##_set_wakeup_time (efi_bool_t enabled, efi_time_t *tm)                                  \
 {                                                                                              \
        struct ia64_fpreg fr[6];                                                                \
+       efi_time_t *atm = 0;                                                                    \
        efi_status_t ret;                                                                       \
                                                                                                \
+       if (tm)                                                                                 \
+               atm = adjust_arg(tm);                                                           \
        ia64_save_scratch_fpregs(fr);                                                           \
        ret = efi_call_##prefix((efi_set_wakeup_time_t *) __va(runtime->set_wakeup_time),       \
-                               enabled, adjust_arg(tm));                                       \
+                               enabled, atm);                                                  \
        ia64_load_scratch_fpregs(fr);                                                           \
        return ret;                                                                             \
 }
@@ -104,11 +109,14 @@ prefix##_get_variable (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,         \
                       unsigned long *data_size, void *data)                            \
 {                                                                                      \
        struct ia64_fpreg fr[6];                                                        \
+       u32 *aattr = 0;                                                                 \
        efi_status_t ret;                                                               \
                                                                                        \
+       if (attr)                                                                       \
+               aattr = adjust_arg(attr);                                               \
        ia64_save_scratch_fpregs(fr);                                                   \
        ret = efi_call_##prefix((efi_get_variable_t *) __va(runtime->get_variable),     \
-                               adjust_arg(name), adjust_arg(vendor), adjust_arg(attr), \
+                               adjust_arg(name), adjust_arg(vendor), aattr,            \
                                adjust_arg(data_size), adjust_arg(data));               \
        ia64_load_scratch_fpregs(fr);                                                   \
        return ret;                                                                     \
@@ -164,33 +172,41 @@ prefix##_reset_system (int reset_type, efi_status_t status,                       \
                       unsigned long data_size, efi_char16_t *data)             \
 {                                                                              \
        struct ia64_fpreg fr[6];                                                \
+       efi_char16_t *adata = 0;                                                \
+                                                                               \
+       if (data)                                                               \
+               adata = adjust_arg(data);                                       \
                                                                                \
        ia64_save_scratch_fpregs(fr);                                           \
        efi_call_##prefix((efi_reset_system_t *) __va(runtime->reset_system),   \
-                         reset_type, status, data_size, adjust_arg(data));     \
+                         reset_type, status, data_size, adata);                \
        /* should not return, but just in case... */                            \
        ia64_load_scratch_fpregs(fr);                                           \
 }
 
-STUB_GET_TIME(phys, __pa)
-STUB_SET_TIME(phys, __pa)
-STUB_GET_WAKEUP_TIME(phys, __pa)
-STUB_SET_WAKEUP_TIME(phys, __pa)
-STUB_GET_VARIABLE(phys, __pa)
-STUB_GET_NEXT_VARIABLE(phys, __pa)
-STUB_SET_VARIABLE(phys, __pa)
-STUB_GET_NEXT_HIGH_MONO_COUNT(phys, __pa)
-STUB_RESET_SYSTEM(phys, __pa)
-
-STUB_GET_TIME(virt, )
-STUB_SET_TIME(virt, )
-STUB_GET_WAKEUP_TIME(virt, )
-STUB_SET_WAKEUP_TIME(virt, )
-STUB_GET_VARIABLE(virt, )
-STUB_GET_NEXT_VARIABLE(virt, )
-STUB_SET_VARIABLE(virt, )
-STUB_GET_NEXT_HIGH_MONO_COUNT(virt, )
-STUB_RESET_SYSTEM(virt, )
+#define phys_ptr(arg)  ((__typeof__(arg)) ia64_tpa(arg))
+
+STUB_GET_TIME(phys, phys_ptr)
+STUB_SET_TIME(phys, phys_ptr)
+STUB_GET_WAKEUP_TIME(phys, phys_ptr)
+STUB_SET_WAKEUP_TIME(phys, phys_ptr)
+STUB_GET_VARIABLE(phys, phys_ptr)
+STUB_GET_NEXT_VARIABLE(phys, phys_ptr)
+STUB_SET_VARIABLE(phys, phys_ptr)
+STUB_GET_NEXT_HIGH_MONO_COUNT(phys, phys_ptr)
+STUB_RESET_SYSTEM(phys, phys_ptr)
+
+#define id(arg)        arg
+
+STUB_GET_TIME(virt, id)
+STUB_SET_TIME(virt, id)
+STUB_GET_WAKEUP_TIME(virt, id)
+STUB_SET_WAKEUP_TIME(virt, id)
+STUB_GET_VARIABLE(virt, id)
+STUB_GET_NEXT_VARIABLE(virt, id)
+STUB_SET_VARIABLE(virt, id)
+STUB_GET_NEXT_HIGH_MONO_COUNT(virt, id)
+STUB_RESET_SYSTEM(virt, id)
 
 void
 efi_gettimeofday (struct timespec *ts)
@@ -290,6 +306,7 @@ efi_memmap_walk (efi_freemem_callback_t callback, void *arg)
        void *efi_map_start, *efi_map_end, *p, *q;
        efi_memory_desc_t *md, *check_md;
        u64 efi_desc_size, start, end, granule_addr, last_granule_addr, first_non_wb_addr = 0;
+       unsigned long total_mem = 0;
 
        efi_map_start = __va(ia64_boot_param->efi_memmap);
        efi_map_end   = efi_map_start + ia64_boot_param->efi_memmap_size;
@@ -331,12 +348,18 @@ efi_memmap_walk (efi_freemem_callback_t callback, void *arg)
                        trim_top(md, last_granule_addr);
 
                if (is_available_memory(md)) {
-                       if (md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) > mem_limit) {
-                               if (md->phys_addr > mem_limit)
+                       if (md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) > max_addr) {
+                               if (md->phys_addr > max_addr)
                                        continue;
-                               md->num_pages = (mem_limit - md->phys_addr) >> EFI_PAGE_SHIFT;
+                               md->num_pages = (max_addr - md->phys_addr) >> EFI_PAGE_SHIFT;
                        }
 
+                       if (total_mem >= mem_limit)
+                               continue;
+                       total_mem += (md->num_pages << EFI_PAGE_SHIFT);
+                       if (total_mem > mem_limit)
+                               md->num_pages -= ((total_mem - mem_limit) >> EFI_PAGE_SHIFT);
+
                        if (md->num_pages == 0)
                                continue;
 
@@ -470,7 +493,13 @@ efi_init (void)
        for (cp = saved_command_line; *cp; ) {
                if (memcmp(cp, "mem=", 4) == 0) {
                        cp += 4;
-                       mem_limit = memparse(cp, &end) - 1;
+                       mem_limit = memparse(cp, &end) - 2;
+                       if (end != cp)
+                               break;
+                       cp = end;
+               } else if (memcmp(cp, "max_addr=", 9) == 0) {
+                       cp += 9;
+                       max_addr = memparse(cp, &end) - 1;
                        if (end != cp)
                                break;
                        cp = end;
@@ -481,8 +510,8 @@ efi_init (void)
                                ++cp;
                }
        }
-       if (mem_limit != ~0UL)
-               printk(KERN_INFO "Ignoring memory above %luMB\n", mem_limit >> 20);
+       if (max_addr != ~0UL)
+               printk(KERN_INFO "Ignoring memory above %luMB\n", max_addr >> 20);
 
        efi.systab = __va(ia64_boot_param->efi_systab);