ia64/xen-unstable

changeset 6649:d105692072a4

Fix PCI iomem resource fixup.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Sep 05 19:53:44 2005 +0000 (2005-09-05)
parents 22599cd6aae0
children aeaa3c83f6e5
files linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/e820.c xen/arch/x86/dom0_ops.c xen/common/domain.c xen/common/memory.c xen/include/public/dom0_ops.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c	Mon Sep 05 19:43:04 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c	Mon Sep 05 19:53:44 2005 +0000
     1.3 @@ -1235,10 +1235,64 @@ static void __init
     1.4  legacy_init_iomem_resources(struct resource *code_resource, struct resource *data_resource)
     1.5  {
     1.6  	int i;
     1.7 +#ifdef CONFIG_XEN
     1.8 +	dom0_op_t op;
     1.9 +	struct dom0_memory_map_entry *map;
    1.10 +	unsigned long gapstart, gapsize;
    1.11 +	unsigned long long last;
    1.12 +#endif
    1.13  
    1.14  #ifdef CONFIG_XEN_PRIVILEGED_GUEST
    1.15  	probe_roms();
    1.16  #endif
    1.17 +
    1.18 +#ifdef CONFIG_XEN
    1.19 +	map = alloc_bootmem_low_pages(PAGE_SIZE);
    1.20 +	op.cmd = DOM0_PHYSICAL_MEMORY_MAP;
    1.21 +	op.u.physical_memory_map.memory_map = map;
    1.22 +	op.u.physical_memory_map.max_map_entries =
    1.23 +		PAGE_SIZE / sizeof(struct dom0_memory_map_entry);
    1.24 +	BUG_ON(HYPERVISOR_dom0_op(&op));
    1.25 +
    1.26 +	last = 0x100000000ULL;
    1.27 +	gapstart = 0x10000000;
    1.28 +	gapsize = 0x400000;
    1.29 +
    1.30 +	for (i = op.u.physical_memory_map.nr_map_entries - 1; i >= 0; i--) {
    1.31 +		struct resource *res;
    1.32 +
    1.33 +		if ((last > map[i].end) && ((last - map[i].end) > gapsize)) {
    1.34 +			gapsize = last - map[i].end;
    1.35 +			gapstart = map[i].end;
    1.36 +		}
    1.37 +		if (map[i].start < last)
    1.38 +			last = map[i].start;
    1.39 +
    1.40 +		if (map[i].end > 0x100000000ULL)
    1.41 +			continue;
    1.42 +		res = alloc_bootmem_low(sizeof(struct resource));
    1.43 +		res->name = map[i].is_ram ? "System RAM" : "reserved";
    1.44 +		res->start = map[i].start;
    1.45 +		res->end = map[i].end - 1;
    1.46 +		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
    1.47 +		request_resource(&iomem_resource, res);
    1.48 +	}
    1.49 +
    1.50 +	free_bootmem(__pa(map), PAGE_SIZE);
    1.51 +
    1.52 +	/*
    1.53 +	 * Start allocating dynamic PCI memory a bit into the gap,
    1.54 +	 * aligned up to the nearest megabyte.
    1.55 +	 *
    1.56 +	 * Question: should we try to pad it up a bit (do something
    1.57 +	 * like " + (gapsize >> 3)" in there too?). We now have the
    1.58 +	 * technology.
    1.59 +	 */
    1.60 +	pci_mem_start = (gapstart + 0xfffff) & ~0xfffff;
    1.61 +
    1.62 +	printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n",
    1.63 +		pci_mem_start, gapstart, gapsize);
    1.64 +#else
    1.65  	for (i = 0; i < e820.nr_map; i++) {
    1.66  		struct resource *res;
    1.67  		if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
    1.68 @@ -1264,6 +1318,7 @@ legacy_init_iomem_resources(struct resou
    1.69  			request_resource(res, data_resource);
    1.70  		}
    1.71  	}
    1.72 +#endif
    1.73  }
    1.74  
    1.75  /*
    1.76 @@ -1271,23 +1326,29 @@ legacy_init_iomem_resources(struct resou
    1.77   */
    1.78  static void __init register_memory(void)
    1.79  {
    1.80 +#ifndef CONFIG_XEN
    1.81  	unsigned long gapstart, gapsize;
    1.82  	unsigned long long last;
    1.83 +#endif
    1.84  	int	      i;
    1.85  
    1.86 +	/* Nothing to do if not running in dom0. */
    1.87 +	if (!(xen_start_info->flags & SIF_INITDOMAIN))
    1.88 +		return;
    1.89 +
    1.90  	if (efi_enabled)
    1.91  		efi_initialize_iomem_resources(&code_resource, &data_resource);
    1.92  	else
    1.93  		legacy_init_iomem_resources(&code_resource, &data_resource);
    1.94  
    1.95 -	if (xen_start_info->flags & SIF_INITDOMAIN)
    1.96 -		/* EFI systems may still have VGA */
    1.97 -		request_resource(&iomem_resource, &video_ram_resource);
    1.98 +	/* EFI systems may still have VGA */
    1.99 +	request_resource(&iomem_resource, &video_ram_resource);
   1.100  
   1.101  	/* request I/O space for devices used on all i[345]86 PCs */
   1.102  	for (i = 0; i < STANDARD_IO_RESOURCES; i++)
   1.103  		request_resource(&ioport_resource, &standard_io_resources[i]);
   1.104  
   1.105 +#ifndef CONFIG_XEN
   1.106  	/*
   1.107  	 * Search for the bigest gap in the low 32 bits of the e820
   1.108  	 * memory space.
   1.109 @@ -1328,6 +1389,7 @@ static void __init register_memory(void)
   1.110  
   1.111  	printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n",
   1.112  		pci_mem_start, gapstart, gapsize);
   1.113 +#endif
   1.114  }
   1.115  
   1.116  /* Use inline assembly to define this because the nops are defined 
     2.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/e820.c	Mon Sep 05 19:43:04 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/e820.c	Mon Sep 05 19:53:44 2005 +0000
     2.3 @@ -517,11 +517,10 @@ void __init setup_memory_region(void)
     2.4  }
     2.5  
     2.6  #else  /* CONFIX_XEN */
     2.7 +
     2.8  extern unsigned long xen_override_max_pfn;
     2.9  extern union xen_start_info_union xen_start_info_union;
    2.10 -/*
    2.11 - * Guest physical starts from 0.
    2.12 - */
    2.13 +
    2.14  unsigned long __init e820_end_of_ram(void)
    2.15  {
    2.16          unsigned long max_end_pfn = xen_start_info->nr_pages;
    2.17 @@ -532,11 +531,69 @@ unsigned long __init e820_end_of_ram(voi
    2.18          return xen_override_max_pfn;
    2.19  }
    2.20  
    2.21 -
    2.22 -
    2.23  void __init e820_reserve_resources(void) 
    2.24  {
    2.25 -	return;			/* Xen won't have reserved entries */
    2.26 +	dom0_op_t op;
    2.27 +	struct dom0_memory_map_entry *map;
    2.28 +	unsigned long gapstart, gapsize, last;
    2.29 +	int i, found = 0;
    2.30 +
    2.31 +	if (!(xen_start_info->flags & SIF_INITDOMAIN))
    2.32 +		return;
    2.33 +
    2.34 +	map = alloc_bootmem_low_pages(PAGE_SIZE);
    2.35 +	op.cmd = DOM0_PHYSICAL_MEMORY_MAP;
    2.36 +	op.u.physical_memory_map.memory_map = map;
    2.37 +	op.u.physical_memory_map.max_map_entries =
    2.38 +		PAGE_SIZE / sizeof(struct dom0_memory_map_entry);
    2.39 +	BUG_ON(HYPERVISOR_dom0_op(&op));
    2.40 +
    2.41 +	last = 0x100000000ULL;
    2.42 +	gapstart = 0x10000000;
    2.43 +	gapsize = 0x400000;
    2.44 +
    2.45 +	for (i = op.u.physical_memory_map.nr_map_entries - 1; i >= 0; i--) {
    2.46 +		struct resource *res;
    2.47 +
    2.48 +		if ((last > map[i].end) && ((last - map[i].end) > gapsize)) {
    2.49 +			gapsize = last - map[i].end;
    2.50 +			gapstart = map[i].end;
    2.51 +			found = 1;
    2.52 +		}
    2.53 +		if (map[i].start < last)
    2.54 +			last = map[i].start;
    2.55 +
    2.56 +		if (map[i].end > 0x100000000ULL)
    2.57 +			continue;
    2.58 +		res = alloc_bootmem_low(sizeof(struct resource));
    2.59 +		res->name = map[i].is_ram ? "System RAM" : "reserved";
    2.60 +		res->start = map[i].start;
    2.61 +		res->end = map[i].end - 1;
    2.62 +		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
    2.63 +		request_resource(&iomem_resource, res);
    2.64 +	}
    2.65 +
    2.66 +	free_bootmem(__pa(map), PAGE_SIZE);
    2.67 +
    2.68 +	if (!found) {
    2.69 +		HYPERVISOR_memory_op(XENMEM_maximum_ram_page, &gapstart);
    2.70 +		gapstart = (gapstart << PAGE_SHIFT) + 1024*1024;
    2.71 +		printk(KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit address range\n"
    2.72 +		       KERN_ERR "PCI: Unassigned devices with 32bit resource registers may break!\n");
    2.73 +	}
    2.74 +
    2.75 +	/*
    2.76 +	 * Start allocating dynamic PCI memory a bit into the gap,
    2.77 +	 * aligned up to the nearest megabyte.
    2.78 +	 *
    2.79 +	 * Question: should we try to pad it up a bit (do something
    2.80 +	 * like " + (gapsize >> 3)" in there too?). We now have the
    2.81 +	 * technology.
    2.82 +	 */
    2.83 +	pci_mem_start = (gapstart + 0xfffff) & ~0xfffff;
    2.84 +
    2.85 +	printk(KERN_INFO "Allocating PCI resources starting at %lx (gap: %lx:%lx)\n",
    2.86 +		pci_mem_start, gapstart, gapsize);
    2.87  }
    2.88  
    2.89  #endif
    2.90 @@ -558,6 +615,7 @@ unsigned long pci_mem_start = 0xaeedbabe
    2.91   */
    2.92  __init void e820_setup_gap(void)
    2.93  {
    2.94 +#ifndef CONFIG_XEN
    2.95  	unsigned long gapstart, gapsize;
    2.96  	unsigned long last;
    2.97  	int i;
    2.98 @@ -606,4 +664,5 @@ unsigned long pci_mem_start = 0xaeedbabe
    2.99  
   2.100  	printk(KERN_INFO "Allocating PCI resources starting at %lx (gap: %lx:%lx)\n",
   2.101  		pci_mem_start, gapstart, gapsize);
   2.102 +#endif
   2.103  }
     3.1 --- a/xen/arch/x86/dom0_ops.c	Mon Sep 05 19:43:04 2005 +0000
     3.2 +++ b/xen/arch/x86/dom0_ops.c	Mon Sep 05 19:53:44 2005 +0000
     3.3 @@ -389,9 +389,31 @@ long arch_do_dom0_op(dom0_op_t *op, dom0
     3.4      }
     3.5      break;
     3.6  
     3.7 +    case DOM0_PHYSICAL_MEMORY_MAP:
     3.8 +    {
     3.9 +        struct dom0_memory_map_entry entry;
    3.10 +        int i;
    3.11 +
    3.12 +        for ( i = 0; i < e820.nr_map; i++ )
    3.13 +        {
    3.14 +            if ( i >= op->u.physical_memory_map.max_map_entries )
    3.15 +                break;
    3.16 +            entry.start  = e820.map[i].addr;
    3.17 +            entry.end    = e820.map[i].addr + e820.map[i].size;
    3.18 +            entry.is_ram = (e820.map[i].type == E820_RAM);
    3.19 +            (void)copy_to_user(
    3.20 +                &op->u.physical_memory_map.memory_map[i],
    3.21 +                &entry, sizeof(entry));
    3.22 +        }
    3.23 +
    3.24 +        op->u.physical_memory_map.nr_map_entries = i;
    3.25 +        (void)copy_to_user(u_dom0_op, op, sizeof(*op));
    3.26 +    }
    3.27 +    break;
    3.28 +
    3.29      default:
    3.30          ret = -ENOSYS;
    3.31 -
    3.32 +        break;
    3.33      }
    3.34  
    3.35      return ret;
     4.1 --- a/xen/common/domain.c	Mon Sep 05 19:43:04 2005 +0000
     4.2 +++ b/xen/common/domain.c	Mon Sep 05 19:53:44 2005 +0000
     4.3 @@ -176,10 +176,7 @@ static __init int domain_shutdown_finali
     4.4  void domain_shutdown(u8 reason)
     4.5  {
     4.6      struct domain *d = current->domain;
     4.7 -    struct vcpu *v;
     4.8 -
     4.9 -    if(reason == SHUTDOWN_crash) 
    4.10 -        printk("Domain %d crash detected.\n", d->domain_id); 
    4.11 +    struct vcpu   *v;
    4.12  
    4.13      if ( d->domain_id == 0 )
    4.14      {
     5.1 --- a/xen/common/memory.c	Mon Sep 05 19:43:04 2005 +0000
     5.2 +++ b/xen/common/memory.c	Mon Sep 05 19:53:44 2005 +0000
     5.3 @@ -190,7 +190,7 @@ long do_memory_op(int cmd, void *arg)
     5.4      case XENMEM_maximum_ram_page:
     5.5          if ( put_user(max_page, (unsigned long *)arg) )
     5.6              return -EFAULT;
     5.7 -        rc = -ENOSYS;
     5.8 +        rc = 0;
     5.9          break;
    5.10  
    5.11      default:
     6.1 --- a/xen/include/public/dom0_ops.h	Mon Sep 05 19:43:04 2005 +0000
     6.2 +++ b/xen/include/public/dom0_ops.h	Mon Sep 05 19:53:44 2005 +0000
     6.3 @@ -374,6 +374,18 @@ typedef struct {
     6.4      int quirk_id;
     6.5  } dom0_platform_quirk_t;
     6.6  
     6.7 +#define DOM0_PHYSICAL_MEMORY_MAP 40
     6.8 +typedef struct {
     6.9 +    /* IN variables. */
    6.10 +    int max_map_entries;
    6.11 +    /* OUT variables. */
    6.12 +    int nr_map_entries;
    6.13 +    struct dom0_memory_map_entry {
    6.14 +        u64 start, end;
    6.15 +        int is_ram;
    6.16 +    } *memory_map;
    6.17 +} dom0_physical_memory_map_t;
    6.18 +
    6.19  typedef struct {
    6.20      u32 cmd;
    6.21      u32 interface_version; /* DOM0_INTERFACE_VERSION */
    6.22 @@ -408,6 +420,7 @@ typedef struct {
    6.23          dom0_getvcpucontext_t    getvcpucontext;
    6.24          dom0_getdomaininfolist_t getdomaininfolist;
    6.25          dom0_platform_quirk_t    platform_quirk;
    6.26 +        dom0_physical_memory_map_t physical_memory_map;
    6.27      } u;
    6.28  } dom0_op_t;
    6.29