mali_kbase_config.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. *
  3. * (C) COPYRIGHT 2010-2016 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_config.h
  17. * Configuration API and Attributes for KBase
  18. */
  19. #ifndef _KBASE_CONFIG_H_
  20. #define _KBASE_CONFIG_H_
  21. #include <asm/page.h>
  22. #include <mali_malisw.h>
  23. #include <mali_kbase_backend_config.h>
  24. /**
  25. * @addtogroup base_api
  26. * @{
  27. */
  28. /**
  29. * @addtogroup base_kbase_api
  30. * @{
  31. */
  32. /**
  33. * @addtogroup kbase_config Configuration API and Attributes
  34. * @{
  35. */
  36. #include <linux/rbtree.h>
  37. /* Forward declaration of struct kbase_device */
  38. struct kbase_device;
  39. /**
  40. * kbase_platform_funcs_conf - Specifies platform init/term function pointers
  41. *
  42. * Specifies the functions pointers for platform specific initialization and
  43. * termination. By default no functions are required. No additional platform
  44. * specific control is necessary.
  45. */
  46. struct kbase_platform_funcs_conf {
  47. /**
  48. * platform_init_func - platform specific init function pointer
  49. * @kbdev - kbase_device pointer
  50. *
  51. * Returns 0 on success, negative error code otherwise.
  52. *
  53. * Function pointer for platform specific initialization or NULL if no
  54. * initialization function is required. At the point this the GPU is
  55. * not active and its power and clocks are in unknown (platform specific
  56. * state) as kbase doesn't yet have control of power and clocks.
  57. *
  58. * The platform specific private pointer kbase_device::platform_context
  59. * can be accessed (and possibly initialized) in here.
  60. */
  61. int (*platform_init_func)(struct kbase_device *kbdev);
  62. /**
  63. * platform_term_func - platform specific termination function pointer
  64. * @kbdev - kbase_device pointer
  65. *
  66. * Function pointer for platform specific termination or NULL if no
  67. * termination function is required. At the point this the GPU will be
  68. * idle but still powered and clocked.
  69. *
  70. * The platform specific private pointer kbase_device::platform_context
  71. * can be accessed (and possibly terminated) in here.
  72. */
  73. void (*platform_term_func)(struct kbase_device *kbdev);
  74. };
  75. /*
  76. * @brief Specifies the callbacks for power management
  77. *
  78. * By default no callbacks will be made and the GPU must not be powered off.
  79. */
  80. struct kbase_pm_callback_conf {
  81. /** Callback for when the GPU is idle and the power to it can be switched off.
  82. *
  83. * The system integrator can decide whether to either do nothing, just switch off
  84. * the clocks to the GPU, or to completely power down the GPU.
  85. * The platform specific private pointer kbase_device::platform_context can be accessed and modified in here. It is the
  86. * platform \em callbacks responsibility to initialize and terminate this pointer if used (see @ref kbase_platform_funcs_conf).
  87. */
  88. void (*power_off_callback)(struct kbase_device *kbdev);
  89. /** Callback for when the GPU is about to become active and power must be supplied.
  90. *
  91. * This function must not return until the GPU is powered and clocked sufficiently for register access to
  92. * succeed. The return value specifies whether the GPU was powered down since the call to power_off_callback.
  93. * If the GPU state has been lost then this function must return 1, otherwise it should return 0.
  94. * The platform specific private pointer kbase_device::platform_context can be accessed and modified in here. It is the
  95. * platform \em callbacks responsibility to initialize and terminate this pointer if used (see @ref kbase_platform_funcs_conf).
  96. *
  97. * The return value of the first call to this function is ignored.
  98. *
  99. * @return 1 if the GPU state may have been lost, 0 otherwise.
  100. */
  101. int (*power_on_callback)(struct kbase_device *kbdev);
  102. /** Callback for when the system is requesting a suspend and GPU power
  103. * must be switched off.
  104. *
  105. * Note that if this callback is present, then this may be called
  106. * without a preceding call to power_off_callback. Therefore this
  107. * callback must be able to take any action that might otherwise happen
  108. * in power_off_callback.
  109. *
  110. * The platform specific private pointer kbase_device::platform_context
  111. * can be accessed and modified in here. It is the platform \em
  112. * callbacks responsibility to initialize and terminate this pointer if
  113. * used (see @ref kbase_platform_funcs_conf).
  114. */
  115. void (*power_suspend_callback)(struct kbase_device *kbdev);
  116. /** Callback for when the system is resuming from a suspend and GPU
  117. * power must be switched on.
  118. *
  119. * Note that if this callback is present, then this may be called
  120. * without a following call to power_on_callback. Therefore this
  121. * callback must be able to take any action that might otherwise happen
  122. * in power_on_callback.
  123. *
  124. * The platform specific private pointer kbase_device::platform_context
  125. * can be accessed and modified in here. It is the platform \em
  126. * callbacks responsibility to initialize and terminate this pointer if
  127. * used (see @ref kbase_platform_funcs_conf).
  128. */
  129. void (*power_resume_callback)(struct kbase_device *kbdev);
  130. /** Callback for handling runtime power management initialization.
  131. *
  132. * The runtime power management callbacks @ref power_runtime_off_callback and @ref power_runtime_on_callback
  133. * will become active from calls made to the OS from within this function.
  134. * The runtime calls can be triggered by calls from @ref power_off_callback and @ref power_on_callback.
  135. * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature.
  136. *
  137. * @return 0 on success, else int error code.
  138. */
  139. int (*power_runtime_init_callback)(struct kbase_device *kbdev);
  140. /** Callback for handling runtime power management termination.
  141. *
  142. * The runtime power management callbacks @ref power_runtime_off_callback and @ref power_runtime_on_callback
  143. * should no longer be called by the OS on completion of this function.
  144. * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature.
  145. */
  146. void (*power_runtime_term_callback)(struct kbase_device *kbdev);
  147. /** Callback for runtime power-off power management callback
  148. *
  149. * For linux this callback will be called by the kernel runtime_suspend callback.
  150. * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature.
  151. *
  152. * @return 0 on success, else OS error code.
  153. */
  154. void (*power_runtime_off_callback)(struct kbase_device *kbdev);
  155. /** Callback for runtime power-on power management callback
  156. *
  157. * For linux this callback will be called by the kernel runtime_resume callback.
  158. * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature.
  159. */
  160. int (*power_runtime_on_callback)(struct kbase_device *kbdev);
  161. /*
  162. * Optional callback for checking if GPU can be suspended when idle
  163. *
  164. * This callback will be called by the runtime power management core
  165. * when the reference count goes to 0 to provide notification that the
  166. * GPU now seems idle.
  167. *
  168. * If this callback finds that the GPU can't be powered off, or handles
  169. * suspend by powering off directly or queueing up a power off, a
  170. * non-zero value must be returned to prevent the runtime PM core from
  171. * also triggering a suspend.
  172. *
  173. * Returning 0 will cause the runtime PM core to conduct a regular
  174. * autosuspend.
  175. *
  176. * This callback is optional and if not provided regular autosuspend
  177. * will be triggered.
  178. *
  179. * Note: The Linux kernel must have CONFIG_PM_RUNTIME enabled to use
  180. * this feature.
  181. *
  182. * Return 0 if GPU can be suspended, positive value if it can not be
  183. * suspeneded by runtime PM, else OS error code
  184. */
  185. int (*power_runtime_idle_callback)(struct kbase_device *kbdev);
  186. };
  187. /**
  188. * kbase_cpuprops_get_default_clock_speed - default for CPU_SPEED_FUNC
  189. * @clock_speed - see kbase_cpu_clk_speed_func for details on the parameters
  190. *
  191. * Returns 0 on success, negative error code otherwise.
  192. *
  193. * Default implementation of CPU_SPEED_FUNC. This function sets clock_speed
  194. * to 100, so will be an underestimate for any real system.
  195. */
  196. int kbase_cpuprops_get_default_clock_speed(u32 * const clock_speed);
  197. /**
  198. * kbase_cpu_clk_speed_func - Type of the function pointer for CPU_SPEED_FUNC
  199. * @param clock_speed - pointer to store the current CPU clock speed in MHz
  200. *
  201. * Returns 0 on success, otherwise negative error code.
  202. *
  203. * This is mainly used to implement OpenCL's clGetDeviceInfo().
  204. */
  205. typedef int (*kbase_cpu_clk_speed_func) (u32 *clock_speed);
  206. /**
  207. * kbase_gpu_clk_speed_func - Type of the function pointer for GPU_SPEED_FUNC
  208. * @param clock_speed - pointer to store the current GPU clock speed in MHz
  209. *
  210. * Returns 0 on success, otherwise negative error code.
  211. * When an error is returned the caller assumes maximum GPU speed stored in
  212. * gpu_freq_khz_max.
  213. *
  214. * If the system timer is not available then this function is required
  215. * for the OpenCL queue profiling to return correct timing information.
  216. *
  217. */
  218. typedef int (*kbase_gpu_clk_speed_func) (u32 *clock_speed);
  219. #ifdef CONFIG_OF
  220. struct kbase_platform_config {
  221. };
  222. #else
  223. /*
  224. * @brief Specifies start and end of I/O memory region.
  225. */
  226. struct kbase_io_memory_region {
  227. u64 start;
  228. u64 end;
  229. };
  230. /*
  231. * @brief Specifies I/O related resources like IRQs and memory region for I/O operations.
  232. */
  233. struct kbase_io_resources {
  234. u32 job_irq_number;
  235. u32 mmu_irq_number;
  236. u32 gpu_irq_number;
  237. struct kbase_io_memory_region io_memory_region;
  238. };
  239. struct kbase_platform_config {
  240. const struct kbase_io_resources *io_resources;
  241. };
  242. #endif // ifdef CONFIG_OF
  243. /**
  244. * @brief Gets the pointer to platform config.
  245. *
  246. * @return Pointer to the platform config
  247. */
  248. struct kbase_platform_config *kbase_get_platform_config(void);
  249. /**
  250. * kbasep_platform_device_init: - Platform specific call to initialize hardware
  251. * @kbdev: kbase device pointer
  252. *
  253. * Function calls a platform defined routine if specified in the configuration
  254. * attributes. The routine can initialize any hardware and context state that
  255. * is required for the GPU block to function.
  256. *
  257. * Return: 0 if no errors have been found in the config.
  258. * Negative error code otherwise.
  259. */
  260. int kbasep_platform_device_init(struct kbase_device *kbdev);
  261. /**
  262. * kbasep_platform_device_term - Platform specific call to terminate hardware
  263. * @kbdev: Kbase device pointer
  264. *
  265. * Function calls a platform defined routine if specified in the configuration
  266. * attributes. The routine can destroy any platform specific context state and
  267. * shut down any hardware functionality that are outside of the Power Management
  268. * callbacks.
  269. *
  270. */
  271. void kbasep_platform_device_term(struct kbase_device *kbdev);
  272. /**
  273. * kbase_platform_early_init - Early initialisation of the platform code
  274. *
  275. * This function will be called when the module is loaded to perform any
  276. * early initialisation required by the platform code. Such as reading
  277. * platform specific device tree entries for the GPU.
  278. *
  279. * Return: 0 for success, any other fail causes module initialisation to fail
  280. */
  281. int kbase_platform_early_init(void);
  282. #ifndef CONFIG_OF
  283. #endif // ifndef CONFIG_OF
  284. /** @} *//* end group kbase_config */
  285. /** @} *//* end group base_kbase_api */
  286. /** @} *//* end group base_api */
  287. #endif // ifndef _KBASE_CONFIG_H_