dma-attrs.h 1.7 KB

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