bouncebuf.h 2.5 KB

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