dma-attrs.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef _DMA_ATTR_H
  2. #define _DMA_ATTR_H
  3. #include <linux/bitmap.h>
  4. #include <linux/bitops.h>
  5. #include <linux/bug.h>
  6. /**
  7. * an enum dma_attr represents an attribute associated with a DMA
  8. * mapping. The semantics of each attribute should be defined in
  9. * Documentation/DMA-attributes.txt.
  10. */
  11. enum dma_attr {
  12. DMA_ATTR_WRITE_BARRIER,
  13. DMA_ATTR_WEAK_ORDERING,
  14. DMA_ATTR_WRITE_COMBINE,
  15. DMA_ATTR_NON_CONSISTENT,
  16. DMA_ATTR_NO_KERNEL_MAPPING,
  17. DMA_ATTR_STRONGLY_ORDERED,
  18. DMA_ATTR_SKIP_ZEROING,
  19. DMA_ATTR_SKIP_CPU_SYNC,
  20. DMA_ATTR_MAX,
  21. };
  22. #define __DMA_ATTRS_LONGS BITS_TO_LONGS(DMA_ATTR_MAX)
  23. /**
  24. * struct dma_attrs - an opaque container for DMA attributes
  25. * @flags - bitmask representing a collection of enum dma_attr
  26. */
  27. struct dma_attrs {
  28. unsigned long flags[__DMA_ATTRS_LONGS];
  29. };
  30. #define DEFINE_DMA_ATTRS(x) \
  31. struct dma_attrs x = { \
  32. .flags = { [0 ... __DMA_ATTRS_LONGS-1] = 0 }, \
  33. }
  34. static inline void init_dma_attrs(struct dma_attrs *attrs)
  35. {
  36. bitmap_zero(attrs->flags, __DMA_ATTRS_LONGS);
  37. }
  38. #ifdef CONFIG_HAVE_DMA_ATTRS
  39. /**
  40. * dma_set_attr - set a specific attribute
  41. * @attr: attribute to set
  42. * @attrs: struct dma_attrs (may be NULL)
  43. */
  44. static inline void dma_set_attr(enum dma_attr attr, struct dma_attrs *attrs)
  45. {
  46. if (attrs == NULL)
  47. return;
  48. BUG_ON(attr >= DMA_ATTR_MAX);
  49. __set_bit(attr, attrs->flags);
  50. }
  51. /**
  52. * dma_get_attr - check for a specific attribute
  53. * @attr: attribute to set
  54. * @attrs: struct dma_attrs (may be NULL)
  55. */
  56. static inline int dma_get_attr(enum dma_attr attr, struct dma_attrs *attrs)
  57. {
  58. if (attrs == NULL)
  59. return 0;
  60. BUG_ON(attr >= DMA_ATTR_MAX);
  61. return test_bit(attr, attrs->flags);
  62. }
  63. #else /* !CONFIG_HAVE_DMA_ATTRS */
  64. static inline void dma_set_attr(enum dma_attr attr, struct dma_attrs *attrs)
  65. {
  66. }
  67. static inline int dma_get_attr(enum dma_attr attr, struct dma_attrs *attrs)
  68. {
  69. return 0;
  70. }
  71. #endif /* CONFIG_HAVE_DMA_ATTRS */
  72. #endif /* _DMA_ATTR_H */