ia64/xen-unstable

changeset 2062:a4c9a5d96b3c

bitkeeper revision 1.1136 (410fcd1dXCUIdIRu9TcJZuNDJEcV9w)

Merge coherent alloc routines in 2.4/2.6.
author kaf24@scramble.cl.cam.ac.uk
date Tue Aug 03 17:36:29 2004 +0000 (2004-08-03)
parents 20a45872cb42
children ef4ec427c032
files .rootkeys linux-2.4.26-xen-sparse/arch/xen/kernel/pci-dma.c linux-2.4.26-xen-sparse/mkbuildtree linux-2.6.7-xen-sparse/arch/xen/i386/kernel/pci-dma.c
line diff
     1.1 --- a/.rootkeys	Tue Aug 03 17:21:57 2004 +0000
     1.2 +++ b/.rootkeys	Tue Aug 03 17:36:29 2004 +0000
     1.3 @@ -70,7 +70,6 @@ 3e5a4e65Hy_1iUvMTPsNqGNXd9uFpg linux-2.4
     1.4  3e5a4e65RMGcuA-HCn3-wNx3fFQwdg linux-2.4.26-xen-sparse/arch/xen/kernel/i386_ksyms.c
     1.5  3e5a4e653U6cELGv528IxOLHvCq8iA linux-2.4.26-xen-sparse/arch/xen/kernel/irq.c
     1.6  3e5a4e65muT6SU3ck47IP87Q7Ti5hA linux-2.4.26-xen-sparse/arch/xen/kernel/ldt.c
     1.7 -4051db84bZeRX7a_Kh6VyyDuT5FOIg linux-2.4.26-xen-sparse/arch/xen/kernel/pci-dma.c
     1.8  4051db95N9N99FjsRwi49YKUNHWI8A linux-2.4.26-xen-sparse/arch/xen/kernel/pci-pc.c
     1.9  3e5a4e65IGt3WwQDNiL4h-gYWgNTWQ linux-2.4.26-xen-sparse/arch/xen/kernel/process.c
    1.10  3e5a4e66tR-qJMLj3MppcKqmvuI2XQ linux-2.4.26-xen-sparse/arch/xen/kernel/setup.c
     2.1 --- a/linux-2.4.26-xen-sparse/arch/xen/kernel/pci-dma.c	Tue Aug 03 17:21:57 2004 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,81 +0,0 @@
     2.4 -/*
     2.5 - * Dynamic DMA mapping support.
     2.6 - *
     2.7 - * On i386 there is no hardware dynamic DMA address translation,
     2.8 - * so consistent alloc/free are merely page allocation/freeing.
     2.9 - * The rest of the dynamic DMA mapping interface is implemented
    2.10 - * in asm/pci.h.
    2.11 - */
    2.12 -
    2.13 -#include <linux/types.h>
    2.14 -#include <linux/mm.h>
    2.15 -#include <linux/string.h>
    2.16 -#include <linux/pci.h>
    2.17 -#include <asm/io.h>
    2.18 -
    2.19 -void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
    2.20 -			   dma_addr_t *dma_handle)
    2.21 -{
    2.22 -	void *ret;
    2.23 -	int gfp = GFP_ATOMIC;
    2.24 -	unsigned int order = get_order(size);
    2.25 -	unsigned long vstart;
    2.26 -
    2.27 -	if (hwdev == NULL || ((u32)hwdev->dma_mask < 0xffffffff))
    2.28 -		gfp |= GFP_DMA;
    2.29 -
    2.30 -	ret = (void *)vstart = __get_free_pages(gfp, order);
    2.31 -	if (ret == NULL)
    2.32 -		return ret;
    2.33 -
    2.34 -	/*
    2.35 -	 * Ensure multi-page extents are contiguous in machine memory.
    2.36 -	 * This code could be cleaned up some, and the number of
    2.37 -	 * hypercalls reduced.
    2.38 -	 */
    2.39 -	if (size > PAGE_SIZE) {
    2.40 -		pgd_t         *pgd; 
    2.41 -		pmd_t         *pmd;
    2.42 -		pte_t         *pte;
    2.43 -		unsigned long  pfn, i;
    2.44 -		/* 1. Zap current PTEs, giving away the underlying pages. */
    2.45 -		for (i = 0; i < (1<<order); i++) {
    2.46 -			pgd = pgd_offset_k(   (vstart + (i*PAGE_SIZE)));
    2.47 -			pmd = pmd_offset(pgd, (vstart + (i*PAGE_SIZE)));
    2.48 -			pte = pte_offset(pmd, (vstart + (i*PAGE_SIZE)));
    2.49 -			pfn = pte->pte_low >> PAGE_SHIFT;
    2.50 -			queue_l1_entry_update(pte, 0);
    2.51 -			flush_page_update_queue();
    2.52 -			if (HYPERVISOR_dom_mem_op(MEMOP_decrease_reservation, 
    2.53 -				&pfn, 1, 0) != 1) BUG();
    2.54 -		}
    2.55 -		/* 2. Get a new contiguous memory extent. */
    2.56 -		if (HYPERVISOR_dom_mem_op(MEMOP_increase_reservation,
    2.57 -			&pfn, 1, order) != 1) BUG();
    2.58 -		/* 3. Map the new extent in place of old pages. */
    2.59 -		for (i = 0; i < (1<<order); i++) {
    2.60 -			pgd = pgd_offset_k(   (vstart + (i*PAGE_SIZE)));
    2.61 -			pmd = pmd_offset(pgd, (vstart + (i*PAGE_SIZE)));
    2.62 -			pte = pte_offset(pmd, (vstart + (i*PAGE_SIZE)));
    2.63 -			queue_l1_entry_update(pte, 
    2.64 -				((pfn+i)<<PAGE_SHIFT)|__PAGE_KERNEL);
    2.65 -			queue_machphys_update(pfn+i,
    2.66 -				(__pa(ret)>>PAGE_SHIFT)+i);
    2.67 -			phys_to_machine_mapping[(__pa(ret)>>PAGE_SHIFT)+i] =
    2.68 -				pfn+i;
    2.69 -                        flush_page_update_queue();
    2.70 -		}
    2.71 -		flush_page_update_queue();
    2.72 -	}
    2.73 -
    2.74 -	memset(ret, 0, size);
    2.75 -	*dma_handle = virt_to_bus(ret);
    2.76 -
    2.77 -	return ret;
    2.78 -}
    2.79 -
    2.80 -void pci_free_consistent(struct pci_dev *hwdev, size_t size,
    2.81 -			 void *vaddr, dma_addr_t dma_handle)
    2.82 -{
    2.83 -	free_pages((unsigned long)vaddr, get_order(size));
    2.84 -}
     3.1 --- a/linux-2.4.26-xen-sparse/mkbuildtree	Tue Aug 03 17:21:57 2004 +0000
     3.2 +++ b/linux-2.4.26-xen-sparse/mkbuildtree	Tue Aug 03 17:36:29 2004 +0000
     3.3 @@ -221,6 +221,7 @@ ln -sf ../../i386/kernel/sys_i386.c
     3.4  ln -sf ../../../${LINUX_26}/arch/xen/kernel/ctrl_if.c
     3.5  ln -sf ../../../${LINUX_26}/arch/xen/kernel/evtchn.c
     3.6  ln -sf ../../../${LINUX_26}/arch/xen/i386/kernel/ioport.c
     3.7 +ln -sf ../../../${LINUX_26}/arch/xen/i386/kernel/pci-dma.c
     3.8  
     3.9  cd ${AD}/arch/xen/lib
    3.10  ln -sf ../../i386/lib/checksum.S 
     4.1 --- a/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/pci-dma.c	Tue Aug 03 17:21:57 2004 +0000
     4.2 +++ b/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/pci-dma.c	Tue Aug 03 17:36:29 2004 +0000
     4.3 @@ -11,20 +11,34 @@
     4.4  #include <linux/mm.h>
     4.5  #include <linux/string.h>
     4.6  #include <linux/pci.h>
     4.7 +#include <linux/version.h>
     4.8  #include <asm/io.h>
     4.9  
    4.10 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
    4.11 +#define pte_offset_kernel pte_offset
    4.12 +void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
    4.13 +			   dma_addr_t *dma_handle)
    4.14 +#else
    4.15  void *dma_alloc_coherent(struct device *dev, size_t size,
    4.16  			   dma_addr_t *dma_handle, int gfp)
    4.17 +#endif
    4.18  {
    4.19  	void *ret;
    4.20  	unsigned int order = get_order(size);
    4.21  	unsigned long vstart;
    4.22  
    4.23 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
    4.24 +	int gfp = GFP_ATOMIC;
    4.25 +
    4.26 +	if (hwdev == NULL || ((u32)hwdev->dma_mask < 0xffffffff))
    4.27 +		gfp |= GFP_DMA;
    4.28 +#else
    4.29  	/* ignore region specifiers */
    4.30  	gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
    4.31  
    4.32  	if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
    4.33  		gfp |= GFP_DMA;
    4.34 +#endif
    4.35  
    4.36  	ret = (void *)vstart = __get_free_pages(gfp, order);
    4.37  	if (ret == NULL)
    4.38 @@ -76,8 +90,13 @@ void *dma_alloc_coherent(struct device *
    4.39  	return ret;
    4.40  }
    4.41  
    4.42 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
    4.43 +void pci_free_consistent(struct pci_dev *hwdev, size_t size,
    4.44 +			 void *vaddr, dma_addr_t dma_handle)
    4.45 +#else
    4.46  void dma_free_coherent(struct device *dev, size_t size,
    4.47  			 void *vaddr, dma_addr_t dma_handle)
    4.48 +#endif
    4.49  {
    4.50  	free_pages((unsigned long)vaddr, get_order(size));
    4.51  }