ia64/xen-unstable

changeset 4681:7f38080250df

bitkeeper revision 1.1389.1.1 (4270eaa9i26XkdEPCi0_DHgtMgxvAw)

fix 2.4 build
author smh22@firebug.cl.cam.ac.uk
date Thu Apr 28 13:52:41 2005 +0000 (2005-04-28)
parents 3000c660f103
children 38a02ee9a9c8
files .rootkeys linux-2.4.29-xen-sparse/arch/xen/kernel/pci-dma.c
line diff
     1.1 --- a/.rootkeys	Thu Apr 28 08:56:40 2005 +0000
     1.2 +++ b/.rootkeys	Thu Apr 28 13:52:41 2005 +0000
     1.3 @@ -152,6 +152,7 @@ 3e5a4e65RMGcuA-HCn3-wNx3fFQwdg linux-2.4
     1.4  4241709bNBs1q4Ss32YW0CyFVOGhEg linux-2.4.29-xen-sparse/arch/xen/kernel/ioport.c
     1.5  3e5a4e653U6cELGv528IxOLHvCq8iA linux-2.4.29-xen-sparse/arch/xen/kernel/irq.c
     1.6  3e5a4e65muT6SU3ck47IP87Q7Ti5hA linux-2.4.29-xen-sparse/arch/xen/kernel/ldt.c
     1.7 +4270e964iKFC24KiVm6jC5Eo7MxV6w linux-2.4.29-xen-sparse/arch/xen/kernel/pci-dma.c
     1.8  4051db95N9N99FjsRwi49YKUNHWI8A linux-2.4.29-xen-sparse/arch/xen/kernel/pci-pc.c
     1.9  3e5a4e65IGt3WwQDNiL4h-gYWgNTWQ linux-2.4.29-xen-sparse/arch/xen/kernel/process.c
    1.10  3e5a4e66tR-qJMLj3MppcKqmvuI2XQ linux-2.4.29-xen-sparse/arch/xen/kernel/setup.c
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/linux-2.4.29-xen-sparse/arch/xen/kernel/pci-dma.c	Thu Apr 28 13:52:41 2005 +0000
     2.3 @@ -0,0 +1,137 @@
     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 <linux/version.h>
    2.18 +#include <asm/io.h>
    2.19 +#include <asm-xen/balloon.h>
    2.20 +
    2.21 +#define pte_offset_kernel pte_offset
    2.22 +
    2.23 +struct dma_coherent_mem {
    2.24 +	void		*virt_base;
    2.25 +	u32		device_base;
    2.26 +	int		size;
    2.27 +	int		flags;
    2.28 +	unsigned long	*bitmap;
    2.29 +};
    2.30 +
    2.31 +static void
    2.32 +xen_contig_memory(unsigned long vstart, unsigned int order)
    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 +	pgd_t         *pgd; 
    2.40 +	pmd_t         *pmd;
    2.41 +	pte_t         *pte;
    2.42 +	unsigned long  pfn, i, flags;
    2.43 +
    2.44 +	scrub_pages(vstart, 1 << order);
    2.45 +
    2.46 +        balloon_lock(flags);
    2.47 +
    2.48 +	/* 1. Zap current PTEs, giving away the underlying pages. */
    2.49 +	for (i = 0; i < (1<<order); i++) {
    2.50 +		pgd = pgd_offset_k(   (vstart + (i*PAGE_SIZE)));
    2.51 +		pmd = pmd_offset(pgd, (vstart + (i*PAGE_SIZE)));
    2.52 +		pte = pte_offset_kernel(pmd, (vstart + (i*PAGE_SIZE)));
    2.53 +		pfn = pte->pte_low >> PAGE_SHIFT;
    2.54 +		HYPERVISOR_update_va_mapping(
    2.55 +			vstart + (i*PAGE_SIZE), __pte_ma(0), 0);
    2.56 +		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
    2.57 +			INVALID_P2M_ENTRY;
    2.58 +		if (HYPERVISOR_dom_mem_op(MEMOP_decrease_reservation, 
    2.59 +					  &pfn, 1, 0) != 1) BUG();
    2.60 +	}
    2.61 +	/* 2. Get a new contiguous memory extent. */
    2.62 +	if (HYPERVISOR_dom_mem_op(MEMOP_increase_reservation,
    2.63 +				  &pfn, 1, order) != 1) BUG();
    2.64 +	/* 3. Map the new extent in place of old pages. */
    2.65 +	for (i = 0; i < (1<<order); i++) {
    2.66 +		pgd = pgd_offset_k(   (vstart + (i*PAGE_SIZE)));
    2.67 +		pmd = pmd_offset(pgd, (vstart + (i*PAGE_SIZE)));
    2.68 +		pte = pte_offset_kernel(pmd, (vstart + (i*PAGE_SIZE)));
    2.69 +		HYPERVISOR_update_va_mapping(
    2.70 +			vstart + (i*PAGE_SIZE),
    2.71 +			__pte_ma(((pfn+i)<<PAGE_SHIFT)|__PAGE_KERNEL), 0);
    2.72 +		xen_machphys_update(
    2.73 +			pfn+i, (__pa(vstart)>>PAGE_SHIFT)+i);
    2.74 +		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
    2.75 +			pfn+i;
    2.76 +	}
    2.77 +	/* Flush updates through and flush the TLB. */
    2.78 +	flush_tlb_all();
    2.79 +
    2.80 +        balloon_unlock(flags);
    2.81 +}
    2.82 +
    2.83 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
    2.84 +void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
    2.85 +			   dma_addr_t *dma_handle)
    2.86 +#else
    2.87 +void *dma_alloc_coherent(struct device *dev, size_t size,
    2.88 +			   dma_addr_t *dma_handle, int gfp)
    2.89 +#endif
    2.90 +{
    2.91 +	void *ret;
    2.92 +	unsigned int order = get_order(size);
    2.93 +	unsigned long vstart;
    2.94 +
    2.95 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
    2.96 +	int gfp = GFP_ATOMIC;
    2.97 +
    2.98 +	if (hwdev == NULL || ((u32)hwdev->dma_mask < 0xffffffff))
    2.99 +		gfp |= GFP_DMA;
   2.100 +#else
   2.101 +	struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL;
   2.102 +
   2.103 +	/* ignore region specifiers */
   2.104 +	gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
   2.105 +
   2.106 +	if (mem) {
   2.107 +		int page = bitmap_find_free_region(mem->bitmap, mem->size,
   2.108 +						     order);
   2.109 +		if (page >= 0) {
   2.110 +			*dma_handle = mem->device_base + (page << PAGE_SHIFT);
   2.111 +			ret = mem->virt_base + (page << PAGE_SHIFT);
   2.112 +			memset(ret, 0, size);
   2.113 +			return ret;
   2.114 +		}
   2.115 +		if (mem->flags & DMA_MEMORY_EXCLUSIVE)
   2.116 +			return NULL;
   2.117 +	}
   2.118 +
   2.119 +	if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
   2.120 +		gfp |= GFP_DMA;
   2.121 +#endif
   2.122 +
   2.123 +	vstart = __get_free_pages(gfp, order);
   2.124 +	ret = (void *)vstart;
   2.125 +	if (ret == NULL)
   2.126 +		return ret;
   2.127 +
   2.128 +	xen_contig_memory(vstart, order);
   2.129 +
   2.130 +	memset(ret, 0, size);
   2.131 +	*dma_handle = virt_to_bus(ret);
   2.132 +
   2.133 +	return ret;
   2.134 +}
   2.135 +
   2.136 +void pci_free_consistent(struct pci_dev *hwdev, size_t size,
   2.137 +			 void *vaddr, dma_addr_t dma_handle)
   2.138 +{
   2.139 +	free_pages((unsigned long)vaddr, get_order(size));
   2.140 +}