dma.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Dynamic DMA mapping support.
  3. *
  4. * On cris there is no hardware dynamic DMA address translation,
  5. * so consistent alloc/free are merely page allocation/freeing.
  6. * The rest of the dynamic DMA mapping interface is implemented
  7. * in asm/pci.h.
  8. *
  9. * Borrowed from i386.
  10. */
  11. #include <linux/types.h>
  12. #include <linux/mm.h>
  13. #include <linux/string.h>
  14. #include <linux/pci.h>
  15. #include <linux/gfp.h>
  16. #include <asm/io.h>
  17. void *dma_alloc_coherent(struct device *dev, size_t size,
  18. dma_addr_t *dma_handle, gfp_t gfp)
  19. {
  20. void *ret;
  21. int order = get_order(size);
  22. /* ignore region specifiers */
  23. gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
  24. if (dma_alloc_from_coherent(dev, size, dma_handle, &ret))
  25. return ret;
  26. if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
  27. gfp |= GFP_DMA;
  28. ret = (void *)__get_free_pages(gfp, order);
  29. if (ret != NULL) {
  30. memset(ret, 0, size);
  31. *dma_handle = virt_to_phys(ret);
  32. }
  33. return ret;
  34. }
  35. void dma_free_coherent(struct device *dev, size_t size,
  36. void *vaddr, dma_addr_t dma_handle)
  37. {
  38. int order = get_order(size);
  39. if (!dma_release_from_coherent(dev, order, vaddr))
  40. free_pages((unsigned long)vaddr, order);
  41. }