dma-mapping.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. static inline void *dma_alloc_coherent(struct device *dev, size_t size,
  22. dma_addr_t *dma_handle, gfp_t flag)
  23. {
  24. struct dma_map_ops *ops = get_dma_ops(dev);
  25. void *cpu_addr;
  26. cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
  27. debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
  28. return cpu_addr;
  29. }
  30. static inline void dma_free_coherent(struct device *dev, size_t size,
  31. void *cpu_addr, dma_addr_t dma_handle)
  32. {
  33. struct dma_map_ops *ops = get_dma_ops(dev);
  34. debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
  35. ops->free_coherent(dev, size, cpu_addr, dma_handle);
  36. }
  37. static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  38. {
  39. return (dma_addr == DMA_ERROR_CODE);
  40. }
  41. static inline int dma_set_mask(struct device *dev, u64 mask)
  42. {
  43. #ifdef CONFIG_PCI
  44. if (dev->bus == &pci_bus_type) {
  45. if (!dev->dma_mask || !dma_supported(dev, mask))
  46. return -EINVAL;
  47. *dev->dma_mask = mask;
  48. return 0;
  49. }
  50. #endif
  51. return -EINVAL;
  52. }
  53. #endif