pci-dma.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* pci-dma.c: Dynamic DMA mapping support for the FRV CPUs that have MMUs
  2. *
  3. * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/types.h>
  12. #include <linux/dma-mapping.h>
  13. #include <linux/list.h>
  14. #include <linux/pci.h>
  15. #include <linux/highmem.h>
  16. #include <linux/scatterlist.h>
  17. #include <asm/io.h>
  18. void *dma_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t gfp)
  19. {
  20. void *ret;
  21. ret = consistent_alloc(gfp, size, dma_handle);
  22. if (ret)
  23. memset(ret, 0, size);
  24. return ret;
  25. }
  26. EXPORT_SYMBOL(dma_alloc_coherent);
  27. void dma_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle)
  28. {
  29. consistent_free(vaddr);
  30. }
  31. EXPORT_SYMBOL(dma_free_coherent);
  32. dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
  33. enum dma_data_direction direction)
  34. {
  35. BUG_ON(direction == DMA_NONE);
  36. frv_cache_wback_inv((unsigned long) ptr, (unsigned long) ptr + size);
  37. return virt_to_bus(ptr);
  38. }
  39. EXPORT_SYMBOL(dma_map_single);
  40. int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  41. enum dma_data_direction direction)
  42. {
  43. unsigned long dampr2;
  44. void *vaddr;
  45. int i;
  46. BUG_ON(direction == DMA_NONE);
  47. dampr2 = __get_DAMPR(2);
  48. for (i = 0; i < nents; i++) {
  49. vaddr = kmap_atomic_primary(sg_page(&sg[i]), __KM_CACHE);
  50. frv_dcache_writeback((unsigned long) vaddr,
  51. (unsigned long) vaddr + PAGE_SIZE);
  52. }
  53. kunmap_atomic_primary(vaddr, __KM_CACHE);
  54. if (dampr2) {
  55. __set_DAMPR(2, dampr2);
  56. __set_IAMPR(2, dampr2);
  57. }
  58. return nents;
  59. }
  60. EXPORT_SYMBOL(dma_map_sg);
  61. dma_addr_t dma_map_page(struct device *dev, struct page *page, unsigned long offset,
  62. size_t size, enum dma_data_direction direction)
  63. {
  64. BUG_ON(direction == DMA_NONE);
  65. flush_dcache_page(page);
  66. return (dma_addr_t) page_to_phys(page) + offset;
  67. }
  68. EXPORT_SYMBOL(dma_map_page);