dma-attrs.h 1.8 KB

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