dma-attrs.h 1.7 KB

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