dma-attrs.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_MAX,
  17. };
  18. #define __DMA_ATTRS_LONGS BITS_TO_LONGS(DMA_ATTR_MAX)
  19. /**
  20. * struct dma_attrs - an opaque container for DMA attributes
  21. * @flags - bitmask representing a collection of enum dma_attr
  22. */
  23. struct dma_attrs {
  24. unsigned long flags[__DMA_ATTRS_LONGS];
  25. };
  26. #define DEFINE_DMA_ATTRS(x) \
  27. struct dma_attrs x = { \
  28. .flags = { [0 ... __DMA_ATTRS_LONGS-1] = 0 }, \
  29. }
  30. static inline void init_dma_attrs(struct dma_attrs *attrs)
  31. {
  32. bitmap_zero(attrs->flags, __DMA_ATTRS_LONGS);
  33. }
  34. #ifdef CONFIG_HAVE_DMA_ATTRS
  35. /**
  36. * dma_set_attr - set a specific attribute
  37. * @attr: attribute to set
  38. * @attrs: struct dma_attrs (may be NULL)
  39. */
  40. static inline void dma_set_attr(enum dma_attr attr, struct dma_attrs *attrs)
  41. {
  42. if (attrs == NULL)
  43. return;
  44. BUG_ON(attr >= DMA_ATTR_MAX);
  45. __set_bit(attr, attrs->flags);
  46. }
  47. /**
  48. * dma_get_attr - check for a specific attribute
  49. * @attr: attribute to set
  50. * @attrs: struct dma_attrs (may be NULL)
  51. */
  52. static inline int dma_get_attr(enum dma_attr attr, struct dma_attrs *attrs)
  53. {
  54. if (attrs == NULL)
  55. return 0;
  56. BUG_ON(attr >= DMA_ATTR_MAX);
  57. return test_bit(attr, attrs->flags);
  58. }
  59. #else /* !CONFIG_HAVE_DMA_ATTRS */
  60. static inline void dma_set_attr(enum dma_attr attr, struct dma_attrs *attrs)
  61. {
  62. }
  63. static inline int dma_get_attr(enum dma_attr attr, struct dma_attrs *attrs)
  64. {
  65. return 0;
  66. }
  67. #endif /* CONFIG_HAVE_DMA_ATTRS */
  68. #endif /* _DMA_ATTR_H */