dma-mapping.h 1.9 KB

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