mali_kbase_pm.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. *
  3. * (C) COPYRIGHT 2010-2015 ARM Limited. All rights reserved.
  4. *
  5. * This program is free software and is provided to you under the terms of the
  6. * GNU General Public License version 2 as published by the Free Software
  7. * Foundation, and any use by you of this program is subject to the terms
  8. * of such GNU licence.
  9. *
  10. * A copy of the licence is included with the program, and can also be obtained
  11. * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  12. * Boston, MA 02110-1301, USA.
  13. *
  14. */
  15. /**
  16. * @file mali_kbase_pm.h
  17. * Power management API definitions
  18. */
  19. #ifndef _KBASE_PM_H_
  20. #define _KBASE_PM_H_
  21. #include "mali_kbase_hwaccess_pm.h"
  22. #define PM_ENABLE_IRQS 0x01
  23. #define PM_HW_ISSUES_DETECT 0x02
  24. /** Initialize the power management framework.
  25. *
  26. * Must be called before any other power management function
  27. *
  28. * @param kbdev The kbase device structure for the device (must be a valid pointer)
  29. *
  30. * @return 0 if the power management framework was successfully initialized.
  31. */
  32. int kbase_pm_init(struct kbase_device *kbdev);
  33. /** Power up GPU after all modules have been initialized and interrupt handlers installed.
  34. *
  35. * @param kbdev The kbase device structure for the device (must be a valid pointer)
  36. *
  37. * @param flags Flags to pass on to kbase_pm_init_hw
  38. *
  39. * @return 0 if powerup was successful.
  40. */
  41. int kbase_pm_powerup(struct kbase_device *kbdev, unsigned int flags);
  42. /**
  43. * Halt the power management framework.
  44. * Should ensure that no new interrupts are generated,
  45. * but allow any currently running interrupt handlers to complete successfully.
  46. * The GPU is forced off by the time this function returns, regardless of
  47. * whether or not the active power policy asks for the GPU to be powered off.
  48. *
  49. * @param kbdev The kbase device structure for the device (must be a valid pointer)
  50. */
  51. void kbase_pm_halt(struct kbase_device *kbdev);
  52. /** Terminate the power management framework.
  53. *
  54. * No power management functions may be called after this
  55. * (except @ref kbase_pm_init)
  56. *
  57. * @param kbdev The kbase device structure for the device (must be a valid pointer)
  58. */
  59. void kbase_pm_term(struct kbase_device *kbdev);
  60. /** Increment the count of active contexts.
  61. *
  62. * This function should be called when a context is about to submit a job. It informs the active power policy that the
  63. * GPU is going to be in use shortly and the policy is expected to start turning on the GPU.
  64. *
  65. * This function will block until the GPU is available.
  66. *
  67. * This function ASSERTS if a suspend is occuring/has occurred whilst this is
  68. * in use. Use kbase_pm_contect_active_unless_suspending() instead.
  69. *
  70. * @note a Suspend is only visible to Kernel threads; user-space threads in a
  71. * syscall cannot witness a suspend, because they are frozen before the suspend
  72. * begins.
  73. *
  74. * @param kbdev The kbase device structure for the device (must be a valid pointer)
  75. */
  76. void kbase_pm_context_active(struct kbase_device *kbdev);
  77. /** Handler codes for doing kbase_pm_context_active_handle_suspend() */
  78. enum kbase_pm_suspend_handler {
  79. /** A suspend is not expected/not possible - this is the same as
  80. * kbase_pm_context_active() */
  81. KBASE_PM_SUSPEND_HANDLER_NOT_POSSIBLE,
  82. /** If we're suspending, fail and don't increase the active count */
  83. KBASE_PM_SUSPEND_HANDLER_DONT_INCREASE,
  84. /** If we're suspending, succeed and allow the active count to increase iff
  85. * it didn't go from 0->1 (i.e., we didn't re-activate the GPU).
  86. *
  87. * This should only be used when there is a bounded time on the activation
  88. * (e.g. guarantee it's going to be idled very soon after) */
  89. KBASE_PM_SUSPEND_HANDLER_DONT_REACTIVATE
  90. };
  91. /** Suspend 'safe' variant of kbase_pm_context_active()
  92. *
  93. * If a suspend is in progress, this allows for various different ways of
  94. * handling the suspend. Refer to @ref enum kbase_pm_suspend_handler for details.
  95. *
  96. * We returns a status code indicating whether we're allowed to keep the GPU
  97. * active during the suspend, depending on the handler code. If the status code
  98. * indicates a failure, the caller must abort whatever operation it was
  99. * attempting, and potentially queue it up for after the OS has resumed.
  100. *
  101. * @param kbdev The kbase device structure for the device (must be a valid pointer)
  102. * @param suspend_handler The handler code for how to handle a suspend that might occur
  103. * @return zero Indicates success
  104. * @return non-zero Indicates failure due to the system being suspending/suspended.
  105. */
  106. int kbase_pm_context_active_handle_suspend(struct kbase_device *kbdev, enum kbase_pm_suspend_handler suspend_handler);
  107. /** Decrement the reference count of active contexts.
  108. *
  109. * This function should be called when a context becomes idle. After this call the GPU may be turned off by the power
  110. * policy so the calling code should ensure that it does not access the GPU's registers.
  111. *
  112. * @param kbdev The kbase device structure for the device (must be a valid pointer)
  113. */
  114. void kbase_pm_context_idle(struct kbase_device *kbdev);
  115. /**
  116. * Suspend the GPU and prevent any further register accesses to it from Kernel
  117. * threads.
  118. *
  119. * This is called in response to an OS suspend event, and calls into the various
  120. * kbase components to complete the suspend.
  121. *
  122. * @note the mechanisms used here rely on all user-space threads being frozen
  123. * by the OS before we suspend. Otherwise, an IOCTL could occur that powers up
  124. * the GPU e.g. via atom submission.
  125. *
  126. * @param kbdev The kbase device structure for the device (must be a valid pointer)
  127. */
  128. void kbase_pm_suspend(struct kbase_device *kbdev);
  129. /**
  130. * Resume the GPU, allow register accesses to it, and resume running atoms on
  131. * the GPU.
  132. *
  133. * This is called in response to an OS resume event, and calls into the various
  134. * kbase components to complete the resume.
  135. *
  136. * @param kbdev The kbase device structure for the device (must be a valid pointer)
  137. */
  138. void kbase_pm_resume(struct kbase_device *kbdev);
  139. /**
  140. * kbase_pm_vsync_callback - vsync callback
  141. *
  142. * @buffer_updated: 1 if a new frame was displayed, 0 otherwise
  143. * @data: Pointer to the kbase device as returned by kbase_find_device()
  144. *
  145. * Callback function used to notify the power management code that a vsync has
  146. * occurred on the display.
  147. */
  148. void kbase_pm_vsync_callback(int buffer_updated, void *data);
  149. #endif // ifndef _KBASE_PM_H_