lkml.org 
[lkml]   [2008]   [Sep]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH] swiotlb: fix dma_alloc_coherent allocation failures with swiotlb
    Date
    The SWIOTLB version of dma_alloc_coherent allocates all memory with
    GFP_DMA unconditionally. This leads sometimes unnecessary to allocation
    failures. This patch makes the allocation strategy to use the DMA32 zone
    first if this is possible. The changes are boot tested on AMD64 and
    compile tested for i386 and IA64.

    Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
    Cc: tony.luck@intel.com
    Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
    ---
    lib/swiotlb.c | 23 +++++++++++++++++------
    1 files changed, 17 insertions(+), 6 deletions(-)

    diff --git a/lib/swiotlb.c b/lib/swiotlb.c
    index 977edbd..6ba077f 100644
    --- a/lib/swiotlb.c
    +++ b/lib/swiotlb.c
    @@ -466,13 +466,24 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size,
    dma_addr_t dev_addr;
    void *ret;
    int order = get_order(size);
    + unsigned long dma_mask;

    - /*
    - * XXX fix me: the DMA API should pass us an explicit DMA mask
    - * instead, or use ZONE_DMA32 (ia64 overloads ZONE_DMA to be a ~32
    - * bit range instead of a 16MB one).
    - */
    - flags |= GFP_DMA;
    + if (hwdev->dma_mask == NULL)
    + return NULL;
    +
    + flags &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
    + flags |= __GFP_ZERO;
    +
    + dma_mask = hwdev->coherent_dma_mask;
    + if (!dma_mask)
    + dma_mask = *(hwdev->dma_mask);
    +
    + if (dma_mask <= ISA_DMA_THRESHOLD)
    + flags |= GFP_DMA;
    +#ifdef CONFIG_X86_64
    + else if (dma_mask <= DMA_32BIT_MASK)
    + flags |= GFP_DMA32;
    +#endif

    ret = (void *)__get_free_pages(flags, order);
    if (ret && address_needs_mapping(hwdev, virt_to_bus(ret))) {
    --
    1.5.3.7



    \
     
     \ /
      Last update: 2008-09-03 17:07    [W:0.021 / U:32.416 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site