22a0d96f9a720c38f1705e3f913e9a259e863c28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_tlstream.h
1 /*
2  *
3  * (C) COPYRIGHT 2015-2016 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 #if !defined(_KBASE_TLSTREAM_H)
19 #define _KBASE_TLSTREAM_H
20
21 #include <mali_kbase.h>
22
23 /*****************************************************************************/
24
25 /**
26  * kbase_tlstream_init - initialize timeline infrastructure in kernel
27  * Return: zero on success, negative number on error
28  */
29 int kbase_tlstream_init(void);
30
31 /**
32  * kbase_tlstream_term - terminate timeline infrastructure in kernel
33  *
34  * Timeline need have to been previously enabled with kbase_tlstream_init().
35  */
36 void kbase_tlstream_term(void);
37
38 /**
39  * kbase_tlstream_acquire - acquire timeline stream file descriptor
40  * @kctx: kernel common context
41  * @fd:   timeline stream file descriptor
42  *
43  * This descriptor is meant to be used by userspace timeline to gain access to
44  * kernel timeline stream. This stream is later broadcasted by user space to the
45  * timeline client.
46  * Only one entity can own the descriptor at any given time. Descriptor shall be
47  * closed if unused. If descriptor cannot be obtained (i.e. when it is already
48  * being used) argument fd will contain negative value.
49  *
50  * Return: zero on success (this does not necessarily mean that stream
51  *         descriptor could be returned), negative number on error
52  */
53 int kbase_tlstream_acquire(struct kbase_context *kctx, int *fd);
54
55 /**
56  * kbase_tlstream_flush_streams - flush timeline streams.
57  *
58  * Function will flush pending data in all timeline streams.
59  */
60 void kbase_tlstream_flush_streams(void);
61
62 /**
63  * kbase_tlstream_reset_body_streams - reset timeline body streams.
64  *
65  * Function will discard pending data in all timeline body streams.
66  */
67 void kbase_tlstream_reset_body_streams(void);
68
69 #if MALI_UNIT_TEST
70 /**
71  * kbase_tlstream_test - start timeline stream data generator
72  * @tpw_count: number of trace point writers in each context
73  * @msg_delay: time delay in milliseconds between trace points written by one
74  *             writer
75  * @msg_count: number of trace points written by one writer
76  * @aux_msg:   if non-zero aux messages will be included
77  *
78  * This test starts a requested number of asynchronous writers in both IRQ and
79  * thread context. Each writer will generate required number of test
80  * tracepoints (tracepoints with embedded information about writer that
81  * should be verified by user space reader). Tracepoints will be emitted in
82  * all timeline body streams. If aux_msg is non-zero writer will also
83  * generate not testable tracepoints (tracepoints without information about
84  * writer). These tracepoints are used to check correctness of remaining
85  * timeline message generating functions. Writer will wait requested time
86  * between generating another set of messages. This call blocks until all
87  * writers finish.
88  */
89 void kbase_tlstream_test(
90                 unsigned int tpw_count,
91                 unsigned int msg_delay,
92                 unsigned int msg_count,
93                 int          aux_msg);
94
95 /**
96  * kbase_tlstream_stats - read timeline stream statistics
97  * @bytes_collected: will hold number of bytes read by the user
98  * @bytes_generated: will hold number of bytes generated by trace points
99  */
100 void kbase_tlstream_stats(u32 *bytes_collected, u32 *bytes_generated);
101 #endif /* MALI_UNIT_TEST */
102
103 /*****************************************************************************/
104
105 void __kbase_tlstream_tl_summary_new_ctx(void *context, u32 nr, u32 tgid);
106 void __kbase_tlstream_tl_summary_new_gpu(void *gpu, u32 id, u32 core_count);
107 void __kbase_tlstream_tl_summary_new_lpu(void *lpu, u32 nr, u32 fn);
108 void __kbase_tlstream_tl_summary_lifelink_lpu_gpu(void *lpu, void *gpu);
109 void __kbase_tlstream_tl_summary_new_as(void *as, u32 nr);
110 void __kbase_tlstream_tl_summary_lifelink_as_gpu(void *as, void *gpu);
111 void __kbase_tlstream_tl_new_ctx(void *context, u32 nr, u32 tgid);
112 void __kbase_tlstream_tl_new_atom(void *atom, u32 nr);
113 void __kbase_tlstream_tl_del_ctx(void *context);
114 void __kbase_tlstream_tl_del_atom(void *atom);
115 void __kbase_tlstream_tl_ret_ctx_lpu(void *context, void *lpu);
116 void __kbase_tlstream_tl_ret_atom_ctx(void *atom, void *context);
117 void __kbase_tlstream_tl_ret_atom_lpu(
118                 void *atom, void *lpu, const char *attrib_match_list);
119 void __kbase_tlstream_tl_nret_ctx_lpu(void *context, void *lpu);
120 void __kbase_tlstream_tl_nret_atom_ctx(void *atom, void *context);
121 void __kbase_tlstream_tl_nret_atom_lpu(void *atom, void *lpu);
122 void __kbase_tlstream_tl_ret_as_ctx(void *as, void *ctx);
123 void __kbase_tlstream_tl_nret_as_ctx(void *as, void *ctx);
124 void __kbase_tlstream_tl_ret_atom_as(void *atom, void *as);
125 void __kbase_tlstream_tl_nret_atom_as(void *atom, void *as);
126 void __kbase_tlstream_tl_dep_atom_atom(void *atom1, void *atom2);
127 void __kbase_tlstream_tl_ndep_atom_atom(void *atom1, void *atom2);
128 void __kbase_tlstream_tl_rdep_atom_atom(void *atom1, void *atom2);
129 void __kbase_tlstream_tl_attrib_atom_config(
130                 void *atom, u64 jd, u64 affinity, u32 config);
131 void __kbase_tlstream_tl_attrib_as_config(
132                 void *as, u64 transtab, u64 memattr, u64 transcfg);
133 void __kbase_tlstream_jd_gpu_soft_reset(void *gpu);
134 void __kbase_tlstream_aux_pm_state(u32 core_type, u64 state);
135 void __kbase_tlstream_aux_issue_job_softstop(void *katom);
136 void __kbase_tlstream_aux_job_softstop(u32 js_id);
137 void __kbase_tlstream_aux_job_softstop_ex(struct kbase_jd_atom *katom);
138 void __kbase_tlstream_aux_pagefault(u32 ctx_nr, u64 page_count_change);
139 void __kbase_tlstream_aux_pagesalloc(u32 ctx_nr, u64 page_count);
140
141 extern atomic_t kbase_tlstream_enabled;
142
143 #define __TRACE_IF_ENABLED(trace_name, ...)                         \
144         do {                                                        \
145                 int enabled = atomic_read(&kbase_tlstream_enabled); \
146                 if (enabled)                                        \
147                         __kbase_tlstream_##trace_name(__VA_ARGS__); \
148         } while (0)
149
150 /*****************************************************************************/
151
152 /**
153  * kbase_tlstream_tl_summary_new_ctx - create context object in timeline
154  *                                     summary
155  * @context: name of the context object
156  * @nr:      context number
157  * @tgid:    thread Group Id
158  *
159  * Function emits a timeline message informing about context creation. Context
160  * is created with context number (its attribute), that can be used to link
161  * kbase context with userspace context.
162  * This message is directed to timeline summary stream.
163  */
164 #define kbase_tlstream_tl_summary_new_ctx(context, nr, tgid) \
165         __TRACE_IF_ENABLED(tl_summary_new_ctx, context, nr, tgid)
166
167 /**
168  * kbase_tlstream_tl_summary_new_gpu - create GPU object in timeline summary
169  * @gpu:        name of the GPU object
170  * @id:         id value of this GPU
171  * @core_count: number of cores this GPU hosts
172  *
173  * Function emits a timeline message informing about GPU creation. GPU is
174  * created with two attributes: id and core count.
175  * This message is directed to timeline summary stream.
176  */
177 #define kbase_tlstream_tl_summary_new_gpu(gpu, id, core_count) \
178         __TRACE_IF_ENABLED(tl_summary_new_gpu, gpu, id, core_count)
179
180 /**
181  * kbase_tlstream_tl_summary_new_lpu - create LPU object in timeline summary
182  * @lpu: name of the Logical Processing Unit object
183  * @nr:  sequential number assigned to this LPU
184  * @fn:  property describing this LPU's functional abilities
185  *
186  * Function emits a timeline message informing about LPU creation. LPU is
187  * created with two attributes: number linking this LPU with GPU's job slot
188  * and function bearing information about this LPU abilities.
189  * This message is directed to timeline summary stream.
190  */
191 #define kbase_tlstream_tl_summary_new_lpu(lpu, nr, fn) \
192         __TRACE_IF_ENABLED(tl_summary_new_lpu, lpu, nr, fn)
193
194 /**
195  * kbase_tlstream_tl_summary_lifelink_lpu_gpu - lifelink LPU object to GPU
196  * @lpu: name of the Logical Processing Unit object
197  * @gpu: name of the GPU object
198  *
199  * Function emits a timeline message informing that LPU object shall be deleted
200  * along with GPU object.
201  * This message is directed to timeline summary stream.
202  */
203 #define kbase_tlstream_tl_summary_lifelink_lpu_gpu(lpu, gpu) \
204         __TRACE_IF_ENABLED(tl_summary_lifelink_lpu_gpu, lpu, gpu)
205
206 /**
207  * kbase_tlstream_tl_summary_new_as - create address space object in timeline summary
208  * @as: name of the address space object
209  * @nr: sequential number assigned to this address space
210  *
211  * Function emits a timeline message informing about address space creation.
212  * Address space is created with one attribute: number identifying this
213  * address space.
214  * This message is directed to timeline summary stream.
215  */
216 #define kbase_tlstream_tl_summary_new_as(as, nr) \
217         __TRACE_IF_ENABLED(tl_summary_new_as, as, nr)
218
219 /**
220  * kbase_tlstream_tl_summary_lifelink_as_gpu - lifelink address space object to GPU
221  * @as:  name of the address space object
222  * @gpu: name of the GPU object
223  *
224  * Function emits a timeline message informing that address space object
225  * shall be deleted along with GPU object.
226  * This message is directed to timeline summary stream.
227  */
228 #define kbase_tlstream_tl_summary_lifelink_as_gpu(as, gpu) \
229         __TRACE_IF_ENABLED(tl_summary_lifelink_as_gpu, as, gpu)
230
231 /**
232  * kbase_tlstream_tl_new_ctx - create context object in timeline
233  * @context: name of the context object
234  * @nr:      context number
235  * @tgid:    thread Group Id
236  *
237  * Function emits a timeline message informing about context creation. Context
238  * is created with context number (its attribute), that can be used to link
239  * kbase context with userspace context.
240  */
241 #define kbase_tlstream_tl_new_ctx(context, nr, tgid) \
242         __TRACE_IF_ENABLED(tl_new_ctx, context, nr, tgid)
243
244 /**
245  * kbase_tlstream_tl_new_atom - create atom object in timeline
246  * @atom: name of the atom object
247  * @nr:   sequential number assigned to this atom
248  *
249  * Function emits a timeline message informing about atom creation. Atom is
250  * created with atom number (its attribute) that links it with actual work
251  * bucket id understood by hardware.
252  */
253 #define kbase_tlstream_tl_new_atom(atom, nr) \
254         __TRACE_IF_ENABLED(tl_new_atom, atom, nr)
255
256 /**
257  * kbase_tlstream_tl_del_ctx - destroy context object in timeline
258  * @context: name of the context object
259  *
260  * Function emits a timeline message informing that context object ceased to
261  * exist.
262  */
263 #define kbase_tlstream_tl_del_ctx(context) \
264         __TRACE_IF_ENABLED(tl_del_ctx, context)
265
266 /**
267  * kbase_tlstream_tl_del_atom - destroy atom object in timeline
268  * @atom: name of the atom object
269  *
270  * Function emits a timeline message informing that atom object ceased to
271  * exist.
272  */
273 #define kbase_tlstream_tl_del_atom(atom) \
274         __TRACE_IF_ENABLED(tl_del_atom, atom)
275
276 /**
277  * kbase_tlstream_tl_ret_ctx_lpu - retain context by LPU
278  * @context: name of the context object
279  * @lpu:     name of the Logical Processing Unit object
280  *
281  * Function emits a timeline message informing that context is being held
282  * by LPU and must not be deleted unless it is released.
283  */
284 #define kbase_tlstream_tl_ret_ctx_lpu(context, lpu) \
285         __TRACE_IF_ENABLED(tl_ret_ctx_lpu, context, lpu)
286
287 /**
288  * kbase_tlstream_tl_ret_atom_ctx - retain atom by context
289  * @atom:    name of the atom object
290  * @context: name of the context object
291  *
292  * Function emits a timeline message informing that atom object is being held
293  * by context and must not be deleted unless it is released.
294  */
295 #define kbase_tlstream_tl_ret_atom_ctx(atom, context) \
296         __TRACE_IF_ENABLED(tl_ret_atom_ctx, atom, context)
297
298 /**
299  * kbase_tlstream_tl_ret_atom_lpu - retain atom by LPU
300  * @atom:              name of the atom object
301  * @lpu:               name of the Logical Processing Unit object
302  * @attrib_match_list: list containing match operator attributes
303  *
304  * Function emits a timeline message informing that atom object is being held
305  * by LPU and must not be deleted unless it is released.
306  */
307 #define kbase_tlstream_tl_ret_atom_lpu(atom, lpu, attrib_match_list) \
308         __TRACE_IF_ENABLED(tl_ret_atom_lpu, atom, lpu, attrib_match_list)
309
310 /**
311  * kbase_tlstream_tl_nret_ctx_lpu - release context by LPU
312  * @context: name of the context object
313  * @lpu:     name of the Logical Processing Unit object
314  *
315  * Function emits a timeline message informing that context is being released
316  * by LPU object.
317  */
318 #define kbase_tlstream_tl_nret_ctx_lpu(context, lpu) \
319         __TRACE_IF_ENABLED(tl_nret_ctx_lpu, context, lpu)
320
321 /**
322  * kbase_tlstream_tl_nret_atom_ctx - release atom by context
323  * @atom:    name of the atom object
324  * @context: name of the context object
325  *
326  * Function emits a timeline message informing that atom object is being
327  * released by context.
328  */
329 #define kbase_tlstream_tl_nret_atom_ctx(atom, context) \
330         __TRACE_IF_ENABLED(tl_nret_atom_ctx, atom, context)
331
332 /**
333  * kbase_tlstream_tl_nret_atom_lpu - release atom by LPU
334  * @atom: name of the atom object
335  * @lpu:  name of the Logical Processing Unit object
336  *
337  * Function emits a timeline message informing that atom object is being
338  * released by LPU.
339  */
340 #define kbase_tlstream_tl_nret_atom_lpu(atom, lpu) \
341         __TRACE_IF_ENABLED(tl_nret_atom_lpu, atom, lpu)
342
343 /**
344  * kbase_tlstream_tl_ret_as_ctx - lifelink address space object to context
345  * @as:  name of the address space object
346  * @ctx: name of the context object
347  *
348  * Function emits a timeline message informing that address space object
349  * is being held by the context object.
350  */
351 #define kbase_tlstream_tl_ret_as_ctx(as, ctx) \
352         __TRACE_IF_ENABLED(tl_ret_as_ctx, as, ctx)
353
354 /**
355  * kbase_tlstream_tl_nret_as_ctx - release address space by context
356  * @as:  name of the address space object
357  * @ctx: name of the context object
358  *
359  * Function emits a timeline message informing that address space object
360  * is being released by atom.
361  */
362 #define kbase_tlstream_tl_nret_as_ctx(as, ctx) \
363         __TRACE_IF_ENABLED(tl_nret_as_ctx, as, ctx)
364
365 /**
366  * kbase_tlstream_tl_ret_atom_as - retain atom by address space
367  * @atom: name of the atom object
368  * @as:   name of the address space object
369  *
370  * Function emits a timeline message informing that atom object is being held
371  * by address space and must not be deleted unless it is released.
372  */
373 #define kbase_tlstream_tl_ret_atom_as(atom, as) \
374         __TRACE_IF_ENABLED(tl_ret_atom_as, atom, as)
375
376 /**
377  * kbase_tlstream_tl_nret_atom_as - release atom by address space
378  * @atom: name of the atom object
379  * @as:   name of the address space object
380  *
381  * Function emits a timeline message informing that atom object is being
382  * released by address space.
383  */
384 #define kbase_tlstream_tl_nret_atom_as(atom, as) \
385         __TRACE_IF_ENABLED(tl_nret_atom_as, atom, as)
386
387 /**
388  * kbase_tlstream_tl_dep_atom_atom - parent atom depends on child atom
389  * @atom1: name of the child atom object
390  * @atom2: name of the parent atom object that depends on child atom
391  *
392  * Function emits a timeline message informing that parent atom waits for
393  * child atom object to be completed before start its execution.
394  */
395 #define kbase_tlstream_tl_dep_atom_atom(atom1, atom2) \
396         __TRACE_IF_ENABLED(tl_dep_atom_atom, atom1, atom2)
397
398 /**
399  * kbase_tlstream_tl_ndep_atom_atom - dependency between atoms resolved
400  * @atom1: name of the child atom object
401  * @atom2: name of the parent atom object that depended on child atom
402  *
403  * Function emits a timeline message informing that parent atom execution
404  * dependency on child atom has been resolved.
405  */
406 #define kbase_tlstream_tl_ndep_atom_atom(atom1, atom2) \
407         __TRACE_IF_ENABLED(tl_ndep_atom_atom, atom1, atom2)
408
409 /**
410  * kbase_tlstream_tl_rdep_atom_atom - information about already resolved dependency between atoms
411  * @atom1: name of the child atom object
412  * @atom2: name of the parent atom object that depended on child atom
413  *
414  * Function emits a timeline message informing that parent atom execution
415  * dependency on child atom has been resolved.
416  */
417 #define kbase_tlstream_tl_rdep_atom_atom(atom1, atom2) \
418         __TRACE_IF_ENABLED(tl_rdep_atom_atom, atom1, atom2)
419
420 /**
421  * kbase_tlstream_tl_attrib_atom_config - atom job slot attributes
422  * @atom:     name of the atom object
423  * @jd:       job descriptor address
424  * @affinity: job affinity
425  * @config:   job config
426  *
427  * Function emits a timeline message containing atom attributes.
428  */
429 #define kbase_tlstream_tl_attrib_atom_config(atom, jd, affinity, config) \
430         __TRACE_IF_ENABLED(tl_attrib_atom_config, atom, jd, affinity, config)
431
432 /**
433  * kbase_tlstream_tl_attrib_as_config - address space attributes
434  * @as:       assigned address space
435  * @transtab: configuration of the TRANSTAB register
436  * @memattr:  configuration of the MEMATTR register
437  * @transcfg: configuration of the TRANSCFG register (or zero if not present)
438  *
439  * Function emits a timeline message containing address space attributes.
440  */
441 #define kbase_tlstream_tl_attrib_as_config(as, transtab, memattr, transcfg) \
442         __TRACE_IF_ENABLED(tl_attrib_as_config, as, transtab, memattr, transcfg)
443
444 /**
445  * kbase_tlstream_jd_gpu_soft_reset - The GPU is being soft reset
446  * @gpu:        name of the GPU object
447  *
448  * This imperative tracepoint is specific to job dumping.
449  * Function emits a timeline message indicating GPU soft reset.
450  */
451 #define kbase_tlstream_jd_gpu_soft_reset(gpu) \
452         __TRACE_IF_ENABLED(jd_gpu_soft_reset, gpu)
453
454 /**
455  * kbase_tlstream_aux_pm_state - timeline message: power management state
456  * @core_type: core type (shader, tiler, l2 cache, l3 cache)
457  * @state:     64bits bitmask reporting power state of the cores (1-ON, 0-OFF)
458  */
459 #define kbase_tlstream_aux_pm_state(core_type, state) \
460         __TRACE_IF_ENABLED(aux_pm_state, core_type, state)
461
462 /**
463  * kbase_tlstream_aux_issue_job_softstop - a soft-stop command is being issued
464  * @katom: the atom that is being soft-stopped
465  */
466 #define kbase_tlstream_aux_issue_job_softstop(katom) \
467         __TRACE_IF_ENABLED(aux_issue_job_softstop, katom)
468
469 /**
470  * kbase_tlstream_aux_job_softstop - soft job stop occurred
471  * @js_id: job slot id
472  */
473 #define kbase_tlstream_aux_job_softstop(js_id) \
474         __TRACE_IF_ENABLED(aux_job_softstop, js_id)
475
476 /**
477  * kbase_tlstream_aux_job_softstop_ex - extra info about soft-stopped atom
478  * @katom: the atom that has been soft-stopped
479  *
480  * This trace point adds more details about the soft-stopped atom. These details
481  * can't be safety collected inside the interrupt handler so we're doing it
482  * inside a worker.
483  *
484  * Note: this is not the same information that is recorded in the trace point,
485  * refer to __kbase_tlstream_aux_job_softstop_ex() for more details.
486  */
487 #define kbase_tlstream_aux_job_softstop_ex(katom) \
488         __TRACE_IF_ENABLED(aux_job_softstop_ex, katom)
489
490 /**
491  * kbase_tlstream_aux_pagefault - timeline message: MMU page fault event
492  *                                resulting in new pages being mapped
493  * @ctx_nr:            kernel context number
494  * @page_count_change: number of pages to be added
495  */
496 #define kbase_tlstream_aux_pagefault(ctx_nr, page_count_change) \
497         __TRACE_IF_ENABLED(aux_pagefault, ctx_nr, page_count_change)
498
499 /**
500  * kbase_tlstream_aux_pagesalloc - timeline message: total number of allocated
501  *                                 pages is changed
502  * @ctx_nr:     kernel context number
503  * @page_count: number of pages used by the context
504  */
505 #define kbase_tlstream_aux_pagesalloc(ctx_nr, page_count) \
506         __TRACE_IF_ENABLED(aux_pagesalloc, ctx_nr, page_count)
507
508 #endif /* _KBASE_TLSTREAM_H */
509