bouncebuf.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Generic bounce buffer implementation
  4. *
  5. * Copyright (C) 2012 Marek Vasut <marex@denx.de>
  6. */
  7. #ifndef __INCLUDE_BOUNCEBUF_H__
  8. #define __INCLUDE_BOUNCEBUF_H__
  9. #include <linux/types.h>
  10. /*
  11. * GEN_BB_READ -- Data are read from the buffer eg. by DMA hardware.
  12. * The source buffer is copied into the bounce buffer (if unaligned, otherwise
  13. * the source buffer is used directly) upon start() call, then the operation
  14. * requiring the aligned transfer happens, then the bounce buffer is lost upon
  15. * stop() call.
  16. */
  17. #define GEN_BB_READ (1 << 0)
  18. /*
  19. * GEN_BB_WRITE -- Data are written into the buffer eg. by DMA hardware.
  20. * The source buffer starts in an undefined state upon start() call, then the
  21. * operation requiring the aligned transfer happens, then the bounce buffer is
  22. * copied into the destination buffer (if unaligned, otherwise destination
  23. * buffer is used directly) upon stop() call.
  24. */
  25. #define GEN_BB_WRITE (1 << 1)
  26. /*
  27. * GEN_BB_RW -- Data are read and written into the buffer eg. by DMA hardware.
  28. * The source buffer is copied into the bounce buffer (if unaligned, otherwise
  29. * the source buffer is used directly) upon start() call, then the operation
  30. * requiring the aligned transfer happens, then the bounce buffer is copied
  31. * into the destination buffer (if unaligned, otherwise destination buffer is
  32. * used directly) upon stop() call.
  33. */
  34. #define GEN_BB_RW (GEN_BB_READ | GEN_BB_WRITE)
  35. struct bounce_buffer {
  36. /* Copy of data parameter passed to start() */
  37. void *user_buffer;
  38. /*
  39. * DMA-aligned buffer. This field is always set to the value that
  40. * should be used for DMA; either equal to .user_buffer, or to a
  41. * freshly allocated aligned buffer.
  42. */
  43. void *bounce_buffer;
  44. /* Copy of len parameter passed to start() */
  45. size_t len;
  46. /* DMA-aligned buffer length */
  47. size_t len_aligned;
  48. /* Copy of flags parameter passed to start() */
  49. unsigned int flags;
  50. };
  51. /**
  52. * bounce_buffer_start() -- Start the bounce buffer session
  53. * state: stores state passed between bounce_buffer_{start,stop}
  54. * data: pointer to buffer to be aligned
  55. * len: length of the buffer
  56. * flags: flags describing the transaction, see above.
  57. */
  58. int bounce_buffer_start(struct bounce_buffer *state, void *data,
  59. size_t len, unsigned int flags);
  60. /**
  61. * bounce_buffer_stop() -- Finish the bounce buffer session
  62. * state: stores state passed between bounce_buffer_{start,stop}
  63. */
  64. int bounce_buffer_stop(struct bounce_buffer *state);
  65. #endif