ia64/xen-unstable

changeset 12641:39e40ccf7df5

Allow DMA address width to be overridden with boot parameters:

In Xen: dma_bits=28 (for example)
In Linux: swiotlb_bits=28 (for example)

Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Tue Nov 28 17:15:22 2006 +0000 (2006-11-28)
parents d30be569532d
children 33951d547223
files linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c xen/common/memory.c xen/common/page_alloc.c xen/include/asm-ia64/config.h xen/include/asm-powerpc/config.h xen/include/asm-x86/config.h xen/include/xen/mm.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c	Tue Nov 28 17:04:32 2006 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c	Tue Nov 28 17:15:22 2006 +0000
     1.3 @@ -48,7 +48,7 @@ EXPORT_SYMBOL(swiotlb);
     1.4  #define IO_TLB_SHIFT 11
     1.5  
     1.6  /* Width of DMA addresses in the IO TLB. 30 bits is a b44 limitation. */
     1.7 -#define IO_TLB_DMA_BITS 30
     1.8 +#define DEFAULT_IO_TLB_DMA_BITS 30
     1.9  
    1.10  static int swiotlb_force;
    1.11  static char *iotlb_virt_start;
    1.12 @@ -98,6 +98,15 @@ static struct phys_addr {
    1.13   */
    1.14  static DEFINE_SPINLOCK(io_tlb_lock);
    1.15  
    1.16 +static unsigned int io_tlb_dma_bits = DEFAULT_IO_TLB_DMA_BITS;
    1.17 +static int __init
    1.18 +setup_io_tlb_bits(char *str)
    1.19 +{
    1.20 +	io_tlb_dma_bits = simple_strtoul(str, NULL, 0);
    1.21 +	return 0;
    1.22 +}
    1.23 +__setup("swiotlb_bits=", setup_io_tlb_bits);
    1.24 +
    1.25  static int __init
    1.26  setup_io_tlb_npages(char *str)
    1.27  {
    1.28 @@ -158,7 +167,7 @@ swiotlb_init_with_default_size (size_t d
    1.29  		int rc = xen_create_contiguous_region(
    1.30  			(unsigned long)iotlb_virt_start + (i << IO_TLB_SHIFT),
    1.31  			get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT),
    1.32 -			IO_TLB_DMA_BITS);
    1.33 +			io_tlb_dma_bits);
    1.34  		BUG_ON(rc);
    1.35  	}
    1.36  
    1.37 @@ -183,10 +192,12 @@ swiotlb_init_with_default_size (size_t d
    1.38  
    1.39  	printk(KERN_INFO "Software IO TLB enabled: \n"
    1.40  	       " Aperture:     %lu megabytes\n"
    1.41 -	       " Kernel range: 0x%016lx - 0x%016lx\n",
    1.42 +	       " Kernel range: 0x%016lx - 0x%016lx\n"
    1.43 +	       " Address size: %u bits\n",
    1.44  	       bytes >> 20,
    1.45  	       (unsigned long)iotlb_virt_start,
    1.46 -	       (unsigned long)iotlb_virt_start + bytes);
    1.47 +	       (unsigned long)iotlb_virt_start + bytes,
    1.48 +	       io_tlb_dma_bits);
    1.49  }
    1.50  
    1.51  void
    1.52 @@ -654,7 +665,7 @@ swiotlb_dma_mapping_error(dma_addr_t dma
    1.53  int
    1.54  swiotlb_dma_supported (struct device *hwdev, u64 mask)
    1.55  {
    1.56 -	return (mask >= ((1UL << IO_TLB_DMA_BITS) - 1));
    1.57 +	return (mask >= ((1UL << io_tlb_dma_bits) - 1));
    1.58  }
    1.59  
    1.60  EXPORT_SYMBOL(swiotlb_init);
     2.1 --- a/xen/common/memory.c	Tue Nov 28 17:04:32 2006 +0000
     2.2 +++ b/xen/common/memory.c	Tue Nov 28 17:15:22 2006 +0000
     2.3 @@ -328,7 +328,7 @@ static long memory_exchange(XEN_GUEST_HA
     2.4           (exch.out.address_bits <
     2.5            (get_order_from_pages(max_page) + PAGE_SHIFT)) )
     2.6      {
     2.7 -        if ( exch.out.address_bits < MAX_DMADOM_BITS )
     2.8 +        if ( exch.out.address_bits < dma_bitsize )
     2.9          {
    2.10              rc = -ENOMEM;
    2.11              goto fail_early;
    2.12 @@ -541,7 +541,7 @@ long do_memory_op(unsigned long cmd, XEN
    2.13               (reservation.address_bits <
    2.14                (get_order_from_pages(max_page) + PAGE_SHIFT)) )
    2.15          {
    2.16 -            if ( reservation.address_bits < MAX_DMADOM_BITS )
    2.17 +            if ( reservation.address_bits < dma_bitsize )
    2.18                  return start_extent;
    2.19              args.memflags = MEMF_dma;
    2.20          }
     3.1 --- a/xen/common/page_alloc.c	Tue Nov 28 17:04:32 2006 +0000
     3.2 +++ b/xen/common/page_alloc.c	Tue Nov 28 17:15:22 2006 +0000
     3.3 @@ -46,18 +46,39 @@ static char opt_badpage[100] = "";
     3.4  string_param("badpage", opt_badpage);
     3.5  
     3.6  /*
     3.7 + * Bit width of the DMA heap.
     3.8 + */
     3.9 +unsigned int  dma_bitsize = CONFIG_DMA_BITSIZE;
    3.10 +unsigned long max_dma_mfn = (1UL << (CONFIG_DMA_BITSIZE - PAGE_SHIFT)) - 1;
    3.11 +static void parse_dma_bits(char *s)
    3.12 +{
    3.13 +    unsigned int v = simple_strtol(s, NULL, 0);
    3.14 +    if ( v >= (sizeof(long)*8 + PAGE_SHIFT) )
    3.15 +    {
    3.16 +        dma_bitsize = sizeof(long)*8 + PAGE_SHIFT;
    3.17 +        max_dma_mfn = ~0UL;
    3.18 +    }
    3.19 +    else
    3.20 +    {
    3.21 +        dma_bitsize = v;
    3.22 +        max_dma_mfn = (1UL << (dma_bitsize - PAGE_SHIFT)) - 1;
    3.23 +    }
    3.24 +}
    3.25 +custom_param("dma_bits", parse_dma_bits);
    3.26 +
    3.27 +/*
    3.28   * Amount of memory to reserve in a low-memory (<4GB) pool for specific
    3.29   * allocation requests. Ordinary requests will not fall back to the
    3.30   * lowmem emergency pool.
    3.31   */
    3.32 -static unsigned long lowmem_emergency_pool_pages;
    3.33 -static void parse_lowmem_emergency_pool(char *s)
    3.34 +static unsigned long dma_emergency_pool_pages;
    3.35 +static void parse_dma_emergency_pool(char *s)
    3.36  {
    3.37      unsigned long long bytes;
    3.38      bytes = parse_size_and_unit(s, NULL);
    3.39 -    lowmem_emergency_pool_pages = bytes >> PAGE_SHIFT;
    3.40 +    dma_emergency_pool_pages = bytes >> PAGE_SHIFT;
    3.41  }
    3.42 -custom_param("lowmem_emergency_pool", parse_lowmem_emergency_pool);
    3.43 +custom_param("dma_emergency_pool", parse_dma_emergency_pool);
    3.44  
    3.45  #define round_pgdown(_p)  ((_p)&PAGE_MASK)
    3.46  #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
    3.47 @@ -248,7 +269,7 @@ unsigned long alloc_boot_pages(unsigned 
    3.48  #define NR_ZONES    3
    3.49  
    3.50  #define pfn_dom_zone_type(_pfn)                                 \
    3.51 -    (((_pfn) <= MAX_DMADOM_PFN) ? MEMZONE_DMADOM : MEMZONE_DOM)
    3.52 +    (((_pfn) <= max_dma_mfn) ? MEMZONE_DMADOM : MEMZONE_DOM)
    3.53  
    3.54  static struct list_head heap[NR_ZONES][MAX_NUMNODES][MAX_ORDER+1];
    3.55  
    3.56 @@ -278,6 +299,8 @@ void end_boot_allocator(void)
    3.57          if ( curr_free )
    3.58              init_heap_pages(pfn_dom_zone_type(i), mfn_to_page(i), 1);
    3.59      }
    3.60 +
    3.61 +    printk("Domain heap initialised: DMA width %u bits\n", dma_bitsize);
    3.62  }
    3.63  
    3.64  /* 
    3.65 @@ -575,13 +598,13 @@ void init_domheap_pages(paddr_t ps, padd
    3.66      s_tot = round_pgup(ps) >> PAGE_SHIFT;
    3.67      e_tot = round_pgdown(pe) >> PAGE_SHIFT;
    3.68  
    3.69 -    s_dma = min(s_tot, MAX_DMADOM_PFN + 1);
    3.70 -    e_dma = min(e_tot, MAX_DMADOM_PFN + 1);
    3.71 +    s_dma = min(s_tot, max_dma_mfn + 1);
    3.72 +    e_dma = min(e_tot, max_dma_mfn + 1);
    3.73      if ( s_dma < e_dma )
    3.74          init_heap_pages(MEMZONE_DMADOM, mfn_to_page(s_dma), e_dma - s_dma);
    3.75  
    3.76 -    s_nrm = max(s_tot, MAX_DMADOM_PFN + 1);
    3.77 -    e_nrm = max(e_tot, MAX_DMADOM_PFN + 1);
    3.78 +    s_nrm = max(s_tot, max_dma_mfn + 1);
    3.79 +    e_nrm = max(e_tot, max_dma_mfn + 1);
    3.80      if ( s_nrm < e_nrm )
    3.81          init_heap_pages(MEMZONE_DOM, mfn_to_page(s_nrm), e_nrm - s_nrm);
    3.82  }
    3.83 @@ -655,7 +678,7 @@ struct page_info *__alloc_domheap_pages(
    3.84          if ( unlikely(pg == NULL) &&
    3.85               ((order > MAX_ORDER) ||
    3.86                (avail_heap_pages(MEMZONE_DMADOM,-1) <
    3.87 -               (lowmem_emergency_pool_pages + (1UL << order)))) )
    3.88 +               (dma_emergency_pool_pages + (1UL << order)))) )
    3.89              return NULL;
    3.90      }
    3.91  
    3.92 @@ -799,8 +822,8 @@ unsigned long avail_domheap_pages(void)
    3.93      avail_nrm = avail_heap_pages(MEMZONE_DOM,-1);
    3.94  
    3.95      avail_dma = avail_heap_pages(MEMZONE_DMADOM,-1);
    3.96 -    if ( avail_dma > lowmem_emergency_pool_pages )
    3.97 -        avail_dma -= lowmem_emergency_pool_pages;
    3.98 +    if ( avail_dma > dma_emergency_pool_pages )
    3.99 +        avail_dma -= dma_emergency_pool_pages;
   3.100      else
   3.101          avail_dma = 0;
   3.102  
     4.1 --- a/xen/include/asm-ia64/config.h	Tue Nov 28 17:04:32 2006 +0000
     4.2 +++ b/xen/include/asm-ia64/config.h	Tue Nov 28 17:15:22 2006 +0000
     4.3 @@ -41,9 +41,7 @@
     4.4  #define CONFIG_IOSAPIC
     4.5  #define supervisor_mode_kernel (0)
     4.6  
     4.7 -#define MAX_DMADOM_BITS 30
     4.8 -#define MAX_DMADOM_MASK ((1UL << MAX_DMADOM_BITS) - 1)
     4.9 -#define MAX_DMADOM_PFN  (MAX_DMADOM_MASK >> PAGE_SHIFT)
    4.10 +#define CONFIG_DMA_BITSIZE 30
    4.11  
    4.12  /* If PERFC is used, include privop maps.  */
    4.13  #ifdef PERF_COUNTERS
     5.1 --- a/xen/include/asm-powerpc/config.h	Tue Nov 28 17:04:32 2006 +0000
     5.2 +++ b/xen/include/asm-powerpc/config.h	Tue Nov 28 17:15:22 2006 +0000
     5.3 @@ -70,7 +70,7 @@ extern char __bss_start[];
     5.4  
     5.5  #define supervisor_mode_kernel (0)
     5.6  
     5.7 -#define MAX_DMADOM_PFN (~0UL)
     5.8 +#define CONFIG_DMA_BITSIZE 64
     5.9  
    5.10  #include <asm/powerpc64/config.h>
    5.11  
     6.1 --- a/xen/include/asm-x86/config.h	Tue Nov 28 17:04:32 2006 +0000
     6.2 +++ b/xen/include/asm-x86/config.h	Tue Nov 28 17:15:22 2006 +0000
     6.3 @@ -82,9 +82,7 @@
     6.4  /* Debug stack is restricted to 8kB by guard pages. */
     6.5  #define DEBUG_STACK_SIZE 8192
     6.6  
     6.7 -#define MAX_DMADOM_BITS 30
     6.8 -#define MAX_DMADOM_MASK ((1UL << MAX_DMADOM_BITS) - 1)
     6.9 -#define MAX_DMADOM_PFN  (MAX_DMADOM_MASK >> PAGE_SHIFT)
    6.10 +#define CONFIG_DMA_BITSIZE 30
    6.11  
    6.12  #ifndef __ASSEMBLY__
    6.13  extern unsigned long _end; /* standard ELF symbol */
     7.1 --- a/xen/include/xen/mm.h	Tue Nov 28 17:04:32 2006 +0000
     7.2 +++ b/xen/include/xen/mm.h	Tue Nov 28 17:15:22 2006 +0000
     7.3 @@ -89,6 +89,10 @@ int assign_pages(
     7.4  #define MAX_ORDER 20 /* 2^20 contiguous pages */
     7.5  #endif
     7.6  
     7.7 +/* DMA heap parameters. */
     7.8 +extern unsigned int  dma_bitsize;
     7.9 +extern unsigned long max_dma_mfn;
    7.10 +
    7.11  /* Automatic page scrubbing for dead domains. */
    7.12  extern struct list_head page_scrub_list;
    7.13  #define page_scrub_schedule_work()              \