From: "Siddha, Suresh B" Subject: [Patch] use dev DMA masks in dma_alloc_coherent Date: Thu, 18 Aug 2005 11:23:08 -0700 Message-ID: <20050818112308.B17270@unix-os.sc.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir.Fraser@cl.cam.ac.uk Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org 64bit devices (whose dma_mask and coherent_dma_mask are set to 64bits) can use MEMZONE_DOM while creating contiguous_region for coherent mappings. Please apply the appended patch. Signed-off-by: Suresh Siddha diff -r 84ee014ebd41 linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c Wed Aug 17 20:34:38 2005 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c Thu Aug 18 11:06:42 2005 @@ -129,6 +129,7 @@ struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL; unsigned int order = get_order(size); unsigned long vstart; + unsigned long dma_mask = 0; /* ignore region specifiers */ gfp &= ~(__GFP_DMA | __GFP_HIGHMEM); @@ -145,13 +146,18 @@ return NULL; } - if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff)) - gfp |= GFP_DMA; + if (!dev) + dma_mask = 0xffffffff; + else + /* Kludge to make it bug-to-bug compatible with i386. i386 + uses the normal dma_mask for alloc_coherent. */ + dma_mask = dev->coherent_dma_mask & *dev->dma_mask; vstart = __get_free_pages(gfp, order); ret = (void *)vstart; if (ret != NULL) { + order |= (dma_mask <= 0xffffffff) ? (32 << 8) : 0; xen_create_contiguous_region(vstart, order); memset(ret, 0, size); diff -r 84ee014ebd41 linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c Wed Aug 17 20:34:38 2005 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c Thu Aug 18 11:06:42 2005 @@ -131,7 +131,7 @@ xen_create_contiguous_region( (unsigned long)io_tlb_start, - get_order(io_tlb_nslabs * (1 << IO_TLB_SHIFT))); + get_order(io_tlb_nslabs * (1 << IO_TLB_SHIFT)) | (32 << 8)); io_tlb_end = io_tlb_start + io_tlb_nslabs * (1 << IO_TLB_SHIFT); diff -r 84ee014ebd41 linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c Wed Aug 17 20:34:38 2005 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c Thu Aug 18 11:06:42 2005 @@ -294,7 +294,7 @@ /* 2. Get a new contiguous memory extent. */ BUG_ON(HYPERVISOR_dom_mem_op( - MEMOP_increase_reservation, &mfn, 1, order | (32<<8)) != 1); + MEMOP_increase_reservation, &mfn, 1, order) != 1); /* 3. Map the new extent in place of old pages. */ for (i = 0; i < (1<