dma-mapping.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef ___ASM_SPARC_DMA_MAPPING_H
  2. #define ___ASM_SPARC_DMA_MAPPING_H
  3. #include <linux/scatterlist.h>
  4. #include <linux/mm.h>
  5. #include <linux/dma-debug.h>
  6. #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
  7. int dma_supported(struct device *dev, u64 mask);
  8. #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
  9. #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
  10. static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
  11. enum dma_data_direction dir)
  12. {
  13. /* Since dma_{alloc,free}_noncoherent() allocated coherent memory, this
  14. * routine can be a nop.
  15. */
  16. }
  17. extern struct dma_map_ops *dma_ops;
  18. extern struct dma_map_ops *leon_dma_ops;
  19. extern struct dma_map_ops pci32_dma_ops;
  20. extern struct bus_type pci_bus_type;
  21. static inline struct dma_map_ops *get_dma_ops(struct device *dev)
  22. {
  23. #ifdef CONFIG_SPARC_LEON
  24. if (sparc_cpu_model == sparc_leon)
  25. return leon_dma_ops;
  26. #endif
  27. #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
  28. if (dev->bus == &pci_bus_type)
  29. return &pci32_dma_ops;
  30. #endif
  31. return dma_ops;
  32. }
  33. #include <asm-generic/dma-mapping-common.h>
  34. #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
  35. static inline void *dma_alloc_attrs(struct device *dev, size_t size,
  36. dma_addr_t *dma_handle, gfp_t flag,
  37. struct dma_attrs *attrs)
  38. {
  39. struct dma_map_ops *ops = get_dma_ops(dev);
  40. void *cpu_addr;
  41. cpu_addr = ops->alloc(dev, size, dma_handle, flag, attrs);
  42. debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
  43. return cpu_addr;
  44. }
  45. #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
  46. static inline void dma_free_attrs(struct device *dev, size_t size,
  47. void *cpu_addr, dma_addr_t dma_handle,
  48. struct dma_attrs *attrs)
  49. {
  50. struct dma_map_ops *ops = get_dma_ops(dev);
  51. debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
  52. ops->free(dev, size, cpu_addr, dma_handle, attrs);
  53. }
  54. static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  55. {
  56. debug_dma_mapping_error(dev, dma_addr);
  57. return (dma_addr == DMA_ERROR_CODE);
  58. }
  59. static inline int dma_set_mask(struct device *dev, u64 mask)
  60. {
  61. #ifdef CONFIG_PCI
  62. if (dev->bus == &pci_bus_type) {
  63. if (!dev->dma_mask || !dma_supported(dev, mask))
  64. return -EINVAL;
  65. *dev->dma_mask = mask;
  66. return 0;
  67. }
  68. #endif
  69. return -EINVAL;
  70. }
  71. #endif