mali_kbase_pm_internal.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. * Power management API definitions used internally by GPU backend
  17. */
  18. #ifndef _KBASE_BACKEND_PM_INTERNAL_H_
  19. #define _KBASE_BACKEND_PM_INTERNAL_H_
  20. #include <mali_kbase_hwaccess_pm.h>
  21. #include "mali_kbase_pm_ca.h"
  22. #include "mali_kbase_pm_policy.h"
  23. /**
  24. * kbase_pm_dev_idle - The GPU is idle.
  25. *
  26. * The OS may choose to turn off idle devices
  27. *
  28. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  29. */
  30. void kbase_pm_dev_idle(struct kbase_device *kbdev);
  31. /**
  32. * kbase_pm_dev_activate - The GPU is active.
  33. *
  34. * The OS should avoid opportunistically turning off the GPU while it is active
  35. *
  36. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  37. */
  38. void kbase_pm_dev_activate(struct kbase_device *kbdev);
  39. /**
  40. * kbase_pm_get_present_cores - Get details of the cores that are present in
  41. * the device.
  42. *
  43. * This function can be called by the active power policy to return a bitmask of
  44. * the cores (of a specified type) present in the GPU device and also a count of
  45. * the number of cores.
  46. *
  47. * @kbdev: The kbase device structure for the device (must be a valid
  48. * pointer)
  49. * @type: The type of core (see the enum kbase_pm_core_type enumeration)
  50. *
  51. * Return: The bit mask of cores present
  52. */
  53. u64 kbase_pm_get_present_cores(struct kbase_device *kbdev,
  54. enum kbase_pm_core_type type);
  55. /**
  56. * kbase_pm_get_active_cores - Get details of the cores that are currently
  57. * active in the device.
  58. *
  59. * This function can be called by the active power policy to return a bitmask of
  60. * the cores (of a specified type) that are actively processing work (i.e.
  61. * turned on *and* busy).
  62. *
  63. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  64. * @type: The type of core (see the enum kbase_pm_core_type enumeration)
  65. *
  66. * Return: The bit mask of active cores
  67. */
  68. u64 kbase_pm_get_active_cores(struct kbase_device *kbdev,
  69. enum kbase_pm_core_type type);
  70. /**
  71. * kbase_pm_get_trans_cores - Get details of the cores that are currently
  72. * transitioning between power states.
  73. *
  74. * This function can be called by the active power policy to return a bitmask of
  75. * the cores (of a specified type) that are currently transitioning between
  76. * power states.
  77. *
  78. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  79. * @type: The type of core (see the enum kbase_pm_core_type enumeration)
  80. *
  81. * Return: The bit mask of transitioning cores
  82. */
  83. u64 kbase_pm_get_trans_cores(struct kbase_device *kbdev,
  84. enum kbase_pm_core_type type);
  85. /**
  86. * kbase_pm_get_ready_cores - Get details of the cores that are currently
  87. * powered and ready for jobs.
  88. *
  89. * This function can be called by the active power policy to return a bitmask of
  90. * the cores (of a specified type) that are powered and ready for jobs (they may
  91. * or may not be currently executing jobs).
  92. *
  93. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  94. * @type: The type of core (see the enum kbase_pm_core_type enumeration)
  95. *
  96. * Return: The bit mask of ready cores
  97. */
  98. u64 kbase_pm_get_ready_cores(struct kbase_device *kbdev,
  99. enum kbase_pm_core_type type);
  100. /**
  101. * kbase_pm_clock_on - Turn the clock for the device on, and enable device
  102. * interrupts.
  103. *
  104. * This function can be used by a power policy to turn the clock for the GPU on.
  105. * It should be modified during integration to perform the necessary actions to
  106. * ensure that the GPU is fully powered and clocked.
  107. *
  108. * @kbdev: The kbase device structure for the device (must be a valid
  109. * pointer)
  110. * @is_resume: true if clock on due to resume after suspend, false otherwise
  111. */
  112. void kbase_pm_clock_on(struct kbase_device *kbdev, bool is_resume);
  113. /**
  114. * kbase_pm_clock_off - Disable device interrupts, and turn the clock for the
  115. * device off.
  116. *
  117. * This function can be used by a power policy to turn the clock for the GPU
  118. * off. It should be modified during integration to perform the necessary
  119. * actions to turn the clock off (if this is possible in the integration).
  120. *
  121. * @kbdev: The kbase device structure for the device (must be a valid
  122. * pointer)
  123. * @is_suspend: true if clock off due to suspend, false otherwise
  124. *
  125. * Return: true if clock was turned off, or
  126. * false if clock can not be turned off due to pending page/bus fault
  127. * workers. Caller must flush MMU workqueues and retry
  128. */
  129. bool kbase_pm_clock_off(struct kbase_device *kbdev, bool is_suspend);
  130. /**
  131. * kbase_pm_enable_interrupts - Enable interrupts on the device.
  132. *
  133. * Interrupts are also enabled after a call to kbase_pm_clock_on().
  134. *
  135. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  136. */
  137. void kbase_pm_enable_interrupts(struct kbase_device *kbdev);
  138. /**
  139. * kbase_pm_disable_interrupts - Disable interrupts on the device.
  140. *
  141. * This prevents delivery of Power Management interrupts to the CPU so that
  142. * kbase_pm_check_transitions_nolock() will not be called from the IRQ handler
  143. * until kbase_pm_enable_interrupts() or kbase_pm_clock_on() is called.
  144. *
  145. * Interrupts are also disabled after a call to kbase_pm_clock_off().
  146. *
  147. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  148. */
  149. void kbase_pm_disable_interrupts(struct kbase_device *kbdev);
  150. /**
  151. * kbase_pm_init_hw - Initialize the hardware.
  152. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  153. * @flags: Flags specifying the type of PM init
  154. *
  155. * This function checks the GPU ID register to ensure that the GPU is supported
  156. * by the driver and performs a reset on the device so that it is in a known
  157. * state before the device is used.
  158. *
  159. * Return: 0 if the device is supported and successfully reset.
  160. */
  161. int kbase_pm_init_hw(struct kbase_device *kbdev, unsigned int flags);
  162. /**
  163. * kbase_pm_reset_done - The GPU has been reset successfully.
  164. *
  165. * This function must be called by the GPU interrupt handler when the
  166. * RESET_COMPLETED bit is set. It signals to the power management initialization
  167. * code that the GPU has been successfully reset.
  168. *
  169. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  170. */
  171. void kbase_pm_reset_done(struct kbase_device *kbdev);
  172. /**
  173. * kbase_pm_check_transitions_nolock - Check if there are any power transitions
  174. * to make, and if so start them.
  175. *
  176. * This function will check the desired_xx_state members of
  177. * struct kbase_pm_device_data and the actual status of the hardware to see if
  178. * any power transitions can be made at this time to make the hardware state
  179. * closer to the state desired by the power policy.
  180. *
  181. * The return value can be used to check whether all the desired cores are
  182. * available, and so whether it's worth submitting a job (e.g. from a Power
  183. * Management IRQ).
  184. *
  185. * Note that this still returns true when desired_xx_state has no
  186. * cores. That is: of the no cores desired, none were *un*available. In
  187. * this case, the caller may still need to try submitting jobs. This is because
  188. * the Core Availability Policy might have taken us to an intermediate state
  189. * where no cores are powered, before powering on more cores (e.g. for core
  190. * rotation)
  191. *
  192. * The caller must hold kbase_device.pm.power_change_lock
  193. *
  194. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  195. *
  196. * Return: non-zero when all desired cores are available. That is,
  197. * it's worthwhile for the caller to submit a job.
  198. * false otherwise
  199. */
  200. bool kbase_pm_check_transitions_nolock(struct kbase_device *kbdev);
  201. /**
  202. * kbase_pm_check_transitions_sync - Synchronous and locking variant of
  203. * kbase_pm_check_transitions_nolock()
  204. *
  205. * On returning, the desired state at the time of the call will have been met.
  206. *
  207. * There is nothing to stop the core being switched off by calls to
  208. * kbase_pm_release_cores() or kbase_pm_unrequest_cores(). Therefore, the
  209. * caller must have already made a call to
  210. * kbase_pm_request_cores()/kbase_pm_request_cores_sync() previously.
  211. *
  212. * The usual use-case for this is to ensure cores are 'READY' after performing
  213. * a GPU Reset.
  214. *
  215. * Unlike kbase_pm_check_transitions_nolock(), the caller must not hold
  216. * kbase_device.pm.power_change_lock, because this function will take that
  217. * lock itself.
  218. *
  219. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  220. */
  221. void kbase_pm_check_transitions_sync(struct kbase_device *kbdev);
  222. /**
  223. * kbase_pm_update_cores_state_nolock - Variant of kbase_pm_update_cores_state()
  224. * where the caller must hold
  225. * kbase_device.pm.power_change_lock
  226. *
  227. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  228. */
  229. void kbase_pm_update_cores_state_nolock(struct kbase_device *kbdev);
  230. /**
  231. * kbase_pm_update_cores_state - Update the desired state of shader cores from
  232. * the Power Policy, and begin any power
  233. * transitions.
  234. *
  235. * This function will update the desired_xx_state members of
  236. * struct kbase_pm_device_data by calling into the current Power Policy. It will
  237. * then begin power transitions to make the hardware acheive the desired shader
  238. * core state.
  239. *
  240. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  241. */
  242. void kbase_pm_update_cores_state(struct kbase_device *kbdev);
  243. /**
  244. * kbase_pm_cancel_deferred_poweroff - Cancel any pending requests to power off
  245. * the GPU and/or shader cores.
  246. *
  247. * This should be called by any functions which directly power off the GPU.
  248. *
  249. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  250. */
  251. void kbase_pm_cancel_deferred_poweroff(struct kbase_device *kbdev);
  252. /**
  253. * kbasep_pm_read_present_cores - Read the bitmasks of present cores.
  254. *
  255. * This information is cached to avoid having to perform register reads whenever
  256. * the information is required.
  257. *
  258. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  259. */
  260. void kbasep_pm_read_present_cores(struct kbase_device *kbdev);
  261. /**
  262. * kbasep_pm_metrics_init - Initialize the metrics gathering framework.
  263. *
  264. * This must be called before other metric gathering APIs are called.
  265. *
  266. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  267. *
  268. * Return: 0 on success, error code on error
  269. */
  270. int kbasep_pm_metrics_init(struct kbase_device *kbdev);
  271. /**
  272. * kbasep_pm_metrics_term - Terminate the metrics gathering framework.
  273. *
  274. * This must be called when metric gathering is no longer required. It is an
  275. * error to call any metrics gathering function (other than
  276. * kbasep_pm_metrics_init()) after calling this function.
  277. *
  278. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  279. */
  280. void kbasep_pm_metrics_term(struct kbase_device *kbdev);
  281. /**
  282. * kbase_pm_report_vsync - Function to be called by the frame buffer driver to
  283. * update the vsync metric.
  284. *
  285. * This function should be called by the frame buffer driver to update whether
  286. * the system is hitting the vsync target or not. buffer_updated should be true
  287. * if the vsync corresponded with a new frame being displayed, otherwise it
  288. * should be false. This function does not need to be called every vsync, but
  289. * only when the value of @buffer_updated differs from a previous call.
  290. *
  291. * @kbdev: The kbase device structure for the device (must be a
  292. * valid pointer)
  293. * @buffer_updated: True if the buffer has been updated on this VSync,
  294. * false otherwise
  295. */
  296. void kbase_pm_report_vsync(struct kbase_device *kbdev, int buffer_updated);
  297. /**
  298. * kbase_pm_get_dvfs_action - Determine whether the DVFS system should change
  299. * the clock speed of the GPU.
  300. *
  301. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  302. *
  303. * This function should be called regularly by the DVFS system to check whether
  304. * the clock speed of the GPU needs updating.
  305. */
  306. void kbase_pm_get_dvfs_action(struct kbase_device *kbdev);
  307. /**
  308. * kbase_pm_request_gpu_cycle_counter - Mark that the GPU cycle counter is
  309. * needed
  310. *
  311. * If the caller is the first caller then the GPU cycle counters will be enabled
  312. * along with the l2 cache
  313. *
  314. * The GPU must be powered when calling this function (i.e.
  315. * kbase_pm_context_active() must have been called).
  316. *
  317. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  318. */
  319. void kbase_pm_request_gpu_cycle_counter(struct kbase_device *kbdev);
  320. /**
  321. * kbase_pm_request_gpu_cycle_counter_l2_is_on - Mark GPU cycle counter is
  322. * needed (l2 cache already on)
  323. *
  324. * This is a version of the above function
  325. * (kbase_pm_request_gpu_cycle_counter()) suitable for being called when the
  326. * l2 cache is known to be on and assured to be on until the subsequent call of
  327. * kbase_pm_release_gpu_cycle_counter() such as when a job is submitted. It does
  328. * not sleep and can be called from atomic functions.
  329. *
  330. * The GPU must be powered when calling this function (i.e.
  331. * kbase_pm_context_active() must have been called) and the l2 cache must be
  332. * powered on.
  333. *
  334. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  335. */
  336. void kbase_pm_request_gpu_cycle_counter_l2_is_on(struct kbase_device *kbdev);
  337. /**
  338. * kbase_pm_release_gpu_cycle_counter - Mark that the GPU cycle counter is no
  339. * longer in use
  340. *
  341. * If the caller is the
  342. * last caller then the GPU cycle counters will be disabled. A request must have
  343. * been made before a call to this.
  344. *
  345. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  346. */
  347. void kbase_pm_release_gpu_cycle_counter(struct kbase_device *kbdev);
  348. /**
  349. * kbase_pm_register_access_enable - Enable access to GPU registers
  350. *
  351. * Enables access to the GPU registers before power management has powered up
  352. * the GPU with kbase_pm_powerup().
  353. *
  354. * Access to registers should be done using kbase_os_reg_read()/write() at this
  355. * stage, not kbase_reg_read()/write().
  356. *
  357. * This results in the power management callbacks provided in the driver
  358. * configuration to get called to turn on power and/or clocks to the GPU. See
  359. * kbase_pm_callback_conf.
  360. *
  361. * This should only be used before power management is powered up with
  362. * kbase_pm_powerup()
  363. *
  364. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  365. */
  366. void kbase_pm_register_access_enable(struct kbase_device *kbdev);
  367. /**
  368. * kbase_pm_register_access_disable - Disable early register access
  369. *
  370. * Disables access to the GPU registers enabled earlier by a call to
  371. * kbase_pm_register_access_enable().
  372. *
  373. * This results in the power management callbacks provided in the driver
  374. * configuration to get called to turn off power and/or clocks to the GPU. See
  375. * kbase_pm_callback_conf
  376. *
  377. * This should only be used before power management is powered up with
  378. * kbase_pm_powerup()
  379. *
  380. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  381. */
  382. void kbase_pm_register_access_disable(struct kbase_device *kbdev);
  383. /* NOTE: kbase_pm_is_suspending is in mali_kbase.h, because it is an inline
  384. * function */
  385. /**
  386. * kbase_pm_metrics_is_active - Check if the power management metrics
  387. * collection is active.
  388. *
  389. * Note that this returns if the power management metrics collection was
  390. * active at the time of calling, it is possible that after the call the metrics
  391. * collection enable may have changed state.
  392. *
  393. * The caller must handle the consequence that the state may have changed.
  394. *
  395. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  396. * Return: true if metrics collection was active else false.
  397. */
  398. bool kbase_pm_metrics_is_active(struct kbase_device *kbdev);
  399. /**
  400. * kbase_pm_do_poweron - Power on the GPU, and any cores that are requested.
  401. *
  402. * @kbdev: The kbase device structure for the device (must be a valid
  403. * pointer)
  404. * @is_resume: true if power on due to resume after suspend,
  405. * false otherwise
  406. */
  407. void kbase_pm_do_poweron(struct kbase_device *kbdev, bool is_resume);
  408. /**
  409. * kbase_pm_do_poweroff - Power off the GPU, and any cores that have been
  410. * requested.
  411. *
  412. * @kbdev: The kbase device structure for the device (must be a valid
  413. * pointer)
  414. * @is_suspend: true if power off due to suspend,
  415. * false otherwise
  416. * Return:
  417. * true if power was turned off, else
  418. * false if power can not be turned off due to pending page/bus
  419. * fault workers. Caller must flush MMU workqueues and retry
  420. */
  421. bool kbase_pm_do_poweroff(struct kbase_device *kbdev, bool is_suspend);
  422. #ifdef CONFIG_PM_DEVFREQ
  423. void kbase_pm_get_dvfs_utilisation(struct kbase_device *kbdev,
  424. unsigned long *total, unsigned long *busy);
  425. void kbase_pm_reset_dvfs_utilisation(struct kbase_device *kbdev);
  426. #endif
  427. #ifdef CONFIG_MALI_MIDGARD_DVFS
  428. /**
  429. * kbase_platform_dvfs_event - Report utilisation to DVFS code
  430. *
  431. * Function provided by platform specific code when DVFS is enabled to allow
  432. * the power management metrics system to report utilisation.
  433. *
  434. * @kbdev: The kbase device structure for the device (must be a
  435. * valid pointer)
  436. * @utilisation: The current calculated utilisation by the metrics system.
  437. * @util_gl_share: The current calculated gl share of utilisation.
  438. * @util_cl_share: The current calculated cl share of utilisation per core
  439. * group.
  440. * Return: Returns 0 on failure and non zero on success.
  441. */
  442. int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation,
  443. u32 util_gl_share, u32 util_cl_share[2]);
  444. #endif // ifdef CONFIG_MALI_MIDGARD_DVFS
  445. void kbase_pm_power_changed(struct kbase_device *kbdev);
  446. /**
  447. * kbase_pm_metrics_update - Inform the metrics system that an atom is either
  448. * about to be run or has just completed.
  449. * @kbdev: The kbase device structure for the device (must be a valid pointer)
  450. * @now: Pointer to the timestamp of the change, or NULL to use current time
  451. *
  452. * Caller must hold runpool_irq.lock
  453. */
  454. void kbase_pm_metrics_update(struct kbase_device *kbdev,
  455. ktime_t *now);
  456. /**
  457. * kbase_pm_cache_snoop_enable - Allow CPU snoops on the GPU
  458. * If the GPU does not have coherency this is a no-op
  459. * @kbdev: Device pointer
  460. *
  461. * This function should be called after L2 power up.
  462. */
  463. void kbase_pm_cache_snoop_enable(struct kbase_device *kbdev);
  464. /**
  465. * kbase_pm_cache_snoop_disable - Prevent CPU snoops on the GPU
  466. * If the GPU does not have coherency this is a no-op
  467. * @kbdev: Device pointer
  468. *
  469. * This function should be called before L2 power off.
  470. */
  471. void kbase_pm_cache_snoop_disable(struct kbase_device *kbdev);
  472. #endif // ifndef _KBASE_BACKEND_PM_INTERNAL_H_