mali_kbase_jm.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. *
  3. * (C) COPYRIGHT 2014-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. * HW access job manager common APIs
  17. */
  18. #include <mali_kbase.h>
  19. #include "mali_kbase_hwaccess_jm.h"
  20. #include "mali_kbase_jm.h"
  21. /**
  22. * kbase_jm_next_job() - Attempt to run the next @nr_jobs_to_submit jobs on slot
  23. * @js on the active context.
  24. * @kbdev: Device pointer
  25. * @js: Job slot to run on
  26. * @nr_jobs_to_submit: Number of jobs to attempt to submit
  27. *
  28. * Return: true if slot can still be submitted on, false if slot is now full.
  29. */
  30. static bool kbase_jm_next_job(struct kbase_device *kbdev, int js,
  31. int nr_jobs_to_submit)
  32. {
  33. struct kbase_context *kctx;
  34. int i;
  35. kctx = kbdev->hwaccess.active_kctx;
  36. if (!kctx)
  37. return true;
  38. for (i = 0; i < nr_jobs_to_submit; i++) {
  39. struct kbase_jd_atom *katom = kbase_js_pull(kctx, js);
  40. if (!katom)
  41. return true; /* Context has no jobs on this slot */
  42. kbase_backend_run_atom(kbdev, katom);
  43. }
  44. return false; /* Slot ringbuffer should now be full */
  45. }
  46. u32 kbase_jm_kick(struct kbase_device *kbdev, u32 js_mask)
  47. {
  48. u32 ret_mask = 0;
  49. lockdep_assert_held(&kbdev->js_data.runpool_irq.lock);
  50. while (js_mask) {
  51. int js = ffs(js_mask) - 1;
  52. int nr_jobs_to_submit = kbase_backend_slot_free(kbdev, js);
  53. if (kbase_jm_next_job(kbdev, js, nr_jobs_to_submit))
  54. ret_mask |= (1 << js);
  55. js_mask &= ~(1 << js);
  56. }
  57. return ret_mask;
  58. }
  59. void kbase_jm_try_kick(struct kbase_device *kbdev, u32 js_mask)
  60. {
  61. struct kbasep_js_device_data *js_devdata = &kbdev->js_data;
  62. lockdep_assert_held(&js_devdata->runpool_irq.lock);
  63. if (!down_trylock(&js_devdata->schedule_sem)) {
  64. kbase_jm_kick(kbdev, js_mask);
  65. up(&js_devdata->schedule_sem);
  66. }
  67. }
  68. void kbase_jm_try_kick_all(struct kbase_device *kbdev)
  69. {
  70. struct kbasep_js_device_data *js_devdata = &kbdev->js_data;
  71. lockdep_assert_held(&js_devdata->runpool_irq.lock);
  72. if (!down_trylock(&js_devdata->schedule_sem)) {
  73. kbase_jm_kick_all(kbdev);
  74. up(&js_devdata->schedule_sem);
  75. }
  76. }
  77. void kbase_jm_idle_ctx(struct kbase_device *kbdev, struct kbase_context *kctx)
  78. {
  79. lockdep_assert_held(&kbdev->js_data.runpool_irq.lock);
  80. if (kbdev->hwaccess.active_kctx == kctx)
  81. kbdev->hwaccess.active_kctx = NULL;
  82. }
  83. void kbase_jm_return_atom_to_js(struct kbase_device *kbdev,
  84. struct kbase_jd_atom *katom)
  85. {
  86. lockdep_assert_held(&kbdev->js_data.runpool_irq.lock);
  87. if (katom->event_code != BASE_JD_EVENT_STOPPED &&
  88. katom->event_code != BASE_JD_EVENT_REMOVED_FROM_NEXT) {
  89. kbase_js_complete_atom(katom, NULL);
  90. } else {
  91. kbase_js_unpull(katom->kctx, katom);
  92. }
  93. }
  94. void kbase_jm_complete(struct kbase_device *kbdev, struct kbase_jd_atom *katom,
  95. ktime_t *end_timestamp)
  96. {
  97. lockdep_assert_held(&kbdev->js_data.runpool_irq.lock);
  98. kbase_js_complete_atom(katom, end_timestamp);
  99. }