direct-io.hg

changeset 15313:301267d0db12

[IA64] Update efi.c and efi.h to linux-2.6.21

Signed-off-by: Akio Takebe <takebe_akio@jp.fujitsu.com>
author Alex Williamson <alex.williamson@hp.com>
date Thu May 24 14:43:14 2007 -0600 (2007-05-24)
parents 90f19b7667f7
children 27735ce15f97
files xen/arch/ia64/linux-xen/README.origin xen/arch/ia64/linux-xen/efi.c xen/include/asm-ia64/linux-xen/linux/README.origin xen/include/asm-ia64/linux-xen/linux/efi.h
line diff
     1.1 --- a/xen/arch/ia64/linux-xen/README.origin	Thu May 24 14:20:19 2007 -0600
     1.2 +++ b/xen/arch/ia64/linux-xen/README.origin	Thu May 24 14:43:14 2007 -0600
     1.3 @@ -6,7 +6,6 @@
     1.4  # easily updated to future versions of the corresponding Linux files.
     1.5  
     1.6  cmdline.c		-> linux/lib/cmdline.c
     1.7 -efi.c			-> linux/arch/ia64/kernel/efi.c
     1.8  entry.h			-> linux/arch/ia64/kernel/entry.h
     1.9  entry.S			-> linux/arch/ia64/kernel/entry.S
    1.10  head.S			-> linux/arch/ia64/kernel/head.S
    1.11 @@ -42,3 +41,6 @@ perfmon_generic.h	-> linux/arch/kernel/p
    1.12  perfmon_itanium.h	-> linux/arch/kernel/perfmon_itanium.h
    1.13  perfmon_mckinley.h	-> linux/arch/kernel/perfmon_mckinley.h
    1.14  perfmon_montecito.h	-> linux/arch/kernel/perfmon_montecito.h
    1.15 +
    1.16 +# The files below are from Linux-2.6.21
    1.17 +efi.c			-> linux/arch/ia64/kernel/efi.c
     2.1 --- a/xen/arch/ia64/linux-xen/efi.c	Thu May 24 14:20:19 2007 -0600
     2.2 +++ b/xen/arch/ia64/linux-xen/efi.c	Thu May 24 14:43:14 2007 -0600
     2.3 @@ -8,6 +8,8 @@
     2.4   * Copyright (C) 1999-2003 Hewlett-Packard Co.
     2.5   *	David Mosberger-Tang <davidm@hpl.hp.com>
     2.6   *	Stephane Eranian <eranian@hpl.hp.com>
     2.7 + * (c) Copyright 2006 Hewlett-Packard Development Company, L.P.
     2.8 + *	Bjorn Helgaas <bjorn.helgaas@hp.com>
     2.9   *
    2.10   * All EFI Runtime Services are not implemented yet as EFI only
    2.11   * supports physical mode addressing on SoftSDV. This is to be fixed
    2.12 @@ -18,12 +20,14 @@
    2.13   * Goutham Rao: <goutham.rao@intel.com>
    2.14   *	Skip non-WB memory and ignore empty memory ranges.
    2.15   */
    2.16 -#include <linux/config.h>
    2.17  #include <linux/module.h>
    2.18 +#include <linux/bootmem.h>
    2.19  #include <linux/kernel.h>
    2.20  #include <linux/init.h>
    2.21  #include <linux/types.h>
    2.22  #include <linux/time.h>
    2.23 +#include <linux/efi.h>
    2.24 +#include <linux/kexec.h>
    2.25  
    2.26  #include <asm/io.h>
    2.27  #include <asm/kregs.h>
    2.28 @@ -32,21 +36,24 @@
    2.29  #include <asm/processor.h>
    2.30  #include <asm/mca.h>
    2.31  
    2.32 -#include <linux/efi.h>
    2.33 -
    2.34  #define EFI_DEBUG	0
    2.35  
    2.36  extern efi_status_t efi_call_phys (void *, ...);
    2.37 +#ifdef XEN
    2.38 +/* this should be defined in linux/kernel.h */
    2.39  extern unsigned long long memparse (char *ptr, char **retptr);
    2.40 +/* this should be defined in linux/efi.h */
    2.41 +//#define EFI_INVALID_TABLE_ADDR          (void *)(~0UL)
    2.42 +#endif
    2.43  
    2.44  struct efi efi;
    2.45  EXPORT_SYMBOL(efi);
    2.46  static efi_runtime_services_t *runtime;
    2.47  #if defined(XEN) && !defined(CONFIG_VIRTUAL_FRAME_TABLE)
    2.48  // this is a temporary hack to avoid CONFIG_VIRTUAL_MEM_MAP
    2.49 -static unsigned long mem_limit = ~0UL, max_addr = 0x100000000;
    2.50 +static unsigned long mem_limit = ~0UL, max_addr = 0x100000000UL, min_addr = 0UL;
    2.51  #else
    2.52 -static unsigned long mem_limit = ~0UL, max_addr = ~0UL;
    2.53 +static unsigned long mem_limit = ~0UL, max_addr = ~0UL, min_addr = 0UL;
    2.54  #endif
    2.55  
    2.56  #define efi_call_virt(f, args...)	(*(f))(args)
    2.57 @@ -232,7 +239,7 @@ efi_gettimeofday (struct timespec *ts)
    2.58  #endif
    2.59  
    2.60  static int
    2.61 -is_available_memory (efi_memory_desc_t *md)
    2.62 +is_memory_available (efi_memory_desc_t *md)
    2.63  {
    2.64  	if (!(md->attribute & EFI_MEMORY_WB))
    2.65  		return 0;
    2.66 @@ -256,6 +263,32 @@ typedef struct kern_memdesc {
    2.67  
    2.68  static kern_memdesc_t *kern_memmap;
    2.69  
    2.70 +#define efi_md_size(md)	(md->num_pages << EFI_PAGE_SHIFT)
    2.71 +
    2.72 +static inline u64
    2.73 +kmd_end(kern_memdesc_t *kmd)
    2.74 +{
    2.75 +	return (kmd->start + (kmd->num_pages << EFI_PAGE_SHIFT));
    2.76 +}
    2.77 +
    2.78 +static inline u64
    2.79 +efi_md_end(efi_memory_desc_t *md)
    2.80 +{
    2.81 +	return (md->phys_addr + efi_md_size(md));
    2.82 +}
    2.83 +
    2.84 +static inline int
    2.85 +efi_wb(efi_memory_desc_t *md)
    2.86 +{
    2.87 +	return (md->attribute & EFI_MEMORY_WB);
    2.88 +}
    2.89 +
    2.90 +static inline int
    2.91 +efi_uc(efi_memory_desc_t *md)
    2.92 +{
    2.93 +	return (md->attribute & EFI_MEMORY_UC);
    2.94 +}
    2.95 +
    2.96  static void
    2.97  walk (efi_freemem_callback_t callback, void *arg, u64 attr)
    2.98  {
    2.99 @@ -361,12 +394,11 @@ efi_get_pal_addr (void)
   2.100  #endif
   2.101  		return __va(md->phys_addr);
   2.102  	}
   2.103 -	printk(KERN_WARNING "%s: no PAL-code memory-descriptor found",
   2.104 +	printk(KERN_WARNING "%s: no PAL-code memory-descriptor found\n",
   2.105  	       __FUNCTION__);
   2.106  	return NULL;
   2.107  }
   2.108  
   2.109 -
   2.110  #ifdef XEN
   2.111  void *pal_vaddr = 0;
   2.112  #endif
   2.113 @@ -405,24 +437,22 @@ efi_init (void)
   2.114  	efi_config_table_t *config_tables;
   2.115  	efi_char16_t *c16;
   2.116  	u64 efi_desc_size;
   2.117 -	char *cp, *end, vendor[100] = "unknown";
   2.118 -	extern char saved_command_line[];
   2.119 +	char *cp, vendor[100] = "unknown";
   2.120  	int i;
   2.121  
   2.122  	/* it's too early to be able to use the standard kernel command line support... */
   2.123 +#ifdef XEN
   2.124 +	extern char saved_command_line[];
   2.125  	for (cp = saved_command_line; *cp; ) {
   2.126 +#else
   2.127 +	for (cp = boot_command_line; *cp; ) {
   2.128 +#endif
   2.129  		if (memcmp(cp, "mem=", 4) == 0) {
   2.130 -			cp += 4;
   2.131 -			mem_limit = memparse(cp, &end);
   2.132 -			if (end != cp)
   2.133 -				break;
   2.134 -			cp = end;
   2.135 +			mem_limit = memparse(cp + 4, &cp);
   2.136  		} else if (memcmp(cp, "max_addr=", 9) == 0) {
   2.137 -			cp += 9;
   2.138 -			max_addr = GRANULEROUNDDOWN(memparse(cp, &end));
   2.139 -			if (end != cp)
   2.140 -				break;
   2.141 -			cp = end;
   2.142 +			max_addr = GRANULEROUNDDOWN(memparse(cp + 9, &cp));
   2.143 +		} else if (memcmp(cp, "min_addr=", 9) == 0) {
   2.144 +			min_addr = GRANULEROUNDDOWN(memparse(cp + 9, &cp));
   2.145  		} else {
   2.146  			while (*cp != ' ' && *cp)
   2.147  				++cp;
   2.148 @@ -430,6 +460,8 @@ efi_init (void)
   2.149  				++cp;
   2.150  		}
   2.151  	}
   2.152 +	if (min_addr != 0UL)
   2.153 +		printk(KERN_INFO "Ignoring memory below %luMB\n", min_addr >> 20);
   2.154  	if (max_addr != ~0UL)
   2.155  		printk(KERN_INFO "Ignoring memory above %luMB\n", max_addr >> 20);
   2.156  
   2.157 @@ -453,7 +485,7 @@ efi_init (void)
   2.158  	/* Show what we know for posterity */
   2.159  	c16 = __va(efi.systab->fw_vendor);
   2.160  	if (c16) {
   2.161 -		for (i = 0;i < (int) sizeof(vendor) && *c16; ++i)
   2.162 +		for (i = 0;i < (int) sizeof(vendor) - 1 && *c16; ++i)
   2.163  			vendor[i] = *c16++;
   2.164  		vendor[i] = '\0';
   2.165  	}
   2.166 @@ -461,6 +493,40 @@ efi_init (void)
   2.167  	printk(KERN_INFO "EFI v%u.%.02u by %s:",
   2.168  	       efi.systab->hdr.revision >> 16, efi.systab->hdr.revision & 0xffff, vendor);
   2.169  
   2.170 +#ifndef XEN
   2.171 +	efi.mps        = EFI_INVALID_TABLE_ADDR;
   2.172 +	efi.acpi       = EFI_INVALID_TABLE_ADDR;
   2.173 +	efi.acpi20     = EFI_INVALID_TABLE_ADDR;
   2.174 +	efi.smbios     = EFI_INVALID_TABLE_ADDR;
   2.175 +	efi.sal_systab = EFI_INVALID_TABLE_ADDR;
   2.176 +	efi.boot_info  = EFI_INVALID_TABLE_ADDR;
   2.177 +	efi.hcdp       = EFI_INVALID_TABLE_ADDR;
   2.178 +	efi.uga        = EFI_INVALID_TABLE_ADDR;
   2.179 +
   2.180 +	for (i = 0; i < (int) efi.systab->nr_tables; i++) {
   2.181 +		if (efi_guidcmp(config_tables[i].guid, MPS_TABLE_GUID) == 0) {
   2.182 +			efi.mps = config_tables[i].table;
   2.183 +			printk(" MPS=0x%lx", config_tables[i].table);
   2.184 +		} else if (efi_guidcmp(config_tables[i].guid, ACPI_20_TABLE_GUID) == 0) {
   2.185 +			efi.acpi20 = config_tables[i].table;
   2.186 +			printk(" ACPI 2.0=0x%lx", config_tables[i].table);
   2.187 +		} else if (efi_guidcmp(config_tables[i].guid, ACPI_TABLE_GUID) == 0) {
   2.188 +			efi.acpi = config_tables[i].table;
   2.189 +			printk(" ACPI=0x%lx", config_tables[i].table);
   2.190 +		} else if (efi_guidcmp(config_tables[i].guid, SMBIOS_TABLE_GUID) == 0) {
   2.191 +			efi.smbios = config_tables[i].table;
   2.192 +			printk(" SMBIOS=0x%lx", config_tables[i].table);
   2.193 +		} else if (efi_guidcmp(config_tables[i].guid, SAL_SYSTEM_TABLE_GUID) == 0) {
   2.194 +			efi.sal_systab = config_tables[i].table;
   2.195 +			printk(" SALsystab=0x%lx", config_tables[i].table);
   2.196 +		} else if (efi_guidcmp(config_tables[i].guid, HCDP_TABLE_GUID) == 0) {
   2.197 +			efi.hcdp = config_tables[i].table;
   2.198 +			printk(" HCDP=0x%lx", config_tables[i].table);
   2.199 +		}
   2.200 +	}
   2.201 +#else
   2.202 +	/* Members of efi are set with virtual address in old linux code.
   2.203 +	   The latest linux set wiht physicall address. */
   2.204  	for (i = 0; i < (int) efi.systab->nr_tables; i++) {
   2.205  		if (efi_guidcmp(config_tables[i].guid, MPS_TABLE_GUID) == 0) {
   2.206  			efi.mps = __va(config_tables[i].table);
   2.207 @@ -482,6 +548,7 @@ efi_init (void)
   2.208  			printk(" HCDP=0x%lx", config_tables[i].table);
   2.209  		}
   2.210  	}
   2.211 +#endif
   2.212  	printk("\n");
   2.213  
   2.214  	runtime = __va(efi.systab->runtime);
   2.215 @@ -616,8 +683,20 @@ efi_get_iobase (void)
   2.216  	return 0;
   2.217  }
   2.218  
   2.219 -u32
   2.220 -efi_mem_type (unsigned long phys_addr)
   2.221 +static struct kern_memdesc *
   2.222 +kern_memory_descriptor (unsigned long phys_addr)
   2.223 +{
   2.224 +	struct kern_memdesc *md;
   2.225 +
   2.226 +	for (md = kern_memmap; md->start != ~0UL; md++) {
   2.227 +		if (phys_addr - md->start < (md->num_pages << EFI_PAGE_SHIFT))
   2.228 +			 return md;
   2.229 +	}
   2.230 +	return NULL;
   2.231 +}
   2.232 +
   2.233 +static efi_memory_desc_t *
   2.234 +efi_memory_descriptor (unsigned long phys_addr)
   2.235  {
   2.236  	void *efi_map_start, *efi_map_end, *p;
   2.237  	efi_memory_desc_t *md;
   2.238 @@ -631,58 +710,155 @@ efi_mem_type (unsigned long phys_addr)
   2.239  		md = p;
   2.240  
   2.241  		if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT))
   2.242 -			 return md->type;
   2.243 +			 return md;
   2.244  	}
   2.245 +	return NULL;
   2.246 +}
   2.247 +
   2.248 +u32
   2.249 +efi_mem_type (unsigned long phys_addr)
   2.250 +{
   2.251 +	efi_memory_desc_t *md = efi_memory_descriptor(phys_addr);
   2.252 +
   2.253 +	if (md)
   2.254 +		return md->type;
   2.255  	return 0;
   2.256  }
   2.257  
   2.258  u64
   2.259  efi_mem_attributes (unsigned long phys_addr)
   2.260  {
   2.261 -	void *efi_map_start, *efi_map_end, *p;
   2.262 -	efi_memory_desc_t *md;
   2.263 -	u64 efi_desc_size;
   2.264 +	efi_memory_desc_t *md = efi_memory_descriptor(phys_addr);
   2.265  
   2.266 -	efi_map_start = __va(ia64_boot_param->efi_memmap);
   2.267 -	efi_map_end   = efi_map_start + ia64_boot_param->efi_memmap_size;
   2.268 -	efi_desc_size = ia64_boot_param->efi_memdesc_size;
   2.269 -
   2.270 -	for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
   2.271 -		md = p;
   2.272 -
   2.273 -		if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT))
   2.274 -			return md->attribute;
   2.275 -	}
   2.276 +	if (md)
   2.277 +		return md->attribute;
   2.278  	return 0;
   2.279  }
   2.280  EXPORT_SYMBOL(efi_mem_attributes);
   2.281  
   2.282 -int
   2.283 -valid_phys_addr_range (unsigned long phys_addr, unsigned long *size)
   2.284 +u64
   2.285 +efi_mem_attribute (unsigned long phys_addr, unsigned long size)
   2.286  {
   2.287 -	void *efi_map_start, *efi_map_end, *p;
   2.288 -	efi_memory_desc_t *md;
   2.289 -	u64 efi_desc_size;
   2.290 +	unsigned long end = phys_addr + size;
   2.291 +	efi_memory_desc_t *md = efi_memory_descriptor(phys_addr);
   2.292 +	u64 attr;
   2.293  
   2.294 -	efi_map_start = __va(ia64_boot_param->efi_memmap);
   2.295 -	efi_map_end   = efi_map_start + ia64_boot_param->efi_memmap_size;
   2.296 -	efi_desc_size = ia64_boot_param->efi_memdesc_size;
   2.297 +	if (!md)
   2.298 +		return 0;
   2.299  
   2.300 -	for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
   2.301 -		md = p;
   2.302 +	/*
   2.303 +	 * EFI_MEMORY_RUNTIME is not a memory attribute; it just tells
   2.304 +	 * the kernel that firmware needs this region mapped.
   2.305 +	 */
   2.306 +	attr = md->attribute & ~EFI_MEMORY_RUNTIME;
   2.307 +	do {
   2.308 +		unsigned long md_end = efi_md_end(md);
   2.309  
   2.310 -		if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT)) {
   2.311 -			if (!(md->attribute & EFI_MEMORY_WB))
   2.312 -				return 0;
   2.313 +		if (end <= md_end)
   2.314 +			return attr;
   2.315  
   2.316 -			if (*size > md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - phys_addr)
   2.317 -				*size = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - phys_addr;
   2.318 -			return 1;
   2.319 -		}
   2.320 -	}
   2.321 +		md = efi_memory_descriptor(md_end);
   2.322 +		if (!md || (md->attribute & ~EFI_MEMORY_RUNTIME) != attr)
   2.323 +			return 0;
   2.324 +	} while (md);
   2.325  	return 0;
   2.326  }
   2.327  
   2.328 +u64
   2.329 +kern_mem_attribute (unsigned long phys_addr, unsigned long size)
   2.330 +{
   2.331 +	unsigned long end = phys_addr + size;
   2.332 +	struct kern_memdesc *md;
   2.333 +	u64 attr;
   2.334 +
   2.335 +	/*
   2.336 +	 * This is a hack for ioremap calls before we set up kern_memmap.
   2.337 +	 * Maybe we should do efi_memmap_init() earlier instead.
   2.338 +	 */
   2.339 +	if (!kern_memmap) {
   2.340 +		attr = efi_mem_attribute(phys_addr, size);
   2.341 +		if (attr & EFI_MEMORY_WB)
   2.342 +			return EFI_MEMORY_WB;
   2.343 +		return 0;
   2.344 +	}
   2.345 +
   2.346 +	md = kern_memory_descriptor(phys_addr);
   2.347 +	if (!md)
   2.348 +		return 0;
   2.349 +
   2.350 +	attr = md->attribute;
   2.351 +	do {
   2.352 +		unsigned long md_end = kmd_end(md);
   2.353 +
   2.354 +		if (end <= md_end)
   2.355 +			return attr;
   2.356 +
   2.357 +		md = kern_memory_descriptor(md_end);
   2.358 +		if (!md || md->attribute != attr)
   2.359 +			return 0;
   2.360 +	} while (md);
   2.361 +	return 0;
   2.362 +}
   2.363 +EXPORT_SYMBOL(kern_mem_attribute);
   2.364 +
   2.365 +#ifndef XEN
   2.366 +int
   2.367 +valid_phys_addr_range (unsigned long phys_addr, unsigned long size)
   2.368 +{
   2.369 +	u64 attr;
   2.370 +
   2.371 +	/*
   2.372 +	 * /dev/mem reads and writes use copy_to_user(), which implicitly
   2.373 +	 * uses a granule-sized kernel identity mapping.  It's really
   2.374 +	 * only safe to do this for regions in kern_memmap.  For more
   2.375 +	 * details, see Documentation/ia64/aliasing.txt.
   2.376 +	 */
   2.377 +	attr = kern_mem_attribute(phys_addr, size);
   2.378 +	if (attr & EFI_MEMORY_WB || attr & EFI_MEMORY_UC)
   2.379 +		return 1;
   2.380 +	return 0;
   2.381 +}
   2.382 +
   2.383 +int
   2.384 +valid_mmap_phys_addr_range (unsigned long pfn, unsigned long size)
   2.385 +{
   2.386 +	/*
   2.387 +	 * MMIO regions are often missing from the EFI memory map.
   2.388 +	 * We must allow mmap of them for programs like X, so we
   2.389 +	 * currently can't do any useful validation.
   2.390 +	 */
   2.391 +	return 1;
   2.392 +}
   2.393 +
   2.394 +pgprot_t
   2.395 +phys_mem_access_prot(struct file *file, unsigned long pfn, unsigned long size,
   2.396 +		     pgprot_t vma_prot)
   2.397 +{
   2.398 +	unsigned long phys_addr = pfn << PAGE_SHIFT;
   2.399 +	u64 attr;
   2.400 +
   2.401 +	/*
   2.402 +	 * For /dev/mem mmap, we use user mappings, but if the region is
   2.403 +	 * in kern_memmap (and hence may be covered by a kernel mapping),
   2.404 +	 * we must use the same attribute as the kernel mapping.
   2.405 +	 */
   2.406 +	attr = kern_mem_attribute(phys_addr, size);
   2.407 +	if (attr & EFI_MEMORY_WB)
   2.408 +		return pgprot_cacheable(vma_prot);
   2.409 +	else if (attr & EFI_MEMORY_UC)
   2.410 +		return pgprot_noncached(vma_prot);
   2.411 +
   2.412 +	/*
   2.413 +	 * Some chipsets don't support UC access to memory.  If
   2.414 +	 * WB is supported, we prefer that.
   2.415 +	 */
   2.416 +	if (efi_mem_attribute(phys_addr, size) & EFI_MEMORY_WB)
   2.417 +		return pgprot_cacheable(vma_prot);
   2.418 +
   2.419 +	return pgprot_noncached(vma_prot);
   2.420 +}
   2.421 +#endif
   2.422 +
   2.423  int __init
   2.424  efi_uart_console_only(void)
   2.425  {
   2.426 @@ -728,32 +904,6 @@ efi_uart_console_only(void)
   2.427  	return 0;
   2.428  }
   2.429  
   2.430 -#define efi_md_size(md)	(md->num_pages << EFI_PAGE_SHIFT)
   2.431 -
   2.432 -static inline u64
   2.433 -kmd_end(kern_memdesc_t *kmd)
   2.434 -{
   2.435 -	return (kmd->start + (kmd->num_pages << EFI_PAGE_SHIFT));
   2.436 -}
   2.437 -
   2.438 -static inline u64
   2.439 -efi_md_end(efi_memory_desc_t *md)
   2.440 -{
   2.441 -	return (md->phys_addr + efi_md_size(md));
   2.442 -}
   2.443 -
   2.444 -static inline int
   2.445 -efi_wb(efi_memory_desc_t *md)
   2.446 -{
   2.447 -	return (md->attribute & EFI_MEMORY_WB);
   2.448 -}
   2.449 -
   2.450 -static inline int
   2.451 -efi_uc(efi_memory_desc_t *md)
   2.452 -{
   2.453 -	return (md->attribute & EFI_MEMORY_UC);
   2.454 -}
   2.455 -
   2.456  /*
   2.457   * Look for the first granule aligned memory descriptor memory
   2.458   * that is big enough to hold EFI memory map. Make sure this
   2.459 @@ -799,14 +949,15 @@ find_memmap_space (void)
   2.460  			}
   2.461  			contig_high = GRANULEROUNDDOWN(contig_high);
   2.462  		}
   2.463 -		if (!is_available_memory(md) || md->type == EFI_LOADER_DATA)
   2.464 +		if (!is_memory_available(md) || md->type == EFI_LOADER_DATA)
   2.465  			continue;
   2.466  
   2.467  		/* Round ends inward to granule boundaries */
   2.468  		as = max(contig_low, md->phys_addr);
   2.469  		ae = min(contig_high, efi_md_end(md));
   2.470  
   2.471 -		/* keep within max_addr= command line arg */
   2.472 +		/* keep within max_addr= and min_addr= command line arg */
   2.473 +		as = max(as, min_addr);
   2.474  		ae = min(ae, max_addr);
   2.475  		if (ae <= as)
   2.476  			continue;
   2.477 @@ -835,7 +986,7 @@ find_memmap_space (void)
   2.478  void
   2.479  efi_memmap_init(unsigned long *s, unsigned long *e)
   2.480  {
   2.481 -	struct kern_memdesc *k, *prev = 0;
   2.482 +	struct kern_memdesc *k, *prev = NULL;
   2.483  	u64	contig_low=0, contig_high=0;
   2.484  	u64	as, ae, lim;
   2.485  	void *efi_map_start, *efi_map_end, *p, *q;
   2.486 @@ -882,9 +1033,14 @@ efi_memmap_init(unsigned long *s, unsign
   2.487  			}
   2.488  			contig_high = GRANULEROUNDDOWN(contig_high);
   2.489  		}
   2.490 -		if (!is_available_memory(md))
   2.491 +		if (!is_memory_available(md))
   2.492  			continue;
   2.493  
   2.494 +#ifdef CONFIG_CRASH_DUMP
   2.495 +		/* saved_max_pfn should ignore max_addr= command line arg */
   2.496 +		if (saved_max_pfn < (efi_md_end(md) >> PAGE_SHIFT))
   2.497 +			saved_max_pfn = (efi_md_end(md) >> PAGE_SHIFT);
   2.498 +#endif
   2.499  		/*
   2.500  		 * Round ends inward to granule boundaries
   2.501  		 * Give trimmings to uncached allocator
   2.502 @@ -924,7 +1080,8 @@ efi_memmap_init(unsigned long *s, unsign
   2.503  		} else
   2.504  			ae = efi_md_end(md);
   2.505  
   2.506 -		/* keep within max_addr= command line arg */
   2.507 +		/* keep within max_addr= and min_addr= command line arg */
   2.508 +		as = max(as, min_addr);
   2.509  		ae = min(ae, max_addr);
   2.510  		if (ae <= as)
   2.511  			continue;
   2.512 @@ -952,3 +1109,174 @@ efi_memmap_init(unsigned long *s, unsign
   2.513  	*s = (u64)kern_memmap;
   2.514  	*e = (u64)++k;
   2.515  }
   2.516 +
   2.517 +#ifndef XEN
   2.518 +void
   2.519 +efi_initialize_iomem_resources(struct resource *code_resource,
   2.520 +			       struct resource *data_resource)
   2.521 +{
   2.522 +	struct resource *res;
   2.523 +	void *efi_map_start, *efi_map_end, *p;
   2.524 +	efi_memory_desc_t *md;
   2.525 +	u64 efi_desc_size;
   2.526 +	char *name;
   2.527 +	unsigned long flags;
   2.528 +
   2.529 +	efi_map_start = __va(ia64_boot_param->efi_memmap);
   2.530 +	efi_map_end   = efi_map_start + ia64_boot_param->efi_memmap_size;
   2.531 +	efi_desc_size = ia64_boot_param->efi_memdesc_size;
   2.532 +
   2.533 +	res = NULL;
   2.534 +
   2.535 +	for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
   2.536 +		md = p;
   2.537 +
   2.538 +		if (md->num_pages == 0) /* should not happen */
   2.539 +			continue;
   2.540 +
   2.541 +		flags = IORESOURCE_MEM;
   2.542 +		switch (md->type) {
   2.543 +
   2.544 +			case EFI_MEMORY_MAPPED_IO:
   2.545 +			case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
   2.546 +				continue;
   2.547 +
   2.548 +			case EFI_LOADER_CODE:
   2.549 +			case EFI_LOADER_DATA:
   2.550 +			case EFI_BOOT_SERVICES_DATA:
   2.551 +			case EFI_BOOT_SERVICES_CODE:
   2.552 +			case EFI_CONVENTIONAL_MEMORY:
   2.553 +				if (md->attribute & EFI_MEMORY_WP) {
   2.554 +					name = "System ROM";
   2.555 +					flags |= IORESOURCE_READONLY;
   2.556 +				} else {
   2.557 +					name = "System RAM";
   2.558 +				}
   2.559 +				break;
   2.560 +
   2.561 +			case EFI_ACPI_MEMORY_NVS:
   2.562 +				name = "ACPI Non-volatile Storage";
   2.563 +				flags |= IORESOURCE_BUSY;
   2.564 +				break;
   2.565 +
   2.566 +			case EFI_UNUSABLE_MEMORY:
   2.567 +				name = "reserved";
   2.568 +				flags |= IORESOURCE_BUSY | IORESOURCE_DISABLED;
   2.569 +				break;
   2.570 +
   2.571 +			case EFI_RESERVED_TYPE:
   2.572 +			case EFI_RUNTIME_SERVICES_CODE:
   2.573 +			case EFI_RUNTIME_SERVICES_DATA:
   2.574 +			case EFI_ACPI_RECLAIM_MEMORY:
   2.575 +			default:
   2.576 +				name = "reserved";
   2.577 +				flags |= IORESOURCE_BUSY;
   2.578 +				break;
   2.579 +		}
   2.580 +
   2.581 +		if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) {
   2.582 +			printk(KERN_ERR "failed to alocate resource for iomem\n");
   2.583 +			return;
   2.584 +		}
   2.585 +
   2.586 +		res->name = name;
   2.587 +		res->start = md->phys_addr;
   2.588 +		res->end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - 1;
   2.589 +		res->flags = flags;
   2.590 +
   2.591 +		if (insert_resource(&iomem_resource, res) < 0)
   2.592 +			kfree(res);
   2.593 +		else {
   2.594 +			/*
   2.595 +			 * We don't know which region contains
   2.596 +			 * kernel data so we try it repeatedly and
   2.597 +			 * let the resource manager test it.
   2.598 +			 */
   2.599 +			insert_resource(res, code_resource);
   2.600 +			insert_resource(res, data_resource);
   2.601 +#ifdef CONFIG_KEXEC
   2.602 +                        insert_resource(res, &efi_memmap_res);
   2.603 +                        insert_resource(res, &boot_param_res);
   2.604 +			if (crashk_res.end > crashk_res.start)
   2.605 +				insert_resource(res, &crashk_res);
   2.606 +#endif
   2.607 +		}
   2.608 +	}
   2.609 +}
   2.610 +
   2.611 +#ifdef CONFIG_KEXEC
   2.612 +/* find a block of memory aligned to 64M exclude reserved regions
   2.613 +   rsvd_regions are sorted
   2.614 + */
   2.615 +unsigned long __init
   2.616 +kdump_find_rsvd_region (unsigned long size,
   2.617 +		struct rsvd_region *r, int n)
   2.618 +{
   2.619 +  int i;
   2.620 +  u64 start, end;
   2.621 +  u64 alignment = 1UL << _PAGE_SIZE_64M;
   2.622 +  void *efi_map_start, *efi_map_end, *p;
   2.623 +  efi_memory_desc_t *md;
   2.624 +  u64 efi_desc_size;
   2.625 +
   2.626 +  efi_map_start = __va(ia64_boot_param->efi_memmap);
   2.627 +  efi_map_end   = efi_map_start + ia64_boot_param->efi_memmap_size;
   2.628 +  efi_desc_size = ia64_boot_param->efi_memdesc_size;
   2.629 +
   2.630 +  for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
   2.631 +	  md = p;
   2.632 +	  if (!efi_wb(md))
   2.633 +		  continue;
   2.634 +	  start = ALIGN(md->phys_addr, alignment);
   2.635 +	  end = efi_md_end(md);
   2.636 +	  for (i = 0; i < n; i++) {
   2.637 +		if (__pa(r[i].start) >= start && __pa(r[i].end) < end) {
   2.638 +			if (__pa(r[i].start) > start + size)
   2.639 +				return start;
   2.640 +			start = ALIGN(__pa(r[i].end), alignment);
   2.641 +			if (i < n-1 && __pa(r[i+1].start) < start + size)
   2.642 +				continue;
   2.643 +			else
   2.644 +				break;
   2.645 +		}
   2.646 +	  }
   2.647 +	  if (end > start + size)
   2.648 +		return start;
   2.649 +  }
   2.650 +
   2.651 +  printk(KERN_WARNING "Cannot reserve 0x%lx byte of memory for crashdump\n",
   2.652 +	size);
   2.653 +  return ~0UL;
   2.654 +}
   2.655 +#endif
   2.656 +
   2.657 +#ifdef CONFIG_PROC_VMCORE
   2.658 +/* locate the size find a the descriptor at a certain address */
   2.659 +unsigned long
   2.660 +vmcore_find_descriptor_size (unsigned long address)
   2.661 +{
   2.662 +	void *efi_map_start, *efi_map_end, *p;
   2.663 +	efi_memory_desc_t *md;
   2.664 +	u64 efi_desc_size;
   2.665 +	unsigned long ret = 0;
   2.666 +
   2.667 +	efi_map_start = __va(ia64_boot_param->efi_memmap);
   2.668 +	efi_map_end   = efi_map_start + ia64_boot_param->efi_memmap_size;
   2.669 +	efi_desc_size = ia64_boot_param->efi_memdesc_size;
   2.670 +
   2.671 +	for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
   2.672 +		md = p;
   2.673 +		if (efi_wb(md) && md->type == EFI_LOADER_DATA
   2.674 +		    && md->phys_addr == address) {
   2.675 +			ret = efi_md_size(md);
   2.676 +			break;
   2.677 +		}
   2.678 +	}
   2.679 +
   2.680 +	if (ret == 0)
   2.681 +		printk(KERN_WARNING "Cannot locate EFI vmcore descriptor\n");
   2.682 +
   2.683 +	return ret;
   2.684 +}
   2.685 +#endif
   2.686 +#endif /* XEN */
     3.1 --- a/xen/include/asm-ia64/linux-xen/linux/README.origin	Thu May 24 14:20:19 2007 -0600
     3.2 +++ b/xen/include/asm-ia64/linux-xen/linux/README.origin	Thu May 24 14:43:14 2007 -0600
     3.3 @@ -5,7 +5,6 @@
     3.4  # (e.g. with #ifdef XEN or XEN in a comment) so that they can be
     3.5  # easily updated to future versions of the corresponding Linux files.
     3.6  
     3.7 -efi.h			-> linux/include/linux/efi.h
     3.8  gfp.h	 		-> linux/include/linux/gfp.h
     3.9  hardirq.h 		-> linux/include/linux/hardirq.h
    3.10  interrupt.h 		-> linux/include/linux/interrupt.h
    3.11 @@ -17,3 +16,6 @@ oprofile.h		-> linux/include/linux/oprof
    3.12  pci.h			-> linux/include/linux/pci.h
    3.13  kobject.h		-> linux/include/linux/kobject.h
    3.14  device.h		-> linux/include/linux/device.h
    3.15 +
    3.16 +# The files below are from Linux-2.6.21
    3.17 +efi.h			-> linux/include/linux/efi.h
     4.1 --- a/xen/include/asm-ia64/linux-xen/linux/efi.h	Thu May 24 14:20:19 2007 -0600
     4.2 +++ b/xen/include/asm-ia64/linux-xen/linux/efi.h	Thu May 24 14:43:14 2007 -0600
     4.3 @@ -91,11 +91,6 @@ typedef	struct {
     4.4  
     4.5  #define EFI_PAGE_SHIFT		12
     4.6  
     4.7 -/*
     4.8 - * For current x86 implementations of EFI, there is
     4.9 - * additional padding in the mem descriptors.  This is not
    4.10 - * the case in ia64.  Need to have this fixed in the f/w.
    4.11 - */
    4.12  typedef struct {
    4.13  	u32 type;
    4.14  	u32 pad;
    4.15 @@ -103,9 +98,6 @@ typedef struct {
    4.16  	u64 virt_addr;
    4.17  	u64 num_pages;
    4.18  	u64 attribute;
    4.19 -#if defined (__i386__)
    4.20 -	u64 pad1;
    4.21 -#endif
    4.22  } efi_memory_desc_t;
    4.23  
    4.24  typedef int (*efi_freemem_callback_t) (unsigned long start, unsigned long end, void *arg);
    4.25 @@ -240,17 +232,36 @@ typedef struct {
    4.26  } efi_system_table_t;
    4.27  
    4.28  struct efi_memory_map {
    4.29 +#ifndef XEN
    4.30 +	void *phys_map;
    4.31 +	void *map;
    4.32 +#else
    4.33  	efi_memory_desc_t *phys_map;
    4.34  	efi_memory_desc_t *map;
    4.35 +#endif
    4.36 +	void *map_end;
    4.37  	int nr_map;
    4.38  	unsigned long desc_version;
    4.39 +	unsigned long desc_size;
    4.40  };
    4.41  
    4.42 +#define EFI_INVALID_TABLE_ADDR		(~0UL)
    4.43 +
    4.44  /*
    4.45   * All runtime access to EFI goes through this structure:
    4.46   */
    4.47  extern struct efi {
    4.48  	efi_system_table_t *systab;	/* EFI system table */
    4.49 +#ifndef XEN
    4.50 +	unsigned long mps;		/* MPS table */
    4.51 +	unsigned long acpi;		/* ACPI table  (IA64 ext 0.71) */
    4.52 +	unsigned long acpi20;		/* ACPI table  (ACPI 2.0) */
    4.53 +	unsigned long smbios;		/* SM BIOS table */
    4.54 +	unsigned long sal_systab;	/* SAL system table */
    4.55 +	unsigned long boot_info;	/* boot info table */
    4.56 +	unsigned long hcdp;		/* HCDP table */
    4.57 +	unsigned long uga;		/* UGA table */
    4.58 +#else
    4.59  	void *mps;			/* MPS table */
    4.60  	void *acpi;			/* ACPI table  (IA64 ext 0.71) */
    4.61  	void *acpi20;			/* ACPI table  (ACPI 2.0) */
    4.62 @@ -259,6 +270,7 @@ extern struct efi {
    4.63  	void *boot_info;		/* boot info table */
    4.64  	void *hcdp;			/* HCDP table */
    4.65  	void *uga;			/* UGA table */
    4.66 +#endif
    4.67  	efi_get_time_t *get_time;
    4.68  	efi_set_time_t *set_time;
    4.69  	efi_get_wakeup_time_t *get_wakeup_time;
    4.70 @@ -302,11 +314,15 @@ extern void efi_enter_virtual_mode (void
    4.71  extern u64 efi_get_iobase (void);
    4.72  extern u32 efi_mem_type (unsigned long phys_addr);
    4.73  extern u64 efi_mem_attributes (unsigned long phys_addr);
    4.74 +extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
    4.75 +extern int efi_mem_attribute_range (unsigned long phys_addr, unsigned long size,
    4.76 +				    u64 attr);
    4.77  extern int __init efi_uart_console_only (void);
    4.78  extern void efi_initialize_iomem_resources(struct resource *code_resource,
    4.79  					struct resource *data_resource);
    4.80 -extern unsigned long __init efi_get_time(void);
    4.81 -extern int __init efi_set_rtc_mmss(unsigned long nowtime);
    4.82 +extern unsigned long efi_get_time(void);
    4.83 +extern int efi_set_rtc_mmss(unsigned long nowtime);
    4.84 +extern int is_available_memory(efi_memory_desc_t * md);
    4.85  extern struct efi_memory_map memmap;
    4.86  
    4.87  /**