dma-attrs.h 1.8 KB

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