dma-mapping.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. extern struct dma_map_ops *dma_ops;
  11. extern struct dma_map_ops *leon_dma_ops;
  12. extern struct dma_map_ops pci32_dma_ops;
  13. extern struct bus_type pci_bus_type;
  14. static inline struct dma_map_ops *get_dma_ops(struct device *dev)
  15. {
  16. #ifdef CONFIG_SPARC_LEON
  17. if (sparc_cpu_model == sparc_leon)
  18. return leon_dma_ops;
  19. #endif
  20. #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
  21. if (dev->bus == &pci_bus_type)
  22. return &pci32_dma_ops;
  23. #endif
  24. return dma_ops;
  25. }
  26. #include <asm-generic/dma-mapping-common.h>
  27. #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
  28. static inline void *dma_alloc_attrs(struct device *dev, size_t size,
  29. dma_addr_t *dma_handle, gfp_t flag,
  30. struct dma_attrs *attrs)
  31. {
  32. struct dma_map_ops *ops = get_dma_ops(dev);
  33. void *cpu_addr;
  34. cpu_addr = ops->alloc(dev, size, dma_handle, flag, attrs);
  35. debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
  36. return cpu_addr;
  37. }
  38. #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
  39. static inline void dma_free_attrs(struct device *dev, size_t size,
  40. void *cpu_addr, dma_addr_t dma_handle,
  41. struct dma_attrs *attrs)
  42. {
  43. struct dma_map_ops *ops = get_dma_ops(dev);
  44. debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
  45. ops->free(dev, size, cpu_addr, dma_handle, attrs);
  46. }
  47. static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  48. {
  49. debug_dma_mapping_error(dev, dma_addr);
  50. return (dma_addr == DMA_ERROR_CODE);
  51. }
  52. static inline int dma_set_mask(struct device *dev, u64 mask)
  53. {
  54. #ifdef CONFIG_PCI
  55. if (dev->bus == &pci_bus_type) {
  56. if (!dev->dma_mask || !dma_supported(dev, mask))
  57. return -EINVAL;
  58. *dev->dma_mask = mask;
  59. return 0;
  60. }
  61. #endif
  62. return -EINVAL;
  63. }
  64. #endif