rk3288 gpu : update GPU driver r4p0_eac version
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_jm.h
1 /*
2  *
3  * (C) COPYRIGHT 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
17
18
19
20 /**
21  * @file mali_kbase_jm.h
22  * Job Manager Low-level APIs.
23  */
24
25 #ifndef _KBASE_JM_H_
26 #define _KBASE_JM_H_
27
28 #include <mali_kbase_hw.h>
29 #include <mali_kbase_debug.h>
30 #include <linux/atomic.h>
31
32 /**
33  * @addtogroup base_api
34  * @{
35  */
36
37 /**
38  * @addtogroup base_kbase_api
39  * @{
40  */
41
42 /**
43  * @addtogroup kbase_jm Job Manager Low-level APIs
44  * @{
45  *
46  */
47
48 static INLINE int kbasep_jm_is_js_free(kbase_device *kbdev, int js, kbase_context *kctx)
49 {
50         KBASE_DEBUG_ASSERT(kbdev != NULL);
51         KBASE_DEBUG_ASSERT(0 <= js && js < kbdev->gpu_props.num_job_slots);
52
53         return !kbase_reg_read(kbdev, JOB_SLOT_REG(js, JSn_COMMAND_NEXT), kctx);
54 }
55
56 /**
57  * This checks that:
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.
61  */
62 static INLINE mali_bool kbasep_jm_is_submit_slots_free(kbase_device *kbdev, int js, kbase_context *kctx)
63 {
64         KBASE_DEBUG_ASSERT(kbdev != NULL);
65         KBASE_DEBUG_ASSERT(0 <= js && js < kbdev->gpu_props.num_job_slots);
66
67         if (atomic_read(&kbdev->reset_gpu) != KBASE_RESET_GPU_NOT_PENDING) {
68                 /* The GPU is being reset - so prevent submission */
69                 return MALI_FALSE;
70         }
71
72         return (mali_bool) (kbasep_jm_is_js_free(kbdev, js, kctx)
73                             && kbdev->jm_slots[js].submitted_nr < (BASE_JM_SUBMIT_SLOTS - 2));
74 }
75
76 /**
77  * Initialize a submit slot
78  */
79 static INLINE void kbasep_jm_init_submit_slot(kbase_jm_slot *slot)
80 {
81         slot->submitted_nr = 0;
82         slot->submitted_head = 0;
83 }
84
85 /**
86  * Find the atom at the idx'th element in the queue without removing it, starting at the head with idx==0.
87  */
88 static INLINE kbase_jd_atom *kbasep_jm_peek_idx_submit_slot(kbase_jm_slot *slot, u8 idx)
89 {
90         u8 pos;
91         kbase_jd_atom *katom;
92
93         KBASE_DEBUG_ASSERT(idx < BASE_JM_SUBMIT_SLOTS);
94
95         pos = (slot->submitted_head + idx) & BASE_JM_SUBMIT_SLOTS_MASK;
96         katom = slot->submitted[pos];
97
98         return katom;
99 }
100
101 /**
102  * Pop front of the submitted
103  */
104 static INLINE kbase_jd_atom *kbasep_jm_dequeue_submit_slot(kbase_jm_slot *slot)
105 {
106         u8 pos;
107         kbase_jd_atom *katom;
108
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);
113
114         /* rotate the buffers */
115         slot->submitted_head = (slot->submitted_head + 1) & BASE_JM_SUBMIT_SLOTS_MASK;
116         slot->submitted_nr--;
117
118         KBASE_LOG(2, katom->kctx->kbdev->dev, "katom %p new head %u", (void *)katom, (unsigned int)slot->submitted_head);
119
120         return katom;
121 }
122
123 /* Pop back of the submitted queue (unsubmit a job)
124  */
125 static INLINE kbase_jd_atom *kbasep_jm_dequeue_tail_submit_slot(kbase_jm_slot *slot)
126 {
127         u8 pos;
128
129         slot->submitted_nr--;
130
131         pos = (slot->submitted_head + slot->submitted_nr) & BASE_JM_SUBMIT_SLOTS_MASK;
132
133         return slot->submitted[pos];
134 }
135
136 static INLINE u8 kbasep_jm_nr_jobs_submitted(kbase_jm_slot *slot)
137 {
138         return slot->submitted_nr;
139 }
140
141 /**
142  * Push back of the submitted
143  */
144 static INLINE void kbasep_jm_enqueue_submit_slot(kbase_jm_slot *slot, kbase_jd_atom *katom)
145 {
146         u8 nr;
147         u8 pos;
148         nr = slot->submitted_nr++;
149         KBASE_DEBUG_ASSERT(nr < BASE_JM_SUBMIT_SLOTS);
150
151         pos = (slot->submitted_head + nr) & BASE_JM_SUBMIT_SLOTS_MASK;
152         slot->submitted[pos] = katom;
153 }
154
155 /**
156  * @brief Query whether a job peeked/dequeued from the submit slots is a
157  * 'dummy' job that is used for hardware workaround purposes.
158  *
159  * Any time a job is peeked/dequeued from the submit slots, this should be
160  * queried on that job.
161  *
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.
165  *
166  * @param[in] kbdev kbase device pointer
167  * @param[in] atom The atom to query
168  *
169  * @return    MALI_TRUE if \a atom is for a dummy job, in which case you must not
170  *            attempt to use it.
171  * @return    MALI_FALSE otherwise, and \a atom is safe to use.
172  */
173 static INLINE mali_bool kbasep_jm_is_dummy_workaround_job(kbase_device *kbdev, kbase_jd_atom *atom)
174 {
175         /* Query the set of workaround jobs here */
176         /* none exists today */
177         return MALI_FALSE;
178 }
179
180 /**
181  * @brief Submit a job to a certain job-slot
182  *
183  * The caller must check kbasep_jm_is_submit_slots_free() != MALI_FALSE before calling this.
184  *
185  * The following locking conditions are made on the caller:
186  * - it must hold the kbasep_js_device_data::runpoool_irq::lock
187  */
188 void kbase_job_submit_nolock(kbase_device *kbdev, kbase_jd_atom *katom, int js);
189
190 /**
191  * @brief Complete the head job on a particular job-slot
192  */
193 void kbase_job_done_slot(kbase_device *kbdev, int s, u32 completion_code, u64 job_tail, ktime_t *end_timestamp);
194
195           /** @} *//* end group kbase_jm */
196           /** @} *//* end group base_kbase_api */
197           /** @} *//* end group base_api */
198
199 #endif                          /* _KBASE_JM_H_ */