mali_kbase_pm_defs.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*
  2. *
  3. * (C) COPYRIGHT 2014-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. * Backend-specific Power Manager definitions
  17. */
  18. #ifndef _KBASE_PM_HWACCESS_DEFS_H_
  19. #define _KBASE_PM_HWACCESS_DEFS_H_
  20. #include "mali_kbase_pm_ca_fixed.h"
  21. #include "mali_kbase_pm_always_on.h"
  22. #include "mali_kbase_pm_coarse_demand.h"
  23. #include "mali_kbase_pm_demand.h"
  24. /* Forward definition - see mali_kbase.h */
  25. struct kbase_device;
  26. struct kbase_jd_atom;
  27. /**
  28. * enum kbase_pm_core_type - The types of core in a GPU.
  29. *
  30. * These enumerated values are used in calls to
  31. * - kbase_pm_get_present_cores()
  32. * - kbase_pm_get_active_cores()
  33. * - kbase_pm_get_trans_cores()
  34. * - kbase_pm_get_ready_cores().
  35. *
  36. * They specify which type of core should be acted on. These values are set in
  37. * a manner that allows core_type_to_reg() function to be simpler and more
  38. * efficient.
  39. *
  40. * @KBASE_PM_CORE_L2: The L2 cache
  41. * @KBASE_PM_CORE_SHADER: Shader cores
  42. * @KBASE_PM_CORE_TILER: Tiler cores
  43. */
  44. enum kbase_pm_core_type {
  45. KBASE_PM_CORE_L2 = L2_PRESENT_LO,
  46. KBASE_PM_CORE_SHADER = SHADER_PRESENT_LO,
  47. KBASE_PM_CORE_TILER = TILER_PRESENT_LO
  48. };
  49. /**
  50. * struct kbasep_pm_metrics_data - Metrics data collected for use by the power
  51. * management framework.
  52. *
  53. * @time_period_start: time at which busy/idle measurements started
  54. * @time_busy: number of ns the GPU was busy executing jobs since the
  55. * @time_period_start timestamp.
  56. * @time_idle: number of ns since time_period_start the GPU was not executing
  57. * jobs since the @time_period_start timestamp.
  58. * @prev_busy: busy time in ns of previous time period.
  59. * Updated when metrics are reset.
  60. * @prev_idle: idle time in ns of previous time period
  61. * Updated when metrics are reset.
  62. * @gpu_active: true when the GPU is executing jobs. false when
  63. * not. Updated when the job scheduler informs us a job in submitted
  64. * or removed from a GPU slot.
  65. * @busy_cl: number of ns the GPU was busy executing CL jobs. Note that
  66. * if two CL jobs were active for 400ns, this value would be updated
  67. * with 800.
  68. * @busy_gl: number of ns the GPU was busy executing GL jobs. Note that
  69. * if two GL jobs were active for 400ns, this value would be updated
  70. * with 800.
  71. * @active_cl_ctx: number of CL jobs active on the GPU. Array is per-device.
  72. * @active_gl_ctx: number of GL jobs active on the GPU. Array is per-slot. As
  73. * GL jobs never run on slot 2 this slot is not recorded.
  74. * @lock: spinlock protecting the kbasep_pm_metrics_data structure
  75. * @timer: timer to regularly make DVFS decisions based on the power
  76. * management metrics.
  77. * @timer_active: boolean indicating @timer is running
  78. * @platform_data: pointer to data controlled by platform specific code
  79. * @kbdev: pointer to kbase device for which metrics are collected
  80. *
  81. */
  82. struct kbasep_pm_metrics_data {
  83. ktime_t time_period_start;
  84. u32 time_busy;
  85. u32 time_idle;
  86. u32 prev_busy;
  87. u32 prev_idle;
  88. bool gpu_active;
  89. u32 busy_cl[2];
  90. u32 busy_gl;
  91. u32 active_cl_ctx[2];
  92. u32 active_gl_ctx[2]; /* GL jobs can only run on 2 of the 3 job slots */
  93. spinlock_t lock;
  94. #ifdef CONFIG_MALI_MIDGARD_DVFS
  95. struct hrtimer timer;
  96. bool timer_active;
  97. #endif
  98. void *platform_data;
  99. struct kbase_device *kbdev;
  100. };
  101. union kbase_pm_policy_data {
  102. struct kbasep_pm_policy_always_on always_on;
  103. struct kbasep_pm_policy_coarse_demand coarse_demand;
  104. struct kbasep_pm_policy_demand demand;
  105. };
  106. union kbase_pm_ca_policy_data {
  107. struct kbasep_pm_ca_policy_fixed fixed;
  108. };
  109. /**
  110. * struct kbase_pm_backend_data - Data stored per device for power management.
  111. *
  112. * This structure contains data for the power management framework. There is one
  113. * instance of this structure per device in the system.
  114. *
  115. * @ca_current_policy: The policy that is currently actively controlling core
  116. * availability.
  117. * @pm_current_policy: The policy that is currently actively controlling the
  118. * power state.
  119. * @ca_policy_data: Private data for current CA policy
  120. * @pm_policy_data: Private data for current PM policy
  121. * @ca_in_transition: Flag indicating when core availability policy is
  122. * transitioning cores. The core availability policy must
  123. * set this when a change in core availability is occurring.
  124. * power_change_lock must be held when accessing this.
  125. * @reset_done: Flag when a reset is complete
  126. * @reset_done_wait: Wait queue to wait for changes to @reset_done
  127. * @l2_powered_wait: Wait queue for whether the l2 cache has been powered as
  128. * requested
  129. * @l2_powered: State indicating whether all the l2 caches are powered.
  130. * Non-zero indicates they're *all* powered
  131. * Zero indicates that some (or all) are not powered
  132. * @gpu_cycle_counter_requests: The reference count of active gpu cycle counter
  133. * users
  134. * @gpu_cycle_counter_requests_lock: Lock to protect @gpu_cycle_counter_requests
  135. * @desired_shader_state: A bit mask identifying the shader cores that the
  136. * power policy would like to be on. The current state
  137. * of the cores may be different, but there should be
  138. * transitions in progress that will eventually achieve
  139. * this state (assuming that the policy doesn't change
  140. * its mind in the mean time).
  141. * @powering_on_shader_state: A bit mask indicating which shader cores are
  142. * currently in a power-on transition
  143. * @desired_tiler_state: A bit mask identifying the tiler cores that the power
  144. * policy would like to be on. See @desired_shader_state
  145. * @powering_on_tiler_state: A bit mask indicating which tiler core are
  146. * currently in a power-on transition
  147. * @powering_on_l2_state: A bit mask indicating which l2-caches are currently
  148. * in a power-on transition
  149. * @gpu_in_desired_state: This flag is set if the GPU is powered as requested
  150. * by the desired_xxx_state variables
  151. * @gpu_in_desired_state_wait: Wait queue set when @gpu_in_desired_state != 0
  152. * @gpu_powered: Set to true when the GPU is powered and register
  153. * accesses are possible, false otherwise
  154. * @instr_enabled: Set to true when instrumentation is enabled,
  155. * false otherwise
  156. * @cg1_disabled: Set if the policy wants to keep the second core group
  157. * powered off
  158. * @driver_ready_for_irqs: Debug state indicating whether sufficient
  159. * initialization of the driver has occurred to handle
  160. * IRQs
  161. * @gpu_powered_lock: Spinlock that must be held when writing @gpu_powered or
  162. * accessing @driver_ready_for_irqs
  163. * @metrics: Structure to hold metrics for the GPU
  164. * @gpu_poweroff_pending: number of poweroff timer ticks until the GPU is
  165. * powered off
  166. * @shader_poweroff_pending_time: number of poweroff timer ticks until shaders
  167. * are powered off
  168. * @gpu_poweroff_timer: Timer for powering off GPU
  169. * @gpu_poweroff_wq: Workqueue to power off GPU on when timer fires
  170. * @gpu_poweroff_work: Workitem used on @gpu_poweroff_wq
  171. * @shader_poweroff_pending: Bit mask of shaders to be powered off on next
  172. * timer callback
  173. * @poweroff_timer_needed: true if the poweroff timer is currently required,
  174. * false otherwise
  175. * @poweroff_timer_running: true if the poweroff timer is currently running,
  176. * false otherwise
  177. * power_change_lock should be held when accessing,
  178. * unless there is no way the timer can be running (eg
  179. * hrtimer_cancel() was called immediately before)
  180. * @callback_power_on: Callback when the GPU needs to be turned on. See
  181. * &struct kbase_pm_callback_conf
  182. * @callback_power_off: Callback when the GPU may be turned off. See
  183. * &struct kbase_pm_callback_conf
  184. * @callback_power_suspend: Callback when a suspend occurs and the GPU needs to
  185. * be turned off. See &struct kbase_pm_callback_conf
  186. * @callback_power_resume: Callback when a resume occurs and the GPU needs to
  187. * be turned on. See &struct kbase_pm_callback_conf
  188. * @callback_power_runtime_on: Callback when the GPU needs to be turned on. See
  189. * &struct kbase_pm_callback_conf
  190. * @callback_power_runtime_off: Callback when the GPU may be turned off. See
  191. * &struct kbase_pm_callback_conf
  192. * @callback_power_runtime_idle: Optional callback when the GPU may be idle. See
  193. * &struct kbase_pm_callback_conf
  194. *
  195. * Note:
  196. * During an IRQ, @ca_current_policy or @pm_current_policy can be NULL when the
  197. * policy is being changed with kbase_pm_ca_set_policy() or
  198. * kbase_pm_set_policy(). The change is protected under
  199. * kbase_device.pm.power_change_lock. Direct access to this
  200. * from IRQ context must therefore check for NULL. If NULL, then
  201. * kbase_pm_ca_set_policy() or kbase_pm_set_policy() will re-issue the policy
  202. * functions that would have been done under IRQ.
  203. */
  204. struct kbase_pm_backend_data {
  205. const struct kbase_pm_ca_policy *ca_current_policy;
  206. const struct kbase_pm_policy *pm_current_policy;
  207. union kbase_pm_ca_policy_data ca_policy_data;
  208. union kbase_pm_policy_data pm_policy_data;
  209. bool ca_in_transition;
  210. bool reset_done;
  211. wait_queue_head_t reset_done_wait;
  212. wait_queue_head_t l2_powered_wait;
  213. int l2_powered;
  214. int gpu_cycle_counter_requests;
  215. spinlock_t gpu_cycle_counter_requests_lock;
  216. u64 desired_shader_state;
  217. u64 powering_on_shader_state;
  218. u64 desired_tiler_state;
  219. u64 powering_on_tiler_state;
  220. u64 powering_on_l2_state;
  221. bool gpu_in_desired_state;
  222. wait_queue_head_t gpu_in_desired_state_wait;
  223. bool gpu_powered;
  224. bool instr_enabled;
  225. bool cg1_disabled;
  226. #ifdef CONFIG_MALI_DEBUG
  227. bool driver_ready_for_irqs;
  228. #endif
  229. spinlock_t gpu_powered_lock;
  230. struct kbasep_pm_metrics_data metrics;
  231. int gpu_poweroff_pending;
  232. int shader_poweroff_pending_time;
  233. struct hrtimer gpu_poweroff_timer;
  234. struct workqueue_struct *gpu_poweroff_wq;
  235. struct work_struct gpu_poweroff_work;
  236. u64 shader_poweroff_pending;
  237. bool poweroff_timer_needed;
  238. bool poweroff_timer_running;
  239. int (*callback_power_on)(struct kbase_device *kbdev);
  240. void (*callback_power_off)(struct kbase_device *kbdev);
  241. void (*callback_power_suspend)(struct kbase_device *kbdev);
  242. void (*callback_power_resume)(struct kbase_device *kbdev);
  243. int (*callback_power_runtime_on)(struct kbase_device *kbdev);
  244. void (*callback_power_runtime_off)(struct kbase_device *kbdev);
  245. int (*callback_power_runtime_idle)(struct kbase_device *kbdev);
  246. };
  247. /* List of policy IDs */
  248. enum kbase_pm_policy_id {
  249. KBASE_PM_POLICY_ID_DEMAND = 1,
  250. KBASE_PM_POLICY_ID_ALWAYS_ON,
  251. KBASE_PM_POLICY_ID_COARSE_DEMAND,
  252. };
  253. typedef u32 kbase_pm_policy_flags;
  254. /**
  255. * struct kbase_pm_policy - Power policy structure.
  256. *
  257. * Each power policy exposes a (static) instance of this structure which
  258. * contains function pointers to the policy's methods.
  259. *
  260. * @name: The name of this policy
  261. * @init: Function called when the policy is selected
  262. * @term: Function called when the policy is unselected
  263. * @get_core_mask: Function called to get the current shader core mask
  264. * @get_core_active: Function called to get the current overall GPU power
  265. * state
  266. * @flags: Field indicating flags for this policy
  267. * @id: Field indicating an ID for this policy. This is not
  268. * necessarily the same as its index in the list returned
  269. * by kbase_pm_list_policies().
  270. * It is used purely for debugging.
  271. */
  272. struct kbase_pm_policy {
  273. char *name;
  274. /**
  275. * Function called when the policy is selected
  276. *
  277. * This should initialize the kbdev->pm.pm_policy_data structure. It
  278. * should not attempt to make any changes to hardware state.
  279. *
  280. * It is undefined what state the cores are in when the function is
  281. * called.
  282. *
  283. * @kbdev: The kbase device structure for the device (must be a
  284. * valid pointer)
  285. */
  286. void (*init)(struct kbase_device *kbdev);
  287. /**
  288. * Function called when the policy is unselected.
  289. *
  290. * @kbdev: The kbase device structure for the device (must be a
  291. * valid pointer)
  292. */
  293. void (*term)(struct kbase_device *kbdev);
  294. /**
  295. * Function called to get the current shader core mask
  296. *
  297. * The returned mask should meet or exceed (kbdev->shader_needed_bitmap
  298. * | kbdev->shader_inuse_bitmap).
  299. *
  300. * @kbdev: The kbase device structure for the device (must be a
  301. * valid pointer)
  302. *
  303. * Return: The mask of shader cores to be powered
  304. */
  305. u64 (*get_core_mask)(struct kbase_device *kbdev);
  306. /**
  307. * Function called to get the current overall GPU power state
  308. *
  309. * This function should consider the state of kbdev->pm.active_count. If
  310. * this count is greater than 0 then there is at least one active
  311. * context on the device and the GPU should be powered. If it is equal
  312. * to 0 then there are no active contexts and the GPU could be powered
  313. * off if desired.
  314. *
  315. * @kbdev: The kbase device structure for the device (must be a
  316. * valid pointer)
  317. *
  318. * Return: true if the GPU should be powered, false otherwise
  319. */
  320. bool (*get_core_active)(struct kbase_device *kbdev);
  321. kbase_pm_policy_flags flags;
  322. enum kbase_pm_policy_id id;
  323. };
  324. enum kbase_pm_ca_policy_id {
  325. KBASE_PM_CA_POLICY_ID_FIXED = 1,
  326. KBASE_PM_CA_POLICY_ID_RANDOM
  327. };
  328. typedef u32 kbase_pm_ca_policy_flags;
  329. /**
  330. * struct kbase_pm_ca_policy - Core availability policy structure.
  331. *
  332. * Each core availability policy exposes a (static) instance of this structure
  333. * which contains function pointers to the policy's methods.
  334. *
  335. * @name: The name of this policy
  336. * @init: Function called when the policy is selected
  337. * @term: Function called when the policy is unselected
  338. * @get_core_mask: Function called to get the current shader core
  339. * availability mask
  340. * @update_core_status: Function called to update the current core status
  341. * @flags: Field indicating flags for this policy
  342. * @id: Field indicating an ID for this policy. This is not
  343. * necessarily the same as its index in the list returned
  344. * by kbase_pm_list_policies().
  345. * It is used purely for debugging.
  346. */
  347. struct kbase_pm_ca_policy {
  348. char *name;
  349. /**
  350. * Function called when the policy is selected
  351. *
  352. * This should initialize the kbdev->pm.ca_policy_data structure. It
  353. * should not attempt to make any changes to hardware state.
  354. *
  355. * It is undefined what state the cores are in when the function is
  356. * called.
  357. *
  358. * @kbdev The kbase device structure for the device (must be a
  359. * valid pointer)
  360. */
  361. void (*init)(struct kbase_device *kbdev);
  362. /**
  363. * Function called when the policy is unselected.
  364. *
  365. * @kbdev The kbase device structure for the device (must be a
  366. * valid pointer)
  367. */
  368. void (*term)(struct kbase_device *kbdev);
  369. /**
  370. * Function called to get the current shader core availability mask
  371. *
  372. * When a change in core availability is occurring, the policy must set
  373. * kbdev->pm.ca_in_transition to true. This is to indicate that
  374. * reporting changes in power state cannot be optimized out, even if
  375. * kbdev->pm.desired_shader_state remains unchanged. This must be done
  376. * by any functions internal to the Core Availability Policy that change
  377. * the return value of kbase_pm_ca_policy::get_core_mask.
  378. *
  379. * @kbdev The kbase device structure for the device (must be a
  380. * valid pointer)
  381. *
  382. * Return: The current core availability mask
  383. */
  384. u64 (*get_core_mask)(struct kbase_device *kbdev);
  385. /**
  386. * Function called to update the current core status
  387. *
  388. * If none of the cores in core group 0 are ready or transitioning, then
  389. * the policy must ensure that the next call to get_core_mask does not
  390. * return 0 for all cores in core group 0. It is an error to disable
  391. * core group 0 through the core availability policy.
  392. *
  393. * When a change in core availability has finished, the policy must set
  394. * kbdev->pm.ca_in_transition to false. This is to indicate that
  395. * changes in power state can once again be optimized out when
  396. * kbdev->pm.desired_shader_state is unchanged.
  397. *
  398. * @kbdev: The kbase device structure for the device
  399. * (must be a valid pointer)
  400. * @cores_ready: The mask of cores currently powered and
  401. * ready to run jobs
  402. * @cores_transitioning: The mask of cores currently transitioning
  403. * power state
  404. */
  405. void (*update_core_status)(struct kbase_device *kbdev, u64 cores_ready,
  406. u64 cores_transitioning);
  407. kbase_pm_ca_policy_flags flags;
  408. /**
  409. * Field indicating an ID for this policy. This is not necessarily the
  410. * same as its index in the list returned by kbase_pm_list_policies().
  411. * It is used purely for debugging.
  412. */
  413. enum kbase_pm_ca_policy_id id;
  414. };
  415. #endif // ifndef _KBASE_PM_HWACCESS_DEFS_H_