dma-attrs.h 1.8 KB

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