pci-dma.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/export.h>
  16. #include <linux/highmem.h>
  17. #include <linux/scatterlist.h>
  18. #include <asm/io.h>
  19. void *dma_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t gfp)
  20. {
  21. void *ret;
  22. ret = consistent_alloc(gfp, size, dma_handle);
  23. if (ret)
  24. memset(ret, 0, size);
  25. return ret;
  26. }
  27. EXPORT_SYMBOL(dma_alloc_coherent);
  28. void dma_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle)
  29. {
  30. consistent_free(vaddr);
  31. }
  32. EXPORT_SYMBOL(dma_free_coherent);
  33. dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
  34. enum dma_data_direction direction)
  35. {
  36. BUG_ON(direction == DMA_NONE);
  37. frv_cache_wback_inv((unsigned long) ptr, (unsigned long) ptr + size);
  38. return virt_to_bus(ptr);
  39. }
  40. EXPORT_SYMBOL(dma_map_single);
  41. int dma_map_sg(struct device *dev, struct scatterlist *sglist, int nents,
  42. enum dma_data_direction direction)
  43. {
  44. unsigned long dampr2;
  45. void *vaddr;
  46. int i;
  47. struct scatterlist *sg;
  48. BUG_ON(direction == DMA_NONE);
  49. dampr2 = __get_DAMPR(2);
  50. for_each_sg(sglist, sg, nents, i) {
  51. vaddr = kmap_atomic_primary(sg_page(sg));
  52. frv_dcache_writeback((unsigned long) vaddr,
  53. (unsigned long) vaddr + PAGE_SIZE);
  54. }
  55. kunmap_atomic_primary(vaddr);
  56. if (dampr2) {
  57. __set_DAMPR(2, dampr2);
  58. __set_IAMPR(2, dampr2);
  59. }
  60. return nents;
  61. }
  62. EXPORT_SYMBOL(dma_map_sg);
  63. dma_addr_t dma_map_page(struct device *dev, struct page *page, unsigned long offset,
  64. size_t size, enum dma_data_direction direction)
  65. {
  66. BUG_ON(direction == DMA_NONE);
  67. flush_dcache_page(page);
  68. return (dma_addr_t) page_to_phys(page) + offset;
  69. }
  70. EXPORT_SYMBOL(dma_map_page);