dma.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file COPYING in the main directory of this archive
  4. * for more details.
  5. */
  6. #include <linux/dma-mapping.h>
  7. #include <linux/kernel.h>
  8. #include <linux/scatterlist.h>
  9. #include <linux/module.h>
  10. #include <asm/pgalloc.h>
  11. static void *dma_alloc(struct device *dev, size_t size,
  12. dma_addr_t *dma_handle, gfp_t gfp,
  13. unsigned long attrs)
  14. {
  15. void *ret;
  16. /* ignore region specifiers */
  17. gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
  18. if (dev == NULL || (*dev->dma_mask < 0xffffffff))
  19. gfp |= GFP_DMA;
  20. ret = (void *)__get_free_pages(gfp, get_order(size));
  21. if (ret != NULL) {
  22. memset(ret, 0, size);
  23. *dma_handle = virt_to_phys(ret);
  24. }
  25. return ret;
  26. }
  27. static void dma_free(struct device *dev, size_t size,
  28. void *vaddr, dma_addr_t dma_handle,
  29. unsigned long attrs)
  30. {
  31. free_pages((unsigned long)vaddr, get_order(size));
  32. }
  33. static dma_addr_t map_page(struct device *dev, struct page *page,
  34. unsigned long offset, size_t size,
  35. enum dma_data_direction direction,
  36. unsigned long attrs)
  37. {
  38. return page_to_phys(page) + offset;
  39. }
  40. static int map_sg(struct device *dev, struct scatterlist *sgl,
  41. int nents, enum dma_data_direction direction,
  42. unsigned long attrs)
  43. {
  44. struct scatterlist *sg;
  45. int i;
  46. for_each_sg(sgl, sg, nents, i) {
  47. sg->dma_address = sg_phys(sg);
  48. }
  49. return nents;
  50. }
  51. struct dma_map_ops h8300_dma_map_ops = {
  52. .alloc = dma_alloc,
  53. .free = dma_free,
  54. .map_page = map_page,
  55. .map_sg = map_sg,
  56. };
  57. EXPORT_SYMBOL(h8300_dma_map_ops);