dma-attrs.h 1.7 KB

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