dma-heap.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * DMABUF Heaps Allocation Infrastructure
  4. *
  5. * Copyright (C) 2011 Google, Inc.
  6. * Copyright (C) 2019 Linaro Ltd.
  7. */
  8. #ifndef _DMA_HEAPS_H
  9. #define _DMA_HEAPS_H
  10. #include <linux/cdev.h>
  11. #include <linux/types.h>
  12. struct dma_heap;
  13. /**
  14. * struct dma_heap_ops - ops to operate on a given heap
  15. * @allocate: allocate dmabuf and return struct dma_buf ptr
  16. * @get_pool_size: if heap maintains memory pools, get pool size in bytes
  17. *
  18. * allocate returns dmabuf on success, ERR_PTR(-errno) on error.
  19. */
  20. struct dma_heap_ops {
  21. struct dma_buf *(*allocate)(struct dma_heap *heap,
  22. unsigned long len,
  23. unsigned long fd_flags,
  24. unsigned long heap_flags);
  25. long (*get_pool_size)(struct dma_heap *heap);
  26. };
  27. /**
  28. * struct dma_heap_export_info - information needed to export a new dmabuf heap
  29. * @name: used for debugging/device-node name
  30. * @ops: ops struct for this heap
  31. * @priv: heap exporter private data
  32. *
  33. * Information needed to export a new dmabuf heap.
  34. */
  35. struct dma_heap_export_info {
  36. const char *name;
  37. const struct dma_heap_ops *ops;
  38. void *priv;
  39. };
  40. /**
  41. * dma_heap_get_drvdata() - get per-heap driver data
  42. * @heap: DMA-Heap to retrieve private data for
  43. *
  44. * Returns:
  45. * The per-heap data for the heap.
  46. */
  47. void *dma_heap_get_drvdata(struct dma_heap *heap);
  48. /**
  49. * dma_heap_get_dev() - get device struct for the heap
  50. * @heap: DMA-Heap to retrieve device struct from
  51. *
  52. * Returns:
  53. * The device struct for the heap.
  54. */
  55. struct device *dma_heap_get_dev(struct dma_heap *heap);
  56. /**
  57. * dma_heap_get_name() - get heap name
  58. * @heap: DMA-Heap to retrieve private data for
  59. *
  60. * Returns:
  61. * The char* for the heap name.
  62. */
  63. const char *dma_heap_get_name(struct dma_heap *heap);
  64. /**
  65. * dma_heap_add - adds a heap to dmabuf heaps
  66. * @exp_info: information needed to register this heap
  67. */
  68. struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info);
  69. /**
  70. * dma_heap_put - drops a reference to a dmabuf heaps, potentially freeing it
  71. * @heap: heap pointer
  72. */
  73. void dma_heap_put(struct dma_heap *heap);
  74. /**
  75. * dma_heap_find - Returns the registered dma_heap with the specified name
  76. * @name: Name of the heap to find
  77. *
  78. * NOTE: dma_heaps returned from this function MUST be released
  79. * using dma_heap_put() when the user is done.
  80. */
  81. struct dma_heap *dma_heap_find(const char *name);
  82. /**
  83. * dma_heap_buffer_alloc - Allocate dma-buf from a dma_heap
  84. * @heap: dma_heap to allocate from
  85. * @len: size to allocate
  86. * @fd_flags: flags to set on returned dma-buf fd
  87. * @heap_flags: flags to pass to the dma heap
  88. *
  89. * This is for internal dma-buf allocations only.
  90. */
  91. struct dma_buf *dma_heap_buffer_alloc(struct dma_heap *heap, size_t len,
  92. unsigned int fd_flags,
  93. unsigned int heap_flags);
  94. /** dma_heap_buffer_free - Free dma_buf allocated by dma_heap_buffer_alloc
  95. * @dma_buf: dma_buf to free
  96. *
  97. * This is really only a simple wrapper to dma_buf_put()
  98. */
  99. void dma_heap_buffer_free(struct dma_buf *);
  100. /**
  101. * dma_heap_bufferfd_alloc - Allocate dma-buf fd from a dma_heap
  102. * @heap: dma_heap to allocate from
  103. * @len: size to allocate
  104. * @fd_flags: flags to set on returned dma-buf fd
  105. * @heap_flags: flags to pass to the dma heap
  106. */
  107. int dma_heap_bufferfd_alloc(struct dma_heap *heap, size_t len,
  108. unsigned int fd_flags,
  109. unsigned int heap_flags);
  110. #endif /* _DMA_HEAPS_H */