3 * (C) COPYRIGHT 2014-2015 ARM Limited. All rights reserved.
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
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.
20 * HW access job manager common APIs
23 #include <mali_kbase.h>
24 #include "mali_kbase_hwaccess_jm.h"
25 #include "mali_kbase_jm.h"
28 * kbase_jm_next_job() - Attempt to run the next @nr_jobs_to_submit jobs on slot
29 * @js on the active context.
30 * @kbdev: Device pointer
31 * @js: Job slot to run on
32 * @nr_jobs_to_submit: Number of jobs to attempt to submit
34 * Return: true if slot can still be submitted on, false if slot is now full.
36 static bool kbase_jm_next_job(struct kbase_device *kbdev, int js,
37 int nr_jobs_to_submit)
39 struct kbase_context *kctx;
42 kctx = kbdev->hwaccess.active_kctx;
47 for (i = 0; i < nr_jobs_to_submit; i++) {
48 struct kbase_jd_atom *katom = kbase_js_pull(kctx, js);
51 return true; /* Context has no jobs on this slot */
53 kbase_backend_run_atom(kbdev, katom);
56 return false; /* Slot ringbuffer should now be full */
59 u32 kbase_jm_kick(struct kbase_device *kbdev, u32 js_mask)
63 lockdep_assert_held(&kbdev->js_data.runpool_irq.lock);
66 int js = ffs(js_mask) - 1;
67 int nr_jobs_to_submit = kbase_backend_slot_free(kbdev, js);
69 if (kbase_jm_next_job(kbdev, js, nr_jobs_to_submit))
70 ret_mask |= (1 << js);
72 js_mask &= ~(1 << js);
78 void kbase_jm_try_kick(struct kbase_device *kbdev, u32 js_mask)
80 struct kbasep_js_device_data *js_devdata = &kbdev->js_data;
82 lockdep_assert_held(&js_devdata->runpool_irq.lock);
84 if (!down_trylock(&js_devdata->schedule_sem)) {
85 kbase_jm_kick(kbdev, js_mask);
86 up(&js_devdata->schedule_sem);
90 void kbase_jm_try_kick_all(struct kbase_device *kbdev)
92 struct kbasep_js_device_data *js_devdata = &kbdev->js_data;
94 lockdep_assert_held(&js_devdata->runpool_irq.lock);
96 if (!down_trylock(&js_devdata->schedule_sem)) {
97 kbase_jm_kick_all(kbdev);
98 up(&js_devdata->schedule_sem);
102 void kbase_jm_idle_ctx(struct kbase_device *kbdev, struct kbase_context *kctx)
104 lockdep_assert_held(&kbdev->js_data.runpool_irq.lock);
106 if (kbdev->hwaccess.active_kctx == kctx)
107 kbdev->hwaccess.active_kctx = NULL;
110 void kbase_jm_return_atom_to_js(struct kbase_device *kbdev,
111 struct kbase_jd_atom *katom)
113 lockdep_assert_held(&kbdev->js_data.runpool_irq.lock);
115 if (katom->event_code != BASE_JD_EVENT_STOPPED &&
116 katom->event_code != BASE_JD_EVENT_REMOVED_FROM_NEXT) {
117 kbase_js_complete_atom(katom, NULL);
119 kbase_js_unpull(katom->kctx, katom);
123 void kbase_jm_complete(struct kbase_device *kbdev, struct kbase_jd_atom *katom,
124 ktime_t *end_timestamp)
126 lockdep_assert_held(&kbdev->js_data.runpool_irq.lock);
128 kbase_js_complete_atom(katom, end_timestamp);