1 /*
2 *
3 * (C) COPYRIGHT 2012-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
17
18
19
20 /**
21 * @file mali_kbase_js_ctx_attr.h
22 * Job Scheduler Context Attribute APIs
23 */
24
25 #ifndef _KBASE_JS_CTX_ATTR_H_
26 #define _KBASE_JS_CTX_ATTR_H_
27
28 /**
29 * @addtogroup base_api
30 * @{
31 */
32
33 /**
34 * @addtogroup base_kbase_api
35 * @{
36 */
37
38 /**
39 * @addtogroup kbase_js
40 * @{
41 */
42
43 /**
44 * Set the initial attributes of a context (when context create flags are set)
45 *
46 * Requires:
47 * - Hold the jsctx_mutex
48 */
49 void kbasep_js_ctx_attr_set_initial_attrs(struct kbase_device *kbdev, struct kbase_context *kctx);
50
51 /**
52 * Retain all attributes of a context
53 *
54 * This occurs on scheduling in the context on the runpool (but after
55 * is_scheduled is set)
56 *
57 * Requires:
58 * - jsctx mutex
59 * - runpool_irq spinlock
60 * - ctx->is_scheduled is true
61 */
62 void kbasep_js_ctx_attr_runpool_retain_ctx(struct kbase_device *kbdev, struct kbase_context *kctx);
63
64 /**
65 * Release all attributes of a context
66 *
67 * This occurs on scheduling out the context from the runpool (but before
68 * is_scheduled is cleared)
69 *
70 * Requires:
71 * - jsctx mutex
72 * - runpool_irq spinlock
73 * - ctx->is_scheduled is true
74 *
75 * @return true indicates a change in ctx attributes state of the runpool.
76 * In this state, the scheduler might be able to submit more jobs than
77 * previously, and so the caller should ensure kbasep_js_try_run_next_job_nolock()
78 * or similar is called sometime later.
79 * @return false indicates no change in ctx attributes state of the runpool.
80 */
81 bool kbasep_js_ctx_attr_runpool_release_ctx(struct kbase_device *kbdev, struct kbase_context *kctx);
82
83 /**
84 * Retain all attributes of an atom
85 *
86 * This occurs on adding an atom to a context
87 *
88 * Requires:
89 * - jsctx mutex
90 * - If the context is scheduled, then runpool_irq spinlock must also be held
91 */
92 void kbasep_js_ctx_attr_ctx_retain_atom(struct kbase_device *kbdev, struct kbase_context *kctx, struct kbase_jd_atom *katom);
93
94 /**
95 * Release all attributes of an atom, given its retained state.
96 *
97 * This occurs after (permanently) removing an atom from a context
98 *
99 * Requires:
100 * - jsctx mutex
101 * - If the context is scheduled, then runpool_irq spinlock must also be held
102 *
103 * This is a no-op when \a katom_retained_state is invalid.
104 *
105 * @return true indicates a change in ctx attributes state of the runpool.
106 * In this state, the scheduler might be able to submit more jobs than
107 * previously, and so the caller should ensure kbasep_js_try_run_next_job_nolock()
108 * or similar is called sometime later.
109 * @return false indicates no change in ctx attributes state of the runpool.
110 */
111 bool kbasep_js_ctx_attr_ctx_release_atom(struct kbase_device *kbdev, struct kbase_context *kctx, struct kbasep_js_atom_retained_state *katom_retained_state);
112
113 /**
114 * Requires:
115 * - runpool_irq spinlock
116 */
kbasep_js_ctx_attr_count_on_runpool(struct kbase_device * kbdev,enum kbasep_js_ctx_attr attribute)117 static inline s8 kbasep_js_ctx_attr_count_on_runpool(struct kbase_device *kbdev, enum kbasep_js_ctx_attr attribute)
118 {
119 struct kbasep_js_device_data *js_devdata;
120
121 KBASE_DEBUG_ASSERT(kbdev != NULL);
122 KBASE_DEBUG_ASSERT(attribute < KBASEP_JS_CTX_ATTR_COUNT);
123 js_devdata = &kbdev->js_data;
124
125 return js_devdata->runpool_irq.ctx_attr_ref_count[attribute];
126 }
127
128 /**
129 * Requires:
130 * - runpool_irq spinlock
131 */
kbasep_js_ctx_attr_is_attr_on_runpool(struct kbase_device * kbdev,enum kbasep_js_ctx_attr attribute)132 static inline bool kbasep_js_ctx_attr_is_attr_on_runpool(struct kbase_device *kbdev, enum kbasep_js_ctx_attr attribute)
133 {
134 /* In general, attributes are 'on' when they have a non-zero refcount (note: the refcount will never be < 0) */
135 return (bool) kbasep_js_ctx_attr_count_on_runpool(kbdev, attribute);
136 }
137
138 /**
139 * Requires:
140 * - jsctx mutex
141 */
kbasep_js_ctx_attr_is_attr_on_ctx(struct kbase_context * kctx,enum kbasep_js_ctx_attr attribute)142 static inline bool kbasep_js_ctx_attr_is_attr_on_ctx(struct kbase_context *kctx, enum kbasep_js_ctx_attr attribute)
143 {
144 struct kbasep_js_kctx_info *js_kctx_info;
145
146 KBASE_DEBUG_ASSERT(kctx != NULL);
147 KBASE_DEBUG_ASSERT(attribute < KBASEP_JS_CTX_ATTR_COUNT);
148 js_kctx_info = &kctx->jctx.sched_info;
149
150 /* In general, attributes are 'on' when they have a refcount (which should never be < 0) */
151 return (bool) (js_kctx_info->ctx.ctx_attr_ref_count[attribute]);
152 }
153
154 /** @} *//* end group kbase_js */
155 /** @} *//* end group base_kbase_api */
156 /** @} *//* end group base_api */
157
158 #endif /* _KBASE_JS_DEFS_H_ */
159