dma_free_coherent() needs irqs enabled (sigh)
authorDavid Brownell <david-b@pacbell.net>
Fri, 10 Aug 2007 20:10:27 +0000 (13:10 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 12 Oct 2007 22:03:15 +0000 (15:03 -0700)
On at least ARM (and I'm told MIPS too) dma_free_coherent() has a newish
call context requirement: unlike its dma_alloc_coherent() sibling, it may
not be called with IRQs disabled.  (This was new behavior on ARM as of late
2005, caused by ARM SMP updates.) This little surprise can be annoyingly
driver-visible.

Since it looks like that restriction won't be removed, this patch changes
the definition of the API to include that requirement.  Also, to help catch
nonportable drivers, it updates the x86 and swiotlb versions to include the
relevant warnings.  (I already observed that it trips on the
bus_reset_tasklet of the new firewire_ohci driver.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: David Miller <davem@davemloft.net>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Documentation/DMA-API.txt
arch/x86/kernel/pci-dma_32.c
arch/x86/kernel/pci-dma_64.c
lib/swiotlb.c

index cc7a8c39fb6fbf224483355cd169a2cee0d6a30a..b939ebb62871ec6b743b02cd78be1ca6d230baae 100644 (file)
@@ -68,6 +68,9 @@ size and dma_handle must all be the same as those passed into the
 consistent allocate.  cpu_addr must be the virtual address returned by
 the consistent allocate.
 
+Note that unlike their sibling allocation calls, these routines
+may only be called with IRQs enabled.
+
 
 Part Ib - Using small dma-coherent buffers
 ------------------------------------------
index 048f09b62553e638ecb6c0ba89528a4f9665b014..0aae2f3847a5486fe657ce3403179c6359aabeca 100644 (file)
@@ -63,7 +63,8 @@ void dma_free_coherent(struct device *dev, size_t size,
 {
        struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL;
        int order = get_order(size);
-       
+
+       WARN_ON(irqs_disabled());       /* for portability */
        if (mem && vaddr >= mem->virt_base && vaddr < (mem->virt_base + (mem->size << PAGE_SHIFT))) {
                int page = (vaddr - mem->virt_base) >> PAGE_SHIFT;
 
index 29711445c8187464c6c00b14938451c23732df3e..9576a2eb375ed81f5aee52e657676cd74dbad4f9 100644 (file)
@@ -167,6 +167,7 @@ EXPORT_SYMBOL(dma_alloc_coherent);
 void dma_free_coherent(struct device *dev, size_t size,
                         void *vaddr, dma_addr_t bus)
 {
+       WARN_ON(irqs_disabled());       /* for portability */
        if (dma_ops->unmap_single)
                dma_ops->unmap_single(dev, bus, size, 0);
        free_pages((unsigned long)vaddr, get_order(size));
index a7381d55663a9f219f8313a4801614309ba9d207..30c1400e749e8299be6767e32e9f3531ae18a0a4 100644 (file)
@@ -497,6 +497,7 @@ void
 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
                      dma_addr_t dma_handle)
 {
+       WARN_ON(irqs_disabled());
        if (!(vaddr >= (void *)io_tlb_start
                     && vaddr < (void *)io_tlb_end))
                free_pages((unsigned long) vaddr, get_order(size));