1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3 *
4 * (C) COPYRIGHT 2012-2015, 2018, 2020-2022 ARM Limited. All rights reserved.
5 *
6 * This program is free software and is provided to you under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation, and any use by you of this program is subject to the terms
9 * of such GNU license.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you can access it online at
18 * http://www.gnu.org/licenses/gpl-2.0.html.
19 *
20 */
21
22 /**
23 * DOC: Job Scheduler Context Attribute APIs
24 */
25
26 #ifndef _KBASE_JS_CTX_ATTR_H_
27 #define _KBASE_JS_CTX_ATTR_H_
28
29 /**
30 * kbasep_js_ctx_attr_runpool_retain_ctx - Retain all attributes of a context
31 *
32 * @kbdev: KBase device
33 * @kctx: KBase context
34 *
35 * This occurs on scheduling in the context on the runpool (but after
36 * is_scheduled is set)
37 *
38 * Requires:
39 * - jsctx mutex
40 * - runpool_irq spinlock
41 * - ctx->is_scheduled is true
42 */
43 void kbasep_js_ctx_attr_runpool_retain_ctx(struct kbase_device *kbdev, struct kbase_context *kctx);
44
45 /**
46 * kbasep_js_ctx_attr_runpool_release_ctx - Release all attributes of a context
47 *
48 * @kbdev: KBase device
49 * @kctx: KBase context
50 *
51 * This occurs on scheduling out the context from the runpool (but before
52 * is_scheduled is cleared)
53 *
54 * Requires:
55 * - jsctx mutex
56 * - runpool_irq spinlock
57 * - ctx->is_scheduled is true
58 *
59 * Return: true indicates a change in ctx attributes state of the runpool.
60 * In this state, the scheduler might be able to submit more jobs than
61 * previously, and so the caller should ensure kbasep_js_try_run_next_job_nolock()
62 * or similar is called sometime later.
63 * false indicates no change in ctx attributes state of the runpool.
64 */
65 bool kbasep_js_ctx_attr_runpool_release_ctx(struct kbase_device *kbdev, struct kbase_context *kctx);
66
67 /**
68 * kbasep_js_ctx_attr_ctx_retain_atom - Retain all attributes of an atom
69 *
70 * @kbdev: KBase device
71 * @kctx: KBase context
72 * @katom: Atom
73 *
74 * This occurs on adding an atom to a context
75 *
76 * Requires:
77 * - jsctx mutex
78 * - If the context is scheduled, then runpool_irq spinlock must also be held
79 */
80 void kbasep_js_ctx_attr_ctx_retain_atom(struct kbase_device *kbdev, struct kbase_context *kctx, struct kbase_jd_atom *katom);
81
82 /**
83 * kbasep_js_ctx_attr_ctx_release_atom - Release all attributes of an atom,
84 * given its retained state.
85 *
86 * @kbdev: KBase device
87 * @kctx: KBase context
88 * @katom_retained_state: Retained state
89 *
90 * This occurs after (permanently) removing an atom from a context
91 *
92 * Requires:
93 * - jsctx mutex
94 * - If the context is scheduled, then runpool_irq spinlock must also be held
95 *
96 * This is a no-op when \a katom_retained_state is invalid.
97 *
98 * Return: true indicates a change in ctx attributes state of the runpool.
99 * In this state, the scheduler might be able to submit more jobs than
100 * previously, and so the caller should ensure kbasep_js_try_run_next_job_nolock()
101 * or similar is called sometime later.
102 * false indicates no change in ctx attributes state of the runpool.
103 */
104 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);
105
106 /*
107 * Requires:
108 * - runpool_irq spinlock
109 */
kbasep_js_ctx_attr_count_on_runpool(struct kbase_device * kbdev,enum kbasep_js_ctx_attr attribute)110 static inline s8 kbasep_js_ctx_attr_count_on_runpool(struct kbase_device *kbdev, enum kbasep_js_ctx_attr attribute)
111 {
112 struct kbasep_js_device_data *js_devdata;
113
114 KBASE_DEBUG_ASSERT(kbdev != NULL);
115 KBASE_DEBUG_ASSERT(attribute < KBASEP_JS_CTX_ATTR_COUNT);
116 js_devdata = &kbdev->js_data;
117
118 return js_devdata->runpool_irq.ctx_attr_ref_count[attribute];
119 }
120
121 /*
122 * Requires:
123 * - runpool_irq spinlock
124 */
kbasep_js_ctx_attr_is_attr_on_runpool(struct kbase_device * kbdev,enum kbasep_js_ctx_attr attribute)125 static inline bool kbasep_js_ctx_attr_is_attr_on_runpool(struct kbase_device *kbdev, enum kbasep_js_ctx_attr attribute)
126 {
127 /* In general, attributes are 'on' when they have a non-zero refcount (note: the refcount will never be < 0) */
128 return (bool) kbasep_js_ctx_attr_count_on_runpool(kbdev, attribute);
129 }
130
131 /*
132 * Requires:
133 * - jsctx mutex
134 */
kbasep_js_ctx_attr_is_attr_on_ctx(struct kbase_context * kctx,enum kbasep_js_ctx_attr attribute)135 static inline bool kbasep_js_ctx_attr_is_attr_on_ctx(struct kbase_context *kctx, enum kbasep_js_ctx_attr attribute)
136 {
137 struct kbasep_js_kctx_info *js_kctx_info;
138
139 KBASE_DEBUG_ASSERT(kctx != NULL);
140 KBASE_DEBUG_ASSERT(attribute < KBASEP_JS_CTX_ATTR_COUNT);
141 js_kctx_info = &kctx->jctx.sched_info;
142
143 /* In general, attributes are 'on' when they have a refcount (which should never be < 0) */
144 return (bool) (js_kctx_info->ctx.ctx_attr_ref_count[attribute]);
145 }
146
147 #endif /* _KBASE_JS_DEFS_H_ */
148