3 * (C) COPYRIGHT 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.
21 * @file mali_kbase_jm.h
22 * Job Manager Low-level APIs.
28 #include <mali_kbase_hw.h>
29 #include <mali_kbase_debug.h>
30 #include <linux/atomic.h>
33 * @addtogroup base_api
38 * @addtogroup base_kbase_api
43 * @addtogroup kbase_jm Job Manager Low-level APIs
48 static INLINE int kbasep_jm_is_js_free(kbase_device *kbdev, int js, kbase_context *kctx)
50 KBASE_DEBUG_ASSERT(kbdev != NULL);
51 KBASE_DEBUG_ASSERT(0 <= js && js < kbdev->gpu_props.num_job_slots);
53 return !kbase_reg_read(kbdev, JOB_SLOT_REG(js, JSn_COMMAND_NEXT), kctx);
58 * - there is enough space in the GPU's buffers (JSn_NEXT and JSn_HEAD registers) to accomodate the job.
59 * - there is enough space to track the job in a our Submit Slots. Note that we have to maintain space to
60 * requeue one job in case the next registers on the hardware need to be cleared.
62 static INLINE mali_bool kbasep_jm_is_submit_slots_free(kbase_device *kbdev, int js, kbase_context *kctx)
64 KBASE_DEBUG_ASSERT(kbdev != NULL);
65 KBASE_DEBUG_ASSERT(0 <= js && js < kbdev->gpu_props.num_job_slots);
67 if (atomic_read(&kbdev->reset_gpu) != KBASE_RESET_GPU_NOT_PENDING) {
68 /* The GPU is being reset - so prevent submission */
72 return (mali_bool) (kbasep_jm_is_js_free(kbdev, js, kctx)
73 && kbdev->jm_slots[js].submitted_nr < (BASE_JM_SUBMIT_SLOTS - 2));
77 * Initialize a submit slot
79 static INLINE void kbasep_jm_init_submit_slot(kbase_jm_slot *slot)
81 slot->submitted_nr = 0;
82 slot->submitted_head = 0;
86 * Find the atom at the idx'th element in the queue without removing it, starting at the head with idx==0.
88 static INLINE kbase_jd_atom *kbasep_jm_peek_idx_submit_slot(kbase_jm_slot *slot, u8 idx)
93 KBASE_DEBUG_ASSERT(idx < BASE_JM_SUBMIT_SLOTS);
95 pos = (slot->submitted_head + idx) & BASE_JM_SUBMIT_SLOTS_MASK;
96 katom = slot->submitted[pos];
102 * Pop front of the submitted
104 static INLINE kbase_jd_atom *kbasep_jm_dequeue_submit_slot(kbase_jm_slot *slot)
107 kbase_jd_atom *katom;
109 pos = slot->submitted_head & BASE_JM_SUBMIT_SLOTS_MASK;
110 katom = slot->submitted[pos];
111 slot->submitted[pos] = NULL; /* Just to catch bugs... */
112 KBASE_DEBUG_ASSERT(katom);
114 /* rotate the buffers */
115 slot->submitted_head = (slot->submitted_head + 1) & BASE_JM_SUBMIT_SLOTS_MASK;
116 slot->submitted_nr--;
118 KBASE_LOG(2, katom->kctx->kbdev->dev, "katom %p new head %u", (void *)katom, (unsigned int)slot->submitted_head);
123 /* Pop back of the submitted queue (unsubmit a job)
125 static INLINE kbase_jd_atom *kbasep_jm_dequeue_tail_submit_slot(kbase_jm_slot *slot)
129 slot->submitted_nr--;
131 pos = (slot->submitted_head + slot->submitted_nr) & BASE_JM_SUBMIT_SLOTS_MASK;
133 return slot->submitted[pos];
136 static INLINE u8 kbasep_jm_nr_jobs_submitted(kbase_jm_slot *slot)
138 return slot->submitted_nr;
142 * Push back of the submitted
144 static INLINE void kbasep_jm_enqueue_submit_slot(kbase_jm_slot *slot, kbase_jd_atom *katom)
148 nr = slot->submitted_nr++;
149 KBASE_DEBUG_ASSERT(nr < BASE_JM_SUBMIT_SLOTS);
151 pos = (slot->submitted_head + nr) & BASE_JM_SUBMIT_SLOTS_MASK;
152 slot->submitted[pos] = katom;
156 * @brief Query whether a job peeked/dequeued from the submit slots is a
157 * 'dummy' job that is used for hardware workaround purposes.
159 * Any time a job is peeked/dequeued from the submit slots, this should be
160 * queried on that job.
162 * If a \a atom is indicated as being a dummy job, then you <b>must not attempt
163 * to use \a atom</b>. This is because its members will not necessarily be
164 * initialized, and so could lead to a fault if they were used.
166 * @param[in] kbdev kbase device pointer
167 * @param[in] atom The atom to query
169 * @return MALI_TRUE if \a atom is for a dummy job, in which case you must not
171 * @return MALI_FALSE otherwise, and \a atom is safe to use.
173 static INLINE mali_bool kbasep_jm_is_dummy_workaround_job(kbase_device *kbdev, kbase_jd_atom *atom)
175 /* Query the set of workaround jobs here */
176 /* none exists today */
181 * @brief Submit a job to a certain job-slot
183 * The caller must check kbasep_jm_is_submit_slots_free() != MALI_FALSE before calling this.
185 * The following locking conditions are made on the caller:
186 * - it must hold the kbasep_js_device_data::runpoool_irq::lock
188 void kbase_job_submit_nolock(kbase_device *kbdev, kbase_jd_atom *katom, int js);
191 * @brief Complete the head job on a particular job-slot
193 void kbase_job_done_slot(kbase_device *kbdev, int s, u32 completion_code, u64 job_tail, ktime_t *end_timestamp);
195 /** @} *//* end group kbase_jm */
196 /** @} *//* end group base_kbase_api */
197 /** @} *//* end group base_api */
199 #endif /* _KBASE_JM_H_ */