cgs_linux.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright 2015 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. *
  23. */
  24. #ifndef _CGS_LINUX_H
  25. #define _CGS_LINUX_H
  26. #include "cgs_common.h"
  27. /**
  28. * cgs_import_gpu_mem() - Import dmabuf handle
  29. * @cgs_device: opaque device handle
  30. * @dmabuf_fd: DMABuf file descriptor
  31. * @handle: memory handle (output)
  32. *
  33. * Must be called in the process context that dmabuf_fd belongs to.
  34. *
  35. * Return: 0 on success, -errno otherwise
  36. */
  37. typedef int (*cgs_import_gpu_mem_t)(void *cgs_device, int dmabuf_fd,
  38. cgs_handle_t *handle);
  39. /**
  40. * cgs_irq_source_set_func() - Callback for enabling/disabling interrupt sources
  41. * @private_data: private data provided to cgs_add_irq_source
  42. * @src_id: interrupt source ID
  43. * @type: interrupt type
  44. * @enabled: 0 = disable source, non-0 = enable source
  45. *
  46. * Return: 0 on success, -errno otherwise
  47. */
  48. typedef int (*cgs_irq_source_set_func_t)(void *private_data,
  49. unsigned src_id, unsigned type,
  50. int enabled);
  51. /**
  52. * cgs_irq_handler_func() - Interrupt handler callback
  53. * @private_data: private data provided to cgs_add_irq_source
  54. * @src_id: interrupt source ID
  55. * @iv_entry: pointer to raw ih ring entry
  56. *
  57. * This callback runs in interrupt context.
  58. *
  59. * Return: 0 on success, -errno otherwise
  60. */
  61. typedef int (*cgs_irq_handler_func_t)(void *private_data,
  62. unsigned src_id, const uint32_t *iv_entry);
  63. /**
  64. * cgs_add_irq_source() - Add an IRQ source
  65. * @cgs_device: opaque device handle
  66. * @src_id: interrupt source ID
  67. * @num_types: number of interrupt types that can be independently enabled
  68. * @set: callback function to enable/disable an interrupt type
  69. * @handler: interrupt handler callback
  70. * @private_data: private data to pass to callback functions
  71. *
  72. * The same IRQ source can be added only once. Adding an IRQ source
  73. * indicates ownership of that IRQ source and all its IRQ types.
  74. *
  75. * Return: 0 on success, -errno otherwise
  76. */
  77. typedef int (*cgs_add_irq_source_t)(void *cgs_device, unsigned src_id,
  78. unsigned num_types,
  79. cgs_irq_source_set_func_t set,
  80. cgs_irq_handler_func_t handler,
  81. void *private_data);
  82. /**
  83. * cgs_irq_get() - Request enabling an IRQ source and type
  84. * @cgs_device: opaque device handle
  85. * @src_id: interrupt source ID
  86. * @type: interrupt type
  87. *
  88. * cgs_irq_get and cgs_irq_put calls must be balanced. They count
  89. * "references" to IRQ sources.
  90. *
  91. * Return: 0 on success, -errno otherwise
  92. */
  93. typedef int (*cgs_irq_get_t)(void *cgs_device, unsigned src_id, unsigned type);
  94. /**
  95. * cgs_irq_put() - Indicate IRQ source is no longer needed
  96. * @cgs_device: opaque device handle
  97. * @src_id: interrupt source ID
  98. * @type: interrupt type
  99. *
  100. * cgs_irq_get and cgs_irq_put calls must be balanced. They count
  101. * "references" to IRQ sources. Even after cgs_irq_put is called, the
  102. * IRQ handler may still be called if there are more refecences to
  103. * the IRQ source.
  104. *
  105. * Return: 0 on success, -errno otherwise
  106. */
  107. typedef int (*cgs_irq_put_t)(void *cgs_device, unsigned src_id, unsigned type);
  108. struct cgs_os_ops {
  109. cgs_import_gpu_mem_t import_gpu_mem;
  110. /* IRQ handling */
  111. cgs_add_irq_source_t add_irq_source;
  112. cgs_irq_get_t irq_get;
  113. cgs_irq_put_t irq_put;
  114. };
  115. #define cgs_import_gpu_mem(dev,dmabuf_fd,handle) \
  116. CGS_OS_CALL(import_gpu_mem,dev,dmabuf_fd,handle)
  117. #define cgs_add_irq_source(dev,src_id,num_types,set,handler,private_data) \
  118. CGS_OS_CALL(add_irq_source,dev,src_id,num_types,set,handler, \
  119. private_data)
  120. #define cgs_irq_get(dev,src_id,type) \
  121. CGS_OS_CALL(irq_get,dev,src_id,type)
  122. #define cgs_irq_put(dev,src_id,type) \
  123. CGS_OS_CALL(irq_put,dev,src_id,type)
  124. #endif /* _CGS_LINUX_H */