Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Extensible Firmware Interface |
| 3 | * |
| 4 | * Based on Extensible Firmware Interface Specification version 0.9 April 30, 1999 |
| 5 | * |
| 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> |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 11 | * (c) Copyright 2006 Hewlett-Packard Development Company, L.P. |
| 12 | * Bjorn Helgaas <bjorn.helgaas@hp.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
| 14 | * All EFI Runtime Services are not implemented yet as EFI only |
| 15 | * supports physical mode addressing on SoftSDV. This is to be fixed |
| 16 | * in a future version. --drummond 1999-07-20 |
| 17 | * |
| 18 | * Implemented EFI runtime services and virtual mode calls. --davidm |
| 19 | * |
| 20 | * Goutham Rao: <goutham.rao@intel.com> |
| 21 | * Skip non-WB memory and ignore empty memory ranges. |
| 22 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/module.h> |
Horms | f4a5709 | 2007-03-06 02:34:21 -0800 | [diff] [blame] | 24 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/kernel.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/time.h> |
| 29 | #include <linux/efi.h> |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 30 | #include <linux/kexec.h> |
Mel Gorman | ed7ed36 | 2007-07-17 04:03:14 -0700 | [diff] [blame] | 31 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | #include <asm/io.h> |
| 34 | #include <asm/kregs.h> |
| 35 | #include <asm/meminit.h> |
| 36 | #include <asm/pgtable.h> |
| 37 | #include <asm/processor.h> |
| 38 | #include <asm/mca.h> |
| 39 | |
| 40 | #define EFI_DEBUG 0 |
| 41 | |
| 42 | extern efi_status_t efi_call_phys (void *, ...); |
| 43 | |
| 44 | struct efi efi; |
| 45 | EXPORT_SYMBOL(efi); |
| 46 | static efi_runtime_services_t *runtime; |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 47 | static unsigned long mem_limit = ~0UL, max_addr = ~0UL, min_addr = 0UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define efi_call_virt(f, args...) (*(f))(args) |
| 50 | |
| 51 | #define STUB_GET_TIME(prefix, adjust_arg) \ |
| 52 | static efi_status_t \ |
| 53 | prefix##_get_time (efi_time_t *tm, efi_time_cap_t *tc) \ |
| 54 | { \ |
| 55 | struct ia64_fpreg fr[6]; \ |
| 56 | efi_time_cap_t *atc = NULL; \ |
| 57 | efi_status_t ret; \ |
| 58 | \ |
| 59 | if (tc) \ |
| 60 | atc = adjust_arg(tc); \ |
| 61 | ia64_save_scratch_fpregs(fr); \ |
| 62 | ret = efi_call_##prefix((efi_get_time_t *) __va(runtime->get_time), adjust_arg(tm), atc); \ |
| 63 | ia64_load_scratch_fpregs(fr); \ |
| 64 | return ret; \ |
| 65 | } |
| 66 | |
| 67 | #define STUB_SET_TIME(prefix, adjust_arg) \ |
| 68 | static efi_status_t \ |
| 69 | prefix##_set_time (efi_time_t *tm) \ |
| 70 | { \ |
| 71 | struct ia64_fpreg fr[6]; \ |
| 72 | efi_status_t ret; \ |
| 73 | \ |
| 74 | ia64_save_scratch_fpregs(fr); \ |
| 75 | ret = efi_call_##prefix((efi_set_time_t *) __va(runtime->set_time), adjust_arg(tm)); \ |
| 76 | ia64_load_scratch_fpregs(fr); \ |
| 77 | return ret; \ |
| 78 | } |
| 79 | |
| 80 | #define STUB_GET_WAKEUP_TIME(prefix, adjust_arg) \ |
| 81 | static efi_status_t \ |
| 82 | prefix##_get_wakeup_time (efi_bool_t *enabled, efi_bool_t *pending, efi_time_t *tm) \ |
| 83 | { \ |
| 84 | struct ia64_fpreg fr[6]; \ |
| 85 | efi_status_t ret; \ |
| 86 | \ |
| 87 | ia64_save_scratch_fpregs(fr); \ |
| 88 | ret = efi_call_##prefix((efi_get_wakeup_time_t *) __va(runtime->get_wakeup_time), \ |
| 89 | adjust_arg(enabled), adjust_arg(pending), adjust_arg(tm)); \ |
| 90 | ia64_load_scratch_fpregs(fr); \ |
| 91 | return ret; \ |
| 92 | } |
| 93 | |
| 94 | #define STUB_SET_WAKEUP_TIME(prefix, adjust_arg) \ |
| 95 | static efi_status_t \ |
| 96 | prefix##_set_wakeup_time (efi_bool_t enabled, efi_time_t *tm) \ |
| 97 | { \ |
| 98 | struct ia64_fpreg fr[6]; \ |
| 99 | efi_time_t *atm = NULL; \ |
| 100 | efi_status_t ret; \ |
| 101 | \ |
| 102 | if (tm) \ |
| 103 | atm = adjust_arg(tm); \ |
| 104 | ia64_save_scratch_fpregs(fr); \ |
| 105 | ret = efi_call_##prefix((efi_set_wakeup_time_t *) __va(runtime->set_wakeup_time), \ |
| 106 | enabled, atm); \ |
| 107 | ia64_load_scratch_fpregs(fr); \ |
| 108 | return ret; \ |
| 109 | } |
| 110 | |
| 111 | #define STUB_GET_VARIABLE(prefix, adjust_arg) \ |
| 112 | static efi_status_t \ |
| 113 | prefix##_get_variable (efi_char16_t *name, efi_guid_t *vendor, u32 *attr, \ |
| 114 | unsigned long *data_size, void *data) \ |
| 115 | { \ |
| 116 | struct ia64_fpreg fr[6]; \ |
| 117 | u32 *aattr = NULL; \ |
| 118 | efi_status_t ret; \ |
| 119 | \ |
| 120 | if (attr) \ |
| 121 | aattr = adjust_arg(attr); \ |
| 122 | ia64_save_scratch_fpregs(fr); \ |
| 123 | ret = efi_call_##prefix((efi_get_variable_t *) __va(runtime->get_variable), \ |
| 124 | adjust_arg(name), adjust_arg(vendor), aattr, \ |
| 125 | adjust_arg(data_size), adjust_arg(data)); \ |
| 126 | ia64_load_scratch_fpregs(fr); \ |
| 127 | return ret; \ |
| 128 | } |
| 129 | |
| 130 | #define STUB_GET_NEXT_VARIABLE(prefix, adjust_arg) \ |
| 131 | static efi_status_t \ |
| 132 | prefix##_get_next_variable (unsigned long *name_size, efi_char16_t *name, efi_guid_t *vendor) \ |
| 133 | { \ |
| 134 | struct ia64_fpreg fr[6]; \ |
| 135 | efi_status_t ret; \ |
| 136 | \ |
| 137 | ia64_save_scratch_fpregs(fr); \ |
| 138 | ret = efi_call_##prefix((efi_get_next_variable_t *) __va(runtime->get_next_variable), \ |
| 139 | adjust_arg(name_size), adjust_arg(name), adjust_arg(vendor)); \ |
| 140 | ia64_load_scratch_fpregs(fr); \ |
| 141 | return ret; \ |
| 142 | } |
| 143 | |
| 144 | #define STUB_SET_VARIABLE(prefix, adjust_arg) \ |
| 145 | static efi_status_t \ |
| 146 | prefix##_set_variable (efi_char16_t *name, efi_guid_t *vendor, unsigned long attr, \ |
| 147 | unsigned long data_size, void *data) \ |
| 148 | { \ |
| 149 | struct ia64_fpreg fr[6]; \ |
| 150 | efi_status_t ret; \ |
| 151 | \ |
| 152 | ia64_save_scratch_fpregs(fr); \ |
| 153 | ret = efi_call_##prefix((efi_set_variable_t *) __va(runtime->set_variable), \ |
| 154 | adjust_arg(name), adjust_arg(vendor), attr, data_size, \ |
| 155 | adjust_arg(data)); \ |
| 156 | ia64_load_scratch_fpregs(fr); \ |
| 157 | return ret; \ |
| 158 | } |
| 159 | |
| 160 | #define STUB_GET_NEXT_HIGH_MONO_COUNT(prefix, adjust_arg) \ |
| 161 | static efi_status_t \ |
| 162 | prefix##_get_next_high_mono_count (u32 *count) \ |
| 163 | { \ |
| 164 | struct ia64_fpreg fr[6]; \ |
| 165 | efi_status_t ret; \ |
| 166 | \ |
| 167 | ia64_save_scratch_fpregs(fr); \ |
| 168 | ret = efi_call_##prefix((efi_get_next_high_mono_count_t *) \ |
| 169 | __va(runtime->get_next_high_mono_count), adjust_arg(count)); \ |
| 170 | ia64_load_scratch_fpregs(fr); \ |
| 171 | return ret; \ |
| 172 | } |
| 173 | |
| 174 | #define STUB_RESET_SYSTEM(prefix, adjust_arg) \ |
| 175 | static void \ |
| 176 | prefix##_reset_system (int reset_type, efi_status_t status, \ |
| 177 | unsigned long data_size, efi_char16_t *data) \ |
| 178 | { \ |
| 179 | struct ia64_fpreg fr[6]; \ |
| 180 | efi_char16_t *adata = NULL; \ |
| 181 | \ |
| 182 | if (data) \ |
| 183 | adata = adjust_arg(data); \ |
| 184 | \ |
| 185 | ia64_save_scratch_fpregs(fr); \ |
| 186 | efi_call_##prefix((efi_reset_system_t *) __va(runtime->reset_system), \ |
| 187 | reset_type, status, data_size, adata); \ |
| 188 | /* should not return, but just in case... */ \ |
| 189 | ia64_load_scratch_fpregs(fr); \ |
| 190 | } |
| 191 | |
| 192 | #define phys_ptr(arg) ((__typeof__(arg)) ia64_tpa(arg)) |
| 193 | |
| 194 | STUB_GET_TIME(phys, phys_ptr) |
| 195 | STUB_SET_TIME(phys, phys_ptr) |
| 196 | STUB_GET_WAKEUP_TIME(phys, phys_ptr) |
| 197 | STUB_SET_WAKEUP_TIME(phys, phys_ptr) |
| 198 | STUB_GET_VARIABLE(phys, phys_ptr) |
| 199 | STUB_GET_NEXT_VARIABLE(phys, phys_ptr) |
| 200 | STUB_SET_VARIABLE(phys, phys_ptr) |
| 201 | STUB_GET_NEXT_HIGH_MONO_COUNT(phys, phys_ptr) |
| 202 | STUB_RESET_SYSTEM(phys, phys_ptr) |
| 203 | |
| 204 | #define id(arg) arg |
| 205 | |
| 206 | STUB_GET_TIME(virt, id) |
| 207 | STUB_SET_TIME(virt, id) |
| 208 | STUB_GET_WAKEUP_TIME(virt, id) |
| 209 | STUB_SET_WAKEUP_TIME(virt, id) |
| 210 | STUB_GET_VARIABLE(virt, id) |
| 211 | STUB_GET_NEXT_VARIABLE(virt, id) |
| 212 | STUB_SET_VARIABLE(virt, id) |
| 213 | STUB_GET_NEXT_HIGH_MONO_COUNT(virt, id) |
| 214 | STUB_RESET_SYSTEM(virt, id) |
| 215 | |
| 216 | void |
| 217 | efi_gettimeofday (struct timespec *ts) |
| 218 | { |
| 219 | efi_time_t tm; |
| 220 | |
Li Zefan | 4b07ae9 | 2007-11-06 13:40:39 -0800 | [diff] [blame] | 221 | if ((*efi.get_time)(&tm, NULL) != EFI_SUCCESS) { |
| 222 | memset(ts, 0, sizeof(*ts)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | return; |
Li Zefan | 4b07ae9 | 2007-11-06 13:40:39 -0800 | [diff] [blame] | 224 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | ts->tv_sec = mktime(tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second); |
| 227 | ts->tv_nsec = tm.nanosecond; |
| 228 | } |
| 229 | |
| 230 | static int |
Christoph Lameter | 66888a6 | 2006-12-04 14:58:35 -0800 | [diff] [blame] | 231 | is_memory_available (efi_memory_desc_t *md) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
| 233 | if (!(md->attribute & EFI_MEMORY_WB)) |
| 234 | return 0; |
| 235 | |
| 236 | switch (md->type) { |
| 237 | case EFI_LOADER_CODE: |
| 238 | case EFI_LOADER_DATA: |
| 239 | case EFI_BOOT_SERVICES_CODE: |
| 240 | case EFI_BOOT_SERVICES_DATA: |
| 241 | case EFI_CONVENTIONAL_MEMORY: |
| 242 | return 1; |
| 243 | } |
| 244 | return 0; |
| 245 | } |
| 246 | |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 247 | typedef struct kern_memdesc { |
| 248 | u64 attribute; |
| 249 | u64 start; |
| 250 | u64 num_pages; |
| 251 | } kern_memdesc_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 253 | static kern_memdesc_t *kern_memmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 255 | #define efi_md_size(md) (md->num_pages << EFI_PAGE_SHIFT) |
| 256 | |
| 257 | static inline u64 |
| 258 | kmd_end(kern_memdesc_t *kmd) |
| 259 | { |
| 260 | return (kmd->start + (kmd->num_pages << EFI_PAGE_SHIFT)); |
| 261 | } |
| 262 | |
| 263 | static inline u64 |
| 264 | efi_md_end(efi_memory_desc_t *md) |
| 265 | { |
| 266 | return (md->phys_addr + efi_md_size(md)); |
| 267 | } |
| 268 | |
| 269 | static inline int |
| 270 | efi_wb(efi_memory_desc_t *md) |
| 271 | { |
| 272 | return (md->attribute & EFI_MEMORY_WB); |
| 273 | } |
| 274 | |
| 275 | static inline int |
| 276 | efi_uc(efi_memory_desc_t *md) |
| 277 | { |
| 278 | return (md->attribute & EFI_MEMORY_UC); |
| 279 | } |
| 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | static void |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 282 | walk (efi_freemem_callback_t callback, void *arg, u64 attr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 284 | kern_memdesc_t *k; |
| 285 | u64 start, end, voff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 287 | voff = (attr == EFI_MEMORY_WB) ? PAGE_OFFSET : __IA64_UNCACHED_OFFSET; |
| 288 | for (k = kern_memmap; k->start != ~0UL; k++) { |
| 289 | if (k->attribute != attr) |
| 290 | continue; |
| 291 | start = PAGE_ALIGN(k->start); |
| 292 | end = (k->start + (k->num_pages << EFI_PAGE_SHIFT)) & PAGE_MASK; |
| 293 | if (start < end) |
| 294 | if ((*callback)(start + voff, end + voff, arg) < 0) |
| 295 | return; |
| 296 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /* |
| 300 | * Walks the EFI memory map and calls CALLBACK once for each EFI memory descriptor that |
| 301 | * has memory that is available for OS use. |
| 302 | */ |
| 303 | void |
| 304 | efi_memmap_walk (efi_freemem_callback_t callback, void *arg) |
| 305 | { |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 306 | walk(callback, arg, EFI_MEMORY_WB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | /* |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 310 | * Walks the EFI memory map and calls CALLBACK once for each EFI memory descriptor that |
| 311 | * has memory that is available for uncached allocator. |
Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 312 | */ |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 313 | void |
| 314 | efi_memmap_walk_uc (efi_freemem_callback_t callback, void *arg) |
Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 315 | { |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 316 | walk(callback, arg, EFI_MEMORY_UC); |
Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 319 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | * Look for the PAL_CODE region reported by EFI and maps it using an |
| 321 | * ITR to enable safe PAL calls in virtual mode. See IA-64 Processor |
| 322 | * Abstraction Layer chapter 11 in ADAG |
| 323 | */ |
| 324 | |
| 325 | void * |
| 326 | efi_get_pal_addr (void) |
| 327 | { |
| 328 | void *efi_map_start, *efi_map_end, *p; |
| 329 | efi_memory_desc_t *md; |
| 330 | u64 efi_desc_size; |
| 331 | int pal_code_count = 0; |
| 332 | u64 vaddr, mask; |
| 333 | |
| 334 | efi_map_start = __va(ia64_boot_param->efi_memmap); |
| 335 | efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size; |
| 336 | efi_desc_size = ia64_boot_param->efi_memdesc_size; |
| 337 | |
| 338 | for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) { |
| 339 | md = p; |
| 340 | if (md->type != EFI_PAL_CODE) |
| 341 | continue; |
| 342 | |
| 343 | if (++pal_code_count > 1) { |
| 344 | printk(KERN_ERR "Too many EFI Pal Code memory ranges, dropped @ %lx\n", |
| 345 | md->phys_addr); |
| 346 | continue; |
| 347 | } |
| 348 | /* |
| 349 | * The only ITLB entry in region 7 that is used is the one installed by |
| 350 | * __start(). That entry covers a 64MB range. |
| 351 | */ |
| 352 | mask = ~((1 << KERNEL_TR_PAGE_SHIFT) - 1); |
| 353 | vaddr = PAGE_OFFSET + md->phys_addr; |
| 354 | |
| 355 | /* |
| 356 | * We must check that the PAL mapping won't overlap with the kernel |
| 357 | * mapping. |
| 358 | * |
| 359 | * PAL code is guaranteed to be aligned on a power of 2 between 4k and |
| 360 | * 256KB and that only one ITR is needed to map it. This implies that the |
| 361 | * PAL code is always aligned on its size, i.e., the closest matching page |
| 362 | * size supported by the TLB. Therefore PAL code is guaranteed never to |
| 363 | * cross a 64MB unless it is bigger than 64MB (very unlikely!). So for |
| 364 | * now the following test is enough to determine whether or not we need a |
| 365 | * dedicated ITR for the PAL code. |
| 366 | */ |
| 367 | if ((vaddr & mask) == (KERNEL_START & mask)) { |
| 368 | printk(KERN_INFO "%s: no need to install ITR for PAL code\n", |
| 369 | __FUNCTION__); |
| 370 | continue; |
| 371 | } |
| 372 | |
| 373 | if (md->num_pages << EFI_PAGE_SHIFT > IA64_GRANULE_SIZE) |
| 374 | panic("Woah! PAL code size bigger than a granule!"); |
| 375 | |
| 376 | #if EFI_DEBUG |
| 377 | mask = ~((1 << IA64_GRANULE_SHIFT) - 1); |
| 378 | |
| 379 | printk(KERN_INFO "CPU %d: mapping PAL code [0x%lx-0x%lx) into [0x%lx-0x%lx)\n", |
| 380 | smp_processor_id(), md->phys_addr, |
| 381 | md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT), |
| 382 | vaddr & mask, (vaddr & mask) + IA64_GRANULE_SIZE); |
| 383 | #endif |
| 384 | return __va(md->phys_addr); |
| 385 | } |
Horms | 9473252 | 2007-02-05 10:17:38 +0900 | [diff] [blame] | 386 | printk(KERN_WARNING "%s: no PAL-code memory-descriptor found\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | __FUNCTION__); |
| 388 | return NULL; |
| 389 | } |
| 390 | |
| 391 | void |
| 392 | efi_map_pal_code (void) |
| 393 | { |
| 394 | void *pal_vaddr = efi_get_pal_addr (); |
| 395 | u64 psr; |
| 396 | |
| 397 | if (!pal_vaddr) |
| 398 | return; |
| 399 | |
| 400 | /* |
| 401 | * Cannot write to CRx with PSR.ic=1 |
| 402 | */ |
| 403 | psr = ia64_clear_ic(); |
| 404 | ia64_itr(0x1, IA64_TR_PALCODE, GRANULEROUNDDOWN((unsigned long) pal_vaddr), |
| 405 | pte_val(pfn_pte(__pa(pal_vaddr) >> PAGE_SHIFT, PAGE_KERNEL)), |
| 406 | IA64_GRANULE_SHIFT); |
| 407 | ia64_set_psr(psr); /* restore psr */ |
| 408 | ia64_srlz_i(); |
| 409 | } |
| 410 | |
| 411 | void __init |
| 412 | efi_init (void) |
| 413 | { |
| 414 | void *efi_map_start, *efi_map_end; |
| 415 | efi_config_table_t *config_tables; |
| 416 | efi_char16_t *c16; |
| 417 | u64 efi_desc_size; |
Zou Nan hai | 9d78f43 | 2006-02-07 11:35:46 +0800 | [diff] [blame] | 418 | char *cp, vendor[100] = "unknown"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | int i; |
| 420 | |
| 421 | /* it's too early to be able to use the standard kernel command line support... */ |
Alon Bar-Lev | a8d91b8 | 2007-02-12 00:54:12 -0800 | [diff] [blame] | 422 | for (cp = boot_command_line; *cp; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | if (memcmp(cp, "mem=", 4) == 0) { |
Zou Nan hai | 9d78f43 | 2006-02-07 11:35:46 +0800 | [diff] [blame] | 424 | mem_limit = memparse(cp + 4, &cp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } else if (memcmp(cp, "max_addr=", 9) == 0) { |
Zou Nan hai | 9d78f43 | 2006-02-07 11:35:46 +0800 | [diff] [blame] | 426 | max_addr = GRANULEROUNDDOWN(memparse(cp + 9, &cp)); |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 427 | } else if (memcmp(cp, "min_addr=", 9) == 0) { |
| 428 | min_addr = GRANULEROUNDDOWN(memparse(cp + 9, &cp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } else { |
| 430 | while (*cp != ' ' && *cp) |
| 431 | ++cp; |
| 432 | while (*cp == ' ') |
| 433 | ++cp; |
| 434 | } |
| 435 | } |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 436 | if (min_addr != 0UL) |
| 437 | printk(KERN_INFO "Ignoring memory below %luMB\n", min_addr >> 20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | if (max_addr != ~0UL) |
| 439 | printk(KERN_INFO "Ignoring memory above %luMB\n", max_addr >> 20); |
| 440 | |
| 441 | efi.systab = __va(ia64_boot_param->efi_systab); |
| 442 | |
| 443 | /* |
| 444 | * Verify the EFI Table |
| 445 | */ |
| 446 | if (efi.systab == NULL) |
| 447 | panic("Woah! Can't find EFI system table.\n"); |
| 448 | if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) |
| 449 | panic("Woah! EFI system table signature incorrect\n"); |
Bjorn Helgaas | 873ec74 | 2007-05-08 00:29:57 -0700 | [diff] [blame] | 450 | if ((efi.systab->hdr.revision >> 16) == 0) |
| 451 | printk(KERN_WARNING "Warning: EFI system table version " |
| 452 | "%d.%02d, expected 1.00 or greater\n", |
| 453 | efi.systab->hdr.revision >> 16, |
| 454 | efi.systab->hdr.revision & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | config_tables = __va(efi.systab->tables); |
| 457 | |
| 458 | /* Show what we know for posterity */ |
| 459 | c16 = __va(efi.systab->fw_vendor); |
| 460 | if (c16) { |
Zou Nan hai | ecdd5da | 2006-02-07 11:25:55 +0800 | [diff] [blame] | 461 | for (i = 0;i < (int) sizeof(vendor) - 1 && *c16; ++i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | vendor[i] = *c16++; |
| 463 | vendor[i] = '\0'; |
| 464 | } |
| 465 | |
| 466 | printk(KERN_INFO "EFI v%u.%.02u by %s:", |
| 467 | efi.systab->hdr.revision >> 16, efi.systab->hdr.revision & 0xffff, vendor); |
| 468 | |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 469 | efi.mps = EFI_INVALID_TABLE_ADDR; |
| 470 | efi.acpi = EFI_INVALID_TABLE_ADDR; |
| 471 | efi.acpi20 = EFI_INVALID_TABLE_ADDR; |
| 472 | efi.smbios = EFI_INVALID_TABLE_ADDR; |
| 473 | efi.sal_systab = EFI_INVALID_TABLE_ADDR; |
| 474 | efi.boot_info = EFI_INVALID_TABLE_ADDR; |
| 475 | efi.hcdp = EFI_INVALID_TABLE_ADDR; |
| 476 | efi.uga = EFI_INVALID_TABLE_ADDR; |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | for (i = 0; i < (int) efi.systab->nr_tables; i++) { |
| 479 | if (efi_guidcmp(config_tables[i].guid, MPS_TABLE_GUID) == 0) { |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 480 | efi.mps = config_tables[i].table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | printk(" MPS=0x%lx", config_tables[i].table); |
| 482 | } else if (efi_guidcmp(config_tables[i].guid, ACPI_20_TABLE_GUID) == 0) { |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 483 | efi.acpi20 = config_tables[i].table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | printk(" ACPI 2.0=0x%lx", config_tables[i].table); |
| 485 | } else if (efi_guidcmp(config_tables[i].guid, ACPI_TABLE_GUID) == 0) { |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 486 | efi.acpi = config_tables[i].table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | printk(" ACPI=0x%lx", config_tables[i].table); |
| 488 | } else if (efi_guidcmp(config_tables[i].guid, SMBIOS_TABLE_GUID) == 0) { |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 489 | efi.smbios = config_tables[i].table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | printk(" SMBIOS=0x%lx", config_tables[i].table); |
| 491 | } else if (efi_guidcmp(config_tables[i].guid, SAL_SYSTEM_TABLE_GUID) == 0) { |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 492 | efi.sal_systab = config_tables[i].table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | printk(" SALsystab=0x%lx", config_tables[i].table); |
| 494 | } else if (efi_guidcmp(config_tables[i].guid, HCDP_TABLE_GUID) == 0) { |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 495 | efi.hcdp = config_tables[i].table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | printk(" HCDP=0x%lx", config_tables[i].table); |
| 497 | } |
| 498 | } |
| 499 | printk("\n"); |
| 500 | |
| 501 | runtime = __va(efi.systab->runtime); |
| 502 | efi.get_time = phys_get_time; |
| 503 | efi.set_time = phys_set_time; |
| 504 | efi.get_wakeup_time = phys_get_wakeup_time; |
| 505 | efi.set_wakeup_time = phys_set_wakeup_time; |
| 506 | efi.get_variable = phys_get_variable; |
| 507 | efi.get_next_variable = phys_get_next_variable; |
| 508 | efi.set_variable = phys_set_variable; |
| 509 | efi.get_next_high_mono_count = phys_get_next_high_mono_count; |
| 510 | efi.reset_system = phys_reset_system; |
| 511 | |
| 512 | efi_map_start = __va(ia64_boot_param->efi_memmap); |
| 513 | efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size; |
| 514 | efi_desc_size = ia64_boot_param->efi_memdesc_size; |
| 515 | |
| 516 | #if EFI_DEBUG |
| 517 | /* print EFI memory map: */ |
| 518 | { |
| 519 | efi_memory_desc_t *md; |
| 520 | void *p; |
| 521 | |
| 522 | for (i = 0, p = efi_map_start; p < efi_map_end; ++i, p += efi_desc_size) { |
| 523 | md = p; |
| 524 | printk("mem%02u: type=%u, attr=0x%lx, range=[0x%016lx-0x%016lx) (%luMB)\n", |
| 525 | i, md->type, md->attribute, md->phys_addr, |
| 526 | md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT), |
| 527 | md->num_pages >> (20 - EFI_PAGE_SHIFT)); |
| 528 | } |
| 529 | } |
| 530 | #endif |
| 531 | |
| 532 | efi_map_pal_code(); |
| 533 | efi_enter_virtual_mode(); |
| 534 | } |
| 535 | |
| 536 | void |
| 537 | efi_enter_virtual_mode (void) |
| 538 | { |
| 539 | void *efi_map_start, *efi_map_end, *p; |
| 540 | efi_memory_desc_t *md; |
| 541 | efi_status_t status; |
| 542 | u64 efi_desc_size; |
| 543 | |
| 544 | efi_map_start = __va(ia64_boot_param->efi_memmap); |
| 545 | efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size; |
| 546 | efi_desc_size = ia64_boot_param->efi_memdesc_size; |
| 547 | |
| 548 | for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) { |
| 549 | md = p; |
| 550 | if (md->attribute & EFI_MEMORY_RUNTIME) { |
| 551 | /* |
| 552 | * Some descriptors have multiple bits set, so the order of |
| 553 | * the tests is relevant. |
| 554 | */ |
| 555 | if (md->attribute & EFI_MEMORY_WB) { |
| 556 | md->virt_addr = (u64) __va(md->phys_addr); |
| 557 | } else if (md->attribute & EFI_MEMORY_UC) { |
| 558 | md->virt_addr = (u64) ioremap(md->phys_addr, 0); |
| 559 | } else if (md->attribute & EFI_MEMORY_WC) { |
| 560 | #if 0 |
| 561 | md->virt_addr = ia64_remap(md->phys_addr, (_PAGE_A | _PAGE_P |
| 562 | | _PAGE_D |
| 563 | | _PAGE_MA_WC |
| 564 | | _PAGE_PL_0 |
| 565 | | _PAGE_AR_RW)); |
| 566 | #else |
| 567 | printk(KERN_INFO "EFI_MEMORY_WC mapping\n"); |
| 568 | md->virt_addr = (u64) ioremap(md->phys_addr, 0); |
| 569 | #endif |
| 570 | } else if (md->attribute & EFI_MEMORY_WT) { |
| 571 | #if 0 |
| 572 | md->virt_addr = ia64_remap(md->phys_addr, (_PAGE_A | _PAGE_P |
| 573 | | _PAGE_D | _PAGE_MA_WT |
| 574 | | _PAGE_PL_0 |
| 575 | | _PAGE_AR_RW)); |
| 576 | #else |
| 577 | printk(KERN_INFO "EFI_MEMORY_WT mapping\n"); |
| 578 | md->virt_addr = (u64) ioremap(md->phys_addr, 0); |
| 579 | #endif |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | status = efi_call_phys(__va(runtime->set_virtual_address_map), |
| 585 | ia64_boot_param->efi_memmap_size, |
| 586 | efi_desc_size, ia64_boot_param->efi_memdesc_version, |
| 587 | ia64_boot_param->efi_memmap); |
| 588 | if (status != EFI_SUCCESS) { |
| 589 | printk(KERN_WARNING "warning: unable to switch EFI into virtual mode " |
| 590 | "(status=%lu)\n", status); |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * Now that EFI is in virtual mode, we call the EFI functions more efficiently: |
| 596 | */ |
| 597 | efi.get_time = virt_get_time; |
| 598 | efi.set_time = virt_set_time; |
| 599 | efi.get_wakeup_time = virt_get_wakeup_time; |
| 600 | efi.set_wakeup_time = virt_set_wakeup_time; |
| 601 | efi.get_variable = virt_get_variable; |
| 602 | efi.get_next_variable = virt_get_next_variable; |
| 603 | efi.set_variable = virt_set_variable; |
| 604 | efi.get_next_high_mono_count = virt_get_next_high_mono_count; |
| 605 | efi.reset_system = virt_reset_system; |
| 606 | } |
| 607 | |
| 608 | /* |
| 609 | * Walk the EFI memory map looking for the I/O port range. There can only be one entry of |
| 610 | * this type, other I/O port ranges should be described via ACPI. |
| 611 | */ |
| 612 | u64 |
| 613 | efi_get_iobase (void) |
| 614 | { |
| 615 | void *efi_map_start, *efi_map_end, *p; |
| 616 | efi_memory_desc_t *md; |
| 617 | u64 efi_desc_size; |
| 618 | |
| 619 | efi_map_start = __va(ia64_boot_param->efi_memmap); |
| 620 | efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size; |
| 621 | efi_desc_size = ia64_boot_param->efi_memdesc_size; |
| 622 | |
| 623 | for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) { |
| 624 | md = p; |
| 625 | if (md->type == EFI_MEMORY_MAPPED_IO_PORT_SPACE) { |
| 626 | if (md->attribute & EFI_MEMORY_UC) |
| 627 | return md->phys_addr; |
| 628 | } |
| 629 | } |
| 630 | return 0; |
| 631 | } |
| 632 | |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 633 | static struct kern_memdesc * |
| 634 | kern_memory_descriptor (unsigned long phys_addr) |
| 635 | { |
| 636 | struct kern_memdesc *md; |
| 637 | |
| 638 | for (md = kern_memmap; md->start != ~0UL; md++) { |
| 639 | if (phys_addr - md->start < (md->num_pages << EFI_PAGE_SHIFT)) |
| 640 | return md; |
| 641 | } |
Keith Owens | e037cda | 2006-07-17 15:41:59 +1000 | [diff] [blame] | 642 | return NULL; |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 643 | } |
| 644 | |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 645 | static efi_memory_desc_t * |
| 646 | efi_memory_descriptor (unsigned long phys_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
| 648 | void *efi_map_start, *efi_map_end, *p; |
| 649 | efi_memory_desc_t *md; |
| 650 | u64 efi_desc_size; |
| 651 | |
| 652 | efi_map_start = __va(ia64_boot_param->efi_memmap); |
| 653 | efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size; |
| 654 | efi_desc_size = ia64_boot_param->efi_memdesc_size; |
| 655 | |
| 656 | for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) { |
| 657 | md = p; |
| 658 | |
| 659 | if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT)) |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 660 | return md; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
Keith Owens | e037cda | 2006-07-17 15:41:59 +1000 | [diff] [blame] | 662 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Bjorn Helgaas | 6d40fc5 | 2007-03-30 10:35:43 -0600 | [diff] [blame] | 665 | static int |
| 666 | efi_memmap_intersects (unsigned long phys_addr, unsigned long size) |
| 667 | { |
| 668 | void *efi_map_start, *efi_map_end, *p; |
| 669 | efi_memory_desc_t *md; |
| 670 | u64 efi_desc_size; |
| 671 | unsigned long end; |
| 672 | |
| 673 | efi_map_start = __va(ia64_boot_param->efi_memmap); |
| 674 | efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size; |
| 675 | efi_desc_size = ia64_boot_param->efi_memdesc_size; |
| 676 | |
| 677 | end = phys_addr + size; |
| 678 | |
| 679 | for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) { |
| 680 | md = p; |
| 681 | |
| 682 | if (md->phys_addr < end && efi_md_end(md) > phys_addr) |
| 683 | return 1; |
| 684 | } |
| 685 | return 0; |
| 686 | } |
| 687 | |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 688 | u32 |
| 689 | efi_mem_type (unsigned long phys_addr) |
| 690 | { |
| 691 | efi_memory_desc_t *md = efi_memory_descriptor(phys_addr); |
| 692 | |
| 693 | if (md) |
| 694 | return md->type; |
| 695 | return 0; |
| 696 | } |
| 697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | u64 |
| 699 | efi_mem_attributes (unsigned long phys_addr) |
| 700 | { |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 701 | efi_memory_desc_t *md = efi_memory_descriptor(phys_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 703 | if (md) |
| 704 | return md->attribute; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | return 0; |
| 706 | } |
| 707 | EXPORT_SYMBOL(efi_mem_attributes); |
| 708 | |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 709 | u64 |
| 710 | efi_mem_attribute (unsigned long phys_addr, unsigned long size) |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 711 | { |
Bjorn Helgaas | 136939a | 2006-03-26 01:37:05 -0800 | [diff] [blame] | 712 | unsigned long end = phys_addr + size; |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 713 | efi_memory_desc_t *md = efi_memory_descriptor(phys_addr); |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 714 | u64 attr; |
| 715 | |
| 716 | if (!md) |
| 717 | return 0; |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 718 | |
Bjorn Helgaas | 136939a | 2006-03-26 01:37:05 -0800 | [diff] [blame] | 719 | /* |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 720 | * EFI_MEMORY_RUNTIME is not a memory attribute; it just tells |
| 721 | * the kernel that firmware needs this region mapped. |
Bjorn Helgaas | 136939a | 2006-03-26 01:37:05 -0800 | [diff] [blame] | 722 | */ |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 723 | attr = md->attribute & ~EFI_MEMORY_RUNTIME; |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 724 | do { |
Bjorn Helgaas | 136939a | 2006-03-26 01:37:05 -0800 | [diff] [blame] | 725 | unsigned long md_end = efi_md_end(md); |
| 726 | |
| 727 | if (end <= md_end) |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 728 | return attr; |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 729 | |
| 730 | md = efi_memory_descriptor(md_end); |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 731 | if (!md || (md->attribute & ~EFI_MEMORY_RUNTIME) != attr) |
Bjorn Helgaas | 136939a | 2006-03-26 01:37:05 -0800 | [diff] [blame] | 732 | return 0; |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 733 | } while (md); |
| 734 | return 0; |
| 735 | } |
| 736 | |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 737 | u64 |
| 738 | kern_mem_attribute (unsigned long phys_addr, unsigned long size) |
| 739 | { |
| 740 | unsigned long end = phys_addr + size; |
| 741 | struct kern_memdesc *md; |
| 742 | u64 attr; |
| 743 | |
| 744 | /* |
| 745 | * This is a hack for ioremap calls before we set up kern_memmap. |
| 746 | * Maybe we should do efi_memmap_init() earlier instead. |
| 747 | */ |
| 748 | if (!kern_memmap) { |
| 749 | attr = efi_mem_attribute(phys_addr, size); |
| 750 | if (attr & EFI_MEMORY_WB) |
| 751 | return EFI_MEMORY_WB; |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | md = kern_memory_descriptor(phys_addr); |
| 756 | if (!md) |
| 757 | return 0; |
| 758 | |
| 759 | attr = md->attribute; |
| 760 | do { |
| 761 | unsigned long md_end = kmd_end(md); |
| 762 | |
| 763 | if (end <= md_end) |
| 764 | return attr; |
| 765 | |
| 766 | md = kern_memory_descriptor(md_end); |
| 767 | if (!md || md->attribute != attr) |
| 768 | return 0; |
| 769 | } while (md); |
| 770 | return 0; |
| 771 | } |
| 772 | EXPORT_SYMBOL(kern_mem_attribute); |
| 773 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | int |
Bjorn Helgaas | 136939a | 2006-03-26 01:37:05 -0800 | [diff] [blame] | 775 | valid_phys_addr_range (unsigned long phys_addr, unsigned long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 777 | u64 attr; |
| 778 | |
| 779 | /* |
| 780 | * /dev/mem reads and writes use copy_to_user(), which implicitly |
| 781 | * uses a granule-sized kernel identity mapping. It's really |
| 782 | * only safe to do this for regions in kern_memmap. For more |
| 783 | * details, see Documentation/ia64/aliasing.txt. |
| 784 | */ |
| 785 | attr = kern_mem_attribute(phys_addr, size); |
| 786 | if (attr & EFI_MEMORY_WB || attr & EFI_MEMORY_UC) |
| 787 | return 1; |
| 788 | return 0; |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 789 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 791 | int |
Lennert Buytenhek | 06c67be | 2006-07-10 04:45:27 -0700 | [diff] [blame] | 792 | valid_mmap_phys_addr_range (unsigned long pfn, unsigned long size) |
Bjorn Helgaas | 80851ef | 2006-01-08 01:04:13 -0800 | [diff] [blame] | 793 | { |
Bjorn Helgaas | 6d40fc5 | 2007-03-30 10:35:43 -0600 | [diff] [blame] | 794 | unsigned long phys_addr = pfn << PAGE_SHIFT; |
| 795 | u64 attr; |
| 796 | |
| 797 | attr = efi_mem_attribute(phys_addr, size); |
| 798 | |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 799 | /* |
Bjorn Helgaas | 6d40fc5 | 2007-03-30 10:35:43 -0600 | [diff] [blame] | 800 | * /dev/mem mmap uses normal user pages, so we don't need the entire |
| 801 | * granule, but the entire region we're mapping must support the same |
| 802 | * attribute. |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 803 | */ |
Bjorn Helgaas | 6d40fc5 | 2007-03-30 10:35:43 -0600 | [diff] [blame] | 804 | if (attr & EFI_MEMORY_WB || attr & EFI_MEMORY_UC) |
| 805 | return 1; |
| 806 | |
| 807 | /* |
| 808 | * Intel firmware doesn't tell us about all the MMIO regions, so |
| 809 | * in general we have to allow mmap requests. But if EFI *does* |
| 810 | * tell us about anything inside this region, we should deny it. |
| 811 | * The user can always map a smaller region to avoid the overlap. |
| 812 | */ |
| 813 | if (efi_memmap_intersects(phys_addr, size)) |
| 814 | return 0; |
| 815 | |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 816 | return 1; |
| 817 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 819 | pgprot_t |
| 820 | phys_mem_access_prot(struct file *file, unsigned long pfn, unsigned long size, |
| 821 | pgprot_t vma_prot) |
| 822 | { |
| 823 | unsigned long phys_addr = pfn << PAGE_SHIFT; |
| 824 | u64 attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 826 | /* |
| 827 | * For /dev/mem mmap, we use user mappings, but if the region is |
| 828 | * in kern_memmap (and hence may be covered by a kernel mapping), |
| 829 | * we must use the same attribute as the kernel mapping. |
| 830 | */ |
| 831 | attr = kern_mem_attribute(phys_addr, size); |
| 832 | if (attr & EFI_MEMORY_WB) |
| 833 | return pgprot_cacheable(vma_prot); |
| 834 | else if (attr & EFI_MEMORY_UC) |
| 835 | return pgprot_noncached(vma_prot); |
| 836 | |
| 837 | /* |
| 838 | * Some chipsets don't support UC access to memory. If |
| 839 | * WB is supported, we prefer that. |
| 840 | */ |
| 841 | if (efi_mem_attribute(phys_addr, size) & EFI_MEMORY_WB) |
| 842 | return pgprot_cacheable(vma_prot); |
| 843 | |
| 844 | return pgprot_noncached(vma_prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | int __init |
| 848 | efi_uart_console_only(void) |
| 849 | { |
| 850 | efi_status_t status; |
| 851 | char *s, name[] = "ConOut"; |
| 852 | efi_guid_t guid = EFI_GLOBAL_VARIABLE_GUID; |
| 853 | efi_char16_t *utf16, name_utf16[32]; |
| 854 | unsigned char data[1024]; |
| 855 | unsigned long size = sizeof(data); |
| 856 | struct efi_generic_dev_path *hdr, *end_addr; |
| 857 | int uart = 0; |
| 858 | |
| 859 | /* Convert to UTF-16 */ |
| 860 | utf16 = name_utf16; |
| 861 | s = name; |
| 862 | while (*s) |
| 863 | *utf16++ = *s++ & 0x7f; |
| 864 | *utf16 = 0; |
| 865 | |
| 866 | status = efi.get_variable(name_utf16, &guid, NULL, &size, data); |
| 867 | if (status != EFI_SUCCESS) { |
| 868 | printk(KERN_ERR "No EFI %s variable?\n", name); |
| 869 | return 0; |
| 870 | } |
| 871 | |
| 872 | hdr = (struct efi_generic_dev_path *) data; |
| 873 | end_addr = (struct efi_generic_dev_path *) ((u8 *) data + size); |
| 874 | while (hdr < end_addr) { |
| 875 | if (hdr->type == EFI_DEV_MSG && |
| 876 | hdr->sub_type == EFI_DEV_MSG_UART) |
| 877 | uart = 1; |
| 878 | else if (hdr->type == EFI_DEV_END_PATH || |
| 879 | hdr->type == EFI_DEV_END_PATH2) { |
| 880 | if (!uart) |
| 881 | return 0; |
| 882 | if (hdr->sub_type == EFI_DEV_END_ENTIRE) |
| 883 | return 1; |
| 884 | uart = 0; |
| 885 | } |
| 886 | hdr = (struct efi_generic_dev_path *) ((u8 *) hdr + hdr->length); |
| 887 | } |
| 888 | printk(KERN_ERR "Malformed %s value\n", name); |
| 889 | return 0; |
| 890 | } |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 891 | |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 892 | /* |
| 893 | * Look for the first granule aligned memory descriptor memory |
| 894 | * that is big enough to hold EFI memory map. Make sure this |
| 895 | * descriptor is atleast granule sized so it does not get trimmed |
| 896 | */ |
| 897 | struct kern_memdesc * |
| 898 | find_memmap_space (void) |
| 899 | { |
| 900 | u64 contig_low=0, contig_high=0; |
| 901 | u64 as = 0, ae; |
| 902 | void *efi_map_start, *efi_map_end, *p, *q; |
| 903 | efi_memory_desc_t *md, *pmd = NULL, *check_md; |
| 904 | u64 space_needed, efi_desc_size; |
| 905 | unsigned long total_mem = 0; |
| 906 | |
| 907 | efi_map_start = __va(ia64_boot_param->efi_memmap); |
| 908 | efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size; |
| 909 | efi_desc_size = ia64_boot_param->efi_memdesc_size; |
| 910 | |
| 911 | /* |
| 912 | * Worst case: we need 3 kernel descriptors for each efi descriptor |
| 913 | * (if every entry has a WB part in the middle, and UC head and tail), |
| 914 | * plus one for the end marker. |
| 915 | */ |
| 916 | space_needed = sizeof(kern_memdesc_t) * |
| 917 | (3 * (ia64_boot_param->efi_memmap_size/efi_desc_size) + 1); |
| 918 | |
| 919 | for (p = efi_map_start; p < efi_map_end; pmd = md, p += efi_desc_size) { |
| 920 | md = p; |
| 921 | if (!efi_wb(md)) { |
| 922 | continue; |
| 923 | } |
| 924 | if (pmd == NULL || !efi_wb(pmd) || efi_md_end(pmd) != md->phys_addr) { |
| 925 | contig_low = GRANULEROUNDUP(md->phys_addr); |
| 926 | contig_high = efi_md_end(md); |
| 927 | for (q = p + efi_desc_size; q < efi_map_end; q += efi_desc_size) { |
| 928 | check_md = q; |
| 929 | if (!efi_wb(check_md)) |
| 930 | break; |
| 931 | if (contig_high != check_md->phys_addr) |
| 932 | break; |
| 933 | contig_high = efi_md_end(check_md); |
| 934 | } |
| 935 | contig_high = GRANULEROUNDDOWN(contig_high); |
| 936 | } |
Christoph Lameter | 66888a6 | 2006-12-04 14:58:35 -0800 | [diff] [blame] | 937 | if (!is_memory_available(md) || md->type == EFI_LOADER_DATA) |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 938 | continue; |
| 939 | |
| 940 | /* Round ends inward to granule boundaries */ |
| 941 | as = max(contig_low, md->phys_addr); |
| 942 | ae = min(contig_high, efi_md_end(md)); |
| 943 | |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 944 | /* keep within max_addr= and min_addr= command line arg */ |
| 945 | as = max(as, min_addr); |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 946 | ae = min(ae, max_addr); |
| 947 | if (ae <= as) |
| 948 | continue; |
| 949 | |
| 950 | /* avoid going over mem= command line arg */ |
| 951 | if (total_mem + (ae - as) > mem_limit) |
| 952 | ae -= total_mem + (ae - as) - mem_limit; |
| 953 | |
| 954 | if (ae <= as) |
| 955 | continue; |
| 956 | |
| 957 | if (ae - as > space_needed) |
| 958 | break; |
| 959 | } |
| 960 | if (p >= efi_map_end) |
| 961 | panic("Can't allocate space for kernel memory descriptors"); |
| 962 | |
| 963 | return __va(as); |
| 964 | } |
| 965 | |
| 966 | /* |
| 967 | * Walk the EFI memory map and gather all memory available for kernel |
| 968 | * to use. We can allocate partial granules only if the unavailable |
| 969 | * parts exist, and are WB. |
| 970 | */ |
Bernhard Walle | cb38085 | 2007-10-18 23:41:00 -0700 | [diff] [blame] | 971 | unsigned long |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 972 | efi_memmap_init(unsigned long *s, unsigned long *e) |
| 973 | { |
Keith Owens | e037cda | 2006-07-17 15:41:59 +1000 | [diff] [blame] | 974 | struct kern_memdesc *k, *prev = NULL; |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 975 | u64 contig_low=0, contig_high=0; |
| 976 | u64 as, ae, lim; |
| 977 | void *efi_map_start, *efi_map_end, *p, *q; |
| 978 | efi_memory_desc_t *md, *pmd = NULL, *check_md; |
| 979 | u64 efi_desc_size; |
| 980 | unsigned long total_mem = 0; |
| 981 | |
| 982 | k = kern_memmap = find_memmap_space(); |
| 983 | |
| 984 | efi_map_start = __va(ia64_boot_param->efi_memmap); |
| 985 | efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size; |
| 986 | efi_desc_size = ia64_boot_param->efi_memdesc_size; |
| 987 | |
| 988 | for (p = efi_map_start; p < efi_map_end; pmd = md, p += efi_desc_size) { |
| 989 | md = p; |
| 990 | if (!efi_wb(md)) { |
| 991 | if (efi_uc(md) && (md->type == EFI_CONVENTIONAL_MEMORY || |
| 992 | md->type == EFI_BOOT_SERVICES_DATA)) { |
| 993 | k->attribute = EFI_MEMORY_UC; |
| 994 | k->start = md->phys_addr; |
| 995 | k->num_pages = md->num_pages; |
| 996 | k++; |
| 997 | } |
| 998 | continue; |
| 999 | } |
| 1000 | if (pmd == NULL || !efi_wb(pmd) || efi_md_end(pmd) != md->phys_addr) { |
| 1001 | contig_low = GRANULEROUNDUP(md->phys_addr); |
| 1002 | contig_high = efi_md_end(md); |
| 1003 | for (q = p + efi_desc_size; q < efi_map_end; q += efi_desc_size) { |
| 1004 | check_md = q; |
| 1005 | if (!efi_wb(check_md)) |
| 1006 | break; |
| 1007 | if (contig_high != check_md->phys_addr) |
| 1008 | break; |
| 1009 | contig_high = efi_md_end(check_md); |
| 1010 | } |
| 1011 | contig_high = GRANULEROUNDDOWN(contig_high); |
| 1012 | } |
Christoph Lameter | 66888a6 | 2006-12-04 14:58:35 -0800 | [diff] [blame] | 1013 | if (!is_memory_available(md)) |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 1014 | continue; |
| 1015 | |
Tony Luck | e55fdf1 | 2007-03-07 16:13:25 -0800 | [diff] [blame] | 1016 | #ifdef CONFIG_CRASH_DUMP |
| 1017 | /* saved_max_pfn should ignore max_addr= command line arg */ |
| 1018 | if (saved_max_pfn < (efi_md_end(md) >> PAGE_SHIFT)) |
| 1019 | saved_max_pfn = (efi_md_end(md) >> PAGE_SHIFT); |
| 1020 | #endif |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 1021 | /* |
| 1022 | * Round ends inward to granule boundaries |
| 1023 | * Give trimmings to uncached allocator |
| 1024 | */ |
| 1025 | if (md->phys_addr < contig_low) { |
| 1026 | lim = min(efi_md_end(md), contig_low); |
| 1027 | if (efi_uc(md)) { |
| 1028 | if (k > kern_memmap && (k-1)->attribute == EFI_MEMORY_UC && |
| 1029 | kmd_end(k-1) == md->phys_addr) { |
| 1030 | (k-1)->num_pages += (lim - md->phys_addr) >> EFI_PAGE_SHIFT; |
| 1031 | } else { |
| 1032 | k->attribute = EFI_MEMORY_UC; |
| 1033 | k->start = md->phys_addr; |
| 1034 | k->num_pages = (lim - md->phys_addr) >> EFI_PAGE_SHIFT; |
| 1035 | k++; |
| 1036 | } |
| 1037 | } |
| 1038 | as = contig_low; |
| 1039 | } else |
| 1040 | as = md->phys_addr; |
| 1041 | |
| 1042 | if (efi_md_end(md) > contig_high) { |
| 1043 | lim = max(md->phys_addr, contig_high); |
| 1044 | if (efi_uc(md)) { |
| 1045 | if (lim == md->phys_addr && k > kern_memmap && |
| 1046 | (k-1)->attribute == EFI_MEMORY_UC && |
| 1047 | kmd_end(k-1) == md->phys_addr) { |
| 1048 | (k-1)->num_pages += md->num_pages; |
| 1049 | } else { |
| 1050 | k->attribute = EFI_MEMORY_UC; |
| 1051 | k->start = lim; |
| 1052 | k->num_pages = (efi_md_end(md) - lim) >> EFI_PAGE_SHIFT; |
| 1053 | k++; |
| 1054 | } |
| 1055 | } |
| 1056 | ae = contig_high; |
| 1057 | } else |
| 1058 | ae = efi_md_end(md); |
| 1059 | |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 1060 | /* keep within max_addr= and min_addr= command line arg */ |
| 1061 | as = max(as, min_addr); |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 1062 | ae = min(ae, max_addr); |
| 1063 | if (ae <= as) |
| 1064 | continue; |
| 1065 | |
| 1066 | /* avoid going over mem= command line arg */ |
| 1067 | if (total_mem + (ae - as) > mem_limit) |
| 1068 | ae -= total_mem + (ae - as) - mem_limit; |
| 1069 | |
| 1070 | if (ae <= as) |
| 1071 | continue; |
| 1072 | if (prev && kmd_end(prev) == md->phys_addr) { |
| 1073 | prev->num_pages += (ae - as) >> EFI_PAGE_SHIFT; |
| 1074 | total_mem += ae - as; |
| 1075 | continue; |
| 1076 | } |
| 1077 | k->attribute = EFI_MEMORY_WB; |
| 1078 | k->start = as; |
| 1079 | k->num_pages = (ae - as) >> EFI_PAGE_SHIFT; |
| 1080 | total_mem += ae - as; |
| 1081 | prev = k++; |
| 1082 | } |
| 1083 | k->start = ~0L; /* end-marker */ |
| 1084 | |
| 1085 | /* reserve the memory we are using for kern_memmap */ |
| 1086 | *s = (u64)kern_memmap; |
| 1087 | *e = (u64)++k; |
Bernhard Walle | cb38085 | 2007-10-18 23:41:00 -0700 | [diff] [blame] | 1088 | |
| 1089 | return total_mem; |
Tony Luck | d8c97d5 | 2005-09-08 12:39:59 -0700 | [diff] [blame] | 1090 | } |
Khalid Aziz | be37912 | 2005-09-19 15:42:36 -0700 | [diff] [blame] | 1091 | |
| 1092 | void |
| 1093 | efi_initialize_iomem_resources(struct resource *code_resource, |
Bernhard Walle | 00bf409 | 2007-10-21 16:42:01 -0700 | [diff] [blame] | 1094 | struct resource *data_resource, |
| 1095 | struct resource *bss_resource) |
Khalid Aziz | be37912 | 2005-09-19 15:42:36 -0700 | [diff] [blame] | 1096 | { |
| 1097 | struct resource *res; |
| 1098 | void *efi_map_start, *efi_map_end, *p; |
| 1099 | efi_memory_desc_t *md; |
| 1100 | u64 efi_desc_size; |
| 1101 | char *name; |
| 1102 | unsigned long flags; |
| 1103 | |
| 1104 | efi_map_start = __va(ia64_boot_param->efi_memmap); |
| 1105 | efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size; |
| 1106 | efi_desc_size = ia64_boot_param->efi_memdesc_size; |
| 1107 | |
| 1108 | res = NULL; |
| 1109 | |
| 1110 | for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) { |
| 1111 | md = p; |
| 1112 | |
| 1113 | if (md->num_pages == 0) /* should not happen */ |
| 1114 | continue; |
| 1115 | |
Yasunori Goto | 887c3cb | 2007-11-14 16:59:20 -0800 | [diff] [blame^] | 1116 | flags = IORESOURCE_MEM | IORESOURCE_BUSY; |
Khalid Aziz | be37912 | 2005-09-19 15:42:36 -0700 | [diff] [blame] | 1117 | switch (md->type) { |
| 1118 | |
| 1119 | case EFI_MEMORY_MAPPED_IO: |
| 1120 | case EFI_MEMORY_MAPPED_IO_PORT_SPACE: |
| 1121 | continue; |
| 1122 | |
| 1123 | case EFI_LOADER_CODE: |
| 1124 | case EFI_LOADER_DATA: |
| 1125 | case EFI_BOOT_SERVICES_DATA: |
| 1126 | case EFI_BOOT_SERVICES_CODE: |
| 1127 | case EFI_CONVENTIONAL_MEMORY: |
| 1128 | if (md->attribute & EFI_MEMORY_WP) { |
| 1129 | name = "System ROM"; |
| 1130 | flags |= IORESOURCE_READONLY; |
| 1131 | } else { |
| 1132 | name = "System RAM"; |
| 1133 | } |
| 1134 | break; |
| 1135 | |
| 1136 | case EFI_ACPI_MEMORY_NVS: |
| 1137 | name = "ACPI Non-volatile Storage"; |
Khalid Aziz | be37912 | 2005-09-19 15:42:36 -0700 | [diff] [blame] | 1138 | break; |
| 1139 | |
| 1140 | case EFI_UNUSABLE_MEMORY: |
| 1141 | name = "reserved"; |
Yasunori Goto | 887c3cb | 2007-11-14 16:59:20 -0800 | [diff] [blame^] | 1142 | flags |= IORESOURCE_DISABLED; |
Khalid Aziz | be37912 | 2005-09-19 15:42:36 -0700 | [diff] [blame] | 1143 | break; |
| 1144 | |
| 1145 | case EFI_RESERVED_TYPE: |
| 1146 | case EFI_RUNTIME_SERVICES_CODE: |
| 1147 | case EFI_RUNTIME_SERVICES_DATA: |
| 1148 | case EFI_ACPI_RECLAIM_MEMORY: |
| 1149 | default: |
| 1150 | name = "reserved"; |
Khalid Aziz | be37912 | 2005-09-19 15:42:36 -0700 | [diff] [blame] | 1151 | break; |
| 1152 | } |
| 1153 | |
Panagiotis Issaris | baf47fb | 2005-11-09 02:08:42 +0100 | [diff] [blame] | 1154 | if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) { |
Khalid Aziz | be37912 | 2005-09-19 15:42:36 -0700 | [diff] [blame] | 1155 | printk(KERN_ERR "failed to alocate resource for iomem\n"); |
| 1156 | return; |
| 1157 | } |
| 1158 | |
| 1159 | res->name = name; |
| 1160 | res->start = md->phys_addr; |
| 1161 | res->end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - 1; |
| 1162 | res->flags = flags; |
| 1163 | |
| 1164 | if (insert_resource(&iomem_resource, res) < 0) |
| 1165 | kfree(res); |
| 1166 | else { |
| 1167 | /* |
| 1168 | * We don't know which region contains |
| 1169 | * kernel data so we try it repeatedly and |
| 1170 | * let the resource manager test it. |
| 1171 | */ |
| 1172 | insert_resource(res, code_resource); |
| 1173 | insert_resource(res, data_resource); |
Bernhard Walle | 00bf409 | 2007-10-21 16:42:01 -0700 | [diff] [blame] | 1174 | insert_resource(res, bss_resource); |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 1175 | #ifdef CONFIG_KEXEC |
| 1176 | insert_resource(res, &efi_memmap_res); |
| 1177 | insert_resource(res, &boot_param_res); |
| 1178 | if (crashk_res.end > crashk_res.start) |
| 1179 | insert_resource(res, &crashk_res); |
| 1180 | #endif |
Khalid Aziz | be37912 | 2005-09-19 15:42:36 -0700 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | } |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 1184 | |
| 1185 | #ifdef CONFIG_KEXEC |
| 1186 | /* find a block of memory aligned to 64M exclude reserved regions |
| 1187 | rsvd_regions are sorted |
| 1188 | */ |
Horms | 2a3a282 | 2007-03-06 16:28:50 +0900 | [diff] [blame] | 1189 | unsigned long __init |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 1190 | kdump_find_rsvd_region (unsigned long size, |
| 1191 | struct rsvd_region *r, int n) |
| 1192 | { |
| 1193 | int i; |
| 1194 | u64 start, end; |
| 1195 | u64 alignment = 1UL << _PAGE_SIZE_64M; |
| 1196 | void *efi_map_start, *efi_map_end, *p; |
| 1197 | efi_memory_desc_t *md; |
| 1198 | u64 efi_desc_size; |
| 1199 | |
| 1200 | efi_map_start = __va(ia64_boot_param->efi_memmap); |
| 1201 | efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size; |
| 1202 | efi_desc_size = ia64_boot_param->efi_memdesc_size; |
| 1203 | |
| 1204 | for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) { |
| 1205 | md = p; |
| 1206 | if (!efi_wb(md)) |
| 1207 | continue; |
| 1208 | start = ALIGN(md->phys_addr, alignment); |
| 1209 | end = efi_md_end(md); |
| 1210 | for (i = 0; i < n; i++) { |
| 1211 | if (__pa(r[i].start) >= start && __pa(r[i].end) < end) { |
| 1212 | if (__pa(r[i].start) > start + size) |
| 1213 | return start; |
| 1214 | start = ALIGN(__pa(r[i].end), alignment); |
| 1215 | if (i < n-1 && __pa(r[i+1].start) < start + size) |
| 1216 | continue; |
| 1217 | else |
| 1218 | break; |
| 1219 | } |
| 1220 | } |
| 1221 | if (end > start + size) |
| 1222 | return start; |
| 1223 | } |
| 1224 | |
| 1225 | printk(KERN_WARNING "Cannot reserve 0x%lx byte of memory for crashdump\n", |
| 1226 | size); |
| 1227 | return ~0UL; |
| 1228 | } |
| 1229 | #endif |
Magnus Damm | cee87af | 2007-03-06 02:34:26 -0800 | [diff] [blame] | 1230 | |
| 1231 | #ifdef CONFIG_PROC_VMCORE |
| 1232 | /* locate the size find a the descriptor at a certain address */ |
Simon Horman | 1775fe85 | 2007-10-29 17:10:29 +0900 | [diff] [blame] | 1233 | unsigned long __init |
Magnus Damm | cee87af | 2007-03-06 02:34:26 -0800 | [diff] [blame] | 1234 | vmcore_find_descriptor_size (unsigned long address) |
| 1235 | { |
| 1236 | void *efi_map_start, *efi_map_end, *p; |
| 1237 | efi_memory_desc_t *md; |
| 1238 | u64 efi_desc_size; |
| 1239 | unsigned long ret = 0; |
| 1240 | |
| 1241 | efi_map_start = __va(ia64_boot_param->efi_memmap); |
| 1242 | efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size; |
| 1243 | efi_desc_size = ia64_boot_param->efi_memdesc_size; |
| 1244 | |
| 1245 | for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) { |
| 1246 | md = p; |
| 1247 | if (efi_wb(md) && md->type == EFI_LOADER_DATA |
| 1248 | && md->phys_addr == address) { |
| 1249 | ret = efi_md_size(md); |
| 1250 | break; |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | if (ret == 0) |
| 1255 | printk(KERN_WARNING "Cannot locate EFI vmcore descriptor\n"); |
| 1256 | |
| 1257 | return ret; |
| 1258 | } |
| 1259 | #endif |