ia64/xen-unstable

changeset 2048:6bd1a212061d

bitkeeper revision 1.1108.54.1 (410f6f7a8sttwKzJ5rdNrGdqP7qDCw)

Make dma_alloc_coherent request contiguous memory from Xen.
author cl349@freefall.cl.cam.ac.uk
date Tue Aug 03 10:56:58 2004 +0000 (2004-08-03)
parents 37da92a66bd8
children ebaca727e2a7
files linux-2.6.7-xen-sparse/arch/xen/i386/kernel/pci-dma.c
line diff
     1.1 --- a/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/pci-dma.c	Tue Aug 03 09:36:46 2004 +0000
     1.2 +++ b/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/pci-dma.c	Tue Aug 03 10:56:58 2004 +0000
     1.3 @@ -17,18 +17,62 @@ void *dma_alloc_coherent(struct device *
     1.4  			   dma_addr_t *dma_handle, int gfp)
     1.5  {
     1.6  	void *ret;
     1.7 +	unsigned int order = get_order(size);
     1.8 +	unsigned long vstart;
     1.9 +
    1.10  	/* ignore region specifiers */
    1.11  	gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
    1.12  
    1.13  	if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
    1.14  		gfp |= GFP_DMA;
    1.15  
    1.16 -	ret = (void *)__get_free_pages(gfp, get_order(size));
    1.17 +	ret = (void *)vstart = __get_free_pages(gfp, order);
    1.18 +	if (ret == NULL)
    1.19 +		return ret;
    1.20  
    1.21 -	if (ret != NULL) {
    1.22 -		memset(ret, 0, size);
    1.23 -		*dma_handle = virt_to_bus(ret);
    1.24 +	/*
    1.25 +	 * Ensure multi-page extents are contiguous in machine memory.
    1.26 +	 * This code could be cleaned up some, and the number of
    1.27 +	 * hypercalls reduced.
    1.28 +	 */
    1.29 +	if (size > PAGE_SIZE) {
    1.30 +		pgd_t         *pgd; 
    1.31 +		pmd_t         *pmd;
    1.32 +		pte_t         *pte;
    1.33 +		unsigned long  pfn, i;
    1.34 +		/* 1. Zap current PTEs, giving away the underlying pages. */
    1.35 +		for (i = 0; i < (1<<order); i++) {
    1.36 +			pgd = pgd_offset_k(   (vstart + (i*PAGE_SIZE)));
    1.37 +			pmd = pmd_offset(pgd, (vstart + (i*PAGE_SIZE)));
    1.38 +			pte = pte_offset_kernel(pmd, (vstart + (i*PAGE_SIZE)));
    1.39 +			pfn = pte->pte_low >> PAGE_SHIFT;
    1.40 +			queue_l1_entry_update(pte, 0);
    1.41 +			flush_page_update_queue();
    1.42 +			if (HYPERVISOR_dom_mem_op(MEMOP_decrease_reservation, 
    1.43 +						  &pfn, 1, 0) != 1) BUG();
    1.44 +		}
    1.45 +		/* 2. Get a new contiguous memory extent. */
    1.46 +		if (HYPERVISOR_dom_mem_op(MEMOP_increase_reservation,
    1.47 +					  &pfn, 1, order) != 1) BUG();
    1.48 +		/* 3. Map the new extent in place of old pages. */
    1.49 +		for (i = 0; i < (1<<order); i++) {
    1.50 +			pgd = pgd_offset_k(   (vstart + (i*PAGE_SIZE)));
    1.51 +			pmd = pmd_offset(pgd, (vstart + (i*PAGE_SIZE)));
    1.52 +			pte = pte_offset_kernel(pmd, (vstart + (i*PAGE_SIZE)));
    1.53 +			queue_l1_entry_update(
    1.54 +				pte, ((pfn+i)<<PAGE_SHIFT)|__PAGE_KERNEL);
    1.55 +			queue_machphys_update(
    1.56 +				pfn+i, (__pa(ret)>>PAGE_SHIFT)+i);
    1.57 +			phys_to_machine_mapping[(__pa(ret)>>PAGE_SHIFT)+i] =
    1.58 +				pfn+i;
    1.59 +                        flush_page_update_queue();
    1.60 +		}
    1.61 +		flush_page_update_queue();
    1.62  	}
    1.63 +
    1.64 +	memset(ret, 0, size);
    1.65 +	*dma_handle = virt_to_bus(ret);
    1.66 +
    1.67  	return ret;
    1.68  }
    1.69